Skip to content

Commit

Permalink
New timesheet back fill buton. (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeburg authored Nov 14, 2024
1 parent 54c57a4 commit e873090
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 9 deletions.
31 changes: 31 additions & 0 deletions app/components/person/timesheet-backfill.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{#if this.session.isAdmin}}
<UiButton @type="secondary" @size="sm" @onClick={{this.openDialog}}>
Back Fill Service Years
</UiButton>
{{/if}}

{{#if this.yearsForm}}
<ModalDialog @onEscape={{this.cancelDialog}} as |Modal|>
<ChForm @formFor={{this.yearsForm}} @formId="years" @onSubmit={{this.submitYears}} as |f|>
<Modal.title>Select Years To Back Fill</Modal.title>
<Modal.body>
<p>
For each selected year, a single Dirt timesheet entry will be created with an on-duty time of Jan 1st at
12:00:00 and an off-duty time of Jan 1st at 12:01:00. Any year that already has any timesheet entries,
regardless of position, will be skipped.
</p>
<FormRow>
<f.checkboxGroup @name="years" @label="Years" @options={{this.yearOptions}} />
</FormRow>
</Modal.body>
<Modal.footer @align="start">
<f.submit @label="Submit"/>
<UiCancelButton @onClick={{this.cancelDialog}} />
</Modal.footer>
</ChForm>
</ModalDialog>
{{/if}}

{{#if this.isSubmitting}}
<LoadingDialog/>
{{/if}}
106 changes: 106 additions & 0 deletions app/components/person/timesheet-backfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import Component from '@glimmer/component';
import {service} from '@ember/service';
import EmberObject, {action} from '@ember/object';
import {tracked} from '@glimmer/tracking';
import {DIRT} from "clubhouse/constants/positions";
import {STATUS_VERIFIED} from "clubhouse/models/timesheet";

export default class PersonTimesheetBackfillComponent extends Component {
@service ajax;
@service house;
@service modal;
@service session;
@service store;
@service toast;

@tracked isSubmitting = false;
@tracked yearsForm;
@tracked isAdmin;

constructor() {
super(...arguments);

this.yearOptions = [];
for (let i = 1996; i <= 2010; i++) {
this.yearOptions.push(i);
}
}

@action
openDialog() {
this.yearsForm = EmberObject.create({years: []});
}

@action
cancelDialog() {
this.yearsForm = null;
}

@action
async submitYears(model) {
if (!model.years.length) {
this.modal.info('No Years Selected', 'Select one or more years to back fill.');
return;
}

this.isSubmitting = true;
const {person} = this.args;
const exists = [];
const backFill = [];

for (let year of model.years) {
try {
const {timesheet} = await this.ajax.request('timesheet', {
data: {
person_id: person.id,
year
}
});
if (timesheet.length) {
exists.push(year);
} else {
backFill.push(year);
}
} catch (response) {
this.house.handleErrorResponse(response);
this.isSubmitting = false;
return;
}
}

if (!backFill.length) {
this.modal.info('Already back filled',
'The year(s) selected to back fill already have one or more timesheet entries to represent the year(s). No new entries have been created.');
this.isSubmitting = false;
return;
}

try {
for (let year of backFill) {
const entry = this.store.createRecord('timesheet', {
person_id: person.id,
position_id: DIRT,
on_duty: `${year}-01-01 12:00:00`,
off_duty: `${year}-01-01 12:01:00`,
review_status: STATUS_VERIFIED,
additional_admin_notes: `Back fill entry created to represent year ${year}`,
suppress_duration_warning: true,
});

await entry.save();
}

await person.reload(); // Pick up new timesheet entry years
let message = `<p>The following year(s) were back filled: ${backFill.join(',')}</p>`;
if (exists.length) {
message += `<p>The following year(s) were NOT back filled because timesheet entries already exists for the given year(s): ${exists.join(',')}</p>`;
}
this.modal.info('Year(s) Back Filled', message);
this.yearsForm = null;
} catch (response) {
this.house.handleErrorResponse(response);
} finally {
this.isSubmitting = false;
}
}
}
22 changes: 13 additions & 9 deletions app/templates/person/timesheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{#if this.missingRequestPendingCount}}
<UiAlert @icon="arrow-right" @type="warning">
{{pluralize this.missingRequestPendingCount "Missing Timesheet Entry Request"}} requires attention.
Jump to <a href="#missing-requests">Missing Timesheet Entry Requests</a>
Jump to <a href="#missing-requests">Missing Timesheet Entry Requests</a>
</UiAlert>
{{/if}}

Expand All @@ -30,14 +30,18 @@
{{this.person.callsign}} has not yet confirmed the {{this.year}} timesheet is correct.
</UiAlert>
{{/if}}
{{#if this.canForceConfirmation}}
<p>
As a Tech Ninja, you may {{if this.timesheetInfo.timesheet_confirmed "un-confirm" "confirm"}} the timesheet.
<UiButton @onClick={{this.confirmTimesheetAction}} @type="secondary" @size="sm">
{{if this.timesheetInfo.timesheet_confirmed "Un-Confirm" "Confirm"}} Timesheet
</UiButton>
</p>
{{/if}}
{{/if}}
{{#if this.session.isAdmin}}
<div class="d-flex justify-content-end mb-2">
<div>
<UiButtonRow>
<UiButton @onClick={{this.confirmTimesheetAction}} @type="secondary" @size="sm">
{{if this.timesheetInfo.timesheet_confirmed "Un-Confirm" "Confirm"}} Timesheet
</UiButton>
<Person::TimesheetBackfill @person={{this.person}} />
</UiButtonRow>
</div>
</div>
{{/if}}
{{#if (lt this.year 2008)}}
<p class="text-danger">
Expand Down

0 comments on commit e873090

Please sign in to comment.