From 20a95c7023435b5fcc260875447242c6d2a0d972 Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Mon, 2 May 2022 11:23:55 +0530 Subject: [PATCH 01/22] Task #57978: Mandatory courses strip logic --- .../src/lib/_services/widget-content.model.ts | 3 +- .../card-content/card-content.component.html | 181 ++++++++++++++++++ .../content-strip-multiple.component.ts | 94 ++++++++- .../content-strip-multiple.model.ts | 1 + 4 files changed, 277 insertions(+), 2 deletions(-) diff --git a/library/ws-widget/collection/src/lib/_services/widget-content.model.ts b/library/ws-widget/collection/src/lib/_services/widget-content.model.ts index 47af8c1ed..3c3591e8d 100644 --- a/library/ws-widget/collection/src/lib/_services/widget-content.model.ts +++ b/library/ws-widget/collection/src/lib/_services/widget-content.model.ts @@ -19,7 +19,8 @@ export namespace NsContent { appIcon: string artifactUrl: string averageRating?: any - batches: any + // this will be used to content form enrollment user list + batch?: any body?: string certificationList?: IRelatedContentMeta[] certificationStatus?: TCertificationStatus diff --git a/library/ws-widget/collection/src/lib/card-content/card-content.component.html b/library/ws-widget/collection/src/lib/card-content/card-content.component.html index 8711d537c..e1ce73917 100644 --- a/library/ws-widget/collection/src/lib/card-content/card-content.component.html +++ b/library/ws-widget/collection/src/lib/card-content/card-content.component.html @@ -719,6 +719,187 @@

Reply

+
+ End date : {{ widgetData?.batch?.endDate | date: "MMM yyyy" }} +
+ +
+ + + + +
+
+ + {{ widgetData.content.duration | pipeDurationTransform: 'hms' }} +
+ +
+

100%

+
+
+

{{ widgetData.content?.completionPercentage }} %

+ +
+ + +
+ + +
+ + +
+
+ + + + + + + + + + + + +
+

Reason

+ +
+

+ {{ widgetData.content.reason }} +

