Skip to content

Commit c75078b

Browse files
author
Ahmad Gneady
committed
hide prev/next year in print-preview of charts, and enforce bg colors in same.
for new assignment records, set resource duration same as project when a project is selected. in editable assignments DV of an existing record, add a 'Reset resource duration' button to do the same manually.
1 parent 3255b09 commit c75078b

File tree

3 files changed

+87
-12
lines changed

3 files changed

+87
-12
lines changed

app/hooks/chart-projects.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
</script>
7676

7777
<div class="page-header" style="position: absolute; left: 10vw; top: 3vh; width: 80vw;"><h1 class="text-center">
78-
<a class="btn btn-default btn-lg hspacer-lg" href="chart-projects.php?year=<?php echo $prevYear; ?>"><?php echo $prevYear; ?></a>
78+
<a class="btn btn-default btn-lg hspacer-lg hidden-print" href="chart-projects.php?year=<?php echo $prevYear; ?>"><?php echo $prevYear; ?></a>
7979
<?php echo $year; ?>
80-
<a class="btn btn-default btn-lg hspacer-lg" href="chart-projects.php?year=<?php echo $nextYear; ?>"><?php echo $nextYear; ?></a>
80+
<a class="btn btn-default btn-lg hspacer-lg hidden-print" href="chart-projects.php?year=<?php echo $nextYear; ?>"><?php echo $nextYear; ?></a>
8181

