Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit 36aef6a

Browse files
author
Vladimir Shakhov
committed
#224 update to master
2 parents 9b5661e + 11c76ef commit 36aef6a

20 files changed

+189
-88
lines changed

src/app/app.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { AuthService, ErrorService, LanguageService, LayoutService, Notification
1010
import { RouterUtilsService } from './shared/services/router-utils.service';
1111
import { StyleService } from './shared/services/style.service';
1212
import { ZoneService } from './shared/services/zone.service';
13+
import { StorageService } from './shared/services/storage.service';
14+
import { AsyncJobService } from './shared/services/async-job.service';
15+
import { CacheService } from './shared/services/cache.service';
1316

1417

1518
@Component({
@@ -35,6 +38,9 @@ export class AppComponent implements OnInit, AfterViewInit {
3538
private router: Router,
3639
private error: ErrorService,
3740
private languageService: LanguageService,
41+
private asyncJobService: AsyncJobService,
42+
private cacheService: CacheService,
43+
private storage: StorageService,
3844
private layoutService: LayoutService,
3945
private mdlDialogService: MdlDialogService,
4046
private notification: NotificationService,
@@ -58,13 +64,19 @@ export class AppComponent implements OnInit, AfterViewInit {
5864
this.loadSettings();
5965

6066
this.error.subscribe(e => this.handleError(e));
61-
this.auth.loggedIn.subscribe(loggedIn => {
62-
this.loggedIn = loggedIn;
67+
this.auth.loggedIn.subscribe(isLoggedIn => {
68+
this.loggedIn = isLoggedIn;
6369
this.updateAccount(this.loggedIn);
64-
if (loggedIn) {
70+
if (isLoggedIn) {
71+
this.auth.startInactivityCounter();
6572
this.loadSettings();
6673
this.zoneService.areAllZonesBasic().subscribe(basic => this.disableSecurityGroups = basic);
74+
} else {
75+
this.auth.clearInactivityTimer();
6776
}
77+
this.asyncJobService.completeAllJobs();
78+
this.cacheService.invalidateAll();
79+
this.storage.resetInMemoryStorage();
6880
});
6981

7082
this.layoutService.drawerToggled.subscribe(() => {

src/app/events/event-list.component.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ export class EventListComponent implements OnInit {
6666
}
6767

6868
public getEvents(params = { reload: false }): void {
69-
if (params.reload) { this.loading = true; }
69+
if (params.reload) {
70+
this.loading = true;
71+
}
7072
this.getEventsObservable(params)
71-
.subscribe(() => this.loading = false);
73+
.finally(() => this.loading = false)
74+
.subscribe();
7275
}
7376

7477
public getEventsObservable(params: { reload: boolean }): Observable<Array<Event>> {
@@ -109,7 +112,9 @@ export class EventListComponent implements OnInit {
109112
}
110113

111114
private filterBySearch(events: Array<Event>): Array<Event> {
112-
if (!this.query) { return events; }
115+
if (!this.query) {
116+
return events;
117+
}
113118

114119
const queryLower = this.query.toLowerCase();
115120
return events.filter((event: Event) => {
@@ -169,12 +174,19 @@ export class EventListComponent implements OnInit {
169174
}
170175

171176
private getEventTypes(events: Array<Event>): Array<string> {
172-
return events.reduce((acc, event) => {
177+
const types = events.reduce((acc, event) => {
173178
if (!acc.includes(event.type)) {
174179
acc.push(event.type);
175180
}
176181
return acc;
177182
}, []);
183+
184+
return this.selectedTypes.reduce((acc, type) => {
185+
if (!acc.includes(type)) {
186+
acc.push(type);
187+
}
188+
return acc;
189+
}, types);
178190
}
179191

180192
private initTableModel(translations: any): void {

src/app/shared/components/color-picker/color-picker.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
<div class="color-preview-container" (click)="popover.toggle($event)">
1+
<div
2+
class="color-preview-container"
3+
[class.disabled]="disabled"
4+
(click)="toggle($event)"
5+
>
26
<div
37
class="color-preview"
48
[style.background-color]="selectedColor?.value"
59
></div>
610
</div>
711
<mdl-textfield
812
[value]="selectedColor?.value"
9-
(click)="popover.toggle($event)"
13+
[disabled]="disabled"
14+
(click)="toggle($event)"
1015
readonly
1116
></mdl-textfield>
1217

src/app/shared/components/color-picker/color-picker.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ $input-margin: 10px;
2424
width: 100%;
2525
height: 100%;
2626
}
27+
28+
&.disabled {
29+
cursor: not-allowed;
30+
}
2731
}
2832

2933
:host mdl-textfield {
@@ -32,6 +36,10 @@ $input-margin: 10px;
3236
/deep/ input {
3337
cursor: pointer;
3438
}
39+
40+
/deep/ input:disabled {
41+
cursor: not-allowed;
42+
}
3543
}
3644

3745
.popover-container {

src/app/shared/components/color-picker/color-picker.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
1212
import { MdlPopoverComponent } from '@angular-mdl/popover';
1313
import { Color } from '../../models';
14+
import { toBoolean } from '@angular-mdl/core/components/common/boolean-property';
1415

1516

1617
@Component({
@@ -35,6 +36,15 @@ export class ColorPickerComponent implements OnChanges, ControlValueAccessor {
3536
public colorWidth: number;
3637

3738
private _selectedColor: Color;
39+
private _disabled: boolean;
40+
41+
@Input() public get disabled(): boolean {
42+
return this._disabled;
43+
};
44+
45+
public set disabled(value) {
46+
this._disabled = toBoolean(value);
47+
}
3848

3949
public ngOnChanges(changes: SimpleChanges): void {
4050
if ('colors' in changes) {
@@ -52,6 +62,12 @@ export class ColorPickerComponent implements OnChanges, ControlValueAccessor {
5262
this.propagateChange(this._selectedColor);
5363
}
5464

65+
public toggle(event: Event): void {
66+
if (!this._disabled) {
67+
this.popover.toggle(event);
68+
}
69+
}
70+
5571
public selectColor(color: Color): void {
5672
this.selectedColor = color;
5773
this.popover.hide();

src/app/shared/components/vm-statistics/vm-statistics.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ <h2 mdl-card-title-text>{{ 'STORAGE' | translate }}</h2>
110110
</div>
111111
<mdl-card-actions class="stat-collapse"></mdl-card-actions>
112112
</mdl-card>
113+
<mdl-tooltip #refreshStatistics="mdlTooltip">
114+
{{ 'REFRESH' | translate }}
115+
</mdl-tooltip>

src/app/shared/services/async-job.service.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { Observable } from 'rxjs/Observable';
3+
import { Observer } from 'rxjs/Observer';
34
import { Subject } from 'rxjs/Subject';
45

56
import { AsyncJob } from '../models';
@@ -35,21 +36,25 @@ export class AsyncJobService extends BaseBackendService<AsyncJob<any>> {
3536

3637
public queryJob(job: any, entity = '', entityModel: any = null): Observable<typeof entityModel> {
3738
const jobId = this.getJobId(job);
38-
const jobSubject = new Subject<AsyncJob<typeof entityModel>>();
39-
this.jobs.push(jobSubject);
39+
const jobObservable = Observable.create(observer => {
40+
let interval;
41+
setTimeout(() => {
42+
this._queryJob(jobId, observer, entity, entityModel);
43+
interval = setInterval(() => {
44+
if (jobObservable.isStopped) {
45+
clearInterval(interval);
46+
return;
47+
}
48+
this._queryJob(jobId, observer, entity, entityModel, interval);
49+
}, this.pollingInterval);
50+
this.timerIds.push(interval);
51+
}, this.immediatePollingInterval);
4052

41-
setTimeout(() => {
42-
this._queryJob(jobId, jobSubject, entity, entityModel);
43-
let interval = setInterval(() => {
44-
if (jobSubject.isStopped) {
45-
clearInterval(interval);
46-
return;
47-
}
48-
this._queryJob(jobId, jobSubject, entity, entityModel, interval);
49-
}, this.pollingInterval);
50-
this.timerIds.push(interval);
51-
}, this.immediatePollingInterval);
52-
return jobSubject;
53+
return () => clearInterval(interval);
54+
});
55+
this.jobs.push(jobObservable);
56+
57+
return jobObservable;
5358
}
5459

5560
public completeAllJobs(): void {
@@ -61,7 +66,7 @@ export class AsyncJobService extends BaseBackendService<AsyncJob<any>> {
6166

6267
private _queryJob(
6368
jobId: string,
64-
jobSubject: Subject<AsyncJob<any>>,
69+
observer: Observer<AsyncJob<any>>,
6570
entity: string,
6671
entityModel: any,
6772
interval?: any
@@ -73,10 +78,10 @@ export class AsyncJobService extends BaseBackendService<AsyncJob<any>> {
7378
case JobStatus.InProgress:
7479
return;
7580
case JobStatus.Completed:
76-
jobSubject.next(this.getResult(asyncJob, entity, entityModel));
81+
observer.next(this.getResult(asyncJob, entity, entityModel));
7782
break;
7883
case JobStatus.Failed: {
79-
jobSubject.error(ErrorService.parseError(this.getResponse({ error: asyncJob.result })));
84+
observer.error(ErrorService.parseError(this.getResponse({ error: asyncJob.result })));
8085
break;
8186
}
8287
}
@@ -85,7 +90,7 @@ export class AsyncJobService extends BaseBackendService<AsyncJob<any>> {
8590
clearInterval(interval);
8691
this.timerIds.filter(id => interval !== id);
8792
}
88-
jobSubject.complete();
93+
observer.complete();
8994
this.event.next(asyncJob);
9095
});
9196
}

src/app/shared/services/auth.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('Auth service session', () => {
215215
const inactivityTimeout = 10;
216216
const logout = spyOn(router, 'navigate').and.callThrough();
217217
const refresh = spyOn(authService, 'sendRefreshRequest');
218-
218+
authService.startInactivityCounter();
219219
authService.setInactivityTimeout(inactivityTimeout).subscribe();
220220

221221
tick(getRefreshInterval() * (inactivityTimeout - 1) * 60 / refreshInterval);

src/app/shared/services/auth.service.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import { BaseModelStub } from '../models';
88
import { AsyncJobService } from './async-job.service';
99

1010
import { BaseBackendService } from './base-backend.service';
11-
import { CacheService } from './cache.service';
1211
import { ConfigService } from './config.service';
1312
import { RouterUtilsService } from './router-utils.service';
1413
import { StorageService } from './storage.service';
1514
import { UserService } from './user.service';
1615

17-
import debounce = require('lodash/debounce');
18-
19-
2016
const DEFAULT_SESSION_REFRESH_INTERVAL = 60;
2117

2218
@Injectable()
@@ -33,7 +29,6 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
3329

3430
constructor(
3531
protected asyncJobService: AsyncJobService,
36-
protected cacheService: CacheService,
3732
protected configService: ConfigService,
3833
protected storage: StorageService,
3934
protected router: Router,
@@ -43,33 +38,26 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
4338
) {
4439
super();
4540
this.loggedIn = new BehaviorSubject<boolean>(!!this.userId);
41+
}
4642

47-
debounce(this.refreshSession, 1000, { leading: true });
48-
debounce(this.resetTimer, 1000, { leading: true });
49-
43+
public startInactivityCounter() {
5044
Observable.forkJoin(
5145
this.getInactivityTimeout(),
5246
this.getSessionRefreshInterval()
5347
)
5448
.subscribe(([inactivityTimeout, sessionRefreshInterval]) => {
5549
this.inactivityTimeout = inactivityTimeout;
5650
this.sessionRefreshInterval = sessionRefreshInterval;
57-
this.resetTimer();
51+
this.resetInactivityTimer();
5852
this.addEventListeners();
5953
});
60-
61-
this.loggedIn.subscribe(() => {
62-
this.asyncJobService.completeAllJobs();
63-
this.cacheService.invalidateAll();
64-
this.storage.resetInMemoryStorage();
65-
});
6654
}
6755

6856
public setInactivityTimeout(value: number): Observable<void> {
6957
return this.userService.writeTag('sessionTimeout', value.toString())
7058
.map(() => {
7159
this.inactivityTimeout = value;
72-
this.resetTimer();
60+
this.resetInactivityTimer();
7361
});
7462
}
7563

@@ -174,7 +162,7 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
174162

175163
private refreshSession(): void {
176164
if (++this.numberOfRefreshes * this.sessionRefreshInterval >= this.inactivityTimeout * 60) {
177-
this.clearTimer();
165+
this.clearInactivityTimer();
178166
this.zone.run(() => this.router.navigate(['/logout'], this.routerUtilsService.getRedirectionQueryParams()));
179167
} else {
180168
this.sendRefreshRequest();
@@ -185,23 +173,23 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
185173
const events = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll'.split(' ');
186174
const observables = events.map(event => Observable.fromEvent(document, event));
187175
this.zone.runOutsideAngular(() => {
188-
Observable.merge(...observables).subscribe(() => this.resetTimer());
176+
Observable.merge(...observables).subscribe(() => this.resetInactivityTimer());
189177
});
190178
}
191179

192-
private resetTimer(): void {
193-
this.clearTimer();
180+
private resetInactivityTimer(): void {
181+
this.clearInactivityTimer();
194182
this.numberOfRefreshes = 0;
195183
if (this.inactivityTimeout) {
196-
this.setTimer();
184+
this.setInactivityTimer();
197185
}
198186
}
199187

200-
private clearTimer(): void {
188+
public clearInactivityTimer(): void {
201189
clearInterval(this.refreshTimer);
202190
}
203191

204-
private setTimer(): void {
192+
private setInactivityTimer(): void {
205193
if (this.sessionRefreshInterval && this.inactivityTimeout) {
206194
this.refreshTimer = setInterval(this.refreshSession.bind(this), this.sessionRefreshInterval * 1000);
207195
}

src/app/shared/services/notification.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class NotificationService implements NotificationService {
2222
}
2323

2424
public message(message: string | ParametrizedTranslation): Observable<MdlSnackbarComponent> {
25-
let obs = new Subject<MdlSnackbarComponent>();
25+
const obs = new Subject<MdlSnackbarComponent>();
2626
this.getTranslatedMessage(message)
2727
.switchMap(translatedMessage => {
2828
return this.snackbar.showSnackbar({
@@ -40,7 +40,7 @@ export class NotificationService implements NotificationService {
4040
handler: () => {},
4141
text: 'OK'
4242
}): Observable<MdlSnackbarComponent> {
43-
let obs = new Subject<MdlSnackbarComponent>();
43+
const obs = new Subject<MdlSnackbarComponent>();
4444
this.getTranslatedMessage(message)
4545
.switchMap(translatedMessage => {
4646
return this.snackbar.showSnackbar({message: translatedMessage, action});
@@ -60,7 +60,7 @@ export class NotificationService implements NotificationService {
6060
handler: () => {},
6161
text: 'OK'
6262
}): Observable<MdlSnackbarComponent> {
63-
let obs = new Subject<MdlSnackbarComponent>();
63+
const obs = new Subject<MdlSnackbarComponent>();
6464
this.getTranslatedMessage(message)
6565
.switchMap(translatedMessage => {
6666
return this.snackbar.showSnackbar({

0 commit comments

Comments
 (0)