| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const app = require('../app')
- const moment = require('moment-immutable')
- const { editIcon } = require('../assets')
- app.component('appServicesEntryPage', {
- template: html`
- <app-user-area title-text="{{ctrl.terminalKey}} Service Entry">
- <app-breadcrumb links="[
- { text: 'Home', link: '/dashboard' },
- { text: ctrl.terminalKey + ' Services', link: '/services/' + ctrl.terminalKey },
- { text: ctrl.startDate.format('L') + ' - ' + ctrl.endDate.format('L'), link: '/services/' + ctrl.terminalKey + '/' + ctrl.startDate.format('YYYY-MM-DD') }
- ]"></app-breadcrumb>
- <p>For week of {{::ctrl.startDate.format('LL')}} to {{::ctrl.endDate.format('LL')}}</p>
- <form name="form" ng-submit="ctrl.submit()">
- <table md-table md-progress="ctrl.promise">
- <colgroup>
- <col style="width: 15%" />
- <col ng-repeat="weekday in ::ctrl.weekdays" style="width: 12%" />
- </colgroup>
- <thead md-head>
- <tr md-row>
- <th md-column>Client</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>
- </tr>
- </thead>
- <tbody md-body>
- <tr md-row ng-repeat="sfl in ::ctrl.clientServices track by sfl.id">
- <td md-cell>
- {{::ctrl.clients[sfl.id].name}}
- </td>
- <td md-cell ng-repeat="day in ::sfl.days track by $index">
- <input class="hour-input md-button md-raised" ng-model="day.cartons" type="number" min="0" step="1">
- </td>
- </tr>
- </tbody>
- </table>
- <div>
- <md-button type="submit" class="md-raised md-primary">Submit</md-button>
- </div>
- </form>
- </app-user-area>
- `,
- 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')
- api.clientDictionary().then(clients => {
- this.clients = clients
- })
- this.promise = api.get(`/api/services/${$routeParams.terminal}/${$routeParams.week}`).then(({workdays}) => {
- this.model = workdays
- const clientIds = workdays[0].services.map(x => x.clientId)
- this.clientServices = clientIds.map((id, i) => ({
- id,
- days: this.model.map(wd => wd.services[i])
- }))
- })
- this.submit = async () => {
- const model = {
- workdays: this.model.map(workday => ({
- services: workday.services.map(service => ({
- clientId: service.clientId,
- cartons: service.cartons || null
- }))
- }))
- }
- try {
- await api.patch(`/api/services/${$routeParams.terminal}/${$routeParams.week}`, model)
- $mdToast.showSimple('Services saved.')
- } catch (err) {
- window.err = err
- console.error(err)
- $mdToast.showSimple(`Could not save Services: ${err.message || err.statusText || err}`)
- }
- }
- }
- })
|