+
+ + + + + + + + + + + \ No newline at end of file diff --git a/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.scss b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.scss new file mode 100644 index 000000000..3298670ef --- /dev/null +++ b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.scss @@ -0,0 +1,38 @@ +.container-balanced { + max-width: 1202px; + margin-left: auto!important; + margin-right: auto!important; + height: auto; + min-height: 400px; + + @media (max-width:1024px) { + margin-left: 8px!important; + margin-right: 8px!important; + } +} + +.top_card_container { + margin-top: 30px; +} + +.counts-container { + + .counts-box { + border-right: 1px solid RGBA(0, 0, 0, 0.16); + align-items: center; + justify-content: center; + display: flex; + flex-direction: column; + &:last-child{ + border: 0; + } + } +} + +.cards-container{ + align-items: center; + display: grid!important; + grid-gap: 32px; + grid-template-columns: repeat(auto-fill,276px); + justify-content: flex-start; +} diff --git a/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.spec.ts b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.spec.ts new file mode 100644 index 000000000..18aa83287 --- /dev/null +++ b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing' + +import { MandatoryCourseComponent } from './mandatory-course.component' + +describe('MandatoryCourseComponent', () => { + let component: MandatoryCourseComponent + let fixture: ComponentFixture + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [MandatoryCourseComponent], + }) + .compileComponents() + })) + + beforeEach(() => { + fixture = TestBed.createComponent(MandatoryCourseComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.ts b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.ts new file mode 100644 index 000000000..9e66fc59c --- /dev/null +++ b/project/ws/app/src/lib/routes/mandatory-course/routes/mandatory-course/mandatory-course.component.ts @@ -0,0 +1,113 @@ +import { Component, OnInit, OnDestroy, OnChanges, SimpleChanges } from '@angular/core' +import { NsContent } from '@sunbird-cb/collection/src/public-api' +import { ActivatedRoute } from '@angular/router' +import { NSMandatoryCourseData } from '../../models/mandatory-course.model' + +@Component({ + selector: 'ws-app-mandatory-course', + templateUrl: './mandatory-course.component.html', + styleUrls: ['./mandatory-course.component.scss'], +}) +export class MandatoryCourseComponent implements OnInit, OnDestroy, OnChanges { + public displayLoader = false + defaultThumbnail = '' + stateData: { + param: any, path: any + } | undefined + enrolledCourses: any + mandatoryCourses: any + stats: NSMandatoryCourseData.IMandatoryCourseStats = { + totalCourses: 0, + inprogress: 0, + notStarted: 0, + completed: 0, + } + // searchCompArea = new FormControl('') + titles = [ + { title: 'Learn', url: '/page/learn', icon: 'school' }, + { title: 'Manadatory course', url: 'none', icon: '' }, + ] + + constructor( + private route: ActivatedRoute, + ) { + this.stateData = { param: '', path: 'mandatory-course' } + } + + ngOnInit() { + this.enrolledCourses = this.route.snapshot.data.enrollmentList.data + this.getMandatoryCourses() + } + + getMandatoryCourses() { + let content: NsContent.IContent[] = [] + let contentNew: NsContent.IContent[] = [] + const goals = this.enrolledCourses.reduce((acc: any[], cur: any) => { + if (cur && cur.content && cur.content.primaryCategory === NsContent.EPrimaryCategory.MANDATORY_COURSE_GOAL) { + acc.push(cur) + return acc + } + return acc + // tslint:disable-next-line: align + }, []) + + if (goals && goals.length) { + content = goals.map((c: any) => { + const contentTemp: NsContent.IContent = c.content + contentTemp.batch = c.batch + contentTemp.completionPercentage = c.completionPercentage || 0 + contentTemp.completionStatus = c.completionStatus || 0 + return contentTemp + }) + } + // To filter content with completionPercentage > 0, + // so that only those content will show in home page + // continue learing strip + // if (content && content.length) { + // contentNew = content.filter((c: any) => { + // if (c.completionPercentage && c.completionPercentage > 0) { + // return c + // } + // }) + // } + + // To sort in descending order of the enrolled date + contentNew = content.sort((a: any, b: any) => { + const dateA: any = new Date(a.enrolledDate || 0) + const dateB: any = new Date(b.enrolledDate || 0) + return dateB - dateA + }) + this.mandatoryCourses = contentNew + this.calculateStats() + } + + calculateStats() { + if (this.mandatoryCourses && this.mandatoryCourses.length) { + this.stats.totalCourses = this.mandatoryCourses.length + this.mandatoryCourses.map((c: any) => { + if ((c.completionPercentage > 0 && c.completionPercentage < 100) || c.completionStatus === 1) { + this.stats.inprogress = this.stats.inprogress + 1 + } + if (c.completionStatus === 0) { + this.stats.notStarted = this.stats.notStarted + 1 + } + if (c.completionStatus === 2 || c.completionPercentage >= 100) { + this.stats.completed = this.stats.notStarted + 1 + } + }) + } + } + + ngOnChanges(changes: SimpleChanges) { + if (changes.param.currentValue) { + // this.getSearchedData() + } + } + + ngOnDestroy() { + // if (this.paramSubscription) { + // this.paramSubscription.unsubscribe() + // } + } + +} From 8977d641abbfff28d6130d3a7bf50a849e77fec5 Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Wed, 11 May 2022 20:03:10 +0530 Subject: [PATCH 04/22] Task #57977: mandatory course goal routes in app added --- project/ws/app/src/public-api.ts | 1 + src/app/app-routing.module.ts | 15 +++++++++++++++ src/app/routes/route-mandatory-course.module.ts | 11 +++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/app/routes/route-mandatory-course.module.ts diff --git a/project/ws/app/src/public-api.ts b/project/ws/app/src/public-api.ts index b2c744cb3..72c897651 100755 --- a/project/ws/app/src/public-api.ts +++ b/project/ws/app/src/public-api.ts @@ -35,3 +35,4 @@ export * from './lib/routes/search-v2/searchv2.module' export * from './lib/routes/events/events.module' export * from './lib/routes/browse-by-competency/browse-by-competency.module' export * from './lib/routes/browse-by-provider/browse-by-provider.module' +export * from './lib/routes/mandatory-course/mandatory-course.module' diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 06852e3db..b1c828ab5 100755 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -187,6 +187,21 @@ const routes: Routes = [ pageData: PageResolve, }, }, + { + path: 'app/learn/mandatory-course', + loadChildren: () => + import('./routes/route-mandatory-course.module').then(u => u.RouteMandatoryCourseModule), + canActivate: [GeneralGuard], + data: { + pageType: 'feature', + pageKey: 'mandatory-course', + pageId: 'app/learn/mandatory-course', + module: 'learn', + }, + resolve: { + pageData: PageResolve, + }, + }, { path: 'app/discussion-forum', pathMatch: 'full', diff --git a/src/app/routes/route-mandatory-course.module.ts b/src/app/routes/route-mandatory-course.module.ts new file mode 100644 index 000000000..d92211903 --- /dev/null +++ b/src/app/routes/route-mandatory-course.module.ts @@ -0,0 +1,11 @@ +import { NgModule } from '@angular/core' +import { CommonModule } from '@angular/common' +import { MandatoryCourseModule } from '@ws/app' + +@NgModule({ + imports: [CommonModule, MandatoryCourseModule], + exports: [MandatoryCourseModule], +}) +export class RouteMandatoryCourseModule { + +} From d3f3e8f131db1fe297e580bf19a075bdc4cae0e9 Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Wed, 11 May 2022 20:03:52 +0530 Subject: [PATCH 05/22] Task #57977: mandatory course goal resolver to fetch data --- .../mandatory-course-resolver.service.spec.ts | 12 +++++++ .../mandatory-course-resolver.service.ts | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.spec.ts create mode 100644 project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.ts diff --git a/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.spec.ts b/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.spec.ts new file mode 100644 index 000000000..4220e14bf --- /dev/null +++ b/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing' + +import { MandatoryCourseResolverService } from './mandatory-course-resolver.service' + +describe('MandatoryCourseResolverService', () => { + beforeEach(() => TestBed.configureTestingModule({})) + + it('should be created', () => { + const service: MandatoryCourseResolverService = TestBed.get(MandatoryCourseResolverService) + expect(service).toBeTruthy() + }) +}) diff --git a/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.ts b/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.ts new file mode 100644 index 000000000..6b3b851d9 --- /dev/null +++ b/project/ws/app/src/lib/routes/mandatory-course/resolvers/mandatory-course-resolver.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@angular/core' +import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' +import { Observable, of } from 'rxjs' +import { map, catchError } from 'rxjs/operators' +import { WidgetUserService } from '@sunbird-cb/collection' +import { IResolveResponse, ConfigurationsService } from '@sunbird-cb/utils' +@Injectable({ + providedIn: 'root', +}) + +export class MandatoryCourseResolverService implements + Resolve> | + IResolveResponse> { + constructor( + private configSvc: ConfigurationsService, + private userSvc: WidgetUserService, + ) { + + } + + resolve( + _route: ActivatedRouteSnapshot, + _state: RouterStateSnapshot, + ): Observable> { + let userId = '' + if (this.configSvc.userProfile) { + userId = this.configSvc.userProfile.userId + } + return this.userSvc.fetchUserBatchList(userId).pipe( + map((data: any) => ({ data, error: null })), + catchError(error => of({ error, data: null })), + ) + } +} From c89b6f5d086961c2c28fa3185ef014bd1f5ee2db Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Wed, 11 May 2022 20:04:18 +0530 Subject: [PATCH 06/22] Task #57977: mandatory course goal - card standard changes --- .../src/lib/card-content/card-content.component.html | 9 ++++++--- .../src/lib/card-content/card-content.component.scss | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/ws-widget/collection/src/lib/card-content/card-content.component.html b/library/ws-widget/collection/src/lib/card-content/card-content.component.html index e1ce73917..be13cc4d3 100644 --- a/library/ws-widget/collection/src/lib/card-content/card-content.component.html +++ b/library/ws-widget/collection/src/lib/card-content/card-content.component.html @@ -713,14 +713,14 @@

