From bdbf6eb153291e425c5af30cdf0c6dd7b07cf828 Mon Sep 17 00:00:00 2001 From: rhenck <richard.henck@iqb.hu-berlin.de> Date: Mon, 5 Jul 2021 16:27:22 +0200 Subject: [PATCH] Add message service for displaying messages to the user The extra styling via panelClass needs CSS definition in local project, so can not be set by the Service itself but relies on local CSS rules. --- projects/common/app.module.ts | 4 +++- projects/common/message.service.ts | 13 +++++++++++++ projects/editor/src/app/unit.service.ts | 6 +++--- projects/editor/src/styles.css | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 projects/common/message.service.ts diff --git a/projects/common/app.module.ts b/projects/common/app.module.ts index 3d15f7257..98d352674 100644 --- a/projects/common/app.module.ts +++ b/projects/common/app.module.ts @@ -17,6 +17,7 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatDialogModule } from '@angular/material/dialog'; import { MatTabsModule } from '@angular/material/tabs'; import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; import { ButtonComponent } from './element-components/button.component'; import { CorrectionComponent } from './element-components/compound-components/correction.component'; @@ -76,7 +77,8 @@ import { DropdownComponent } from './element-components/dropdown.component'; RadioButtonGroupComponent, CheckboxComponent, DropdownComponent, - CorrectionComponent + CorrectionComponent, + MatSnackBarModule ] }) export class SharedModule { } diff --git a/projects/common/message.service.ts b/projects/common/message.service.ts new file mode 100644 index 000000000..6ff6669b8 --- /dev/null +++ b/projects/common/message.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { MatSnackBar } from '@angular/material/snack-bar'; + +@Injectable({ + providedIn: 'root' +}) +export class MessageService { + constructor(private _snackBar: MatSnackBar) { } + + showWarning(text: string): void { + this._snackBar.open(text, undefined, { duration: 2000, panelClass: 'snackbar-warning' }); + } +} diff --git a/projects/editor/src/app/unit.service.ts b/projects/editor/src/app/unit.service.ts index f8815f7d8..0d5d8204d 100644 --- a/projects/editor/src/app/unit.service.ts +++ b/projects/editor/src/app/unit.service.ts @@ -7,6 +7,7 @@ import { } from '../../../common/unit'; import { FileService } from '../../../common/file.service'; import * as UnitFactory from './model/UnitFactory'; +import { MessageService } from '../../../common/message.service'; @Injectable({ providedIn: 'root' @@ -21,7 +22,7 @@ export class UnitService { pageSwitch = new Subject(); elementUpdated = new Subject(); - constructor() { + constructor(private messageService: MessageService) { this._unit = new BehaviorSubject(UnitFactory.createUnit()); const initialPage = UnitFactory.createUnitPage(); const initialSection = UnitFactory.createUnitPageSection(); @@ -85,8 +86,7 @@ export class UnitService { deleteSection(): void { if (this._unit.value.pages[this._selectedPageIndex.value].sections.length < 2) { - // TODO show toast - console.log('cant delete last section'); + this.messageService.showWarning('cant delete last section'); } else { const index = this._selectedPageSectionIndex.value; this._unit.value.pages[this._selectedPageIndex.value].sections.splice(index, 1); diff --git a/projects/editor/src/styles.css b/projects/editor/src/styles.css index d22844d29..ed26e0b07 100644 --- a/projects/editor/src/styles.css +++ b/projects/editor/src/styles.css @@ -4,3 +4,5 @@ html, body { height: 100%; } body { margin: 0; } + +.snackbar-warning {border: 3px double #ff4d4d} -- GitLab