Skip to content

Commit 4ef7ff2

Browse files
author
manasa
committed
Made changes to render Todo widget in banner using portalTemplate
1 parent 638c0fd commit 4ef7ff2

File tree

8 files changed

+59
-43
lines changed

8 files changed

+59
-43
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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+
<ng-template [cdkPortalOutlet]="templatePortal$ | async"></ng-template>
67
</div>
78
</div>
89
</div>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { CommonModule } from '@angular/common';
22
import { FormGroup } from '@angular/forms';
33
import { Component, Input, forwardRef } from '@angular/core';
44
import { ComponentMapperComponent } from '@pega/angular-sdk-components';
5+
import { PortalModule } from '@angular/cdk/portal';
6+
import { TodoPortalService } from '../../services/todoportal.service';
57

68
@Component({
79
selector: 'app-banner',
810
templateUrl: './banner.component.html',
911
styleUrls: ['./banner.component.scss'],
10-
imports: [CommonModule, forwardRef(() => ComponentMapperComponent)]
12+
imports: [CommonModule, PortalModule, forwardRef(() => ComponentMapperComponent)]
1113
})
1214
export class BannerComponent {
1315
@Input() pConn$: typeof PConnect;
@@ -20,6 +22,13 @@ export class BannerComponent {
2022
@Input() backgroundImage: string;
2123
@Input() layout$: string;
2224

25+
public templatePortal$: any;
26+
constructor(private todoportalService: TodoPortalService) {}
27+
28+
ngOnInit() {
29+
this.templatePortal$ = this.todoportalService.portal$;
30+
}
31+
2332
getUrl() {
2433
return `url(${this.backgroundImage})`;
2534
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<app-todo
2-
*ngIf="!isMyWorklistChecked; else mediacoTodo"
2+
*ngIf="!isMyWorklistChecked"
33
[pConn$]="pConn$"
44
[caseInfoID$]="caseInfoID$"
55
[datasource$]="datasource$"
@@ -8,15 +8,11 @@
88
type$="TODO"
99
[context$]="context$"
1010
isConfirm="true"
11-
></app-todo>
11+
>
12+
</app-todo>
1213
<ng-template #mediacoTodo>
1314
<div *ngIf="surveyCase">
14-
<div
15-
class="banner-container"
16-
[ngStyle]="{
17-
left: navbar.isCollapsed() ? '32%' : '37%'
18-
}"
19-
>
15+
<div class="banner-container">
2016
<div class="icon-wrapper">
2117
<div class="icon-box">
2218
<img class="quick-link-icon" [src]="img" />

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: fixed;
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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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';
33
import { MatIcon } from '@angular/material/icon';
44
import { publicConstants } from '@pega/pcore-pconnect-typedefs/constants';
55
import { ProgressSpinnerService, TodoComponent as OOTBTodoComponent } from '@pega/angular-sdk-components';
66
import { ErrorMessagesService } from '@pega/angular-sdk-components';
77
import { Utils } from '@pega/angular-sdk-components';
88
import { updateWorkList } from '@pega/angular-sdk-components';
9-
import { NavbarService } from '../../services/navbar.service';
9+
import { TemplatePortal } from '@angular/cdk/portal';
10+
import { TodoPortalService } from '../../services/todoportal.service';
1011

1112
const fetchMyWorkList = (datapage, fields, numberOfRecords, includeTotalCount, context) => {
1213
return PCore.getDataPageUtils()
@@ -87,11 +88,14 @@ export class TodoComponent implements OnInit, OnDestroy {
8788
bLogging = true;
8889
surveyCase: any[];
8990
isMyWorklistChecked: boolean | undefined;
91+
@ViewChild('mediacoTodo') private mediacoTodoTemplate: TemplateRef<any>;
92+
9093
constructor(
94+
private todoportalService: TodoPortalService,
95+
private viewContainerRef: ViewContainerRef,
9196
private psService: ProgressSpinnerService,
9297
private erService: ErrorMessagesService,
93-
private utils: Utils,
94-
public navbar: NavbarService
98+
private utils: Utils
9599
) {}
96100

97101
ngOnInit() {
@@ -105,6 +109,14 @@ export class TodoComponent implements OnInit, OnDestroy {
105109
this.updateToDo();
106110
}
107111

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.todoportalService.setPortal(portal);
118+
}
119+
108120
ngOnDestroy() {
109121
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED } = PCore.getEvents().getCaseEvent();
110122

src/app/_samples/mediaco/components/wss-nav-bar/wss-nav-bar.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { AngularPConnectData, AngularPConnectService, ComponentMapperComponent }
1111
import { logout } from '@pega/auth/lib/sdk-auth-manager';
1212
import { Utils } from '@pega/angular-sdk-components';
1313
import { FooterComponent } from 'src/app/_samples/mediaco/components/footer/footer.component';
14-
import { NavbarService } from '../../services/navbar.service';
1514

1615
// interface WssNavBarProps {
1716
// // If any, enter additional props that only exist on this component
@@ -75,8 +74,7 @@ export class WssNavBarComponent implements OnInit, OnDestroy {
7574
// private cdRef: ChangeDetectorRef,
7675
// private psService: ProgressSpinnerService,
7776
private ngZone: NgZone,
78-
private utils: Utils,
79-
private navbarService: NavbarService
77+
private utils: Utils
8078
) {}
8179

8280
ngOnInit(): void {
@@ -165,7 +163,6 @@ export class WssNavBarComponent implements OnInit, OnDestroy {
165163

166164
toggleMenu() {
167165
this.collapsed = !this.collapsed;
168-
this.navbarService.toggleCollapse();
169166
}
170167

171168
// navPanelCreateButtonClick() {

src/app/_samples/mediaco/services/navbar.service.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// portal.service.ts
2+
import { Injectable } from '@angular/core';
3+
import { TemplatePortal } from '@angular/cdk/portal';
4+
import { BehaviorSubject, Observable } from 'rxjs';
5+
6+
@Injectable({
7+
providedIn: 'root'
8+
})
9+
export class TodoPortalService {
10+
private portalSource = new BehaviorSubject<TemplatePortal<any> | null>(null);
11+
12+
/**
13+
* An observable that components can subscribe to, to get the portal.
14+
*/
15+
public portal$: Observable<TemplatePortal<any> | null> = this.portalSource.asObservable();
16+
17+
/**
18+
* Sets the portal that should be rendered elsewhere.
19+
* @param portal The TemplatePortal to be shared.
20+
*/
21+
setPortal(portal: TemplatePortal<any>) {
22+
this.portalSource.next(portal);
23+
}
24+
}

0 commit comments

Comments
 (0)