1 /*******************************************************************************
2 * Copyright (c) 2017 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial API and implementation and/or initial documentation
11 *******************************************************************************/
12 import {Component, Input, OnChanges, SimpleChanges, OnDestroy} from "@angular/core";
13 import {IntermediateCatchEvent} from "../../../model/workflow/intermediate-catch-event";
14 import {TimerEventDefinitionType} from "../../../model/workflow/timer-event-definition";
15 import {TranslateService} from "@ngx-translate/core";
18 selector: 'wfm-intermediate-catch-event',
19 templateUrl: 'intermediate-catch-event.component.html',
21 export class IntermediateCatchEventComponent implements OnChanges, OnDestroy {
22 @Input() public node: IntermediateCatchEvent;
24 public checkedType: string;
25 public timeType = TimerEventDefinitionType;
26 public timeDate: string;
27 public timeDuration: any = {
37 private localeZh: any = {
39 dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
40 dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
41 monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
42 monthNamesShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
47 constructor(private translate: TranslateService) {
48 this.locale = translate.currentLang.indexOf('zh') > -1 ? this.localeZh : undefined;
51 public ngOnChanges(changes: SimpleChanges): void {
52 if (this.node && this.node.timerEventDefinition) {
53 this.checkedType = this.node.timerEventDefinition.type;
55 if (!this.checkedType) {
56 this.checkedType = this.timeType[this.timeType.timeDuration];
57 } else if (this.checkedType === this.timeType[this.timeType.timeCycle]) {
58 // 兼容老数据,把timeCycle转为timeDuration
59 this.checkedType = this.node.timerEventDefinition.type = this.timeType[this.timeType.timeDuration];
62 if (this.node.timerEventDefinition.timeDuration) {
63 this.transformStringToTimeDuration();
64 } else if (this.node.timerEventDefinition.timeCycle) {
65 // 兼容老数据,把timeCycle转为timeDuration
66 const timeCycleArray = this.node.timerEventDefinition.timeCycle.split('/');
67 this.node.timerEventDefinition.timeDuration = timeCycleArray.length > 1 ? timeCycleArray[1] : timeCycleArray[0];
68 this.node.timerEventDefinition.timeCycle = '';
69 this.transformStringToTimeDuration();
70 } else if (this.node.timerEventDefinition.timeDate) {
71 this.transformISOToDate();
75 public ngOnDestroy(): void {
76 if (this.checkedType === this.timeType[this.timeType.timeDuration]) {
77 this.transformTimeDurationToString();
79 this.timeDateChange();
83 private transformStringToTimeDuration(): void {
86 this.timeDuration.year = this.splitTimeDuration('P', 'Y');
87 this.timeDuration.month = this.splitTimeDuration('Y', 'M');
88 this.timeDuration.day = this.splitTimeDuration('M', 'D');
89 this.timeDuration.hour = this.splitTimeDuration('D', 'H');
90 this.timeDuration.minute = this.splitTimeDuration('H', 'M');
91 this.timeDuration.second = this.splitTimeDuration('M', 'S');
94 private splitTimeDuration(startKey: string, endKey: string): number {
95 const timeDuration = this.node.timerEventDefinition.timeDuration;
96 let start = timeDuration.indexOf(startKey);
97 let end = timeDuration.indexOf(endKey);
98 if (startKey === 'H' || endKey === 'S') {
99 start = timeDuration.lastIndexOf(startKey);
100 end = timeDuration.lastIndexOf(endKey);
102 const result = parseInt(timeDuration.substring(start + 1, end));
110 public timeTypeChange(type: string): void {
111 this.checkedType = type;
112 const timer = this.node.timerEventDefinition;
114 timer.timeCycle = '';
116 timer.timeDuration = '';
119 public transformTimeDurationToString(): void {
121 this.node.timerEventDefinition.timeDuration = 'P'
122 + this.timeDuration.year + 'Y'
123 + this.timeDuration.month + 'M'
124 + this.timeDuration.day + 'D'
125 + 'T' + this.timeDuration.hour + 'H'
126 + this.timeDuration.minute + 'M'
127 + this.timeDuration.second + 'S';
130 private transformISOToDate(): void {
131 this.timeDate = new Date(this.node.timerEventDefinition.timeDate).toString();
134 private pad(value: number): string {
135 let result = value.toString();
136 if (result.length === 1) {
137 result = '0' + result;
142 private transformDateToISO(date: Date): string {
143 return date.getFullYear() + '-' + this.pad(date.getMonth() + 1) + '-' + this.pad(date.getDate()) + 'T'
144 + this.pad(date.getHours()) + ':' + this.pad(date.getMinutes()) + ':' + this.pad(date.getSeconds());
147 public timeDateChange(): void {
148 // 2007-04-05T12:30-02:00
150 const date = new Date(this.timeDate);
151 this.node.timerEventDefinition.timeDate = this.transformDateToISO(date);
152 console.log(this.node.timerEventDefinition.timeDate);