|
|
@@ -1,10 +1,48 @@
|
|
|
const app = require('../app')
|
|
|
+const moment = require('moment-immutable')
|
|
|
+const _ = require('lodash')
|
|
|
+const { previousWeekIcon, previousDayIcon, nextDayIcon, nextWeekIcon } = require('../assets')
|
|
|
|
|
|
app.component('appDashboardPage', {
|
|
|
template: html`
|
|
|
<app-user-area title-text="Dashboard">
|
|
|
|
|
|
- <div flex layout="row">
|
|
|
+ <div>
|
|
|
+ <md-button
|
|
|
+ class="md-fab"
|
|
|
+ ng-click="$ctrl.setOffset($ctrl.offset - 7)">
|
|
|
+ <md-icon md-svg-src="${previousWeekIcon}"></md-icon>
|
|
|
+ </md-button>
|
|
|
+ <md-button
|
|
|
+ class="md-fab"
|
|
|
+ ng-click="$ctrl.setOffset($ctrl.offset - 1)">
|
|
|
+ <md-icon md-svg-src="${previousDayIcon}"></md-icon>
|
|
|
+ </md-button>
|
|
|
+ <md-button
|
|
|
+ style="min-width: auto; width: 3em;"
|
|
|
+ class="md-raised md-mini"
|
|
|
+ ng-repeat="workday in $ctrl.workdays track by workday.formatted"
|
|
|
+ ng-class="{
|
|
|
+ 'md-primary': workday.date.valueOf() == $ctrl.date.valueOf()
|
|
|
+ }"
|
|
|
+ ng-disabled="!workday.hasData"
|
|
|
+ ng-click="$ctrl.setDate(workday.date)"
|
|
|
+ >
|
|
|
+ {{workday.short}}
|
|
|
+ </md-button>
|
|
|
+ <md-button
|
|
|
+ class="md-fab"
|
|
|
+ ng-click="$ctrl.setOffset($ctrl.offset + 1)">
|
|
|
+ <md-icon md-svg-src="${nextDayIcon}"></md-icon>
|
|
|
+ </md-button>
|
|
|
+ <md-button
|
|
|
+ class="md-fab"
|
|
|
+ ng-click="$ctrl.setOffset($ctrl.offset + 7)">
|
|
|
+ <md-icon md-svg-src="${nextWeekIcon}"></md-icon>
|
|
|
+ </md-button>
|
|
|
+ </div>
|
|
|
+ <h2>{{$ctrl.date.format('LL')}}</h2>
|
|
|
+ <div flex layout="row" ng-show="$ctrl.statistics">
|
|
|
<md-card flex ng-repeat="serviceCategory in $ctrl.statistics.serviceCategories">
|
|
|
<md-card-content>
|
|
|
<h2>{{::$ctrl.serviceCategories[serviceCategory.serviceCategory].name}}</h2>
|
|
|
@@ -38,7 +76,7 @@ app.component('appDashboardPage', {
|
|
|
<table md-table>
|
|
|
<thead>
|
|
|
<th align="left">
|
|
|
- <h3>{{::$ctrl.terminals[terminal.terminal].name}}</h3>
|
|
|
+ <h4>{{::$ctrl.terminals[terminal.terminal].name}}</h4>
|
|
|
</th>
|
|
|
<th align="right">
|
|
|
<span ng-if="$index == 0">Cost per Carton</span>
|
|
|
@@ -61,7 +99,7 @@ app.component('appDashboardPage', {
|
|
|
<table md-table>
|
|
|
<thead>
|
|
|
<th align="left">
|
|
|
- <h3>Overall</h3>
|
|
|
+ <h4>Overall</h4>
|
|
|
</th>
|
|
|
<th align="right"></th>
|
|
|
</thead>
|
|
|
@@ -80,7 +118,7 @@ app.component('appDashboardPage', {
|
|
|
</md-card-content>
|
|
|
</md-card>
|
|
|
</div>
|
|
|
- <div flex layout="column" layout-gt-sm="row">
|
|
|
+ <div flex layout="column" ng-show="$ctrl.charts" layout-gt-sm="row">
|
|
|
<md-card flex="50" class="mg-margin md-padding">
|
|
|
<md-card-title>
|
|
|
<md-card-title-text>
|
|
|
@@ -124,11 +162,13 @@ app.component('appDashboardPage', {
|
|
|
`,
|
|
|
controller: function(api, statistics, $scope) {
|
|
|
$scope.Math = Math
|
|
|
- api.statistics().then(stats => {
|
|
|
- this.statistics = stats
|
|
|
- this.charts = statistics.charts(stats.metricsOverTime)
|
|
|
- this.last = stats.last
|
|
|
- })
|
|
|
+ const load = (date) => {
|
|
|
+ api.statistics(date).then(stats => {
|
|
|
+ this.statistics = stats
|
|
|
+ this.charts = statistics.charts(stats.metricsOverTime)
|
|
|
+ this.last = stats.last
|
|
|
+ })
|
|
|
+ }
|
|
|
api.terminals().then(terminals => {
|
|
|
this.terminals = terminals
|
|
|
})
|
|
|
@@ -138,9 +178,48 @@ app.component('appDashboardPage', {
|
|
|
api.serviceCategories().then(serviceCategories => {
|
|
|
this.serviceCategories = serviceCategories
|
|
|
})
|
|
|
+ api.get(`/api/workdays`).then(workdays => {
|
|
|
+ const wds = {}
|
|
|
+ workdays.dates.forEach(x => (wds[x] = true))
|
|
|
+ const getWorkdays = (offset) => {
|
|
|
+ const dates = _.range(offset - 6, offset + 1)
|
|
|
+ .map(x => {
|
|
|
+ const date = moment().startOf('day').add(x, 'days')
|
|
|
+ return {
|
|
|
+ date,
|
|
|
+ formatted: date.format('L'),
|
|
|
+ short: date.format('M/DD'),
|
|
|
+ hasData: wds[date.format('YYYY-MM-DD')]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return dates
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setOffset = (offset) => {
|
|
|
+ this.offset = offset
|
|
|
+ this.workdays = getWorkdays(offset)
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setDate = (date) => {
|
|
|
+ this.date = date
|
|
|
+ this.now = moment()
|
|
|
+ load(date)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ this.setOffset(0)
|
|
|
+ this.setDate(moment(
|
|
|
+ workdays.dates
|
|
|
+ .map(x => moment(x).valueOf())
|
|
|
+ .sort()
|
|
|
+ .pop() || moment.now()
|
|
|
+ ))
|
|
|
+ })
|
|
|
|
|
|
// statistics.costPerCarton().then(statistics => {
|
|
|
// Object.assign(this, statistics)
|
|
|
// })
|
|
|
}
|
|
|
-})
|
|
|
+})
|
|
|
+
|
|
|
+window.moment = moment
|