2019-08-09 19:13:18 +03:00
|
|
|
///
|
2023-01-31 10:43:56 +02:00
|
|
|
/// Copyright © 2016-2023 The Thingsboard Authors
|
2019-08-09 19:13:18 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { Observable } from 'rxjs';
|
2020-02-10 13:15:29 +02:00
|
|
|
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
|
2019-08-09 19:13:18 +03:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-08-28 16:02:27 +03:00
|
|
|
import { AuthService } from '@core/auth/auth.service';
|
2019-10-17 18:23:53 +03:00
|
|
|
import {
|
|
|
|
|
ColorPickerDialogComponent,
|
|
|
|
|
ColorPickerDialogData
|
|
|
|
|
} from '@shared/components/dialog/color-picker-dialog.component';
|
2019-10-24 19:52:19 +03:00
|
|
|
import {
|
|
|
|
|
MaterialIconsDialogComponent,
|
|
|
|
|
MaterialIconsDialogData
|
|
|
|
|
} from '@shared/components/dialog/material-icons-dialog.component';
|
2020-02-11 10:56:43 +02:00
|
|
|
import { ConfirmDialogComponent } from '@shared/components/dialog/confirm-dialog.component';
|
|
|
|
|
import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
|
|
|
|
|
import { TodoDialogComponent } from '@shared/components/dialog/todo-dialog.component';
|
2019-08-09 19:13:18 +03:00
|
|
|
|
|
|
|
|
@Injectable(
|
|
|
|
|
{
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
export class DialogService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private translate: TranslateService,
|
2019-08-28 16:02:27 +03:00
|
|
|
private authService: AuthService,
|
2019-08-09 19:13:18 +03:00
|
|
|
public dialog: MatDialog
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confirm(title: string, message: string, cancel: string = null, ok: string = null, fullscreen: boolean = false): Observable<boolean> {
|
|
|
|
|
const dialogConfig: MatDialogConfig = {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
data: {
|
|
|
|
|
title,
|
|
|
|
|
message,
|
|
|
|
|
cancel: cancel || this.translate.instant('action.cancel'),
|
|
|
|
|
ok: ok || this.translate.instant('action.ok')
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (fullscreen) {
|
|
|
|
|
dialogConfig.panelClass = ['tb-fullscreen-dialog'];
|
|
|
|
|
}
|
|
|
|
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, dialogConfig);
|
|
|
|
|
return dialogRef.afterClosed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alert(title: string, message: string, ok: string = null, fullscreen: boolean = false): Observable<boolean> {
|
|
|
|
|
const dialogConfig: MatDialogConfig = {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
data: {
|
|
|
|
|
title,
|
|
|
|
|
message,
|
|
|
|
|
ok: ok || this.translate.instant('action.ok')
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (fullscreen) {
|
|
|
|
|
dialogConfig.panelClass = ['tb-fullscreen-dialog'];
|
|
|
|
|
}
|
|
|
|
|
const dialogRef = this.dialog.open(AlertDialogComponent, dialogConfig);
|
|
|
|
|
return dialogRef.afterClosed();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 18:23:53 +03:00
|
|
|
colorPicker(color: string): Observable<string> {
|
|
|
|
|
return this.dialog.open<ColorPickerDialogComponent, ColorPickerDialogData, string>(ColorPickerDialogComponent,
|
|
|
|
|
{
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
color
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
materialIconPicker(icon: string): Observable<string> {
|
|
|
|
|
return this.dialog.open<MaterialIconsDialogComponent, MaterialIconsDialogData, string>(MaterialIconsDialogComponent,
|
|
|
|
|
{
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
icon
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 16:02:27 +03:00
|
|
|
private permissionDenied() {
|
|
|
|
|
this.alert(
|
|
|
|
|
this.translate.instant('access.permission-denied'),
|
|
|
|
|
this.translate.instant('access.permission-denied-text'),
|
|
|
|
|
this.translate.instant('action.close')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forbidden(): Observable<boolean> {
|
|
|
|
|
const observable = this.confirm(
|
|
|
|
|
this.translate.instant('access.access-forbidden'),
|
|
|
|
|
this.translate.instant('access.access-forbidden-text'),
|
|
|
|
|
this.translate.instant('action.cancel'),
|
|
|
|
|
this.translate.instant('action.sign-in'),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
observable.subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
this.authService.logout();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return observable;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 13:36:39 +03:00
|
|
|
todo(): Observable<any> {
|
|
|
|
|
const dialogConfig: MatDialogConfig = {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-fullscreen-dialog']
|
|
|
|
|
};
|
|
|
|
|
const dialogRef = this.dialog.open(TodoDialogComponent, dialogConfig);
|
|
|
|
|
return dialogRef.afterClosed();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 19:13:18 +03:00
|
|
|
}
|