-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget-process.html
More file actions
214 lines (181 loc) · 5.55 KB
/
widget-process.html
File metadata and controls
214 lines (181 loc) · 5.55 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<link rel="import" href="../polymer/polymer.html">
<dom-module id="widget-process">
<template>
<style include="iron-flex ">
:host {
display: block;
}
:host([use-toast]) {
display: hidden;
}
paper-progress {
--paper-progress-active-color: var(--accent-color);
width: initial;
}
.error {
color: var(--paper-input-container-invalid-color, var(--error-color));
@apply --paper-input-error;
}
.success {
color: var(--success-color, var(--primary-color));
}
.message {
@apply --paper-font-caption;
}
</style>
<firebase-document path="/triggerStatus/[[path]]" data="{{status}}" exists="{{exists}}"></firebase-document>
<!-- <firebase-document path="/triggerError/[[path]]" data="{{error}}" exists="{{hasError}}"></firebase-document> -->
<template is="dom-if" if="[[!useToast]]">
<paper-progress value="[[lastPercent]]"></paper-progress>
<template is="dom-if" if="[[hasError]]">
<iron-icon icon="error" class="error"></iron-icon> <span class="message error"> [[lastMessage]] </span>
</template>
<template is="dom-if" if="[[exists]]">
<template is="dom-if" if="[[isEqual(status.status, 'success')]]">
<iron-icon icon="check-circle" class="success"></iron-icon> <span class="message success"> Success: [[lastMessage]] </span>
</template>
<template is="dom-if" if="[[isEqual(status.status, 'processing')]]">
<span class="message"> ... processing </span>
<span class="message">[[status.step]]</span>
</template>
</template>
</template>
</template>
<script>
(function() {
/**
* ## WidgetProcess
*
* `<widget-process>` show process handeld by function triggers
* a simple widget bound to process data - used to inform user
*
* @memberof Preignition
* @customElement
* @polymer
* @demo
**/
class WidgetProcess extends
Preignition.mixin.Template(
Polymer.Element) {
static get is() {
return 'widget-process';
}
static get properties() {
return {
/*
* `useToast` set true to hide visuals and use toast messages as notification
*/
useToast: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/*
* `lastMessage` persist message (in case we remove data at `process`)
*/
lastMessage: {
type: String
},
/*
* `status` of the active process (processing, success or error)
*/
status: {
type: Object
},
exists: {
type: Boolean
},
hasError: {
type: Boolean,
notify: true
},
/*
* `lastStatus` persist status
*/
lastStatus: {
type: String
},
/*
* `lastPercent` persist percent
*/
lastPercent: {
type: String
},
/*
* `path` the location of stored process (/processTrigger/{entityType}/{entityKey}/{verb}/{entityType2})
*/
path: {
type: String,
observer: '_observePath'
},
/*
* `completed` flag that turns true when completed.
* Completed is set to true when `exists` goes from true to false (e.g. the process was existing and is now removed = processed without error)
*/
completed: {
type: Boolean,
value: false,
notify: true,
},
/*
* `active` flag that turns true when active
*/
active: {
type: Boolean,
computed: '_computeActive(status.status, exists)',
reflectToAttribute: true,
notify: true,
}
};
}
static get observers() {
return [
'_reflectValue(status.percent, "lastPercent")',
'_reflectValue(status.message, "lastMessage")',
'_observeStatus(status.status)',
];
}
_reflectValue(value, name) {
if (value || value === 0) {
this.set(name, value);
}
if (name === 'lastMessage' && this.useToast && value) {
this.dispatchEvent(new CustomEvent(`toast-${this.status && this.status.status === 'error' ? 'error' : 'auto'}`, { detail: value, bubbles: true, composed: true }));
}
}
_observeStatus(status) {
if (status === 'success') {
this.debounce('widget-process-debounce', () => {
this.completed = true;
}, 100);
}
if (status === 'error') {
this.hasError = true;
}
}
// *** reset the completed whenever the path changes
_observePath(path, old) {
this.hasError = null;
this.completed = false;
this.lastPercent = 0;
this.lastMessage = '';
// Note(cg): we remove process status at db level.
if (old) {
firebase.database().ref(`/triggerStatus/${old}`).remove();
}
}
_computeActive(status, exists) {
return exists === true && status !== 'success';
}
}
customElements.define(WidgetProcess.is, WidgetProcess);
if (!window.Preignition) {
window.Preignition = {};
}
/*
* @namespace MultiChart
*/
window.Preignition.WidgetProcess = WidgetProcess;
})();
</script>
</dom-module>