border-top: 4px solid $color-nav-top-bar;
&.isPwdDisplayed {
- top: $pwd-exp-height;
+ top: $top-notification-height;
}
.navbar-brand,
}
/* ---------------------------------------------------
- isPwdDisplayed
+ topNotification settings
--------------------------------------------------- */
-:host.isPwdDisplayed {
- .cd-navbar-top .cd-navbar-brand {
- top: $pwd-exp-height;
- }
- #sidebar {
- top: $navbar-height + $pwd-exp-height;
- }
+@for $i from 1 through 2 {
+ :host.top-notification-#{$i} {
+ .cd-navbar-top .cd-navbar-brand {
+ top: $top-notification-height * $i;
+ }
- #content {
- top: $navbar-height + $pwd-exp-height;
- }
+ #sidebar {
+ top: $navbar-height + $top-notification-height * $i;
+ }
+
+ #content {
+ top: $navbar-height + $top-notification-height * $i;
+ }
- cd-notifications-sidebar {
- top: $navbar-height + $pwd-exp-height + 10px;
+ cd-notifications-sidebar {
+ top: $navbar-height + $top-notification-height * $i + 10px;
+ }
}
}
});
}
});
+
+ describe('showTopNotification', () => {
+ const notification1 = 'notificationName1';
+ const notification2 = 'notificationName2';
+
+ beforeEach(() => {
+ component.notifications = [];
+ });
+
+ it('should show notification', () => {
+ component.showTopNotification(notification1, true);
+ expect(component.notifications.includes(notification1)).toBeTruthy();
+ expect(component.notifications.length).toBe(1);
+ });
+
+ it('should not add a second notification if it is already shown', () => {
+ component.showTopNotification(notification1, true);
+ component.showTopNotification(notification1, true);
+ expect(component.notifications.includes(notification1)).toBeTruthy();
+ expect(component.notifications.length).toBe(1);
+ });
+
+ it('should add a second notification if the first one is different', () => {
+ component.showTopNotification(notification1, true);
+ component.showTopNotification(notification2, true);
+ expect(component.notifications.includes(notification1)).toBeTruthy();
+ expect(component.notifications.includes(notification2)).toBeTruthy();
+ expect(component.notifications.length).toBe(2);
+ });
+
+ it('should hide an active notification', () => {
+ component.showTopNotification(notification1, true);
+ expect(component.notifications.includes(notification1)).toBeTruthy();
+ expect(component.notifications.length).toBe(1);
+ component.showTopNotification(notification1, false);
+ expect(component.notifications.length).toBe(0);
+ });
+
+ it('should not fail if it tries to hide an inactive notification', () => {
+ expect(() => component.showTopNotification(notification1, false)).not.toThrow();
+ expect(component.notifications.length).toBe(0);
+ });
+
+ it('should keep other notifications if it hides one', () => {
+ component.showTopNotification(notification1, true);
+ component.showTopNotification(notification2, true);
+ expect(component.notifications.length).toBe(2);
+ component.showTopNotification(notification2, false);
+ expect(component.notifications.length).toBe(1);
+ expect(component.notifications.includes(notification1)).toBeTruthy();
+ });
+ });
});
styleUrls: ['./navigation.component.scss']
})
export class NavigationComponent implements OnInit, OnDestroy {
- @HostBinding('class.isPwdDisplayed') isPwdDisplayed = false;
+ notifications: string[] = [];
+ @HostBinding('class') get class(): string {
+ return 'top-notification-' + this.notifications.length;
+ }
permissions: Permissions;
enabledFeature$: FeatureTogglesMap$;
this.summaryData = summary;
})
);
+ /*
+ Note: If you're going to add more top notifications please do not forget to increase
+ the number of generated css-classes in section topNotification settings in the scss
+ file.
+ */
this.subs.add(
this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
- this.isPwdDisplayed = isDisplayed;
+ this.showTopNotification('isPwdDisplayed', isDisplayed);
})
);
}
this.displayedSubMenu = menu;
}
}
+
+ showTopNotification(name: string, isDisplayed: boolean) {
+ if (isDisplayed) {
+ if (!this.notifications.includes(name)) {
+ this.notifications.push(name);
+ }
+ } else {
+ const index = this.notifications.indexOf(name);
+ if (index >= 0) {
+ this.notifications.splice(index, 1);
+ }
+ }
+ }
}
<alert class="no-margin-bottom"
type="{{ alertType }}"
- *ngIf="expirationDays != null && expirationDays <= pwdExpirationSettings.pwdExpirationWarning1"
+ *ngIf="displayNotification"
[dismissible]="true"
(onClose)="close($event)">
<div *ngIf="expirationDays === 0"
alertType: string;
expirationDays: number;
pwdExpirationSettings: CdPwdExpirationSettings;
+ displayNotification = false;
constructor(
private settingsService: SettingsService,
} else {
this.alertType = 'warning';
}
-
+ this.displayNotification = true;
this.authStorageService.isPwdDisplayedSource.next(true);
}
});
close() {
this.authStorageService.isPwdDisplayedSource.next(false);
+ this.displayNotification = false;
}
}
$color-nav-border-top-collapse: $color-white-gray !default;
$navbar-height: 43px;
-$pwd-exp-height: 37.6px;
+$top-notification-height: 37.6px;
/*Helper*/
$color-helper-bg: $color-primary !default;