Newer
Older

Alex ORLUC
committed
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { tap } from 'rxjs/internal/operators/tap';
import { catchError, finalize } from 'rxjs/operators';
import { of } from 'rxjs/internal/observable/of';
import { NotificationService } from './notification/notification.service';
import { AuthService } from './auth.service';
import { AlertComponent } from '../plugins/modal/alert.component';
import { MatDialog } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core';
declare var $: any;
@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(
private translate: TranslateService,
public http: HttpClient,
private notify: NotificationService,
public authService: AuthService,
private dialog: MatDialog,
) { }
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
setScreenWidth(width: number) {
this.screenWidth = width;
}
applyMinorUpdate() {
const loader = '<div id="updateLoading" style="position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width: 200px;text-align: center;"><img src="assets/spinner.gif"></div>';
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
$('body').append(loader);
return new Promise((resolve) => {
this.http.put('../rest/versionsUpdateSQL', {}).pipe(
tap((data: any) => {
resolve(true);
$('#updateLoading').remove();
}),
finalize(() => $('#updateLoading').remove()),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
resolve(true);
return of(false);
})
).subscribe();
});
}
checkAppSecurity() {
this.authService.catchEvent().subscribe((result: any) => {
if (result === 'authenticationInformations') {
if (this.authService.changeKey) {
setTimeout(() => {
this.dialog.open(AlertComponent, {
panelClass: 'maarch-modal',
autoFocus: false,
disableClose: true,
data: {
mode: 'danger',
title: this.translate.instant('lang.warnPrivateKeyTitle'),
msg: this.translate.instant('lang.warnPrivateKey')
}
});
}, 1000);
}
}
});
}