import ngModule from '../module'; import './style.scss'; export default class Controller { constructor($scope, $state, $stateParams) { this.$ = $scope; this.$stateParams = $stateParams; this.$state = $state; this.selectedTicket = null; this.moreOptions = [ {callback: this.goToTurns, name: 'Turns', always: true}, ]; if (!$stateParams.q) { let today = new Date(); let offset = today.getTimezoneOffset() * 60000; today.setHours(0, 0, 0, 0); today.setTime(today.getTime() - offset); let tomorrow = new Date(today); tomorrow.setHours(23, 59, 59, 999); tomorrow.setTime(tomorrow.getTime() - offset); let sixDays = new Date(today); sixDays.setDate(today.getDate() + 6); sixDays.setHours(23, 59, 59, 999); sixDays.setTime(sixDays.getTime() - offset); this.filter = {mine: true, from: today, to: sixDays}; } } $postLink() { if (this.filter) this.onSearch(this.filter); } onSearch(params) { if (params) this.$.model.applyFilter(null, params); else this.$.model.clear(); } goToTurns() { this.$state.go('ticket.weekly'); } onMoreOpen() { let options = this.moreOptions.filter(o => o.always || this.isChecked); this.$.moreButton.data = options; } onMoreChange(callback) { callback.call(this); } compareDate(date) { let today = new Date(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); let comparation = today - timeTicket; if (comparation == 0) return 'warning'; if (comparation < 0) return 'success'; } stateColor(ticket) { if (ticket.alertLevelCode === 'OK') return 'alertOk'; else if (ticket.alertLevelCode === 'FREE') return 'alertFree'; else if (ticket.alertLevel === 1) return 'alert1'; else if (ticket.alertLevel === 0) return 'alert0'; } showDescriptor(event, clientFk) { event.preventDefault(); event.stopImmediatePropagation(); this.$.descriptor.clientFk = clientFk; this.$.descriptor.parent = event.target; this.$.descriptor.show(); } preview(event, ticket) { event.preventDefault(); event.stopImmediatePropagation(); this.selectedTicket = ticket; this.$.summary.show(); } } Controller.$inject = ['$scope', '$state', '$stateParams']; ngModule.component('vnTicketIndex', { template: require('./index.html'), controller: Controller });