-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f4bbb9
commit f1c2fe1
Showing
14 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/app/shared/components/notification/notification.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ng-container *ngFor="let notification of notificationService.notifications"> | ||
|
||
|
||
<cds-alert-group [status]="notification.type" type="banner"> | ||
<cds-alert closable (closeChange)="notificationService.removeNotification(notification)"> | ||
{{notification.message}} | ||
</cds-alert> | ||
</cds-alert-group> | ||
</ng-container> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/shared/components/notification/notification.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { NotificationComponent } from './notification.component'; | ||
|
||
describe('NotificationComponent', () => { | ||
let component: NotificationComponent; | ||
let fixture: ComponentFixture<NotificationComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ NotificationComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NotificationComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/shared/components/notification/notification.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NotificationService } from './notification.service'; | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'commandos-notification', | ||
templateUrl: './notification.component.html', | ||
styleUrls: ['./notification.component.scss'] | ||
}) | ||
export class NotificationComponent implements OnInit { | ||
|
||
constructor( | ||
public notificationService: NotificationService | ||
) { } | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/app/shared/components/notification/notification.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NotificationService } from './notification.service'; | ||
|
||
describe('NotificationService', () => { | ||
let service: NotificationService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NotificationService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/app/shared/components/notification/notification.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
type NotificationType = 'success' | 'error' | 'info' | 'warning'; | ||
type Notification = { type: NotificationType, message: string }; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NotificationService { | ||
|
||
notifications = new Set<Notification>(); | ||
|
||
constructor() { } | ||
|
||
|
||
// add a notification with a status and a message | ||
addNotification(status: NotificationType, message: string, timer: number = 5000) { | ||
const notification: Notification = { type: status, message: message }; | ||
|
||
this.notifications.add(notification); | ||
|
||
if (timer) { | ||
setTimeout(() => { | ||
this.notifications.delete(notification); | ||
}, timer); | ||
} | ||
} | ||
|
||
removeNotification(notification: Notification) { | ||
this.notifications.delete(notification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters