Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mashup code cleanup changes #256

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export const endpoints = {
// loginExperience: loginBoxType.Main
// },

SP_VERSION: '1.00',

AUTH: '/v1/authenticate',
CASES: '/v1/cases',
CASES_V2: '/application/v2/cases',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="progress-box" *ngIf="isProgress$">
<mat-spinner class="progress-spinner"></mat-spinner>
</div>

<div *ngIf="bLoggedIn$; else loading">
<app-header></app-header>
<app-main-screen *ngIf="bHasPConnect$" [pConn$]="pConn$"></app-main-screen>
</div>

<ng-template #loading>
<div>Loading...</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.progress-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
background-color: var(--app-background-color);
position: fixed;
z-index: 99999;
top: 0px;
left: 0px;
opacity: 0.5;
}

.progress-spinner {
text-align: center;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { TopAppMashupComponent } from './top-app-mashup.component';
import { EmbeddedComponent } from './embedded.component';

describe('TopAppMashupComponent', () => {
let component: TopAppMashupComponent;
let fixture: ComponentFixture<TopAppMashupComponent>;
describe('EmbeddedComponent', () => {
let component: EmbeddedComponent;
let fixture: ComponentFixture<EmbeddedComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TopAppMashupComponent]
declarations: [EmbeddedComponent]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TopAppMashupComponent);
fixture = TestBed.createComponent(EmbeddedComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { Subscription } from 'rxjs';
import { getSdkConfig, loginIfNecessary } from '@pega/auth/lib/sdk-auth-manager';

import { ProgressSpinnerService } from 'packages/angular-sdk-components/src/lib/_messages/progress-spinner.service';
import { Utils } from 'packages/angular-sdk-components/src/lib/_helpers/utils';
import { compareSdkPCoreVersions } from 'packages/angular-sdk-components/src/lib/_helpers/versionHelpers';
import { HeaderComponent } from './header/header.component';
import { MainScreenComponent } from './main-screen/main-screen.component';

import { getSdkComponentMap } from 'packages/angular-sdk-components/src/lib/_bridge/helpers/sdk_component_map';
import localSdkComponentMap from 'packages/angular-sdk-components/src/sdk-local-component-map';
import { initializeAuthentication } from './utils';

declare global {
interface Window {
myLoadMashup: Function;
}
}

@Component({
selector: 'app-embedded',
templateUrl: './embedded.component.html',
styleUrls: ['./embedded.component.scss'],
providers: [Utils],
standalone: true,
imports: [CommonModule, MatProgressSpinnerModule, MatToolbarModule, MatIconModule, MatButtonModule, HeaderComponent, MainScreenComponent]
})
export class EmbeddedComponent implements OnInit, OnDestroy {
pConn$: typeof PConnect;

bLoggedIn$ = false;
bHasPConnect$ = false;
isProgress$ = false;

progressSpinnerSubscription: Subscription;

bootstrapShell: any;

constructor(private psservice: ProgressSpinnerService) {}

ngOnInit() {
this.initialize();

// handle showing and hiding the progress spinner
this.progressSpinnerSubscription = this.psservice.getMessage().subscribe(message => {
this.showHideProgress(message.show);
});
}

ngOnDestroy() {
this.progressSpinnerSubscription.unsubscribe();
}

async initialize() {
// Add event listener for when logged in and constellation bootstrap is loaded
document.addEventListener('SdkConstellationReady', () => this.handleSdkConstellationReady());

const { authConfig } = await getSdkConfig();

initializeAuthentication(authConfig);

// Login if needed, without doing an initial main window redirect
const sAppName = window.location.pathname.substring(window.location.pathname.indexOf('/') + 1);
loginIfNecessary({ appName: sAppName, mainRedirect: false });
}

handleSdkConstellationReady() {
this.bLoggedIn$ = true;
// start the portal
this.startMashup();
}

startMashup() {
PCore.onPCoreReady(async renderObj => {
console.log('PCore ready!');

// Check that we're seeing the PCore version we expect
compareSdkPCoreVersions();

// Initialize the SdkComponentMap (local and pega-provided)
await getSdkComponentMap(localSdkComponentMap);
console.log(`SdkComponentMap initialized`);

// Don't call initialRender until SdkComponentMap is fully initialized
this.initialRender(renderObj);
});

window.myLoadMashup('app-root', false); // this is defined in bootstrap shell that's been loaded already
}

initialRender(renderObj) {
// Need to register the callback function for PCore.registerComponentCreator
// This callback is invoked if/when you call a PConnect createComponent
PCore.registerComponentCreator(c11nEnv => {
return c11nEnv;
});

// Change to reflect new use of arg in the callback:
const { props } = renderObj;

this.pConn$ = props.getPConnect();

this.bHasPConnect$ = true;

this.showHideProgress(false);
}

showHideProgress(bShow: boolean) {
this.isProgress$ = bShow;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<mat-toolbar color="primary" class="mc-toolbar">
<mat-toolbar-row class="mc-toolbar-row">
{{ applicationLabel }}
<mat-icon class="mc-icon">router</mat-icon>

<span class="toolbar-spacer"> </span>
</mat-toolbar-row>
</mat-toolbar>
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@
flex: 1 1 auto;
}

.progress-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
background-color: var(--app-background-color);
position: fixed;
z-index: 99999;
top: 0px;
left: 0px;
opacity: 0.5;
}

.progress-spinner {
text-align: center;
}

.example-container {
min-height: 100%;
height: 100%;
Expand Down Expand Up @@ -63,11 +44,3 @@
height: 80px;
width: 60px;
}

/*
.mc-header-svg-icon {
width: 1.4rem;
display: inline-block;
filter: $app-primary-color-filter;
}
*/
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { MCNavComponent } from './mc-nav.component';
import { HeaderComponent } from './header.component';

describe('MCNavComponent', () => {
let component: MCNavComponent;
let fixture: ComponentFixture<MCNavComponent>;
describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [MCNavComponent]
declarations: [HeaderComponent]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MCNavComponent);
fixture = TestBed.createComponent(HeaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatToolbarModule } from '@angular/material/toolbar';

@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss'],
standalone: true,
imports: [CommonModule, MatToolbarModule, MatIconModule, MatButtonModule]
})
export class HeaderComponent implements OnInit {
applicationLabel: string | undefined;

ngOnInit() {
this.applicationLabel = PCore.getEnvironmentInfo().getApplicationLabel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div class="mc-banner">Combine TV, Internet, and Voice for the best deal</div>

<div style="display: flex; justify-content: space-evenly">
<app-bundle-swatch [swatchConfig$]="firstConfig$" (ShopNowButtonClick)="onShopNow($event)"></app-bundle-swatch>
<app-bundle-swatch [swatchConfig$]="secondConfig$" (ShopNowButtonClick)="onShopNow($event)"></app-bundle-swatch>
<app-bundle-swatch [swatchConfig$]="thirdConfig$" (ShopNowButtonClick)="onShopNow($event)"></app-bundle-swatch>
<ng-container *ngFor="let option of shoppingOptionsList">
<app-shopping-card [option]="option" (onShopNowButtonClick)="onShopNow($event)"></app-shopping-card>
</ng-container>
</div>
</div>
<div [hidden]="!showPega$">
Expand Down
Loading
Loading