Skip to content

Commit a8421de

Browse files
[DSC-2059] remove async functions calls from templates of cris item pages and context menus
1 parent 60764b4 commit a8421de

47 files changed

Lines changed: 203 additions & 168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/cris-layout/cris-layout-loader/cris-layout-horizontal/cris-layout-navbar/cris-layout-navbar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<button *ngIf="(windowService.isXsOrSm() | async) && showNav" class="navbar-toggler pl-2 float-right" type="button" (click)="toggleNavbar()"
1+
<button *ngIf="(isXsOrSm$ | async) && showNav" class="navbar-toggler pl-2 float-right" type="button" (click)="toggleNavbar()"
22
aria-controls="collapsingNav" aria-expanded="false" [attr.aria-label]="'nav.toggle' | translate">
33
<span class="navbar-toggler-icon fas fa-bars fa-fw" aria-hidden="true"></span>
44
</button>

src/app/cris-layout/cris-layout-loader/cris-layout-horizontal/cris-layout-navbar/cris-layout-navbar.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
TranslateLoader,
1414
TranslateModule,
1515
} from '@ngx-translate/core';
16-
import { BehaviorSubject } from 'rxjs';
16+
import {
17+
BehaviorSubject,
18+
of,
19+
} from 'rxjs';
1720

1821
import { CrisLayoutTab } from '../../../../core/layout/models/tab.model';
1922
import { Item } from '../../../../core/shared/item.model';
@@ -101,6 +104,7 @@ describe('CrisLayoutNavbarComponent', () => {
101104
component.tabs = loaderMultilevelTabs;
102105
component.item = mockItem;
103106
component.activeTab$ = new BehaviorSubject<CrisLayoutTab>(loaderMultilevelTabs[0]);
107+
component.isXsOrSm$ = of(true);
104108
component.ngOnInit();
105109
fixture.detectChanges();
106110
});
@@ -114,6 +118,7 @@ describe('CrisLayoutNavbarComponent', () => {
114118

115119
beforeEach(() => {
116120
windowServiceStub.setWidth(400);
121+
component.ngOnInit();
117122
fixture.detectChanges();
118123
});
119124

src/app/cris-layout/cris-layout-loader/cris-layout-horizontal/cris-layout-navbar/cris-layout-navbar.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Output,
1414
} from '@angular/core';
1515
import { TranslateModule } from '@ngx-translate/core';
16+
import { Observable } from 'rxjs';
1617

1718
import { CrisLayoutTab } from '../../../../core/layout/models/tab.model';
1819
import { Item } from '../../../../core/shared/item.model';
@@ -59,8 +60,11 @@ export class CrisLayoutNavbarComponent extends CrisLayoutTabsComponent implement
5960

6061
windowService = inject(HostWindowService);
6162

63+
isXsOrSm$: Observable<boolean>;
64+
6265
ngOnInit(): void {
6366
this.init();
67+
this.isXsOrSm$ = this.windowService.isXsOrSm();
6468
}
6569

6670
emitSelected(selectedTab) {

src/app/cris-layout/cris-layout-loader/cris-layout-vertical/cris-layout-sidebar/cris-layout-sidebar.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<div class="wrapper d-flex align-items-stretch" [ngClass]="{'wrapper-close': (isSideBarHidden() | async) !== true,
2-
'container': (hasSidebar() | async) }">
3-
<nav id="sidebar" *ngIf="(hasSidebar() | async) && (isSideBarHidden() | async) !== true && showNav" [ngClass]="{'active': (isSideBarHidden() | async) !== true}">
1+
<div class="wrapper d-flex align-items-stretch" [ngClass]="{'wrapper-close': (isSideBarHidden$ | async) !== true,
2+
'container': (hasSidebar$ | async) }">
3+
<nav id="sidebar" *ngIf="(hasSidebar$ | async) && (isSideBarHidden$ | async) !== true && showNav" [ngClass]="{'active': (isSideBarHidden$ | async) !== true}">
44
<div>
55
<ul class="list-unstyled components mb-5">
66
<ng-container *ngIf="!!(activeTab$ |async)">
@@ -11,17 +11,17 @@
1111
</div>
1212
</nav>
1313
<div id="content" class="position-relative w-100 pr-0 pt-3 pb-3" [ngClass]="{
14-
'p-0': (hasSidebar() | async) !== true,
15-
'pl-3': (isSideBarHidden() | async) !== true,
16-
'pl-0': (isSideBarHidden() | async) === true
14+
'p-0': (hasSidebar$ | async) !== true,
15+
'pl-3': (isSideBarHidden$ | async) !== true,
16+
'pl-0': (isSideBarHidden$ | async) === true
1717
}">
1818

19-
<div *ngIf="(hasSidebar() | async)">
19+
<div *ngIf="(hasSidebar$ | async)">
2020
<button type="button" class="btn btn-link menu-toggle" (click)="toggleSidebar()">
21-
<i class="fa fa-chevron-circle-{{(isSideBarHidden() | async) ? 'right' : 'left'}} fa-2x" aria-hidden="true"></i>
21+
<i class="fa fa-chevron-circle-{{(isSideBarHidden$ | async) ? 'right' : 'left'}} fa-2x" aria-hidden="true"></i>
2222
</button>
2323
</div>
24-
<div class="d-flex flex-column" [ngClass]="{'pl-4': (hasSidebar() | async)}">
24+
<div class="d-flex flex-column" [ngClass]="{'pl-4': (hasSidebar$ | async)}">
2525
<ng-content></ng-content>
2626
</div>
2727

