This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlog-monitor.ts
133 lines (115 loc) · 3.39 KB
/
log-monitor.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
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
import { Component, Input } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operator/map';
import { StoreDevtools } from '@ngrx/store-devtools';
import { select } from '@ngrx/core/operator/select';
import { LogEntryItem } from './log-entry-item';
@Component({
selector: 'log-monitor',
styles: [`
:host {
display: block;
background-color: #2A2F3A;
font-family: 'monaco', 'Consolas', 'Lucida Console', monospace;
position: relative;
overflow-y: hidden;
width: 100%;
height: 100%;
min-width: 300px;
direction: ltr;
}
.button-bar {
text-align: center;
border-bottom-width: 1px;
border-bottom-style: solid;
border-color: transparent;
z-index: 1;
display: flex;
flex-direction: row;
padding: 0 4px;
}
.elements {
position: absolute;
left: 0;
right: 0;
top: 38px;
bottom: 0;
overflow-x: hidden;
overflow-y: auto;
}
`],
template: `
<div class="button-bar">
<log-monitor-button (action)="handleReset()">
Reset
</log-monitor-button>
<log-monitor-button (action)="handleRollback()">
Revert
</log-monitor-button>
<log-monitor-button (action)="handleSweep()" [disabled]="canSweep$ | async">
Sweep
</log-monitor-button>
<log-monitor-button (action)="handleCommit()" [disabled]="canCommit$ | async">
Commit
</log-monitor-button>
</div>
<div class="elements">
<log-monitor-entry
*ngFor="let item of (items$ | async); let i = index"
[item]="item"
[disabled]="i === 0"
[expandEntries]="expandEntries"
(toggle)="handleToggle($event.id)">
</log-monitor-entry>
</div>
`
})
export class LogMonitorComponent {
@Input() expandEntries: boolean = true;
public items$: Observable<LogEntryItem[]>;
public canRevert$: Observable<boolean>;
public canSweep$: Observable<boolean>;
public canCommit$: Observable<boolean>;
constructor(private devtools: StoreDevtools) {
this.canRevert$ = select.call(devtools.liftedState, s => !(s.computedStates.length > 1 ));
this.canSweep$ = select.call(devtools.liftedState, s => !(s.skippedActionIds.length > 0));
this.canCommit$ = select.call(devtools.liftedState, s => !(s.computedStates.length > 1));
this.items$ = map.call(devtools.liftedState, ({ actionsById, skippedActionIds, stagedActionIds, computedStates }) => {
const actions = [];
for (let i = 0; i < stagedActionIds.length; i++) {
const actionId = stagedActionIds[i];
const action = actionsById[actionId].action;
const { state, error } = computedStates[i];
let previousState;
if (i > 0) {
previousState = computedStates[i - 1].state;
}
actions.push({
key: actionId,
collapsed: skippedActionIds.indexOf(actionId) > -1,
action,
actionId,
state,
previousState,
error
});
}
return actions;
});
}
handleToggle(id: number) {
this.devtools.toggleAction(id);
}
handleReset() {
this.devtools.reset();
}
handleRollback() {
this.devtools.rollback();
}
handleSweep() {
this.devtools.sweep();
}
handleCommit() {
this.devtools.commit();
}
}