2b0e6c6d6a177d648656f041b7c2380f71db54b2
[portal/sdk.git] /
1 import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 import {SemaphoreList} from '../../model/semaphore-list';
3 import {Semaphore} from '../../model/semaphore';
4 import {Format} from '../../model/format';
5
6 @Component({
7   selector: 'app-column-advanced-display',
8   templateUrl: './column-advanced-display.component.html',
9   styleUrls: ['./column-advanced-display.component.css']
10 })
11 export class ColumnAdvancedDisplayComponent implements OnInit {
12
13     @Input('semaphoreArr') semaphoreArr: SemaphoreList;
14     @Input('inputSemaphoreName') inputSemaphoreName: String;
15     @Input('addNew') addNew: boolean;
16     @Input('columnName') columnName: String;
17     @Output() completed = new EventEmitter<any>();
18     semaphoreObjArr: {}[];
19     semaphore: Semaphore;
20     outPutValues: {};
21     newSemaphore: {};
22     rangeColors = [
23         {index: 0, value: '#00FFFF', title: 'Aqua'},
24         {index: 1, value: '#000000', title: 'Black'},
25         {index: 2, value: '#0000FF', title: 'Blue'},
26         {index: 3, value: '#FF00FF', title: 'Fuchsia'},
27         {index: 4, value: '#808080', title: 'Gray'},
28         {index: 5, value: '#008000', title: 'Green'},
29         {index: 6, value: '#00FF00', title: 'Lime'},
30         {index: 7, value: '#800000', title: 'Maroon'},
31         {index: 8, value: '#000080', title: 'Navy'},
32         {index: 9, value: '#808000', title: 'Olive'},
33         {index: 10, value: '#FF9900', title: 'Orange'},
34         {index: 11, value: '#800080', title: 'Purple'},
35         {index: 12, value: '#FF0000', title: 'Red'},
36         {index: 13, value: '#C0C0C0', title: 'Silver'},
37         {index: 14, value: '#008080', title: 'Teal'},
38         {index: 15, value: '#FFFFFF', title: 'White'},
39         {index: 16, value: '#FFFF00', title: 'Yellow'},
40         {index: 17, value: '', title: 'Default'}
41     ];
42     fontFamily = [
43         {index: 0, value: 'Arial,Helvetica,sans-serif', title: 'Arial'},
44         {index: 1, value: 'Courier New,Courier,mono', title: 'Courier'},
45         {index: 2, value: 'Geneva,Arial,Helvetica,sans-serif', title: 'Geneva'},
46         {index: 3, value: 'Georgia,Times New Roman,Times,serif', title: 'Georgia'},
47         {index: 4, value: 'Times New Roman,Times,serif', title: 'Times'},
48         {index: 5, value: 'Verdana,Arial,Helvetica,sans-serif', title: 'Verdana'},
49         {index: 6, value: '', title: 'Default'}
50     ];
51
52   constructor() {
53       this.semaphoreObjArr = new Array();
54       this.outPutValues = new Object();
55       this.newSemaphore = new Object();
56   }
57   ngOnInit() {
58       if (this.addNew) {
59             this.addNewDisplay();
60       } else {
61           for (let semCtr = 0; semCtr < this.semaphoreArr.semaphore.length; semCtr++) {
62               if (this.inputSemaphoreName === this.semaphoreArr.semaphore[semCtr]['semaphoreName']) {
63                   this.semaphore = this.semaphoreArr.semaphore[semCtr];
64               }
65           }
66       }
67   }
68
69     saveDisplayData() {
70       this.outPutValues['semList'] = this.semaphoreArr;
71       this.outPutValues['semId'] = this.semaphore.semaphoreId;
72       this.outPutValues['setCloseDisplay'] = false;
73       this.outPutValues['semName'] = this.semaphore.semaphoreName;
74       this.completed.emit(this.outPutValues);
75     }
76
77     addNewFormat() {
78         let formatCnt = 0;
79         if ( this.semaphore.formatList.format.length > 0) {
80                formatCnt = this.semaphore.formatList.format.length + 1;
81           } else { formatCnt = 1; }
82       this.semaphore.formatList.format.push({
83           bgColor: '',
84           bold: false,
85           expression: '',
86           fontColor: '',
87           fontFace: '',
88           fontSize: '18',
89           italic: false,
90           lessThanValue: '',
91           underline: false,
92           formatId: this.semaphore.semaphoreId + '_fmt' + formatCnt
93       });
94     }
95
96     setStyle(format: Format) {
97         const style = {
98             'background-color': format.bgColor,
99             'color': format.fontColor,
100             'fontSize': format.fontSize + 'px',
101             'font-weight': format.bold ? 'bold' : 'normal',
102             'font-style': format.italic ? 'italic' : 'normal',
103             'font-family': format.fontFace
104         };
105         return style;
106     }
107
108     deleteFormat(format: Format) {
109         const index = this.semaphore.formatList.format.findIndex(d => d === format);
110         this.semaphore.formatList.format.splice(index, 1);
111     }
112
113     addNewDisplay() {
114       let semCount = 0;
115       if ( this.semaphoreArr !== null && this.semaphoreArr.semaphore.length > 0 ) {
116          semCount = this.semaphoreArr.semaphore.length + 1;
117       } else { semCount = 1 ; }
118       this.newSemaphore['comment'] = this.columnName;
119       this.newSemaphore['semaphoreType'] = 'CELL';
120       this.newSemaphore['semaphoreName'] = 'Display Formatting ' + semCount;
121       this.newSemaphore['semaphoreId'] = 'sem' + semCount;
122       this.newSemaphore['formatList'] = {
123            format: new Array({
124                bgColor: '',
125                bold: false,
126                expression: '',
127                fontColor: '',
128                fontFace: '',
129                fontSize: 18,
130                italic: false,
131                lessThanValue: '',
132                underline: false,
133                formatId: this.newSemaphore['semaphoreId'] + '_fmt1'
134            })
135       };
136       this.semaphoreArr.semaphore.push(<Semaphore>this.newSemaphore);
137         for (let semCtr = 0; semCtr < this.semaphoreArr.semaphore.length; semCtr++) {
138             if (this.semaphoreArr.semaphore[semCtr]['semaphoreId'] === this.newSemaphore['semaphoreId']) {
139                 this.semaphore = this.semaphoreArr.semaphore[semCtr];
140             }
141         }
142     }
143
144
145
146 }