|
|
@@ -1,6 +1,7 @@
|
|
|
const app = require('../app')
|
|
|
const moment = require('moment-immutable')
|
|
|
const { editIcon, calculatedIcon, dollarIcon } = require('../assets')
|
|
|
+const _ = require('lodash')
|
|
|
|
|
|
app.component('appLaborEntryPage', {
|
|
|
template: html`
|
|
|
@@ -49,24 +50,26 @@ app.component('appLaborEntryPage', {
|
|
|
<thead md-head>
|
|
|
<tr md-row>
|
|
|
<th md-column>Staff Member</th>
|
|
|
- <th md-column ng-repeat="weekday in ctrl.weekdays">
|
|
|
- <span hide show-xs>{{weekday.min}}</span>
|
|
|
- <span hide show-sm>{{weekday.short}}</span>
|
|
|
- <span hide show-gt-sm>{{weekday.name}}</span>
|
|
|
+ <th md-column ng-repeat="weekday in ::ctrl.weekdays">
|
|
|
+ <span hide show-xs>{{::weekday.min}} {{::weekday.date.format('M/DD')}}</span>
|
|
|
+ <span hide show-sm>{{::weekday.short}} {{::weekday.date.format('M/DD')}}</span>
|
|
|
+ <span hide show-gt-sm>{{::weekday.name}}<br />{{::weekday.date.format('L')}}</span>
|
|
|
</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody md-body>
|
|
|
- <tr md-row ng-repeat="sfl in ctrl.staffMemberLabor track by sfl.id">
|
|
|
+ <tr md-row ng-repeat="sfl in ctrl.staffMemberLabor track by sfl.id" ng-init="$sflIndex = $index">
|
|
|
<td md-cell>
|
|
|
{{ctrl.staffMembers[sfl.id].name}}
|
|
|
</td>
|
|
|
- <td md-cell ng-repeat="day in sfl.days track by $index">
|
|
|
+ <td md-cell ng-repeat="day in sfl.days track by $index" ng-init="$dayIndex = $index">
|
|
|
<input
|
|
|
- class="hour-input md-button md-raised"
|
|
|
+ class="hour-input md-button "
|
|
|
tabindex="{{$index * ctrl.staffMemberLabor.length + ($parent.$index) + 1}}"
|
|
|
ng-model="day.hours"
|
|
|
- type="number" min="0" step="0.01">
|
|
|
+ type="number" min="0" step="0.01"
|
|
|
+ ng-keypress="ctrl.keypress($event)"
|
|
|
+ md-whiteframe="{{(day.hours == ctrl.saved[$sflIndex].days[$dayIndex].hours) ? 1 : 8}}">
|
|
|
</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
@@ -79,12 +82,12 @@ app.component('appLaborEntryPage', {
|
|
|
`,
|
|
|
controllerAs: 'ctrl',
|
|
|
controller: function(api, $routeParams, weekdays, $mdToast) {
|
|
|
- this.weekdays = weekdays
|
|
|
this.terminalKey = $routeParams.terminal
|
|
|
const week = moment($routeParams.week)
|
|
|
if (!week.isSame(week.startOf('week'))) throw new Error('Date is not start of week')
|
|
|
this.startDate = week
|
|
|
this.endDate = week.endOf('week')
|
|
|
+ this.weekdays = weekdays.map(d => Object.assign({}, d, {date: week.add(d.value, 'days')}))
|
|
|
api.staffMemberDictionary().then(staffMembers => {
|
|
|
this.staffMembers = staffMembers
|
|
|
})
|
|
|
@@ -96,10 +99,17 @@ app.component('appLaborEntryPage', {
|
|
|
id,
|
|
|
days: this.model.workdays.map(wd => wd.labor[i])
|
|
|
}))
|
|
|
+ this.saved = _.cloneDeep(this.staffMemberLabor)
|
|
|
+
|
|
|
})
|
|
|
}
|
|
|
load()
|
|
|
- this.submit = async () => {
|
|
|
+ let saveTimer = null
|
|
|
+ this.save = async (delay, then) => {
|
|
|
+ if (saveTimer) {
|
|
|
+ clearTimeout(saveTimer)
|
|
|
+ }
|
|
|
+
|
|
|
const model = {
|
|
|
workweek: this.model.workweek,
|
|
|
workdays: this.model.workdays.map(workday => ({
|
|
|
@@ -109,14 +119,36 @@ app.component('appLaborEntryPage', {
|
|
|
}))
|
|
|
}))
|
|
|
}
|
|
|
- try {
|
|
|
- await api.patch(`/api/labor/${$routeParams.terminal}/${$routeParams.week}`, model)
|
|
|
- $mdToast.showSimple('Labor saved.')
|
|
|
- load()
|
|
|
- } catch (err) {
|
|
|
- window.err = err
|
|
|
- console.error(err)
|
|
|
- $mdToast.showSimple(`Could not save Labor: ${err.message || err.statusText || err}`)
|
|
|
+ const saved = _.cloneDeep(this.staffMemberLabor)
|
|
|
+ saveTimer = setTimeout(async () => {
|
|
|
+ saveTimer = null
|
|
|
+ try {
|
|
|
+ await api.patch(`/api/labor/${$routeParams.terminal}/${$routeParams.week}`, model)
|
|
|
+ $mdToast.showSimple('Labor saved.')
|
|
|
+ this.saved = saved
|
|
|
+ if (then) {
|
|
|
+ then()
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ window.err = err
|
|
|
+ console.error(err)
|
|
|
+ $mdToast.showSimple(`Could not save Labor: ${err.message || err.statusText || err}`)
|
|
|
+ }
|
|
|
+ }, delay || 0)
|
|
|
+ }
|
|
|
+ this.submit = () => this.save(0, load)
|
|
|
+
|
|
|
+ this.keypress = async ($event) => {
|
|
|
+ if ($event.key === 'Enter') {
|
|
|
+
|
|
|
+ const tabIndex = +$event.srcElement.getAttribute('tabindex') + 1
|
|
|
+ const nextElement = document.querySelector(`[tabindex="${tabIndex}"]`)
|
|
|
+ if (nextElement) {
|
|
|
+ $event.returnValue = false
|
|
|
+ nextElement.focus()
|
|
|
+ nextElement.select && nextElement.select()
|
|
|
+ }
|
|
|
+ await this.save(2000)
|
|
|
}
|
|
|
}
|
|
|
}
|