-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathtodo-gadget.component.ts
executable file
·108 lines (86 loc) · 3.29 KB
/
todo-gadget.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {ChangeDetectorRef, Component} from '@angular/core';
import {RuntimeService} from '../../services/runtime.service';
import {GadgetInstanceService} from '../../grid/grid.service';
import {EndPointService} from '../../configuration/tab-endpoint/endpoint.service';
import {GadgetPropertyService} from '../_common/gadget-property.service';
import {GadgetBase} from '../_common/gadget-base';
import {TodoService} from './service';
import {OptionsService} from "../../configuration/tab-options/service"; // todo component
@Component({
selector: 'app-dynamic-component',
moduleId: module.id,
templateUrl: './view.html',
styleUrls: ['../_common/styles-gadget.css']
})
export class TodoGadgetComponent extends GadgetBase {
gadgetHasOperationControls = false;
// runtime document subscription
data: any;
todo: string;
todoList = ['todo 1'];
constructor(protected _todoService: TodoService,
protected _procMonRuntimeService: RuntimeService,
protected _gadgetInstanceService: GadgetInstanceService,
protected _propertyService: GadgetPropertyService,
protected _endPointService: EndPointService,
protected _changeDetectionRef: ChangeDetectorRef,
protected _optionsService: OptionsService) {
super(_procMonRuntimeService,
_gadgetInstanceService,
_propertyService,
_endPointService,
_changeDetectionRef,
_optionsService);
}
public preRun(): void {
this.run();
}
public run() {
this.data = [];
this.initializeRunState(true);
this.updateData(null);
}
public stop() {
this.setStopState(false);
}
public updateData(data: any[]) {
this._todoService.get().subscribe(_data => {
this.data = _data;
},
error => this.handleError(error));
}
public addTodo(todo: string) {
this.todoList.push(todo);
}
public removeTodo(todoIx: number) {
if (this.todoList.length) {
this.todoList.splice(todoIx, 1);
}
}
public updateProperties(updatedProperties: any) {
/**
* todo
* A similar operation exists on the procmman-config-service
* whenever the property page form is saved, the in memory board model
* is updated as well as the gadget instance properties
* which is what the code below does. This can be eliminated with code added to the
* config service or the property page service.
*
* **/
const updatedPropsObject = JSON.parse(updatedProperties);
this.propertyPages.forEach(function (propertyPage) {
for (let x = 0; x < propertyPage.properties.length; x++) {
for (const prop in updatedPropsObject) {
if (updatedPropsObject.hasOwnProperty(prop)) {
if (prop === propertyPage.properties[x].key) {
propertyPage.properties[x].value = updatedPropsObject[prop];
}
}
}
}
});
this.title = updatedPropsObject.title;
this.setEndPoint(updatedPropsObject.endpoint);
this.updateData(null);
}
}