src/app/cris-layout/cris-layout-loader/cris-layout-vertical/cris-layout-sidebar/cris-layout-sidebar.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ export class CrisLayoutSidebarComponent extends CrisLayoutTabsComponent implemen
6060
/**
6161
* A boolean representing if to render or not the sidebar menu
6262
*/
63-
private hasSidebar$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
63+
hasSidebar$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
6464

6565
/**
6666
* This parameter define the status of sidebar (hide/show)
6767
*/
6868
private sidebarStatus$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
6969

70+
isSideBarHidden$: Observable<boolean>;
7071

7172
ngOnInit(): void {
7273
this.init();
@@ -79,6 +80,7 @@ export class CrisLayoutSidebarComponent extends CrisLayoutTabsComponent implemen
7980

8081
// Init the sidebar status
8182
this.sidebarStatus$.next(this.hasSidebar$.value);
83+
this.isSideBarHidden$ = this.isSideBarHidden();
8284
}
8385

8486
/**

src/app/cris-layout/cris-layout-loader/cris-layout-vertical/cris-layout-vertical.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="cris-layout-loader">
2-
<div *ngIf="(windowService.isXsOrSm() | async) !== true" class="vertical-layout">
2+
<div *ngIf="(isXsOrSm$ | async) !== true" class="vertical-layout">
33
<ds-cris-layout-sidebar (selectedTabChange)="selectedTabChanged($event)" [showNav]="tabs.length > 1" [tabs]="tabs" [item]="item">
44
<div *ngIf="showContextMenu" class="container text-right mb-3" [class.px-0]="tabs?.length > 1">
55
<ds-context-menu [contextMenuObject]="item" [contextMenuObjectType]="'ITEM'"></ds-context-menu>
@@ -8,7 +8,7 @@
88
</ds-cris-layout-sidebar>
99
</div>
1010

11-
<div *ngIf="(windowService.isXsOrSm() | async)" class="horizontal-layout">
11+
<div *ngIf="(isXsOrSm$ | async)" class="horizontal-layout">
1212
<ds-cris-layout-navbar [showNav]="(tabs.length - leadingTabs.length) > 1" (selectedTabChange)="selectedTabChanged($event)"
1313
[tabs]="tabs" [item]="item"></ds-cris-layout-navbar>
1414
<div class="container pt-4">

src/app/cris-layout/cris-layout-loader/cris-layout-vertical/cris-layout-vertical.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
Component,
77
Input,
88
} from '@angular/core';
9-
import { BehaviorSubject } from 'rxjs';
9+
import {
10+
BehaviorSubject,
11+
Observable,
12+
} from 'rxjs';
1013

1114
import { CrisLayoutTab } from '../../../core/layout/models/tab.model';
1215
import { Item } from '../../../core/shared/item.model';
@@ -54,8 +57,10 @@ export class CrisLayoutVerticalComponent {
5457

5558

5659
selectedTab$: BehaviorSubject<CrisLayoutTab> = new BehaviorSubject<CrisLayoutTab>(null);
60+
isXsOrSm$: Observable<boolean>;
5761

5862
constructor(public windowService: HostWindowService) {
63+
this.isXsOrSm$ = this.windowService.isXsOrSm();
5964
}
6065

6166
selectedTabChanged(tab: CrisLayoutTab) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ng-container *ngFor="let metric of metricRow.metrics">
22
<ng-container *ngIf="metric">
33
<ds-metric-loader [metric]="metric"
4-
[class.d-none]="(isHidden(metric.id) | async)"
4+
[class.d-none]="isHidden(metric.id)"
55
(hide)="toggleVisibility(metric.id, $event)"></ds-metric-loader>
66
</ng-container>
77
</ng-container>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/metric-row/metric-row.component.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
Component,
88
Input,
99
} from '@angular/core';
10-
import {
11-
BehaviorSubject,
12-
Observable,
13-
of,
14-
} from 'rxjs';
10+
import { BehaviorSubject } from 'rxjs';
1511

1612
import { CrisLayoutMetricRow } from '../../../../../../core/layout/models/tab.model';
1713
import { MetricLoaderComponent } from '../../../../../../shared/metric/metric-loader/metric-loader.component';
@@ -46,11 +42,11 @@ export class MetricRowComponent {
4642
this.isVisible$.next(newMap);
4743
}
4844

49-
isHidden(metricId): Observable<boolean> {
45+
isHidden(metricId): boolean {
5046
if (this.isVisible$.value.has(metricId)) {
51-
return of(this.isVisible$.value.get(metricId));
47+
return this.isVisible$.value.get(metricId);
5248
} else {
53-
return of(false);
49+
return false;
5450
}
5551
}
5652
}

src/app/item-page/alerts/item-alerts.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<span class="align-self-center">{{'item.alerts.withdrawn' | translate}}</span>
99
<div class="gap-2 d-flex">
1010
<a *ngIf="(isAdministrator$ | async) !== true" routerLink="/home" class="btn btn-primary btn-sm">{{"404.link.home-page" | translate}}</a>
11-
<a *ngIf="showReinstateButton$() | async" class="btn btn-primary btn-sm" (click)="openReinstateModal()">{{ 'item.alerts.reinstate-request' | translate}}</a>
11+
<a *ngIf="showReinstateButton$ | async" class="btn btn-primary btn-sm" (click)="openReinstateModal()">{{ 'item.alerts.reinstate-request' | translate}}</a>
1212
</div>
1313
</div>
1414
</ds-alert>

0 commit comments

Comments
 (0)