Skip to content

Commit 71526ff

Browse files
committed
Gantt aggiornato
1 parent 8e76aa0 commit 71526ff

File tree

2 files changed

+47
-51
lines changed

2 files changed

+47
-51
lines changed

src/main/java/eu/rationence/pat/repository/ProjectActivityRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import eu.rationence.pat.model.ProjectActivity;
44
import eu.rationence.pat.model.composite_keys.ProjectActivityCompositeKey;
5+
import org.springframework.data.jpa.repository.Query;
56
import org.springframework.data.repository.CrudRepository;
67
import org.springframework.stereotype.Repository;
78

@@ -12,6 +13,7 @@
1213
public interface ProjectActivityRepository extends CrudRepository<ProjectActivity, ProjectActivityCompositeKey> {
1314
ProjectActivity getActivityByActivityKeyAndProject(String activityKey, String projectKey);
1415

16+
@Query(value = "SELECT * FROM PAT_Activities WHERE c_Project = ?1 ORDER BY d_Start ASC", nativeQuery = true)
1517
List<ProjectActivity> findActivitiesByProject(String projectKey);
1618

1719
<S extends ProjectActivity> S save(S projectActivity);

src/main/resources/templates/activities.html

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,27 @@
122122

123123
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
124124
<script type="text/javascript">
125-
google.charts.load('current', {'packages':['gantt']});
125+
google.charts.load("current", {packages:["timeline"]});
126126
google.charts.setOnLoadCallback(drawChart);
127-
128127
function drawChart() {
129128
if(project_end == null){
130-
let projectGantt = document.getElementById('projectGantt');
129+
let projectGantt = document.getElementById('ganttContainer');
131130
projectGantt.classList.add('hidden');
132131
return;
133132
}
134-
let data = new google.visualization.DataTable();
135-
data.addColumn('string', 'Task ID');
136-
data.addColumn('string', 'Task Name');
137-
data.addColumn('string', 'Resource');
138-
data.addColumn('date', 'Start Date');
139-
data.addColumn('date', 'End Date');
140-
data.addColumn('number', 'Duration');
141-
data.addColumn('number', 'Percent Complete');
142-
data.addColumn('string', 'Dependencies');
143-
data.addColumn('string', 'tooltip');
133+
var container = document.getElementById('ganttChart');
134+
var chart = new google.visualization.Timeline(container);
135+
var data = new google.visualization.DataTable();
136+
data.addColumn({ type: 'string', id: 'Term' });
137+
data.addColumn({ type: 'string', id: 'Name' });
138+
data.addColumn({ type: 'date', id: 'Start' });
139+
data.addColumn({ type: 'date', id: 'End' });
144140

145141
data.addRows([
146-
[project_name, project_name, project_name,
147-
new Date(project_start), new Date(project_end), project_value, 100, null, "Project: "+project_name],
142+
[project_name, project_name,
143+
new Date(project_start), new Date(project_end)],
148144
]);
145+
let colorArray = ["#386671",];
149146

150147
for(let i=0; i<activity_num; i++) {
151148
let activityKey = document.getElementById("activityKey"+i).value;
@@ -155,49 +152,46 @@
155152
let activityDays = document.getElementById("manDays"+i).value * 8;
156153
let activityTotHoursCompiled = document.getElementById("TotHoursCompiled"+activityKey).value;
157154
let activityPercentage = Math.round(100 * (activityTotHoursCompiled / activityDays));
155+
let colorActivityBar = "#59a5b7"
156+
if(activityPercentage > 100)
157+
colorActivityBar = "#9b2222"
158+
else if(activityPercentage === 100)
159+
colorActivityBar = "#32c574"
160+
else if(activityPercentage === 0)
161+
colorActivityBar = "#8AB4B1"
162+
colorArray.push(colorActivityBar)
158163
if(activityDateEnd === "")
159164
activityDateEnd = project_end;
160165
data.addRows([
161-
[activityKey, activityKey, "activity",
162-
new Date(activityDateStart), new Date(activityDateEnd), activityDays, activityPercentage, null, "Compiled Days: " + activityTotHoursCompiled],
166+
[activityKey, "" + Math.round(activityTotHoursCompiled/8) + "/" + activityDays/8 + "gg (" + activityPercentage + "%)",
167+
new Date(activityDateStart), new Date(activityDateEnd)],
163168
]);
164169
}
165-
let options = {
166-
tooltip: {isHtml: true},
167-
gantt: {
168-
criticalPathEnabled: false,
169-
labelStyle: {
170-
fontFamily: "Arial",
171-
fontWeight: "bold",
172-
fontSize: 14,
173-
color: '#f30606'
170+
console.log(colorArray);
171+
var options = {
172+
rowLabelStyle: {
173+
fontSize: 10,
174+
},
175+
backgroundColor: "#f1f7f8",
176+
colors: colorArray,
177+
height: (1+activity_num)*50,
178+
timeline: { showRowLabels: true,
179+
barLabelStyle: {
180+
fontSize: 10
174181
},
175-
trackHeight: 20,
176-
barHeight: 15,
177-
palette: [
178-
{
179-
"color": "#386671",
180-
"dark": "#25454d",
181-
"light": "#73b3c2"
182-
},
183-
{
184-
"color": "#5caabd",
185-
"dark": "#417988",
186-
"light": "#9ee3f6"
187-
},
188-
],
189-
}
182+
},
183+
190184
};
191-
let chart = new google.visualization.Gantt(document.getElementById('chart_div'));
185+
192186
chart.draw(data, options);
193187
}
194-
195188
window.addEventListener('resize', function(event) {
196189
drawChart();
197190
}, true);
198191
</script>
199192

200193

194+
201195
<section class="">
202196
<div class="container mt-6">
203197
<div class="columns">
@@ -366,42 +360,42 @@
366360
<span class="icon has-text-primary is-pulled-right mr-1"
367361
data-tooltip="Order">
368362
<i class="fas fa-sort fa-lg table-button is-clickable"
369-
th:onclick="'sortTable(\'activityKey\',columnList);'"></i>
363+
th:onclick="'sortTable(\'activityKey\',columnList), drawChart();'"></i>
370364
</span>
371365
</th>
372366
<th class="activityTypeCol has-text-primary-dark table-header pl-2">Type
373367
<span class="icon has-text-primary is-pulled-right mr-1"
374368
data-tooltip="Order">
375369
<i class="fas fa-sort fa-lg table-button is-clickable"
376-
th:onclick="'sortTable(\'activityType\',columnList);'"></i>
370+
th:onclick="'sortTable(\'activityType\',columnList), drawChart();'"></i>
377371
</span>
378372
</th>
379373
<th class="dateCol has-text-primary-dark table-header pl-2">Start Date
380374
<span class="icon has-text-primary is-pulled-right mr-1"
381375
data-tooltip="Order">
382376
<i class="fas fa-sort fa-lg table-button is-clickable"
383-
th:onclick="'sortTable(\'dateStart\',columnList);'"></i>
377+
th:onclick="'sortTable(\'dateStart\',columnList), drawChart();'"></i>
384378
</span>
385379
</th>
386380
<th class="dateCol has-text-primary-dark table-header pl-2">End Date
387381
<span class="icon has-text-primary is-pulled-right mr-1"
388382
data-tooltip="Order">
389383
<i class="fas fa-sort fa-lg table-button is-clickable"
390-
th:onclick="'sortTable(\'dateEnd\',columnList);'"></i>
384+
th:onclick="'sortTable(\'dateEnd\',columnList), drawChart();'"></i>
391385
</span>
392386
</th>
393387
<th class="chargedCol has-text-primary-dark table-header pl-2">Charged
394388
<span class="icon has-text-primary is-pulled-right mr-1"
395389
data-tooltip="Order">
396390
<i class="fas fa-sort fa-lg table-button is-clickable"
397-
th:onclick="'sortTable(\'charged\',columnList);'"></i>
391+
th:onclick="'sortTable(\'charged\',columnList), drawChart();'"></i>
398392
</span>
399393
</th>
400394
<th class="manDaysCol has-text-primary-dark table-header pl-2">Days
401395
<span class="icon has-text-primary is-pulled-right mr-1"
402396
data-tooltip="Order">
403397
<i class="fas fa-sort fa-lg table-button is-clickable"
404-
th:onclick="'sortTable(\'manDays\',columnList);'"></i>
398+
th:onclick="'sortTable(\'manDays\',columnList), drawChart();'"></i>
405399
</span>
406400
</th>
407401
<th></th>
@@ -520,11 +514,11 @@
520514
</div>
521515
</div>
522516
</div>
523-
<div id="projectGantt" style="font-weight: bold;">
517+
<div id="ganttContainer" class="mt-2" style="font-weight: bold;">
524518
<p class="subtitle has-text-weight-bold has-text-centered has-text-primary-dark has-text-weight-semibold m-auto mt-5 mb-3">Project summary</p>
525519
<div class="columns is-centered">
526520
<div class="column">
527-
<div id="chart_div"></div>
521+
<div id="ganttChart" class="mt-3"></div>
528522
</div>
529523
</div>
530524
</div>

0 commit comments

Comments
 (0)