Reply

class="mat-subheading-1 title-text ws-mat-text-block-fade-gradient"> {{ widgetData.content.name }} -
+
{{ widgetData.content.description | pipeHtmlTagRemoval }}
-
- End date : {{ widgetData?.batch?.endDate | date: "MMM yyyy" }} +
+ Deadline : {{ widgetData?.content?.batch?.endDate | date: "MMM yyyy" }}
@@ -1062,6 +1062,9 @@

Reason

+
+

Deadline - {{widgetData.content.batch?.endDate | date: "MMM yyyy"}}

+
- Deadline : {{ widgetData?.content?.batch?.endDate | date: "MMM yyyy" }} + Deadline : {{ widgetData?.content?.batch?.endDate | date: "d MMM yyyy" }}
@@ -1063,7 +1063,7 @@

Reason

-

Deadline - {{widgetData.content.batch?.endDate | date: "MMM yyyy"}}

+

Deadline - {{widgetData.content.batch?.endDate | date: "d MMM yyyy"}}

    From 081c7b24d84e9392009b744170f5499e62368697 Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Sat, 21 May 2022 17:33:34 +0530 Subject: [PATCH 21/22] Task #58311: Fixed the competency refresh issue in recommended strip --- .../lib/services/configurations.service.ts | 7 ++ .../competence-all.component.ts | 2 + .../competency-detailed-view.component.ts | 11 +- src/app/services/init.service.ts | 111 ++++++++++++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) diff --git a/library/ws-widget/utils/src/lib/services/configurations.service.ts b/library/ws-widget/utils/src/lib/services/configurations.service.ts index 02949dce1..bf7031562 100644 --- a/library/ws-widget/utils/src/lib/services/configurations.service.ts +++ b/library/ws-widget/utils/src/lib/services/configurations.service.ts @@ -63,6 +63,9 @@ export class ConfigurationsService { tourGuideNotifier = new ReplaySubject() authChangeNotifier = new ReplaySubject(1) + private updateProfile = new BehaviorSubject(false) + updateProfileObservable = this.updateProfile.asObservable() + // Preference Related Values activeThemeObject: NsInstanceConfig.ITheme | null = null activeFontObject: NsInstanceConfig.IFontSize | null = null @@ -89,4 +92,8 @@ export class ConfigurationsService { // '_', // )}` // setHostPath = (sitePath: string) => (sitePath).replace(':', '_') + + updateGlobalProfile(state: boolean) { + this.updateProfile.next(state) + } } diff --git a/project/ws/app/src/lib/routes/competencies/routes/competence-all/competence-all.component.ts b/project/ws/app/src/lib/routes/competencies/routes/competence-all/competence-all.component.ts index 68b9af602..8658ef777 100755 --- a/project/ws/app/src/lib/routes/competencies/routes/competence-all/competence-all.component.ts +++ b/project/ws/app/src/lib/routes/competencies/routes/competence-all/competence-all.component.ts @@ -256,6 +256,7 @@ export class CompetenceAllComponent implements OnInit { // success // this.myCompetencies.push(item) this.snackBar.open(this.successMsg.nativeElement.value, 'X') + this.configSvc.updateGlobalProfile(true) } }, /* tslint:disable */() => { @@ -283,6 +284,7 @@ export class CompetenceAllComponent implements OnInit { if (response) { // success => removed this.snackBar.open(this.successRemoveMsg.nativeElement.value, 'X'); + this.configSvc.updateGlobalProfile(true) } }, /* tslint:disable */() => { diff --git a/project/ws/app/src/lib/routes/competencies/routes/competency-detailed-view/competency-detailed-view.component.ts b/project/ws/app/src/lib/routes/competencies/routes/competency-detailed-view/competency-detailed-view.component.ts index d75a18c8e..c0c51c0b8 100644 --- a/project/ws/app/src/lib/routes/competencies/routes/competency-detailed-view/competency-detailed-view.component.ts +++ b/project/ws/app/src/lib/routes/competencies/routes/competency-detailed-view/competency-detailed-view.component.ts @@ -88,7 +88,6 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { .subscribe((reponse: NSCompetencie.ICompetencieResponse) => { if (reponse.statusInfo && reponse.statusInfo.statusCode === 200) { this.competencyData = reponse.responseData - console.log(this.competencyData) } else { this.competencyData = [] } @@ -133,7 +132,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { .first() .value() - console.log(vc) + // console.log(vc) // this.myCompetencies.push(vc) this.addToProfile(vc, levelId, levelName) // this.reset() @@ -151,7 +150,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { .first() .value() - console.log(vc) + // console.log(vc) if (vc) { this.removeFromProfile(vc) } @@ -178,6 +177,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { this.isAdded = false; // success => removed this.snackBar.open('Removed competency sucessfully', 'X'); + this.configSvc.updateGlobalProfile(true) } }, /* tslint:disable */() => { @@ -201,7 +201,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { competencySelfAttestedLevelValue: levelName || '', } - console.log(newCompetence) + // console.log(newCompetence) const updatedProfile = { ...this.currentProfile } if ( _.get(this, 'currentProfile.competencies') && @@ -227,6 +227,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { // this.myCompetencies.push(item) this.isAdded = true; this.snackBar.open('Compentency added successfully', 'X') + this.configSvc.updateGlobalProfile(true) } }, /* tslint:disable */() => { @@ -248,7 +249,7 @@ export class CompetencyDetailedViewComponent implements OnInit, OnDestroy { const instance = dialogRef.componentInstance; instance.isUpdate = (this.isAdded) ? true : false; dialogRef.afterClosed().subscribe((response: any) => { - console.log(response) + // console.log(response) if (response && response.action === 'ADD') { this.addCompetency(response.id, response.levelId, response.levelName); // this.refreshData(this.currentActivePage) diff --git a/src/app/services/init.service.ts b/src/app/services/init.service.ts index a5bebf343..37a8f8b77 100755 --- a/src/app/services/init.service.ts +++ b/src/app/services/init.service.ts @@ -26,6 +26,7 @@ import { environment } from '../../environments/environment' import _ from 'lodash' import { map } from 'rxjs/operators' import { v4 as uuid } from 'uuid' +import { Subscription } from 'rxjs' // import { of } from 'rxjs' /* tslint:enable */ // interface IDetailsResponse { @@ -44,6 +45,7 @@ const PROXY_CREATE_V8 = '/apis/proxies/v8' const endpoint = { profilePid: '/apis/proxies/v8/api/user/v2/read', + fetchProfileById: (id: string) => `/apis/proxies/v8/api/user/v2/read/${id}`, // profileV2: '/apis/protected/v8/user/profileRegistry/getUserRegistryById', // details: `/apis/protected/v8/user/details?ts=${Date.now()}`, CREATE_USER_API: `${PROXY_CREATE_V8}/discussion/user/v1/create`, @@ -54,6 +56,7 @@ const endpoint = { }) export class InitService { private baseUrl = this.configSvc.baseUrl + updateProfileSubscription: Subscription | null = null httpOptions = { headers: new HttpHeaders({ @@ -111,6 +114,12 @@ export class InitService { } async init() { + // to update the profile from user read api + this.updateProfileSubscription = this.configSvc.updateProfileObservable.subscribe(async (value: boolean) => { + if (value) { + await this.fetchUserDetails() + } + }) // this.logger.removeConsoleAccess() await this.fetchDefaultConfig() // const authenticated = await this.authSvc.initAuth() @@ -354,6 +363,108 @@ export class InitService { } } + // This is a replication of fetchStartUpDetails() method + // only change is calling the read api with userID + // since Backend api is failing if we call the read api twice + private async fetchUserDetails(): Promise { + if (this.configSvc.unMappedUser.id) { + let userPidProfile: any | null = null + try { + userPidProfile = await this.http + .get(endpoint.fetchProfileById(this.configSvc.unMappedUser.id)) + .pipe(map((res: any) => { + // const roles = _.map(_.get(res, 'result.response.roles'), 'role') + // _.set(res, 'result.response.roles', roles) + return _.get(res, 'result.response') + })).toPromise() + if (userPidProfile && userPidProfile.roles && userPidProfile.roles.length > 0 && + this.hasRole(userPidProfile.roles)) { + // if (userPidProfile.result.response.organisations.length > 0) { + // const organisationData = userPidProfile.result.response.organisations + // userRoles = (organisationData[0].roles.length > 0) ? organisationData[0].roles : [] + // } + if (localStorage.getItem('telemetrySessionId')) { + localStorage.removeItem('telemetrySessionId') + } + localStorage.setItem('telemetrySessionId', uuid()) + this.configSvc.unMappedUser = userPidProfile + const profileV2 = _.get(userPidProfile, 'profileDetails') + this.configSvc.userProfile = { + country: _.get(profileV2, 'personalDetails.countryCode') || null, + email: _.get(profileV2, 'profileDetails.officialEmail') || userPidProfile.email, + givenName: userPidProfile.firstName, + userId: userPidProfile.userId, + firstName: userPidProfile.firstName, + lastName: userPidProfile.lastName, + rootOrgId: userPidProfile.rootOrgId, + rootOrgName: userPidProfile.channel, + // tslint:disable-next-line: max-line-length + // userName: `${userPidProfile.firstName ? userPidProfile.firstName : ' '}${userPidProfile.lastName ? userPidProfile.lastName : ' '}`, + userName: userPidProfile.userName, + profileImage: userPidProfile.thumbnail, + departmentName: userPidProfile.channel, + dealerCode: null, + isManager: false, + } + this.configSvc.userProfileV2 = { + userId: _.get(profileV2, 'userId') || userPidProfile.userId, + email: _.get(profileV2, 'personalDetails.officialEmail') || userPidProfile.email, + firstName: _.get(profileV2, 'personalDetails.firstname') || userPidProfile.firstName, + surName: _.get(profileV2, 'personalDetails.surname') || userPidProfile.lastName, + middleName: _.get(profileV2, 'personalDetails.middlename') || '', + departmentName: _.get(profileV2, 'employmentDetails.departmentName') || userPidProfile.channel, + givenName: _.get(userPidProfile, 'userName'), + // tslint:disable-next-line: max-line-length + userName: `${_.get(profileV2, 'personalDetails.firstname') ? _.get(profileV2, 'personalDetails.firstname') : ''}${_.get(profileV2, 'personalDetails.surname') ? _.get(profileV2, 'personalDetails.surname') : ''}`, + profileImage: _.get(profileV2, 'photo') || userPidProfile.thumbnail, + dealerCode: null, + isManager: false, + competencies: _.get(profileV2, 'competencies') || [], + } + + if (!this.configSvc.nodebbUserProfile) { + this.configSvc.nodebbUserProfile = { + username: userPidProfile.userName, + email: 'null', + } + } + } else { + this.authSvc.force_logout() + } + const details = { + group: [], + profileDetailsStatus: !!_.get(userPidProfile, 'profileDetails.mandatoryFieldsExists'), + roles: (userPidProfile.roles || []).map((v: { toLowerCase: () => void; }) => v.toLowerCase()), + tncStatus: !userPidProfile.promptTnC, + isActive: !!!userPidProfile.isDeleted, + } + this.configSvc.hasAcceptedTnc = details.tncStatus + this.configSvc.profileDetailsStatus = details.profileDetailsStatus + // this.configSvc.userRoles = new Set((userRoles || []).map(v => v.toLowerCase())) + // const detailsV: IDetailsResponse = await this.http + // .get(endpoint.details).pipe(retry(3)) + // .toPromise() + this.configSvc.userGroups = new Set(details.group) + this.configSvc.userRoles = new Set((details.roles || []).map((v: string) => v.toLowerCase())) + this.configSvc.isActive = details.isActive + return details + } catch (e) { + this.configSvc.userProfile = null + throw new Error('Invalid user') + } + } else { + return { group: [], profileDetailsStatus: true, roles: new Set(['Public']), tncStatus: true, isActive: true } + // const details: IDetailsResponse = await this.http + // .get(endpoint.details).pipe(retry(3)) + // .toPromise() + // this.configSvc.userGroups = new Set(details.group) + // this.configSvc.userRoles = new Set((details.roles || []).map(v => v.toLowerCase())) + // if (this.configSvc.userProfile && this.configSvc.userProfile.isManager) { + // this.configSvc.userRoles.add('is_manager') + } + + } + private async fetchInstanceConfig(): Promise { // TODO: use the rootOrg and org to fetch the instance const publicConfig = await this.http From fce7f602b10797a6fddcdfa54f3f7c66049ba0ca Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Sat, 21 May 2022 17:34:02 +0530 Subject: [PATCH 22/22] Task #58311: lint fixes --- .../ws-widget/utils/src/lib/services/auth-keycloak.service.ts | 4 ++-- .../src/lib/routes/network-v2/services/network-v2.service.ts | 2 +- src/app/component/root/root.component.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/ws-widget/utils/src/lib/services/auth-keycloak.service.ts b/library/ws-widget/utils/src/lib/services/auth-keycloak.service.ts index d37a0495a..18fcbc145 100644 --- a/library/ws-widget/utils/src/lib/services/auth-keycloak.service.ts +++ b/library/ws-widget/utils/src/lib/services/auth-keycloak.service.ts @@ -169,8 +169,8 @@ export class AuthKeycloakService { storage.removeItem('telemetrySessionId') } try { - sessionStorage.clear(); - localStorage.clear(); + sessionStorage.clear() + localStorage.clear() } catch { } diff --git a/project/ws/app/src/lib/routes/network-v2/services/network-v2.service.ts b/project/ws/app/src/lib/routes/network-v2/services/network-v2.service.ts index 84a42886a..c5750ff1b 100755 --- a/project/ws/app/src/lib/routes/network-v2/services/network-v2.service.ts +++ b/project/ws/app/src/lib/routes/network-v2/services/network-v2.service.ts @@ -29,7 +29,7 @@ export class NetworkV2Service { fetchProfile(userId: string) { return this.http.get(`${API_ENDPOINTS.getUserdetailsV2FromRegistry}/${userId}`) - .pipe(map((res) => { + .pipe(map(res => { // const roles = _.map(_.get(res, 'result.response.roles'), 'role') // _.set(res, 'result.response.roles', roles) return res diff --git a/src/app/component/root/root.component.ts b/src/app/component/root/root.component.ts index 91373b8d8..0556daef8 100755 --- a/src/app/component/root/root.component.ts +++ b/src/app/component/root/root.component.ts @@ -152,7 +152,7 @@ export class RootComponent implements OnInit, AfterViewInit { } @HostListener('window:unload', ['$event']) unloadHandler(event: any) { - if (event && event.type==='unload') { + if (event && event.type === 'unload') { // this.authSvc.logout() } }