mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-7386] remove material module dependency and components conversion to standalone (#9595)
This commit is contained in:
@@ -17,16 +17,18 @@
|
|||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-add-notification-storybook',
|
selector: 'adf-add-notification-storybook',
|
||||||
template: `<button mat-raised-button (click)="showInfo()">Add Notification</button>`
|
standalone: true,
|
||||||
|
imports: [MatButtonModule],
|
||||||
|
template: ` <button mat-raised-button (click)="showInfo()">Add Notification</button>`
|
||||||
})
|
})
|
||||||
export class AddNotificationStorybookComponent {
|
export class AddNotificationStorybookComponent {
|
||||||
|
|
||||||
infoCounter: number = 1;
|
infoCounter: number = 1;
|
||||||
|
|
||||||
constructor(private notificationService: NotificationService) { }
|
constructor(private notificationService: NotificationService) {}
|
||||||
|
|
||||||
showInfo() {
|
showInfo() {
|
||||||
this.notificationService.showInfo(`Example notification ${this.infoCounter}`);
|
this.notificationService.showInfo(`Example notification ${this.infoCounter}`);
|
||||||
|
@@ -1,38 +1,34 @@
|
|||||||
<div (keyup)="onKeyPress($event)" tabindex="-1" role="button" class="adf-notification-history-container">
|
<div (keyup)="onKeyPress($event)" tabindex="-1" role="button" class="adf-notification-history-container">
|
||||||
<button
|
<button mat-button
|
||||||
mat-button
|
[matMenuTriggerFor]="menu"
|
||||||
[matMenuTriggerFor]="menu"
|
[attr.aria-label]="'NOTIFICATIONS.OPEN_HISTORY' | translate"
|
||||||
[attr.aria-label]="'NOTIFICATIONS.OPEN_HISTORY' | translate"
|
title="{{ 'NOTIFICATIONS.OPEN_HISTORY' | translate }}"
|
||||||
title="{{ 'NOTIFICATIONS.OPEN_HISTORY' | translate }}"
|
class="adf-notification-history-menu_button"
|
||||||
class="adf-notification-history-menu_button"
|
id="adf-notification-history-open-button"
|
||||||
id="adf-notification-history-open-button"
|
(menuOpened)="onMenuOpened()">
|
||||||
(menuOpened)="onMenuOpened()"
|
<mat-icon matBadge="⁠"
|
||||||
>
|
[matBadgeHidden]="!notifications.length"
|
||||||
<mat-icon matBadge="⁠" [matBadgeHidden]="!notifications.length" matBadgeColor="accent" matBadgeSize="small">notifications</mat-icon>
|
matBadgeColor="accent"
|
||||||
|
matBadgeSize="small">notifications
|
||||||
|
</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu
|
<mat-menu #menu="matMenu"
|
||||||
#menu="matMenu"
|
[xPosition]="menuPositionX"
|
||||||
[xPosition]="menuPositionX"
|
[yPosition]="menuPositionY"
|
||||||
[yPosition]="menuPositionY"
|
id="adf-notification-history-menu"
|
||||||
id="adf-notification-history-menu"
|
class="adf-notification-history-menu">
|
||||||
class="adf-notification-history-menu"
|
<div class="adf-notification-history-list"
|
||||||
>
|
role="button"
|
||||||
<div
|
tabindex="0"
|
||||||
class="adf-notification-history-list"
|
(keyup.enter)="$event.stopPropagation()"
|
||||||
role="button"
|
(click)="$event.stopPropagation()">
|
||||||
tabindex="0"
|
|
||||||
(keyup.enter)="$event.stopPropagation()"
|
|
||||||
(click)="$event.stopPropagation()"
|
|
||||||
>
|
|
||||||
<div mat-subheader role="menuitem">
|
<div mat-subheader role="menuitem">
|
||||||
<span>{{ 'NOTIFICATIONS.TITLE' | translate }}</span>
|
<span>{{ 'NOTIFICATIONS.TITLE' | translate }}</span>
|
||||||
<button
|
<button *ngIf="notifications.length"
|
||||||
*ngIf="notifications.length"
|
id="adf-notification-history-mark-as-read"
|
||||||
id="adf-notification-history-mark-as-read"
|
mat-icon-button
|
||||||
mat-icon-button
|
title="{{ 'NOTIFICATIONS.MARK_AS_READ' | translate }}"
|
||||||
title="{{ 'NOTIFICATIONS.MARK_AS_READ' | translate }}"
|
(click)="markAsRead()">
|
||||||
(click)="markAsRead()"
|
|
||||||
>
|
|
||||||
<mat-icon>done_all</mat-icon>
|
<mat-icon>done_all</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -41,26 +37,22 @@
|
|||||||
|
|
||||||
<mat-list role="menuitem">
|
<mat-list role="menuitem">
|
||||||
<ng-container *ngIf="notifications.length; else empty_list_template">
|
<ng-container *ngIf="notifications.length; else empty_list_template">
|
||||||
<mat-list-item
|
<mat-list-item *ngFor="let notification of paginatedNotifications"
|
||||||
*ngFor="let notification of paginatedNotifications"
|
class="adf-notification-history-menu-item"
|
||||||
class="adf-notification-history-menu-item"
|
(click)="onNotificationClick(notification)">
|
||||||
(click)="onNotificationClick(notification)"
|
<div *ngIf="notification.initiator; else no_avatar"
|
||||||
>
|
matListAvatar
|
||||||
<div
|
[outerHTML]="notification.initiator | usernameInitials : 'adf-notification-initiator-pic'"></div>
|
||||||
*ngIf="notification.initiator; else no_avatar"
|
|
||||||
matListAvatar
|
|
||||||
[outerHTML]="notification.initiator | usernameInitials : 'adf-notification-initiator-pic'"
|
|
||||||
></div>
|
|
||||||
<ng-template #no_avatar>
|
<ng-template #no_avatar>
|
||||||
<mat-icon mat-list-icon class="adf-notification-history-menu-initiator">{{ notification.icon }}</mat-icon>
|
<mat-icon mat-list-icon
|
||||||
|
class="adf-notification-history-menu-initiator">{{ notification.icon }}
|
||||||
|
</mat-icon>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<p
|
<p class="adf-notification-history-menu-text adf-notification-history-menu-message"
|
||||||
class="adf-notification-history-menu-text adf-notification-history-menu-message"
|
*ngFor="let message of notification.messages"
|
||||||
*ngFor="let message of notification.messages"
|
mat-line
|
||||||
mat-line
|
[matTooltip]="message"
|
||||||
[matTooltip]="message"
|
matTooltipShowDelay="{{ 1000 }}">
|
||||||
matTooltipShowDelay="1000"
|
|
||||||
>
|
|
||||||
{{ message }}
|
{{ message }}
|
||||||
</p>
|
</p>
|
||||||
<p class="adf-notification-history-menu-text adf-notification-history-menu-date" mat-line>
|
<p class="adf-notification-history-menu-text adf-notification-history-menu-date" mat-line>
|
||||||
@@ -69,7 +61,8 @@
|
|||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-template #empty_list_template>
|
<ng-template #empty_list_template>
|
||||||
<mat-list-item id="adf-notification-history-component-no-message" class="adf-notification-history-menu-no-message">
|
<mat-list-item id="adf-notification-history-component-no-message"
|
||||||
|
class="adf-notification-history-menu-no-message">
|
||||||
<p mat-line>{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}</p>
|
<p mat-line>{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}</p>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@@ -21,7 +21,7 @@ import { NotificationHistoryComponent } from './notification-history.component';
|
|||||||
import { OverlayContainer } from '@angular/cdk/overlay';
|
import { OverlayContainer } from '@angular/cdk/overlay';
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
import { StorageService } from '../../common/services/storage.service';
|
import { StorageService } from '../../common/services/storage.service';
|
||||||
import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model';
|
import { NOTIFICATION_TYPE, NotificationModel } from '../models/notification.model';
|
||||||
|
|
||||||
describe('Notification History Component', () => {
|
describe('Notification History Component', () => {
|
||||||
let fixture: ComponentFixture<NotificationHistoryComponent>;
|
let fixture: ComponentFixture<NotificationHistoryComponent>;
|
||||||
|
@@ -15,23 +15,44 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, ViewChild, OnDestroy, OnInit, AfterViewInit, ChangeDetectorRef, ViewEncapsulation } from '@angular/core';
|
import { AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model';
|
import { NOTIFICATION_TYPE, NotificationModel } from '../models/notification.model';
|
||||||
import { MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/menu';
|
import { MatMenuModule, MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/menu';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
import { StorageService } from '../../common/services/storage.service';
|
import { StorageService } from '../../common/services/storage.service';
|
||||||
import { PaginationModel } from '../../models/pagination.model';
|
import { PaginationModel } from '../../models/pagination.model';
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
|
import { MatBadgeModule } from '@angular/material/badge';
|
||||||
|
import { MatListModule } from '@angular/material/list';
|
||||||
|
import { NgForOf, NgIf } from '@angular/common';
|
||||||
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||||
|
import { InitialUsernamePipe, TimeAgoPipe } from '../../pipes';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-notification-history',
|
selector: 'adf-notification-history',
|
||||||
|
standalone: true,
|
||||||
templateUrl: 'notification-history.component.html',
|
templateUrl: 'notification-history.component.html',
|
||||||
styleUrls: ['./notification-history.component.scss'],
|
styleUrls: ['./notification-history.component.scss'],
|
||||||
|
imports: [
|
||||||
|
MatButtonModule,
|
||||||
|
MatMenuModule,
|
||||||
|
TranslateModule,
|
||||||
|
MatIconModule,
|
||||||
|
MatBadgeModule,
|
||||||
|
MatListModule,
|
||||||
|
NgIf,
|
||||||
|
NgForOf,
|
||||||
|
MatTooltipModule,
|
||||||
|
TimeAgoPipe,
|
||||||
|
InitialUsernamePipe
|
||||||
|
],
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterViewInit {
|
export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterViewInit {
|
||||||
|
|
||||||
public static MAX_NOTIFICATION_STACK_LENGTH = 100;
|
public static MAX_NOTIFICATION_STACK_LENGTH = 100;
|
||||||
public static NOTIFICATION_STORAGE = 'notification-history';
|
public static NOTIFICATION_STORAGE = 'notification-history';
|
||||||
|
|
||||||
@@ -55,24 +76,17 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
|
|||||||
paginatedNotifications: NotificationModel[] = [];
|
paginatedNotifications: NotificationModel[] = [];
|
||||||
pagination: PaginationModel;
|
pagination: PaginationModel;
|
||||||
|
|
||||||
constructor(
|
constructor(private notificationService: NotificationService, public storageService: StorageService, public cd: ChangeDetectorRef) {}
|
||||||
private notificationService: NotificationService,
|
|
||||||
public storageService: StorageService,
|
|
||||||
public cd: ChangeDetectorRef) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.notifications = JSON.parse(this.storageService.getItem(NotificationHistoryComponent.NOTIFICATION_STORAGE)) || [];
|
this.notifications = JSON.parse(this.storageService.getItem(NotificationHistoryComponent.NOTIFICATION_STORAGE)) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.notificationService.notifications$
|
this.notificationService.notifications$.pipe(takeUntil(this.onDestroy$)).subscribe((notification: NotificationModel) => {
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
this.addNewNotification(notification);
|
||||||
.subscribe((notification: NotificationModel) => {
|
this.cd.detectChanges();
|
||||||
this.addNewNotification(notification);
|
});
|
||||||
this.cd.detectChanges();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
@@ -92,9 +106,10 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveNotifications() {
|
saveNotifications() {
|
||||||
this.storageService.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify(this.notifications.filter((notification) =>
|
this.storageService.setItem(
|
||||||
notification.type !== NOTIFICATION_TYPE.RECURSIVE
|
NotificationHistoryComponent.NOTIFICATION_STORAGE,
|
||||||
)));
|
JSON.stringify(this.notifications.filter((notification) => notification.type !== NOTIFICATION_TYPE.RECURSIVE))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuOpened() {
|
onMenuOpened() {
|
||||||
|
@@ -15,30 +15,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { MaterialModule } from '../material.module';
|
|
||||||
import { PipeModule } from '../pipes/pipe.module';
|
|
||||||
import { NotificationHistoryComponent } from './components/notification-history.component';
|
import { NotificationHistoryComponent } from './components/notification-history.component';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { PaginationModule } from '../pagination/pagination.module';
|
|
||||||
import { AddNotificationStorybookComponent } from './components/add-notification.stories.component';
|
import { AddNotificationStorybookComponent } from './components/add-notification.stories.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [NotificationHistoryComponent, AddNotificationStorybookComponent],
|
||||||
CommonModule,
|
exports: [NotificationHistoryComponent, AddNotificationStorybookComponent]
|
||||||
MaterialModule,
|
|
||||||
TranslateModule,
|
|
||||||
PipeModule,
|
|
||||||
PaginationModule
|
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
NotificationHistoryComponent,
|
|
||||||
AddNotificationStorybookComponent
|
|
||||||
],
|
|
||||||
exports: [
|
|
||||||
NotificationHistoryComponent,
|
|
||||||
AddNotificationStorybookComponent
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
export class NotificationHistoryModule { }
|
export class NotificationHistoryModule {}
|
||||||
|
Reference in New Issue
Block a user