import ngModule from '../module'; import './style.scss'; export default class Controller { constructor($scope, $state) { this.$ = $scope; this.$state = $state; this.selectedTicket = null; this.moreOptions = [ {callback: this.goToTurns, name: 'Turns', always: true}, ]; 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); // FIXME: History loop // let filter = {myTeam: true, from: today, to: tomorrow}; // $state.go('.', {q: JSON.stringify(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']; ngModule.component('vnTicketIndex', { template: require('./index.html'), controller: Controller });