Skip to content

Commit abb2c5f

Browse files
authored
Add versionHelpers and its use; clean up extra spaces (#12)
1 parent 75fa819 commit abb2c5f

File tree

5 files changed

+142
-98
lines changed

5 files changed

+142
-98
lines changed

src/app/_components/top-app/top-app.component.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { interval } from "rxjs/internal/observable/interval";
44
import { analyzeAndValidateNgModules } from '@angular/compiler';
55
import { Subscribable, Subscription } from 'rxjs';
66
import { NgZone } from '@angular/core';
7+
import { compareSdkPCoreVersions } from 'src/app/_helpers/versionHelpers';
78

89

910
@Component({
@@ -35,37 +36,39 @@ export class TopAppComponent implements OnInit {
3536

3637

3738
constructor(private cdRef: ChangeDetectorRef,
38-
private ngZone: NgZone) {
39+
private ngZone: NgZone) {
3940

4041
}
4142

4243
ngOnInit() {
43-
44+
4445
this.doSubscribe();
4546
}
46-
47+
4748
doSubscribe() {
4849

4950

50-
51+
5152
window.PCore.onPCoreReady( (renderObj: any) => {
52-
53+
// Check that we're seeing the PCore version we expect
54+
compareSdkPCoreVersions();
55+
5356
// Change to reflect new use of arg in the callback:
5457
const { props /*, domContainerID = null */ } = renderObj;
5558

5659
this.ngZone.run( () => {
5760
this.props$ = props;
5861

5962
this.pConn$ = this.props$.getPConnect();
60-
63+
6164
this.sComponentName$ = this.pConn$.getComponentName();
62-
65+
6366
this.store = window.PCore.getStore();
6467
this.PCore$ = window.PCore;
65-
68+
6669
this.arChildren$ = this.pConn$.getChildren();
67-
68-
70+
71+
6972
this.bPCoreReady$ = true;
7073

7174
});

src/app/_helpers/versionHelpers.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* versionHelpers.ts
3+
*
4+
* Container helper functions that can identify which version of
5+
* PCore/PConnect is being run
6+
*/
7+
8+
declare const PCore;
9+
10+
export const sdkVersion = "8.6";
11+
12+
export function is86(): boolean {
13+
let bRet = false;
14+
const theVer = PCore.getPCoreVersion();
15+
16+
if (theVer.includes("1.0") || theVer.includes("8.6")) {
17+
bRet = true;
18+
}
19+
20+
return bRet;
21+
}
22+
23+
export function is87(): boolean {
24+
let bRet = false;
25+
const theVer = PCore.getPCoreVersion();
26+
27+
if (theVer.includes("8.7")) {
28+
bRet = true;
29+
}
30+
31+
return bRet;
32+
}
33+
34+
export function compareSdkPCoreVersions() {
35+
if (is86() && sdkVersion.includes("8.6")) {
36+
// eslint-disable-next-line no-console
37+
console.log(
38+
`sdkVersion: ${sdkVersion} matches PCore version: ${PCore.getPCoreVersion()}`
39+
);
40+
} else {
41+
// eslint-disable-next-line no-console
42+
console.error(
43+
`sdkVersion: ${sdkVersion} does NOT match PCore version: ${PCore.getPCoreVersion()}`
44+
);
45+
}
46+
}

src/app/_samples/full-portal/top-app-mashup/top-app-mashup.component.ts

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { endpoints } from '../../../_services/endpoints';
1212
import { UpdateWorklistService } from '../../../_messages/update-worklist.service';
1313
import { NgZone } from '@angular/core';
1414
import { ServerConfigService } from '../../../_services/server-config.service';
15+
import { compareSdkPCoreVersions } from '../../../_helpers/versionHelpers';
1516

1617

1718
declare global {
@@ -56,7 +57,7 @@ export class TopAppMashupComponent implements OnInit {
5657
props$: any;
5758
PCore$: any;
5859

59-
60+
6061

6162
storeUnsubscribe : any;
6263
store: any;
@@ -81,7 +82,7 @@ export class TopAppMashupComponent implements OnInit {
8182

8283

8384

84-
constructor(private glsservice: GetLoginStatusService,
85+
constructor(private glsservice: GetLoginStatusService,
8586
private cdRef: ChangeDetectorRef,
8687
private snackBar: MatSnackBar,
8788
private settingsDialog: MatDialog,
@@ -90,25 +91,25 @@ export class TopAppMashupComponent implements OnInit {
9091
private uwservice: UpdateWorklistService,
9192
private ngZone: NgZone,
9293
private scservice: ServerConfigService
93-
) {
94+
) {
9495

9596

9697
}
9798

9899
ngOnInit() {
99-
100+
100101
this.scservice.getServerConfig().then( () => {
101102
this.initialize();
102103
});
103-
104+
104105
}
105106

106107
ngOnDestroy() {
107108
this.subscription.unsubscribe();
108109
this.progressSpinnerSubscription.unsubscribe();
109110
this.resetPConnectSubscription.unsubscribe();
110111
}
111-
112+
112113

113114
initialize() {
114115
if (sessionStorage.getItem("userFullName") && sessionStorage.getItem("userPortal")) {
@@ -129,7 +130,7 @@ export class TopAppMashupComponent implements OnInit {
129130
this.bLoggedIn$ = true;
130131
this.userName$ = sessionStorage.getItem("userFullName");
131132
});
132-
133+
133134
this.getPConnectAndUpdate();
134135

135136
}
@@ -148,7 +149,7 @@ export class TopAppMashupComponent implements OnInit {
148149
setTimeout(() => {
149150
window.location.reload();
150151
})
151-
152+
152153
}
153154

154155

@@ -157,7 +158,7 @@ export class TopAppMashupComponent implements OnInit {
157158
);
158159

159160
// handle showing and hiding the progress spinner
160-
this.progressSpinnerSubscription = this.psservice.getMessage().subscribe(message => {
161+
this.progressSpinnerSubscription = this.psservice.getMessage().subscribe(message => {
161162
this.progressSpinnerMessage = message;
162163

163164
this.showHideProgress(this.progressSpinnerMessage.show);
@@ -183,10 +184,10 @@ export class TopAppMashupComponent implements OnInit {
183184
// // update the worklist
184185
// this.uwservice.sendMessage(true);
185186

186-
187+
187188
// });
188189

189-
190+
190191
// }
191192

192193
});
@@ -232,7 +233,7 @@ export class TopAppMashupComponent implements OnInit {
232233
// OATH
233234
oHeaders["Authorization"] = sessionStorage.getItem("oauthUser");
234235
}
235-
236+
236237

237238
oConfig["additionalHeaders"] = oHeaders;
238239

@@ -259,8 +260,10 @@ export class TopAppMashupComponent implements OnInit {
259260
pConnectUpdate(oConfig: any, bootstrapShell: any) {
260261
bootstrapShell.bootstrap(oConfig).then( () => {
261262

262-
263+
263264
window.PCore.onPCoreReady( (renderObj) => {
265+
// Check that we're seeing the PCore version we expect
266+
compareSdkPCoreVersions();
264267

265268

266269
// Change to reflect new use of arg in the callback:
@@ -283,24 +286,24 @@ export class TopAppMashupComponent implements OnInit {
283286

284287

285288
this.ngZone.run( () => {
286-
289+
287290
this.props$ = props;
288-
291+
289292
this.pConn$ = this.props$.getPConnect();
290-
293+
291294
this.sComponentName$ = this.pConn$.getComponentName();
292-
295+
293296
this.store = window.PCore.getStore();
294297
this.PCore$ = window.PCore;
295-
298+
296299
this.arChildren$ = this.pConn$.getChildren();
297-
298-
300+
301+
299302
this.bPCoreReady$ = true;
300303

301-
302-
303-
});
304+
305+
306+
});
304307

305308

306309
} );
@@ -317,15 +320,15 @@ export class TopAppMashupComponent implements OnInit {
317320
(err) => {
318321
alert("error");
319322
}
320-
323+
321324
);
322325
}
323-
326+
324327

325328
showHideProgress(bShow: boolean) {
326329

327330
return;
328-
331+
329332
if (bShow) {
330333

331334
if (!this.isProgress$) {
@@ -361,7 +364,7 @@ export class TopAppMashupComponent implements OnInit {
361364
});
362365
}
363366

364-
367+
365368
}
366369
}
367370

@@ -374,25 +377,27 @@ export class TopAppMashupComponent implements OnInit {
374377
doSubscribe() {
375378

376379

377-
380+
378381
window.PCore.onPCoreReady( (renderObj: any) => {
379-
382+
// Check that we're seeing the PCore version we expect
383+
compareSdkPCoreVersions();
384+
380385
// Change to reflect new use of arg in the callback:
381386
const { props /*, domContainerID = null */ } = renderObj;
382387

383388
this.ngZone.run( () => {
384389
this.props$ = props;
385390

386391
this.pConn$ = this.props$.getPConnect();
387-
392+
388393
this.sComponentName$ = this.pConn$.getComponentName();
389-
394+
390395
this.store = window.PCore.getStore();
391396
this.PCore$ = window.PCore;
392-
397+
393398
this.arChildren$ = this.pConn$.getChildren();
394-
395-
399+
400+
396401
this.bPCoreReady$ = true;
397402

398403
});
@@ -416,7 +421,7 @@ export class TopAppMashupComponent implements OnInit {
416421
// timer.unsubscribe();
417422

418423
// }
419-
424+
420425
// });
421426

422427
}

0 commit comments

Comments
 (0)