Skip to content

Commit 5b558dd

Browse files
4manasamanasatumms2021389
authored
Made changes to render Todo widget in banner using portalTemplate (#626)
* Made changes to render Todo widget in banner using portalTemplate --------- Co-authored-by: manasa <[email protected]> Co-authored-by: Siva Rama Krishna <[email protected]>
1 parent 85d6cf3 commit 5b558dd

File tree

8 files changed

+105
-31
lines changed

8 files changed

+105
-31
lines changed

src/app/_samples/mediaco/components/banner/banner.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<div class="background-image-style">
22
<div class="background-style content">
3-
<div>
3+
<div style="justify-content: center; display: inline-grid">
44
<h1 class="title" [innerHTML]="title"></h1>
55
<p class="message">{{ message }}</p>
6+
7+
<!-- The portal content will be rendered here -->
8+
<ng-container *cdkPortalOutlet="portal$ | async"></ng-container>
69
</div>
710
</div>
811
</div>

src/app/_samples/mediaco/components/banner/banner.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535

3636
.background-image-style {
37-
height: calc(18rem);
37+
height: calc(20rem);
3838
position: sticky;
3939
top: var(--mat-toolbar-standard-height, 64px);
4040
background: var(--mat-toolbar-container-background-color, var(--mat-sys-surface));

src/app/_samples/mediaco/components/banner/banner.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { CommonModule } from '@angular/common';
22
import { FormGroup } from '@angular/forms';
33
import { Component, Input, forwardRef } from '@angular/core';
4+
import { PortalModule, TemplatePortal } from '@angular/cdk/portal';
5+
import { Observable } from 'rxjs';
6+
import { delay } from 'rxjs/operators';
47
import { ComponentMapperComponent } from '@pega/angular-sdk-components';
8+
import { PortalService } from '../../services/portal.service';
59

610
@Component({
711
selector: 'app-banner',
812
templateUrl: './banner.component.html',
913
styleUrls: ['./banner.component.scss'],
10-
imports: [CommonModule, forwardRef(() => ComponentMapperComponent)]
14+
imports: [CommonModule, PortalModule, forwardRef(() => ComponentMapperComponent)]
1115
})
1216
export class BannerComponent {
1317
@Input() pConn$: typeof PConnect;
@@ -20,6 +24,14 @@ export class BannerComponent {
2024
@Input() backgroundImage: string;
2125
@Input() layout$: string;
2226

27+
portal$: Observable<TemplatePortal<any> | null>;
28+
29+
constructor(private portalService: PortalService) {}
30+
31+
ngOnInit() {
32+
this.portal$ = this.portalService.getPortal().pipe(delay(0));
33+
}
34+
2335
getUrl() {
2436
return `url(${this.backgroundImage})`;
2537
}

src/app/_samples/mediaco/components/list-view/list-view.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class ListViewComponent implements OnInit {
7474
.getDataAsync(this.referenceDataPage, this.pConn$.getContextName())
7575
.then(({ data }) => {
7676
this.modifyListData(data);
77-
console.log(data);
7877
});
7978
}
8079

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
<div *ngIf="surveyCase">
2-
<div class="banner-container">
3-
<div class="icon-wrapper">
4-
<div class="icon-box">
5-
<img class="quick-link-icon" [src]="img" />
1+
<app-todo
2+
*ngIf="!isMyWorklistChecked"
3+
[pConn$]="pConn$"
4+
[caseInfoID$]="caseInfoID$"
5+
[datasource$]="datasource$"
6+
[showTodoList$]="showTodoList$"
7+
[headerText$]="headerText$"
8+
type$="TODO"
9+
[context$]="context$"
10+
isConfirm="true"
11+
>
12+
</app-todo>
13+
<ng-template #mediacoTodo>
14+
<div *ngIf="surveyCase">
15+
<div class="banner-container">
16+
<div class="icon-wrapper">
17+
<div class="icon-box">
18+
<img class="quick-link-icon" [src]="img" />
19+
</div>
20+
</div>
21+
<div class="content-text">
22+
<h2>Share Your Experience</h2>
23+
<p>Take a quick survey about your recent experience with MediaCo.</p>
24+
</div>
25+
<div class="action-wrapper">
26+
<button (click)="clickGo(surveyCase)" class="start-btn">
27+
Start
28+
<mat-icon>arrow_forward</mat-icon>
29+
</button>
630
</div>
7-
</div>
8-
<div class="content-text">
9-
<h2>Share Your Experience</h2>
10-
<p>Take a quick survey about your recent experience with MediaCo.</p>
11-
</div>
12-
<div class="action-wrapper">
13-
<button (click)="clickGo(surveyCase)" class="start-btn">
14-
Start
15-
<mat-icon>arrow_forward</mat-icon>
16-
</button>
1731
</div>
1832
</div>
19-
</div>
33+
</ng-template>

src/app/_samples/mediaco/components/todo/todo.component.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $text-white: #ffffff;
44
$btn-text-color: #5c4498;
55

66
.banner-container {
7+
width: 670px;
78
font-family: $font-family;
89
background: linear-gradient(135deg, rgb(103, 80, 164) 0%, rgb(248, 20, 227) 50%, rgb(0, 201, 255) 100%) 0% 0% / 200% 200%;
910

@@ -20,11 +21,6 @@ $btn-text-color: #5c4498;
2021
text-align: center;
2122
padding: 32px 24px;
2223
}
23-
24-
position: absolute;
25-
z-index: 10;
26-
left: 30%;
27-
top: 15rem;
2824
}
2925

3026
.icon-wrapper {
@@ -46,7 +42,7 @@ $btn-text-color: #5c4498;
4642
flex-grow: 1;
4743
display: flex;
4844
flex-direction: column;
49-
justify-content: center;
45+
align-items: flex-start;
5046

5147
h2 {
5248
margin: 0 0 6px 0;

src/app/_samples/mediaco/components/todo/todo.component.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
1+
import { Component, OnInit, OnDestroy, Input, ViewContainerRef, ViewChild, TemplateRef } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3+
import { TemplatePortal } from '@angular/cdk/portal';
34
import { MatIcon } from '@angular/material/icon';
45
import { publicConstants } from '@pega/pcore-pconnect-typedefs/constants';
5-
import { ProgressSpinnerService } from '@pega/angular-sdk-components';
6+
import { ProgressSpinnerService, TodoComponent as OOTBTodoComponent } from '@pega/angular-sdk-components';
67
import { ErrorMessagesService } from '@pega/angular-sdk-components';
78
import { Utils } from '@pega/angular-sdk-components';
89
import { updateWorkList } from '@pega/angular-sdk-components';
10+
import { PortalService } from '../../services/portal.service';
911

1012
const fetchMyWorkList = (datapage, fields, numberOfRecords, includeTotalCount, context) => {
1113
return PCore.getDataPageUtils()
@@ -57,13 +59,14 @@ interface ToDoProps {
5759
myWorkList?: any;
5860
label?: string;
5961
readOnly?: boolean;
62+
isMyWorklistChecked?: boolean;
6063
}
6164

6265
@Component({
63-
selector: 'app-todo',
66+
selector: 'app-mediaco-todo',
6467
templateUrl: './todo.component.html',
6568
styleUrls: ['./todo.component.scss'],
66-
imports: [CommonModule, MatIcon]
69+
imports: [CommonModule, MatIcon, OOTBTodoComponent]
6770
})
6871
export class TodoComponent implements OnInit, OnDestroy {
6972
img = this.utils.getImageSrc('message-circle', this.utils.getSDKStaticContentUrl());
@@ -84,7 +87,12 @@ export class TodoComponent implements OnInit, OnDestroy {
8487
CONSTS: typeof publicConstants;
8588
bLogging = true;
8689
surveyCase: any[];
90+
isMyWorklistChecked: boolean | undefined;
91+
@ViewChild('mediacoTodo', { read: TemplateRef }) private mediacoTodoTemplate: TemplateRef<any>;
92+
8793
constructor(
94+
private portalService: PortalService,
95+
private viewContainerRef: ViewContainerRef,
8896
private psService: ProgressSpinnerService,
8997
private erService: ErrorMessagesService,
9098
private utils: Utils
@@ -101,12 +109,22 @@ export class TodoComponent implements OnInit, OnDestroy {
101109
this.updateToDo();
102110
}
103111

112+
ngAfterViewInit() {
113+
// Create a TemplatePortal from the template and its view context
114+
const portal = new TemplatePortal(this.mediacoTodoTemplate, this.viewContainerRef);
115+
116+
// Set the portal in the shared service
117+
this.portalService.setPortal(portal);
118+
}
119+
104120
ngOnDestroy() {
105121
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED } = PCore.getEvents().getCaseEvent();
106122

107123
PCore.getPubSubUtils().unsubscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, 'updateToDo');
108124
PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_SAVED, CREATE_STAGE_SAVED);
109125
PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_DELETED, CREATE_STAGE_DELETED);
126+
127+
this.portalService.clearPortal();
110128
}
111129

112130
updateList() {
@@ -120,7 +138,7 @@ export class TodoComponent implements OnInit, OnDestroy {
120138

121139
updateToDo() {
122140
this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as ToDoProps;
123-
141+
this.isMyWorklistChecked = this.configProps$?.isMyWorklistChecked;
124142
this.headerText$ = this.headerText$ || this.configProps$.headerText;
125143
this.datasource$ = this.datasource$ || this.configProps$.datasource;
126144
this.myWorkList$ = this.myWorkList$ || this.configProps$.myWorkList;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Injectable } from '@angular/core';
2+
import { TemplatePortal } from '@angular/cdk/portal';
3+
import { BehaviorSubject } from 'rxjs';
4+
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
export class PortalService {
9+
private portal$ = new BehaviorSubject<TemplatePortal<any> | null>(null);
10+
11+
/**
12+
* Sets the portal that should be rendered elsewhere.
13+
* @param portal The TemplatePortal to be shared.
14+
*/
15+
setPortal(portal: TemplatePortal<any>) {
16+
this.portal$.next(portal);
17+
}
18+
19+
/**
20+
* Clears the currently set portal.
21+
*/
22+
clearPortal() {
23+
this.portal$.next(null);
24+
}
25+
26+
/**
27+
* Returns the current portal as an observable.
28+
*/
29+
getPortal() {
30+
return this.portal$.asObservable();
31+
}
32+
}

0 commit comments

Comments
 (0)