@@ -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 ,
@@ -44,7 +47,6 @@ const icons = {
44
47
info : 'info' ,
45
48
warning : 'warning' ,
46
49
error : 'report' ,
47
- action : 'history' ,
48
50
} ;
49
51
50
52
function getPluginName ( src : string ) : string {
@@ -70,13 +72,18 @@ function getPluginName(src: string): string {
70
72
* Renders the `history` to `logUI` and the latest `'error'` [[`LogEntry`]] to
71
73
* `messageUI`.
72
74
*/
73
- export type LoggingElement = Mixin < typeof Logging > ;
75
+ export type HistoringElement = Mixin < typeof Historing > ;
74
76
75
- export function Logging < TBase extends LitElementConstructor > ( Base : TBase ) {
76
- class LoggingElement extends Base {
77
+ export function Historing < TBase extends LitElementConstructor > ( Base : TBase ) {
78
+ class HistoringElement extends Base {
77
79
/** All [[`LogEntry`]]s received so far through [[`LogEvent`]]s. */
78
80
@property ( { type : Array } )
79
- history : LogEntry [ ] = [ ] ;
81
+ log : InfoEntry [ ] = [ ] ;
82
+
83
+ /** All [[`CommitEntry`]]s received so far through [[`LogEvent`]]s */
84
+ @property ( { type : Array } )
85
+ history : CommitEntry [ ] = [ ] ;
86
+
80
87
/** Index of the last [[`EditorAction`]] applied. */
81
88
@property ( { type : Number } )
82
89
editCount = - 1 ;
@@ -86,6 +93,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
86
93
latestIssue ! : IssueDetail ;
87
94
88
95
@query ( '#log' ) logUI ! : Dialog ;
96
+ @query ( '#history' ) historyUI ! : Dialog ;
89
97
@query ( '#diagnostic' ) diagnosticUI ! : Dialog ;
90
98
@query ( '#error' ) errorUI ! : Snackbar ;
91
99
@query ( '#warning' ) warningUI ! : Snackbar ;
@@ -144,16 +152,10 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
144
152
return true ;
145
153
}
146
154
147
- private onLog ( le : LogEvent ) : void {
148
- if ( le . detail . kind === 'reset' ) {
149
- this . history = [ ] ;
150
- this . editCount = - 1 ;
151
- return ;
152
- }
153
-
154
- const entry : LogEntry = {
155
+ private onHistory ( detail : CommitDetail ) {
156
+ const entry : CommitEntry = {
155
157
time : new Date ( ) ,
156
- ...le . detail ,
158
+ ...detail ,
157
159
} ;
158
160
159
161
if ( entry . kind === 'action' ) {
@@ -164,22 +166,51 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
164
166
}
165
167
166
168
this . history . push ( entry ) ;
169
+ this . requestUpdate ( 'history' , [ ] ) ;
170
+ }
171
+
172
+ private onReset ( ) {
173
+ this . log = [ ] ;
174
+ this . history = [ ] ;
175
+ this . editCount = - 1 ;
176
+ }
177
+
178
+ private onInfo ( detail : InfoDetail ) {
179
+ const entry : InfoEntry = {
180
+ time : new Date ( ) ,
181
+ ...detail ,
182
+ } ;
183
+
184
+ this . log . push ( entry ) ;
167
185
if ( ! this . logUI . open ) {
168
186
const ui = {
169
187
error : this . errorUI ,
170
188
warning : this . warningUI ,
171
189
info : this . infoUI ,
172
- action : this . infoUI ,
173
- } [ le . detail . kind ] ;
190
+ } [ detail . kind ] ;
174
191
175
192
ui . close ( ) ;
176
193
ui . show ( ) ;
177
194
}
178
- if ( le . detail . kind == 'error' ) {
195
+ if ( detail . kind == 'error' ) {
179
196
this . errorUI . close ( ) ; // hack to reset timeout
180
197
this . errorUI . show ( ) ;
181
198
}
182
- this . requestUpdate ( 'history' , [ ] ) ;
199
+ this . requestUpdate ( 'log' , [ ] ) ;
200
+ }
201
+
202
+ private onLog ( le : LogEvent ) : void {
203
+ switch ( le . detail . kind ) {
204
+ case 'reset' :
205
+ this . onReset ( ) ;
206
+ break ;
207
+ case 'action' :
208
+ this . onHistory ( le . detail ) ;
209
+ break ;
210
+ default :
211
+ this . onInfo ( le . detail ) ;
212
+ break ;
213
+ }
183
214
}
184
215
185
216
async performUpdate ( ) {
@@ -201,7 +232,36 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
201
232
}
202
233
203
234
renderLogEntry (
204
- entry : LogEntry ,
235
+ entry : InfoEntry ,
236
+ index : number ,
237
+ log : LogEntry [ ]
238
+ ) : TemplateResult {
239
+ return html ` < abbr title ="${ entry . title } ">
240
+ < mwc-list-item
241
+ class ="${ entry . kind } "
242
+ graphic ="icon "
243
+ ?twoline =${ ! ! entry . message }
244
+ ?activated =${ this . editCount == log . length - index - 1 }
245
+ >
246
+ < span >
247
+ <!-- FIXME: replace tt with mwc-chip asap -->
248
+ < tt > ${ entry . time ?. toLocaleString ( ) } </ tt >
249
+ ${ entry . title } </ span
250
+ >
251
+ < span slot ="secondary "> ${ entry . message } </ span >
252
+ < mwc-icon
253
+ slot ="graphic "
254
+ style ="--mdc-theme-text-icon-on-background:var(${ ifDefined (
255
+ iconColors [ entry . kind ]
256
+ ) } ) "
257
+ > ${ icons [ entry . kind ] } </ mwc-icon
258
+ >
259
+ </ mwc-list-item > </ abbr
260
+ > ` ;
261
+ }
262
+
263
+ renderHistoryEntry (
264
+ entry : CommitEntry ,
205
265
index : number ,
206
266
history : LogEntry [ ]
207
267
) : TemplateResult {
@@ -223,18 +283,31 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
223
283
style ="--mdc-theme-text-icon-on-background:var(${ ifDefined (
224
284
iconColors [ entry . kind ]
225
285
) } ) "
226
- > ${ icons [ entry . kind ] } </ mwc-icon
286
+ > history </ mwc-icon
227
287
>
228
288
</ mwc-list-item > </ abbr
229
289
> ` ;
230
290
}
231
291
292
+ private renderLog ( ) : TemplateResult [ ] | TemplateResult {
293
+ if ( this . log . length > 0 )
294
+ return this . log . slice ( ) . reverse ( ) . map ( this . renderLogEntry , this ) ;
295
+ else
296
+ return html `< mwc-list-item disabled graphic ="icon ">
297
+ < span > ${ translate ( 'log.placeholder' ) } </ span >
298
+ < mwc-icon slot ="graphic "> info</ mwc-icon >
299
+ </ mwc-list-item > ` ;
300
+ }
301
+
232
302
private renderHistory ( ) : TemplateResult [ ] | TemplateResult {
233
303
if ( this . history . length > 0 )
234
- return this . history . slice ( ) . reverse ( ) . map ( this . renderLogEntry , this ) ;
304
+ return this . history
305
+ . slice ( )
306
+ . reverse ( )
307
+ . map ( this . renderHistoryEntry , this ) ;
235
308
else
236
309
return html `< mwc-list-item disabled graphic ="icon ">
237
- < span > ${ translate ( 'log .placeholder' ) } </ span >
310
+ < span > ${ translate ( 'history .placeholder' ) } </ span >
238
311
< mwc-icon slot ="graphic "> info</ mwc-icon >
239
312
</ mwc-list-item > ` ;
240
313
}
@@ -310,6 +383,42 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
310
383
) ;
311
384
}
312
385
386
+ private renderLogDialog ( ) : TemplateResult {
387
+ return html ` < mwc-dialog id ="log " heading ="${ translate ( 'log.name' ) } ">
388
+ ${ this . renderFilterButtons ( ) }
389
+ < mwc-list id ="content " wrapFocus > ${ this . renderLog ( ) } </ mwc-list >
390
+ < mwc-button slot ="primaryAction " dialogaction ="close "
391
+ > ${ translate ( 'close' ) } </ mwc-button
392
+ >
393
+ </ mwc-dialog > ` ;
394
+ }
395
+
396
+ private renderHistoryDialog ( ) : TemplateResult {
397
+ return html ` < mwc-dialog
398
+ id ="history "
399
+ heading ="${ translate ( 'history.name' ) } "
400
+ >
401
+ < mwc-list id ="content " wrapFocus > ${ this . renderHistory ( ) } </ mwc-list >
402
+ < mwc-button
403
+ icon ="undo "
404
+ label ="${ translate ( 'undo' ) } "
405
+ ?disabled =${ ! this . canUndo }
406
+ @click =${ this . undo }
407
+ slot="secondaryAction"
408
+ > </ mwc-button >
409
+ < mwc-button
410
+ icon ="redo "
411
+ label ="${ translate ( 'redo' ) } "
412
+ ?disabled =${ ! this . canRedo }
413
+ @click =${ this . redo }
414
+ slot="secondaryAction"
415
+ > </ mwc-button >
416
+ < mwc-button slot ="primaryAction " dialogaction ="close "
417
+ > ${ translate ( 'close' ) } </ mwc-button
418
+ >
419
+ </ mwc-dialog > ` ;
420
+ }
421
+
313
422
render ( ) : TemplateResult {
314
423
return html `${ ifImplemented ( super . render ( ) ) }
315
424
< style >
@@ -327,13 +436,9 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
327
436
# log > mwc-icon-button-toggle : nth-child (4 ) {
328
437
right : 158px ;
329
438
}
330
- # log > mwc-icon-button-toggle : nth-child (5 ) {
331
- right : 206px ;
332
- }
333
439
# content mwc-list-item .info ,
334
440
# content mwc-list-item .warning ,
335
- # content mwc-list-item .error ,
336
- # content mwc-list-item .action {
441
+ # content mwc-list-item .error {
337
442
display : none;
338
443
}
339
444
# infofilter [on ] ~ # content mwc-list-item .info {
@@ -345,9 +450,6 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
345
450
# errorfilter [on ] ~ # content mwc-list-item .error {
346
451
display : flex;
347
452
}
348
- # actionfilter [on ] ~ # content mwc-list-item .action {
349
- display : flex;
350
- }
351
453
352
454
# infofilter [on ] {
353
455
color : var (--cyan );
@@ -365,7 +467,8 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
365
467
color : var (--blue );
366
468
}
367
469
368
- # log {
470
+ # log ,
471
+ # history {
369
472
--mdc-dialog-min-width : 92vw ;
370
473
}
371
474
@@ -379,28 +482,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
379
482
--mdc-list-item-meta-size : 48px ;
380
483
}
381
484
</ style >
382
- < mwc-dialog id ="log " heading ="${ translate ( 'log.name' ) } ">
383
- ${ this . renderFilterButtons ( ) }
384
- < mwc-list id ="content " wrapFocus > ${ this . renderHistory ( ) } </ mwc-list >
385
- < mwc-button
386
- icon ="undo "
387
- label ="${ translate ( 'undo' ) } "
388
- ?disabled =${ ! this . canUndo }
389
- @click =${ this . undo }
390
- slot="secondaryAction"
391
- > </ mwc-button >
392
- < mwc-button
393
- icon ="redo "
394
- label ="${ translate ( 'redo' ) } "
395
- ?disabled =${ ! this . canRedo }
396
- @click =${ this . redo }
397
- slot="secondaryAction"
398
- > </ mwc-button >
399
- < mwc-button slot ="primaryAction " dialogaction ="close "
400
- > ${ translate ( 'close' ) } </ mwc-button
401
- >
402
- </ mwc-dialog >
403
-
485
+ ${ this . renderLogDialog ( ) } ${ this . renderHistoryDialog ( ) }
404
486
< mwc-dialog id ="diagnostic " heading ="${ translate ( 'diag.name' ) } ">
405
487
< filtered-list id ="content " wrapFocus
406
488
> ${ this . renderIssues ( ) } </ filtered-list
@@ -413,18 +495,18 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
413
495
< mwc-snackbar
414
496
id ="info "
415
497
timeoutMs ="4000 "
416
- labelText ="${ this . history
498
+ labelText ="${ this . log
417
499
. slice ( )
418
500
. reverse ( )
419
- . find ( le => le . kind === 'info' || le . kind === 'action' ) ?. title ??
501
+ . find ( le => le . kind === 'info' ) ?. title ??
420
502
get ( 'log.snackbar.placeholder' ) } "
421
503
>
422
504
< mwc-icon-button icon ="close " slot ="dismiss "> </ mwc-icon-button >
423
505
</ mwc-snackbar >
424
506
< mwc-snackbar
425
507
id ="warning "
426
508
timeoutMs ="6000 "
427
- labelText ="${ this . history
509
+ labelText ="${ this . log
428
510
. slice ( )
429
511
. reverse ( )
430
512
. find ( le => le . kind === 'warning' ) ?. title ??
@@ -441,7 +523,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
441
523
< mwc-snackbar
442
524
id ="error "
443
525
timeoutMs ="10000 "
444
- labelText ="${ this . history
526
+ labelText ="${ this . log
445
527
. slice ( )
446
528
. reverse ( )
447
529
. find ( le => le . kind === 'error' ) ?. title ??
@@ -472,5 +554,5 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
472
554
}
473
555
}
474
556
475
- return LoggingElement ;
557
+ return HistoringElement ;
476
558
}
0 commit comments