8282
<button type="button" class="btn btn-default pull-right toggle-today hidden-print" style="margin-top: 3vh;"><i class="glyphicon glyphicon-eye-open"></i> Today</button>
8383
</h1></div>
@@ -180,7 +180,8 @@ class="project"
180180
width: <?php echo intval(($chartEndTS - $chartStartTS + 86400) / 86400 * $chart['dayWidth']); ?>vw;
181181
left: <?php echo intval(($chartStartTS - strtotime("$year-01-01")) / 86400 * $chart['dayWidth'] + $chart['left']); ?>vw;
182182
height: <?php echo intval($chart['projectHeight']); ?>vh;
183-
background-color: <?php echo $projectColor[$id]; ?>;
183+
background-color: <?php echo $projectColor[$id]; ?> !important;
184+
print-color-adjust: exact;
184185
top: <?php
185186
echo (
186187
$chart['top'] +
@@ -194,9 +195,8 @@ class="project"
194195
color: #004 !important;
195196
font-weight: bold;
196197
opacity: 0.5;
197-
filter:alpha(opacity=50);
198-
white-space:nowrap;
199-
overflow:hidden;
198+
white-space: nowrap;
199+
overflow: hidden;
200200
"
201201
title="<?php echo htmlspecialchars($prj['Name']); ?> from <?php echo date('j/n/Y', strtotime($prj['StartDate'])); ?> to <?php echo date('j/n/Y', strtotime($prj['EndDate'])); ?>"
202202
onclick="window.location='../projects_view.php?SelectedID=<?php echo $id; ?>';">

app/hooks/chart-resources.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@
113113
</script>
114114

115115
<div class="page-header" style="position: absolute; left: 10vw; top: 3vh; width: 80vw;"><h1 class="text-center">
116-
<a class="btn btn-default btn-lg hspacer-lg" href="chart-resources.php?year=<?php echo $prevYear; ?>"><?php echo $prevYear; ?></a>
116+
<a class="btn btn-default btn-lg hspacer-lg hidden-print" href="chart-resources.php?year=<?php echo $prevYear; ?>"><?php echo $prevYear; ?></a>
117117
<?php echo $year; ?>
118-
<a class="btn btn-default btn-lg hspacer-lg" href="chart-resources.php?year=<?php echo $nextYear; ?>"><?php echo $nextYear; ?></a>
118+
<a class="btn btn-default btn-lg hspacer-lg hidden-print" href="chart-resources.php?year=<?php echo $nextYear; ?>"><?php echo $nextYear; ?></a>
119119

120120
<button type="button" class="btn btn-default pull-right toggle-today hidden-print" style="margin-top: 3vh;"><i class="glyphicon glyphicon-eye-open"></i> Today</button>
121121
</h1></div>
@@ -222,7 +222,8 @@ class="resource"
222222
width: <?php echo intval(($chartEndTS - $chartStartTS + 86400) / 86400 * $chart['dayWidth']); ?>vw;
223223
left: <?php echo intval(($chartStartTS - strtotime("$year-01-01")) / 86400 * $chart['dayWidth'] + $chart['left']); ?>vw;
224224
height: <?php echo intval($chart['resourceHeight'] * $assDetails['Commitment']); ?>vh;
225-
background-color: <?php echo $projectColor[$assDetails['ProjectId']]; ?>;
225+
background-color: <?php echo $projectColor[$assDetails['ProjectId']]; ?> !important;
226+
print-color-adjust: exact;
226227
top: <?php
227228
echo (
228229
$chart['top'] +
@@ -245,9 +246,8 @@ class="resource"
245246
color: #004 !important;
246247
font-weight: bold;
247248
opacity: 0.5;
248-
filter:alpha(opacity=50);
249-
white-space:nowrap;
250-
overflow:hidden;
249+
white-space: nowrap;
250+
overflow: hidden;
251251
"
252252
title="<?php echo htmlspecialchars($project[$assDetails['ProjectId']].': '.$resource[$assDetails['ResourceId']]); ?>. <?php echo ($assDetails['Commitment'] * 100); ?>% commitment from <?php echo date('j/n/Y', $assDetails['StartTS']); ?> to <?php echo date('j/n/Y', $assDetails['EndTS']); ?>"
253253
onclick="window.location='../assignments_view.php?SelectedID=<?php echo $assDetails['Id']; ?>';">

app/hooks/footer-extras.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<script>
2+
$j(() => {
3+
// only in assignments table
4+
if(AppGini.currentTableName() != 'assignments') return;
5+
6+
// if form not editable, no need to proceed
7+
if(!$j('#insert').length && !$j('#update').length) return;
8+
9+
// function to reset resource duration to the same as project duration
10+
const resetResourceDuration = () => {
11+
const df = AppGini.datetimeFormat(), // example: DD/MM/YYYY
12+
pos = {
13+
d: df.indexOf('DD'),
14+
m: df.indexOf('MM'),
15+
y: df.indexOf('YYYY'),
16+
},
17+
regex = new RegExp(
18+
df.replace('DD', '([0-3]?[0-9])')
19+
.replace('MM', '([01]?[0-9])')
20+
.replace('YYYY', '(\\d{4})'),
21+
'g'
22+
),
23+
pdt = $j('#ProjectDuration').text().trim(),
24+
matches = [ ...pdt.matchAll(regex) ];
25+
26+
if(!matches.length) {
27+
$j('#StartDate-dd, #StartDate-mm, #StartDate, #EndDate-dd, #EndDate-mm, #EndDate').val('');
28+
return;
29+
}
30+
31+
for(p in pos)
32+
if(pos[p] == 0)
33+
pos[p] = 1;
34+
else if(pos[p] > 4)
35+
pos[p] = 3;
36+
else
37+
pos[p] = 2;
38+
39+
$j('#StartDate-dd').val(parseInt(matches[0][pos.d]));
40+
$j('#StartDate-mm').val(parseInt(matches[0][pos.m]));
41+
$j('#StartDate').val(parseInt(matches[0][pos.y]));
42+
43+
$j('#EndDate-dd').val(parseInt(matches[1][pos.d]));
44+
$j('#EndDate-mm').val(parseInt(matches[1][pos.m]));
45+
$j('#EndDate').val(parseInt(matches[1][pos.y]));
46+
}
47+
48+
// for new records, set resource duration same as project when a project is selected
49+
if(!$j('input[name=SelectedID]').val().length) {
50+
// monitor ProjectDuration for text change
51+
// and update resource start and end dates accordingly
52+
let ProjectDuration = '';
53+
setInterval(() => {
54+
const pdt = $j('#ProjectDuration').text().trim();
55+
if(ProjectDuration == pdt) return;
56+
57+
ProjectDuration = pdt;
58+
resetResourceDuration();
59+
}, 50)
60+
61+
// for existing records, add a 'Reset resource duration button' to do the same manually
62+
} else {
63+
const btn = $j(`<button type="button" class="btn btn-default btn-lg vspacer-lg">
64+
<i class="glyphicon glyphicon-refresh"></i> Reset resource duration
65+
</button>`
66+
);
67+
btn.on('click', resetResourceDuration);
68+
69+
$j('<div class="row"><div class="col-lg-9 col-lg-offset-3" id="reset-resource-duration-wrapper"></div></div>')
70+
.insertAfter($j('#EndDate').parents('.form-group'));
71+
72+
btn.appendTo('#reset-resource-duration-wrapper');
73+
}
74+
})
75+
</script>

0 commit comments

Comments
 (0)