From 17e2f2eab994a84b8018b1888fd4255dfa5bac7a Mon Sep 17 00:00:00 2001 From: ramkumar-pacewisdom Date: Fri, 9 Aug 2024 15:00:13 +0530 Subject: [PATCH] side nav fixes --- package-lock.json | 8 +- package.json | 2 +- .../project-details.component.ts | 140 ++++++++++-------- .../sub-tasks-resources.component.ts | 9 +- .../dock/components/tasks/tasks.component.ts | 3 +- .../view-module/layout/layout.component.html | 2 +- .../view-module/layout/layout.component.ts | 17 ++- .../src/lib/lib-project.service.ts | 3 +- .../side-navbar/side-navbar.component.html | 2 +- .../side-navbar/side-navbar.component.ts | 4 +- .../src/lib/services/form/form.service.ts | 10 ++ .../app-main-view/app-main-view.component.ts | 7 + .../create-new/create-new.component.ts | 5 + 13 files changed, 122 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9305c2fc..3739db3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@angular/router": "^17.3.0", "@ngx-translate/core": "^15.0.0", "@ngx-translate/http-loader": "^8.0.0", - "authentication_frontend_library": "0.0.59", + "authentication_frontend_library": "0.0.60", "dynamic-form-ramkumar": "0.0.37", "ng-otp-input": "^1.9.3", "ngx-quill": "^26.0.5", @@ -5423,9 +5423,9 @@ "dev": true }, "node_modules/authentication_frontend_library": { - "version": "0.0.59", - "resolved": "https://registry.npmjs.org/authentication_frontend_library/-/authentication_frontend_library-0.0.59.tgz", - "integrity": "sha512-SiDIZyWjWw75fkv8+CXl0O/KlX8dolh1XWTs1crMDP5mtqGNKELP/SVqi+JfZhZ53WMftTxC34q2CawmOzEB2Q==", + "version": "0.0.60", + "resolved": "https://registry.npmjs.org/authentication_frontend_library/-/authentication_frontend_library-0.0.60.tgz", + "integrity": "sha512-AYEIYIEJc9DbBZv2mkrJGZG9J7XEhXjS/VdiGbdq4jx8uawB+ZdUgaF1syWdHdzmuXOgEvVw355CWIyWN4lEmA==", "dependencies": { "tslib": "^2.3.0" }, diff --git a/package.json b/package.json index 523c5ce3..084e8cb5 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@angular/router": "^17.3.0", "@ngx-translate/core": "^15.0.0", "@ngx-translate/http-loader": "^8.0.0", - "authentication_frontend_library": "0.0.59", + "authentication_frontend_library": "0.0.60", "dynamic-form-ramkumar": "0.0.37", "ng-otp-input": "^1.9.3", "ngx-quill": "^26.0.5", diff --git a/projects/lib-project/src/lib/dock/components/project-details/project-details.component.ts b/projects/lib-project/src/lib/dock/components/project-details/project-details.component.ts index 54c4e46c..922831f3 100644 --- a/projects/lib-project/src/lib/dock/components/project-details/project-details.component.ts +++ b/projects/lib-project/src/lib/dock/components/project-details/project-details.component.ts @@ -6,9 +6,6 @@ import { TranslateModule } from '@ngx-translate/core'; import { Subscription } from 'rxjs/internal/Subscription'; import { MatDialog } from '@angular/material/dialog'; import { DialogPopupComponent, FormService } from 'lib-shared-modules'; -import { from, of } from 'rxjs'; -import { switchMap, map } from 'rxjs/operators'; - @Component({ selector: 'lib-project-details', standalone: true, @@ -16,7 +13,7 @@ import { switchMap, map } from 'rxjs/operators'; templateUrl: './project-details.component.html', styleUrl: './project-details.component.scss', }) -export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChecked { +export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChecked{ dynamicFormData: any; projectId: string | number = ''; intervalId:any; @@ -43,7 +40,7 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec this.startAutoSaving(); this.libProjectService.projectData = {}; this.getFormWithEntitiesAndMap(); - this.subscription.add( // save draft functionality to save form. + this.subscription.add( this.libProjectService.isProjectSave.subscribe( (isProjectSave: boolean) => { if (isProjectSave && this.router.url.includes('project-details')) { @@ -57,6 +54,7 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec (reviewValidation: boolean) => { if(reviewValidation) { this.formMarkTouched(); + this.libProjectService.triggerSendForReview(); } } ) @@ -65,10 +63,9 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec if (this.mode === 'viewOnly' || this.mode === 'review' || this.mode === 'reviewerView') { this.viewOnly = true this.libProjectService.projectData = {}; - this.getFormWithEntitiesAndMap(); + this.getProjectDetailsForViewOnly() } } - ngAfterViewChecked() { if(this.mode == 'edit' && this.projectId) { this.libProjectService.validForm.projectDetails = (this.formLib?.myForm.status === "INVALID" || this.formLib?.subform?.myForm.status === "INVALID") ? "INVALID" : "VALID"; @@ -78,35 +75,76 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec } } } - + getProjectDetailsForViewOnly(){ + this.formService.getFormWithEntities('PROJECT_DETAILS').then((data) => { + if (data) { + this.formDataForTitle = data.controls.find((item:any) => item.name === 'title'); + this.subscription.add( + this.route.queryParams.subscribe((params: any) => { + if (params.projectId) { + if (Object.keys(this.libProjectService.projectData).length > 1) { // project ID will be there so length considered as more than 1 + this.readProjectDeatilsAndMap(data.controls,this.libProjectService.projectData); + } else { + this.subscription.add( + this.libProjectService + .readProject(this.projectId) + .subscribe((res: any) => { + this.libProjectService.setProjectData(res.result); + this.readProjectDeatilsAndMap(data.controls,res.result); + }) + ); + } + } + }) + ); + } + }) + } getFormWithEntitiesAndMap(){ - this.getFormDataAndSubscribe().subscribe((data: any) => { - if (this.projectId) { - this.handleProjectData(data.controls); - } else { - this.readProjectDeatilsAndMap(data.controls,this.libProjectService.projectData); + this.formService.getFormWithEntities('PROJECT_DETAILS').then((data) => { + if (data) { + this.formDataForTitle = data.controls.find((item:any) => item.name === 'title'); + this.subscription.add( + this.route.queryParams.subscribe((params: any) => { + this.projectId = params.projectId; + this.libProjectService.projectData.id = params.projectId; + if (params.projectId) { + if (params.mode === 'edit') { + if (Object.keys(this.libProjectService.projectData).length > 1) { // project ID will be there so length considered as more than 1 + this.readProjectDeatilsAndMap(data.controls,this.libProjectService.projectData); + } else { + this.subscription.add( + this.libProjectService + .readProject(this.projectId) + .subscribe((res: any) => { + this.libProjectService.setProjectData(res.result); + this.readProjectDeatilsAndMap(data.controls,res.result); + this.libProjectService.upDateProjectTitle(); + }) + ); + } + }else{ + if (Object.keys(this.libProjectService.projectData).length > 1) { // project ID will be there so length considered as more than 1 + this.readProjectDeatilsAndMap(data.controls,this.libProjectService.projectData); + } else { + this.subscription.add( + this.libProjectService + .readProject(this.projectId) + .subscribe((res: any) => { + this.libProjectService.setProjectData(res.result); + this.readProjectDeatilsAndMap(data.controls,res.result); + }) + ); + } + } + } else { + this.readProjectDeatilsAndMap(data.controls,this.libProjectService.projectData); + } + }) + ); } }); } - - getFormDataAndSubscribe() { - return from(this.formService.getFormWithEntities('PROJECT_DETAILS')).pipe( - switchMap((data: any) => { - if (data) { - this.formDataForTitle = data.controls.find((item: any) => item.name === 'title'); - return this.route.queryParams.pipe( - map((params: any) => { - this.projectId = params.projectId; - this.libProjectService.projectData.id = params.projectId; - return data; // Return data directly - }) - ); - } else { - return of(null); // Return null or empty observable if data is not present - } - }) - )}; - readProjectDeatilsAndMap(formControls:any,res: any) { formControls.forEach((element: any) => { if (Array.isArray(res[element.name])) { @@ -131,29 +169,10 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec this.libProjectService.validForm.projectDetails = ( this.formLib?.myForm.status === "INVALID" || this.formLib?.subform?.myForm.status === "INVALID") ? "INVALID" : "VALID"; } if(this.libProjectService.projectData.tasks){ - const isValid = this.libProjectService.projectData.tasks.every((task: { name: any; }) => task.name); + const isValid = this.libProjectService.projectData.tasks.every((task: { description: any; }) => task.description); this.libProjectService.validForm.tasks = isValid ? "VALID" : "INVALID"; } } - - handleProjectData(controls: any, updateTitle: boolean = true) { - if (Object.keys(this.libProjectService.projectData).length > 1) { - this.readProjectDeatilsAndMap(controls, this.libProjectService.projectData); - } else { - this.subscription.add( - this.libProjectService - .readProject(this.projectId) - .subscribe((res: any) => { - this.libProjectService.setProjectData(res.result); - this.readProjectDeatilsAndMap(controls, res.result); - if (updateTitle) { - this.libProjectService.upDateProjectTitle(); - } - }) - ); - } - } - startAutoSaving() { this.intervalId = setInterval(() => { if(!this.projectId) { @@ -163,7 +182,6 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec } }, 30000); } - createProject(payload?:any) { // title should be send from calling methods only, due to title can be filled before project creation this.libProjectService .createOrUpdateProject(payload) @@ -181,11 +199,9 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec this.libProjectService.projectData.id = res.result.id; }) } - saveForm() { if (this.libProjectService.projectData.title) { this.libProjectService.validForm.projectDetails = (this.formLib?.myForm.status === "INVALID" || this.formLib?.subform?.myForm.status === "INVALID") ? "INVALID" : "VALID"; - if (this.projectId) { this.libProjectService.updateProjectDraft(this.projectId).subscribe(); } @@ -203,7 +219,6 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec exitButton: 'CONTINUE', }, }); - return dialogRef .afterClosed() .toPromise() @@ -227,9 +242,7 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec } }); } - } - getDynamicFormData(data: any) { const obj: { [key: string]: any } = {}; if (!this.isEvent(data)) { @@ -240,15 +253,12 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec this.libProjectService.validForm.projectDetails = (this.formLib?.myForm.status === "INVALID" || this.formLib?.subform?.myForm.status === "INVALID") ? "INVALID" : "VALID"; } } - - isEvent(data:any) { return typeof data === 'object' && data !== null && 'type' in data && 'target' in data && typeof data.preventDefault === 'function' && typeof data.stopPropagation === 'function'; }; - ngOnDestroy() { this.libProjectService.validForm.projectDetails = ( this.formLib?.myForm.status === "INVALID" || this.formLib?.subform?.myForm.status === "INVALID") ? "INVALID" : "VALID"; this.subscription.unsubscribe(); @@ -259,12 +269,14 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec } if(this.projectId) { this.libProjectService.createOrUpdateProject(this.libProjectService.projectData,this.projectId).subscribe((res)=> console.log(res)) + this.libProjectService.saveProjectFunc(false); + } + else { + this.libProjectService.saveProjectFunc(false); } - this.libProjectService.saveProjectFunc(false); + this.libProjectService.checkSendForReviewValidation(false); } - } - formMarkTouched() { this.formLib?.myForm.markAllAsTouched() this.formLib?.subform?.myForm.markAllAsTouched() diff --git a/projects/lib-project/src/lib/dock/components/sub-tasks-resources/sub-tasks-resources.component.ts b/projects/lib-project/src/lib/dock/components/sub-tasks-resources/sub-tasks-resources.component.ts index ddc833df..ead6d6f5 100644 --- a/projects/lib-project/src/lib/dock/components/sub-tasks-resources/sub-tasks-resources.component.ts +++ b/projects/lib-project/src/lib/dock/components/sub-tasks-resources/sub-tasks-resources.component.ts @@ -94,13 +94,9 @@ export class SubTasksResourcesComponent implements OnInit,OnDestroy{ this.libProjectService.isSendForReviewValidation.subscribe( (reviewValidation: boolean) => { if(reviewValidation) { - if(this.mode == 'edit' && this.projectId) { - if(this.projectId && this.mode == 'edit') { - this.myForm.markAllAsTouched() - } + this.myForm.markAllAsTouched() this.libProjectService.validForm.subTasks = this.subtasks?.status? this.subtasks?.status: "INVALID" - console.log(this.libProjectService.validForm) - } + this.libProjectService.triggerSendForReview(); } } ) @@ -254,6 +250,7 @@ export class SubTasksResourcesComponent implements OnInit,OnDestroy{ this.autoSaveSubscription.unsubscribe(); } this.libProjectService.createOrUpdateProject(this.libProjectService.projectData,this.projectId).subscribe((res)=> console.log(res)) + this.libProjectService.checkSendForReviewValidation(false); } this.subscription.unsubscribe(); } diff --git a/projects/lib-project/src/lib/dock/components/tasks/tasks.component.ts b/projects/lib-project/src/lib/dock/components/tasks/tasks.component.ts index cc868d63..74057db5 100644 --- a/projects/lib-project/src/lib/dock/components/tasks/tasks.component.ts +++ b/projects/lib-project/src/lib/dock/components/tasks/tasks.component.ts @@ -157,7 +157,7 @@ export class TasksComponent implements OnInit, OnDestroy { if(this.mode == 'edit' && this.projectId) { this.tasksForm.markAllAsTouched(); this.libProjectService.validForm.tasks = this.tasks?.status? this.tasks?.status: "INVALID" - console.log(this.libProjectService.validForm) + this.libProjectService.triggerSendForReview(); } } } @@ -255,6 +255,7 @@ export class TasksComponent implements OnInit, OnDestroy { this.libProjectService.validForm.tasks = this.tasks?.status? this.tasks?.status: "INVALID" this.saveTasks() this.libProjectService.createOrUpdateProject(this.libProjectService.projectData,this.projectId).subscribe((res)=> console.log(res)) + this.libProjectService.checkSendForReviewValidation(false); } this.subscription.unsubscribe(); if (this.autoSaveSubscription) { diff --git a/projects/lib-project/src/lib/dock/view-module/layout/layout.component.html b/projects/lib-project/src/lib/dock/view-module/layout/layout.component.html index d56937e1..89fbe55a 100644 --- a/projects/lib-project/src/lib/dock/view-module/layout/layout.component.html +++ b/projects/lib-project/src/lib/dock/view-module/layout/layout.component.html @@ -1,7 +1,7 @@
- +
diff --git a/projects/lib-project/src/lib/dock/view-module/layout/layout.component.ts b/projects/lib-project/src/lib/dock/view-module/layout/layout.component.ts index 8e325c34..a38a4bfe 100644 --- a/projects/lib-project/src/lib/dock/view-module/layout/layout.component.ts +++ b/projects/lib-project/src/lib/dock/view-module/layout/layout.component.ts @@ -14,16 +14,18 @@ export class LayoutComponent { subHeader : any; selctedCardItem : any; headerData:any - sidenavData:any + sidenavData:any; + tabValidation:any; constructor(private libProjectService:LibProjectService,private formService:FormService,private route:ActivatedRoute,private router:Router,) { } ngOnInit(){ - this.libProjectService.validForm={ - projectDetails: "INVALID", - tasks:"INVALID", - subTasks:"VALID" + this.tabValidation={ + projectDetails: "VALID", + tasks:"VALID", + subTasks:"VALID", + certificates:'VALID' } - this. setConfig() + this.setConfig() this.getProjectdata() this.libProjectService.currentProjectMetaData.subscribe(data => { this.sidenavData= data?.sidenavData.sidenav @@ -79,7 +81,7 @@ export class LayoutComponent { } case "SEND_FOR_REVIEW":{ this.libProjectService.checkSendForReviewValidation(true); - this.libProjectService.triggerSendForReview() + this.tabValidation = this.libProjectService.validForm; break; } default: @@ -89,6 +91,5 @@ export class LayoutComponent { navChangeEvent(data:any) { console.log(data) - console.log(this.libProjectService.validForm); } } diff --git a/projects/lib-project/src/lib/lib-project.service.ts b/projects/lib-project/src/lib/lib-project.service.ts index e9e8f930..a7cea9a9 100644 --- a/projects/lib-project/src/lib/lib-project.service.ts +++ b/projects/lib-project/src/lib/lib-project.service.ts @@ -23,7 +23,8 @@ export class LibProjectService { validForm={ projectDetails: "INVALID", tasks:"INVALID", - subTasks:"VALID" + subTasks:"VALID", + certificates:"VALID" } viewOnly:boolean= false; mode:any="edit" diff --git a/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.html b/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.html index 3f8f1701..06665648 100644 --- a/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.html +++ b/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.html @@ -6,7 +6,7 @@ {{ item.icon }} {{ item.label | translate }} - info + info } diff --git a/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.ts b/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.ts index 6408721f..b8ac47ab 100644 --- a/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.ts +++ b/projects/lib-shared-modules/src/lib/components/side-navbar/side-navbar.component.ts @@ -18,6 +18,7 @@ import { CommonModule } from '@angular/common'; export class SideNavbarComponent implements OnInit{ @Input() sidenavData : any[] = []; @Output() navChange = new EventEmitter(); + @Input() tabValidation:any; constructor(private formService:FormService) { @@ -25,9 +26,6 @@ export class SideNavbarComponent implements OnInit{ } ngOnInit() { - this.formService.getPermissions().subscribe((res:any) => { - this.sidenavData = this.formService.checkPermissions(this.sidenavData,res.result) - }) } currentTab(data:any) { diff --git a/projects/lib-shared-modules/src/lib/services/form/form.service.ts b/projects/lib-shared-modules/src/lib/services/form/form.service.ts index b249208b..e036c492 100644 --- a/projects/lib-shared-modules/src/lib/services/form/form.service.ts +++ b/projects/lib-shared-modules/src/lib/services/form/form.service.ts @@ -108,5 +108,15 @@ export class FormService { } } + // checkRolePermissions(data:any,roles:any) { + // if(data && data[0]?.roles) { + // return data.filter((item:any) => + // item.roles.some((role: string) => + // roles.some((perm:any) => perm.roles.includes(role)) + // ) + // ); + // } + // } + } diff --git a/projects/self-creation-portal/src/app/components/app-main-view/app-main-view.component.ts b/projects/self-creation-portal/src/app/components/app-main-view/app-main-view.component.ts index 8a02db26..a2308a1f 100644 --- a/projects/self-creation-portal/src/app/components/app-main-view/app-main-view.component.ts +++ b/projects/self-creation-portal/src/app/components/app-main-view/app-main-view.component.ts @@ -42,6 +42,13 @@ export class AppMainViewComponent { getnavData(){ this.formService.getForm(SIDE_NAV_DATA).subscribe((form) =>{ this.sidenavData = form?.result?.data?.fields?.controls + let userRoles:any = localStorage.getItem('user_roles') + userRoles = JSON.parse(userRoles); + this.sidenavData = this.sidenavData.filter((item:any) => + item.roles.some((role:any) => + userRoles.some((innerRole:any) => innerRole.title === role) + ) + ); }) } diff --git a/projects/self-creation-portal/src/app/components/create-new/create-new.component.ts b/projects/self-creation-portal/src/app/components/create-new/create-new.component.ts index 7f6031dc..f344a6f2 100644 --- a/projects/self-creation-portal/src/app/components/create-new/create-new.component.ts +++ b/projects/self-creation-portal/src/app/components/create-new/create-new.component.ts @@ -56,6 +56,11 @@ export class CreateNewComponent { this.formService.getForm(SOLUTION_LIST).subscribe((form) =>{ this.resourceList = form?.result?.data?.fields?.controls this.resourceList = this.formService.checkPermissions(this.resourceList,res.result) + let userRoles:any = localStorage.getItem('user_roles') + userRoles = JSON.parse(userRoles) + if(!userRoles.find((item:any)=> item.title == 'content_creator')) { + this.router.navigate(['/home/up-for-review']) + } }) }) }