Skip to content

Commit

Permalink
Merge pull request #147 from ramkumar-pacewisdom/dev-ram0
Browse files Browse the repository at this point in the history
Dev ram0
  • Loading branch information
ramkumar-pacewisdom authored Aug 9, 2024
2 parents be4b2c1 + cd686fc commit 2cb6235
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 90 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ 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,
imports: [DynamicFormModule, TranslateModule],
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;
Expand All @@ -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')) {
Expand All @@ -57,6 +54,7 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec
(reviewValidation: boolean) => {
if(reviewValidation) {
this.formMarkTouched();
this.libProjectService.triggerSendForReview();
}
}
)
Expand All @@ -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";
Expand All @@ -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])) {
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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();
}
Expand All @@ -203,7 +219,6 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec
exitButton: 'CONTINUE',
},
});

return dialogRef
.afterClosed()
.toPromise()
Expand All @@ -227,9 +242,7 @@ export class ProjectDetailsComponent implements OnDestroy, OnInit, AfterViewChec
}
});
}

}

getDynamicFormData(data: any) {
const obj: { [key: string]: any } = {};
if (!this.isEvent(data)) {
Expand All @@ -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();
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
)
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<lib-header [backButton]="backButton" [headerData]="headerData" (buttonClick)="onButtonClick($event)"></lib-header>
<div class="main flex">
<div class="min-h-[88vh] max-h-[100vh] sticktop">
<lib-side-navbar [sidenavData]="sidenavData" (navChange)="navChangeEvent($event)"></lib-side-navbar>
<lib-side-navbar [sidenavData]="sidenavData" (navChange)="navChangeEvent($event)" [tabValidation]="tabValidation"></lib-side-navbar>
</div>
<div class="w-full">
<router-outlet></router-outlet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -89,6 +91,5 @@ export class LayoutComponent {

navChangeEvent(data:any) {
console.log(data)
console.log(this.libProjectService.validForm);
}
}
3 changes: 2 additions & 1 deletion projects/lib-project/src/lib/lib-project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class LibProjectService {
validForm={
projectDetails: "INVALID",
tasks:"INVALID",
subTasks:"VALID"
subTasks:"VALID",
certificates:"VALID"
}
viewOnly:boolean= false;
mode:any="edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span class="entry">
<mat-icon>{{ item.icon }}</mat-icon>
<span>{{ item.label | translate }}</span>
<mat-icon class="text-warning error-icon" *ngIf="item.isTabNotValid">info</mat-icon>
<mat-icon class="text-warning error-icon" *ngIf="tabValidation && tabValidation[item.page] == 'INVALID'">info</mat-icon>
</span>
</a>
}
Expand Down
Loading

0 comments on commit 2cb6235

Please sign in to comment.