mirror of https://github.com/abpframework/abp.git
7 changed files with 75 additions and 1 deletions
@ -0,0 +1,22 @@ |
|||||
|
<ng-container *ngFor="let alert of service.alerts$ | async; let i = index"> |
||||
|
<div |
||||
|
class="alert alert-{{ alert.type }} fade show" |
||||
|
[ngClass]="{ 'alert-dismissible fade show': alert.dismissible }" |
||||
|
role="alert" |
||||
|
> |
||||
|
<h4 class="alert-heading" *ngIf="alert.title"> |
||||
|
{{ alert.title | abpLocalization: alert.titleLocalizationParams }} |
||||
|
</h4> |
||||
|
{{ alert.message | abpLocalization: alert.messageLocalizationParams }} |
||||
|
<button |
||||
|
*ngIf="alert.dismissible" |
||||
|
type="button" |
||||
|
class="close" |
||||
|
data-dismiss="alert" |
||||
|
aria-label="Close" |
||||
|
(click)="service.remove(i)" |
||||
|
> |
||||
|
<span aria-hidden="true">×</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</ng-container> |
||||
@ -0,0 +1,11 @@ |
|||||
|
import { Component, ViewEncapsulation } from '@angular/core'; |
||||
|
import { PageAlertService } from '@abp/ng.theme.shared'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'abp-page-alert-container', |
||||
|
templateUrl: './page-alert-container.component.html', |
||||
|
encapsulation: ViewEncapsulation.None, |
||||
|
}) |
||||
|
export class PageAlertContainerComponent { |
||||
|
constructor(public service: PageAlertService) {} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
import { Injectable } from '@angular/core'; |
||||
|
import { InternalStore } from '@abp/ng.core'; |
||||
|
|
||||
|
export type PageAlert = { |
||||
|
type: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark'; |
||||
|
message: string; |
||||
|
dismissible?: boolean; |
||||
|
title?: string; |
||||
|
messageLocalizationParams?: string[]; |
||||
|
titleLocalizationParams?: string[]; |
||||
|
}; |
||||
|
|
||||
|
@Injectable({ providedIn: 'root' }) |
||||
|
export class PageAlertService { |
||||
|
private alerts = new InternalStore<PageAlert[]>([]); |
||||
|
|
||||
|
alerts$ = this.alerts.sliceState(state => state); |
||||
|
|
||||
|
constructor() {} |
||||
|
|
||||
|
show(alert: PageAlert) { |
||||
|
const newAlert: PageAlert = { |
||||
|
...alert, |
||||
|
dismissible: alert.dismissible ?? true, |
||||
|
}; |
||||
|
this.alerts.set([newAlert, ...this.alerts.state]); |
||||
|
} |
||||
|
|
||||
|
remove(index: number) { |
||||
|
const alerts = [...this.alerts.state]; |
||||
|
alerts.splice(index, 1); |
||||
|
this.alerts.set(alerts); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue