@@ -21,8 +21,11 @@ import { Snackbar } from '@material/mwc-snackbar';
21
21
22
22
import './filtered-list.js' ;
23
23
import {
24
+ CommitDetail ,
24
25
CommitEntry ,
25
26
ifImplemented ,
27
+ InfoDetail ,
28
+ InfoEntry ,
26
29
invert ,
27
30
IssueDetail ,
28
31
IssueEvent ,
@@ -40,7 +43,6 @@ const icons = {
40
43
info : 'info' ,
41
44
warning : 'warning' ,
42
45
error : 'report' ,
43
- action : 'history' ,
44
46
} ;
45
47
46
48
function getPluginName ( src : string ) : string {
@@ -66,13 +68,18 @@ function getPluginName(src: string): string {
66
68
* Renders the `history` to `logUI` and the latest `'error'` [[`LogEntry`]] to
67
69
* `messageUI`.
68
70
*/
69
- export type LoggingElement = Mixin < typeof Logging > ;
71
+ export type HistoringElement = Mixin < typeof Historing > ;
70
72
71
- export function Logging < TBase extends LitElementConstructor > ( Base : TBase ) {
72
- class LoggingElement extends Base {
73
+ export function Historing < TBase extends LitElementConstructor > ( Base : TBase ) {
74
+ class HistoringElement extends Base {
73
75
/** All [[`LogEntry`]]s received so far through [[`LogEvent`]]s. */
74
76
@property ( { type : Array } )
75
- history : LogEntry [ ] = [ ] ;
77
+ log : InfoEntry [ ] = [ ] ;
78
+
79
+ /** All [[`CommitEntry`]]s received so far through [[`LogEvent`]]s */
80
+ @property ( { type : Array } )
81
+ history : CommitEntry [ ] = [ ] ;
82
+
76
83
/** Index of the last [[`EditorAction`]] applied. */
77
84
@property ( { type : Number } )
78
85
editCount = - 1 ;
@@ -82,6 +89,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
82
89
latestIssue ! : IssueDetail ;
83
90
84
91
@query ( '#log' ) logUI ! : Dialog ;
92
+ @query ( '#history' ) historyUI ! : Dialog ;
85
93
@query ( '#diagnostic' ) diagnosticUI ! : Dialog ;
86
94
@query ( '#error' ) errorUI ! : Snackbar ;
87
95
@query ( '#warning' ) warningUI ! : Snackbar ;
@@ -140,16 +148,10 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
140
148
return true ;
141
149
}
142
150
143
- private onLog ( le : LogEvent ) : void {
144
- if ( le . detail . kind === 'reset' ) {
145
- this . history = [ ] ;
146
- this . editCount = - 1 ;
147
- return ;
148
- }
149
-
150
- const entry : LogEntry = {
151
+ private onHistory ( detail : CommitDetail ) {
152
+ const entry : CommitEntry = {
151
153
time : new Date ( ) ,
152
- ...le . detail ,
154
+ ...detail ,
153
155
} ;
154
156
155
157
if ( entry . kind === 'action' ) {
@@ -160,22 +162,51 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
160
162
}
161
163
162
164
this . history . push ( entry ) ;
165
+ this . requestUpdate ( 'history' , [ ] ) ;
166
+ }
167
+
168
+ private onReset ( ) {
169
+ this . log = [ ] ;
170
+ this . history = [ ] ;
171
+ this . editCount = - 1 ;
172
+ }
173
+
174
+ private onInfo ( detail : InfoDetail ) {
175
+ const entry : InfoEntry = {
176
+ time : new Date ( ) ,
177
+ ...detail ,
178
+ } ;
179
+
180
+ this . log . push ( entry ) ;
163
181
if ( ! this . logUI . open ) {
164
182
const ui = {
165
183
error : this . errorUI ,
166
184
warning : this . warningUI ,
167
185
info : this . infoUI ,
168
- action : this . infoUI ,
169
- } [ le . detail . kind ] ;
186
+ } [ detail . kind ] ;
170
187
171
188
ui . close ( ) ;
172
189
ui . show ( ) ;
173
190
}
174
- if ( le . detail . kind == 'error' ) {
191
+ if ( detail . kind == 'error' ) {
175
192
this . errorUI . close ( ) ; // hack to reset timeout
176
193
this . errorUI . show ( ) ;
177
194
}
178
- this . requestUpdate ( 'history' , [ ] ) ;
195
+ this . requestUpdate ( 'log' , [ ] ) ;
196
+ }
197
+
198
+ private onLog ( le : LogEvent ) : void {
199
+ switch ( le . detail . kind ) {
200
+ case 'reset' :
201
+ this . onReset ( ) ;
202
+ break ;
203
+ case 'action' :
204
+ this . onHistory ( le . detail ) ;
205
+ break ;
206
+ default :
207
+ this . onInfo ( le . detail ) ;
208
+ break ;
209
+ }
179
210
}
180
211
181
212
async performUpdate ( ) {
@@ -197,7 +228,36 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
197
228
}
198
229
199
230
renderLogEntry (
200
- entry : LogEntry ,
231
+ entry : InfoEntry ,
232
+ index : number ,
233
+ log : LogEntry [ ]
234
+ ) : TemplateResult {
235
+ return html ` < abbr title ="${ entry . title } ">
236
+ < mwc-list-item
237
+ class ="${ entry . kind } "
238
+ graphic ="icon "
239
+ ?twoline =${ ! ! entry . message }
240
+ ?activated =${ this . editCount == log . length - index - 1 }
241
+ >
242
+ < span >
243
+ <!-- FIXME: replace tt with mwc-chip asap -->
244
+ < tt > ${ entry . time ?. toLocaleString ( ) } </ tt >
245
+ ${ entry . title } </ span
246
+ >
247
+ < span slot ="secondary "> ${ entry . message } </ span >
248
+ < mwc-icon
249
+ slot ="graphic "
250
+ style ="--mdc-theme-text-icon-on-background:var(${ ifDefined (
251
+ iconColors [ entry . kind ]
252
+ ) } ) "
253
+ > ${ icons [ entry . kind ] } </ mwc-icon
254
+ >
255
+ </ mwc-list-item > </ abbr
256
+ > ` ;
257
+ }
258
+
259
+ renderHistoryEntry (
260
+ entry : CommitEntry ,
201
261
index : number ,
202
262
history : LogEntry [ ]
203
263
) : TemplateResult {
@@ -219,18 +279,31 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
219
279
style ="--mdc-theme-text-icon-on-background:var(${ ifDefined (
220
280
iconColors [ entry . kind ]
221
281
) } ) "
222
- > ${ icons [ entry . kind ] } </ mwc-icon
282
+ > history </ mwc-icon
223
283
>
224
284
</ mwc-list-item > </ abbr
225
285
> ` ;
226
286
}
227
287
288
+ private renderLog ( ) : TemplateResult [ ] | TemplateResult {
289
+ if ( this . log . length > 0 )
290
+ return this . log . slice ( ) . reverse ( ) . map ( this . renderLogEntry , this ) ;
291
+ else
292
+ return html `< mwc-list-item disabled graphic ="icon ">
293
+ < span > ${ translate ( 'log.placeholder' ) } </ span >
294
+ < mwc-icon slot ="graphic "> info</ mwc-icon >
295
+ </ mwc-list-item > ` ;
296
+ }
297
+
228
298
private renderHistory ( ) : TemplateResult [ ] | TemplateResult {
229
299
if ( this . history . length > 0 )
230
- return this . history . slice ( ) . reverse ( ) . map ( this . renderLogEntry , this ) ;
300
+ return this . history
301
+ . slice ( )
302
+ . reverse ( )
303
+ . map ( this . renderHistoryEntry , this ) ;
231
304
else
232
305
return html `< mwc-list-item disabled graphic ="icon ">
233
- < span > ${ translate ( 'log .placeholder' ) } </ span >
306
+ < span > ${ translate ( 'history .placeholder' ) } </ span >
234
307
< mwc-icon slot ="graphic "> info</ mwc-icon >
235
308
</ mwc-list-item > ` ;
236
309
}
@@ -281,6 +354,42 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
281
354
) ;
282
355
}
283
356
357
+ private renderLogDialog ( ) : TemplateResult {
358
+ return html ` < mwc-dialog id ="log " heading ="${ translate ( 'log.name' ) } ">
359
+ ${ this . renderFilterButtons ( ) }
360
+ < mwc-list id ="content " wrapFocus > ${ this . renderLog ( ) } </ mwc-list >
361
+ < mwc-button slot ="primaryAction " dialogaction ="close "
362
+ > ${ translate ( 'close' ) } </ mwc-button
363
+ >
364
+ </ mwc-dialog > ` ;
365
+ }
366
+
367
+ private renderHistoryDialog ( ) : TemplateResult {
368
+ return html ` < mwc-dialog
369
+ id ="history "
370
+ heading ="${ translate ( 'history.name' ) } "
371
+ >
372
+ < mwc-list id ="content " wrapFocus > ${ this . renderHistory ( ) } </ mwc-list >
373
+ < mwc-button
374
+ icon ="undo "
375
+ label ="${ translate ( 'undo' ) } "
376
+ ?disabled =${ ! this . canUndo }
377
+ @click =${ this . undo }
378
+ slot="secondaryAction"
379
+ > </ mwc-button >
380
+ < mwc-button
381
+ icon ="redo "
382
+ label ="${ translate ( 'redo' ) } "
383
+ ?disabled =${ ! this . canRedo }
384
+ @click =${ this . redo }
385
+ slot="secondaryAction"
386
+ > </ mwc-button >
387
+ < mwc-button slot ="primaryAction " dialogaction ="close "
388
+ > ${ translate ( 'close' ) } </ mwc-button
389
+ >
390
+ </ mwc-dialog > ` ;
391
+ }
392
+
284
393
render ( ) : TemplateResult {
285
394
return html `${ ifImplemented ( super . render ( ) ) }
286
395
< style >
@@ -298,13 +407,9 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
298
407
# log > mwc-icon-button-toggle : nth-child (4 ) {
299
408
right : 158px ;
300
409
}
301
- # log > mwc-icon-button-toggle : nth-child (5 ) {
302
- right : 206px ;
303
- }
304
410
# content mwc-list-item .info ,
305
411
# content mwc-list-item .warning ,
306
- # content mwc-list-item .error ,
307
- # content mwc-list-item .action {
412
+ # content mwc-list-item .error {
308
413
display : none;
309
414
}
310
415
# infofilter [on ] ~ # content mwc-list-item .info {
@@ -316,9 +421,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
316
421
# errorfilter [on ] ~ # content mwc-list-item .error {
317
422
display : flex;
318
423
}
319
- # actionfilter [on ] ~ # content mwc-list-item .action {
320
- display : flex;
321
- }
322
424
323
425
# infofilter [on ] {
324
426
color : var (--cyan );
@@ -336,7 +438,8 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
336
438
color : var (--blue );
337
439
}
338
440
339
- # log {
441
+ # log ,
442
+ # history {
340
443
--mdc-dialog-min-width : 92vw ;
341
444
}
342
445
@@ -346,28 +449,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
346
449
right : 14px ;
347
450
}
348
451
</ style >
349
- < mwc-dialog id ="log " heading ="${ translate ( 'log.name' ) } ">
350
- ${ this . renderFilterButtons ( ) }
351
- < mwc-list id ="content " wrapFocus > ${ this . renderHistory ( ) } </ mwc-list >
352
- < mwc-button
353
- icon ="undo "
354
- label ="${ translate ( 'undo' ) } "
355
- ?disabled =${ ! this . canUndo }
356
- @click =${ this . undo }
357
- slot="secondaryAction"
358
- > </ mwc-button >
359
- < mwc-button
360
- icon ="redo "
361
- label ="${ translate ( 'redo' ) } "
362
- ?disabled =${ ! this . canRedo }
363
- @click =${ this . redo }
364
- slot="secondaryAction"
365
- > </ mwc-button >
366
- < mwc-button slot ="primaryAction " dialogaction ="close "
367
- > ${ translate ( 'close' ) } </ mwc-button
368
- >
369
- </ mwc-dialog >
370
-
452
+ ${ this . renderLogDialog ( ) } ${ this . renderHistoryDialog ( ) }
371
453
< mwc-dialog id ="diagnostic " heading ="${ translate ( 'diag.name' ) } ">
372
454
< filtered-list id ="content " wrapFocus
373
455
> ${ this . renderIssues ( ) } </ filtered-list
@@ -380,18 +462,18 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
380
462
< mwc-snackbar
381
463
id ="info "
382
464
timeoutMs ="4000 "
383
- labelText ="${ this . history
465
+ labelText ="${ this . log
384
466
. slice ( )
385
467
. reverse ( )
386
- . find ( le => le . kind === 'info' || le . kind === 'action' ) ?. title ??
468
+ . find ( le => le . kind === 'info' ) ?. title ??
387
469
get ( 'log.snackbar.placeholder' ) } "
388
470
>
389
471
< mwc-icon-button icon ="close " slot ="dismiss "> </ mwc-icon-button >
390
472
</ mwc-snackbar >
391
473
< mwc-snackbar
392
474
id ="warning "
393
475
timeoutMs ="6000 "
394
- labelText ="${ this . history
476
+ labelText ="${ this . log
395
477
. slice ( )
396
478
. reverse ( )
397
479
. find ( le => le . kind === 'warning' ) ?. title ??
@@ -408,7 +490,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
408
490
< mwc-snackbar
409
491
id ="error "
410
492
timeoutMs ="10000 "
411
- labelText ="${ this . history
493
+ labelText ="${ this . log
412
494
. slice ( )
413
495
. reverse ( )
414
496
. find ( le => le . kind === 'error' ) ?. title ??
@@ -439,5 +521,5 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
439
521
}
440
522
}
441
523
442
- return LoggingElement ;
524
+ return HistoringElement ;
443
525
}
0 commit comments