NotificationsOverlay UI

This commit is contained in:
Patrick Haßel 2024-11-08 11:11:07 +01:00
parent bc68777229
commit 985924086e
4 changed files with 56 additions and 19 deletions

View File

@ -7,9 +7,9 @@ import {Notification} from "./Notification";
}) })
export class NotificationService { export class NotificationService {
public notifications: Notification<any>[] = [ public visible: boolean = false;
new Notification('', 'Test', new Date(), 'test', null),
]; public notifications: Notification<any>[] = [];
constructor( constructor(
protected readonly api: ApiService, protected readonly api: ApiService,
@ -17,4 +17,16 @@ export class NotificationService {
// - // -
} }
dismiss(notification: Notification<any>) {
this.notifications.splice(this.notifications.indexOf(notification), 1);
if (this.notifications.length === 0) {
this.visible = false;
}
// this.api.postNone(['Notification', 'dismiss'], notification.uuid);
}
toggle() {
this.visible = !this.visible;
}
} }

View File

@ -27,14 +27,21 @@
</div> </div>
<router-outlet (activate)="onActivate($event)"/> <router-outlet (activate)="onActivate($event)"/>
<div #notificationsOverlayMobile class="notificationsOverlay notificationsOverlayMobile" *ngIf="notificationsOverlayVisible" (window:resize)="onResize()"> <ng-template #tmp>
<div class="notificationOverlayEntry" *ngFor="let notification of notificationService.notifications"> <div class="notificationOverlayEntry" *ngFor="let notification of notificationService.notifications">
<div class="title">
{{ notification.title }} {{ notification.title }}
</div> </div>
<div class="dismiss" (click)="notificationService.dismiss(notification)">
X
</div>
</div>
</ng-template>
<div #notificationsOverlayMobile class="notificationsOverlay notificationsOverlayMobile" *ngIf="notificationService.visible" (window:resize)="onResize()">
<ng-container *ngTemplateOutlet="tmp"></ng-container>
</div> </div>
<div #notificationsOverlayDesktop class="notificationsOverlay notificationsOverlayDesktop" *ngIf="notificationsOverlayVisible" (window:resize)="onResize()"> <div #notificationsOverlayDesktop class="notificationsOverlay notificationsOverlayDesktop" *ngIf="notificationService.visible" (window:resize)="onResize()">
<div class="notificationOverlayEntry" *ngFor="let notification of notificationService.notifications"> <ng-container *ngTemplateOutlet="tmp"></ng-container>
{{ notification.title }}
</div>
</div> </div>

View File

@ -38,17 +38,37 @@
.notificationsOverlay { .notificationsOverlay {
position: fixed; position: fixed;
background-color: lightgray; background-color: #eaeaea;
border: 1px solid gray; border: 1px solid #aeaeae;
border-top: none;
border-radius: 0 0 @space @space; border-radius: 0 0 @space @space;
box-shadow: -0.5em 0.5em 1em rgba(0, 0, 0, 0.5); box-shadow: 0 0.5em 1em rgba(0, 0, 0, 0.5);
.notificationOverlayEntry { .notificationOverlayEntry {
border-bottom: 1px solid gray;
padding: @halfSpace; padding: @halfSpace;
.title {
float: left;
} }
.notificationOverlayEntry:hover { .dismiss {
float: right;
color: red;
width: 1.5em;
height: 1.5em;
font-weight: bold;
text-align: center;
border-radius: 50%;
}
.dismiss:hover {
background-color: red;
color: black;
}
}
.notificationOverlayEntry:hover:not(:has(div:hover)) {
background-color: lightskyblue; background-color: lightskyblue;
} }

View File

@ -1,6 +1,6 @@
import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {Router, RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router'; import {Router, RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router';
import {JsonPipe, NgForOf, NgIf} from "@angular/common"; import {JsonPipe, NgForOf, NgIf, NgTemplateOutlet} from "@angular/common";
import {UserService} from "./api/User/user.service"; import {UserService} from "./api/User/user.service";
import {Subscription, timer} from "rxjs"; import {Subscription, timer} from "rxjs";
import {NotificationService} from "./api/Notification/notification.service"; import {NotificationService} from "./api/Notification/notification.service";
@ -8,7 +8,7 @@ import {NotificationService} from "./api/Notification/notification.service";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
standalone: true, standalone: true,
imports: [RouterOutlet, RouterLink, RouterLinkActive, NgIf, NgForOf, JsonPipe], imports: [RouterOutlet, RouterLink, RouterLinkActive, NgIf, NgForOf, JsonPipe, NgTemplateOutlet],
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrl: './app.component.less' styleUrl: './app.component.less'
}) })
@ -41,8 +41,6 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit {
this.onResize(); this.onResize();
} }
protected notificationsOverlayVisible: boolean = true;
constructor( constructor(
protected readonly router: Router, protected readonly router: Router,
protected readonly userService: UserService, protected readonly userService: UserService,
@ -69,7 +67,7 @@ export class AppComponent implements OnInit, OnDestroy, AfterViewInit {
} }
toggleMenu() { toggleMenu() {
this.notificationsOverlayVisible = !this.notificationsOverlayVisible; this.notificationService.toggle();
this.onResize(); this.onResize();
} }