Skip to content

Commit

Permalink
Merge pull request #239 from bcgov/stories/ss-770-add-button-to-creat…
Browse files Browse the repository at this point in the history
…e-assignment-duties-for-the-week

SS-770: On Manage Duties Screen - Add a button to create duties
  • Loading branch information
WadeBarnes authored Jun 24, 2024
2 parents a477cc7 + 6d623eb commit f1dd3a0
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions web/src/components/DutyRoster/components/DutyRosterHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
/>
</b-tabs>
</b-navbar-nav>
<b-navbar-nav >
<b-button
v-b-tooltip.hover.noninteractive
title="Populate Assignment Duties"
style="max-height: 40px;"
size="sm"
variant="white"
@click="populateAllAssignmentDutiesForTheCurrentDateRange()"
class="my-1 mr-3">
<b-icon icon="file-plus" font-scale="2.0" variant="white"/>
</b-button>
</b-navbar-nav>
<b-navbar-nav v-if="sheriffFullview">
<b-button
v-b-tooltip.hover.noninteractive
Expand Down Expand Up @@ -373,6 +385,9 @@
@dutyState.State
public sheriffFullview!: boolean;
@dutyState.State
public dutyRangeInfo!: dutyRangeInfoType;
@dutyState.Action
public UpdateDisplayFuelGauge!: (newDisplayFuelGauge: boolean) => void
Expand Down Expand Up @@ -460,6 +475,8 @@
assignmentErrorMsg = '';
assignmentErrorMsgDesc = '';
weekDayNames = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
mounted() {
this.runMethod.$on('addassign', this.addAssignment)
this.selectedDate = moment().format().substring(0,10);
Expand Down Expand Up @@ -765,6 +782,99 @@
})
}
public populateAllAssignmentDutiesForTheCurrentDateRange() {
// Get all assignment for the current location for the current date range
const assignmentsQueryString = `?locationId=${this.location.id}&start=${this.dutyRangeInfo.startDate}&end=${this.dutyRangeInfo.endDate}`;
const assignmentUrl = `api/assignment${assignmentsQueryString}`;
this.$http.get(assignmentUrl).then((response) => {
const assignments = response.data;
if (assignments) {
const dutyRosters: Array<{
startDate: string;
endDate: string;
locationId: number;
assignmentId: number;
timezone: string;
concurrencyToken: 0;
}> = [];
assignments.forEach((assignment) => {
const splitStartTime = assignment.start.split(":");
const splitEndTime = assignment.end.split(":");
if (this.activetab === 'Day') {
const startDate = moment(this.dutyRangeInfo.startDate)
.tz(this.location.timezone)
.hours(splitStartTime[0])
.minutes(splitStartTime[1])
.seconds(splitStartTime[2])
.format();
const endDate = moment(this.dutyRangeInfo.startDate)
.tz(this.location.timezone)
.hours(splitEndTime[0])
.minutes(splitEndTime[1])
.seconds(splitEndTime[1])
.format();
dutyRosters.push({
startDate: startDate,
endDate: endDate,
locationId: this.location.id,
assignmentId: assignment.id,
timezone: this.location.timezone,
concurrencyToken: 0
});
} else {
this.weekDayNames.forEach((day, index) => {
if (!assignment[day]) return;
const startDate = moment(this.dutyRangeInfo.startDate)
.tz(this.location.timezone)
.add(index, 'days')
.hours(splitStartTime[0])
.minutes(splitStartTime[1])
.seconds(splitStartTime[2])
.format();
const endDate = moment(this.dutyRangeInfo.startDate)
.tz(this.location.timezone)
.add(index, 'days')
.hours(splitEndTime[0])
.minutes(splitEndTime[1])
.seconds(splitEndTime[1])
.format();
dutyRosters.push({
startDate: startDate,
endDate: endDate,
locationId: this.location.id,
assignmentId: assignment.id,
timezone: this.location.timezone,
concurrencyToken: 0
});
});
}
});
const dutyRosterUrl = 'api/dutyroster';
// Construct duties for the date range
this.$http.post(dutyRosterUrl, dutyRosters).then((res) => {
this.$emit('change', this.activetab);
}, err => {
this.errorText = err.response.statusText+' '+err.response.status + ' - ' + moment().format();
if (err.response.status != '401') {
this.openErrorModal=true;
}
});
}
});
}
public tabChanged(tabInfo){
this.activetab = tabInfo;
this.loadNewDateRange();
Expand Down

0 comments on commit f1dd3a0

Please sign in to comment.