Skip to content

Commit

Permalink
Merge pull request #608 from mansurskTarento/odcs-designations
Browse files Browse the repository at this point in the history
Odcs designations
  • Loading branch information
christyfernandes authored Aug 8, 2024
2 parents 7b17c68 + 4531f0e commit b098b56
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ITableData } from '@sunbird-cb/collection/lib/ui-org-table/interface/in
import { DesignationsService } from '../../services/designations.service'
import { FormControl } from '@angular/forms'
import { delay } from 'rxjs/operators'
import { HttpErrorResponse } from '@angular/common/http'
import { MatDialog, MatSnackBar } from '@angular/material'
import { ConformationPopupComponent } from '../../dialog-boxes/conformation-popup/conformation-popup.component'
import { ActivatedRoute } from '@angular/router'
Expand Down Expand Up @@ -103,9 +102,7 @@ export class DesignationsComponent implements OnInit {
this.designationConfig = data.pageData.data
})

// console.log('this.configSvc', this.configSvc.orgReadData)
if (this.configSvc.orgReadData && this.configSvc.orgReadData.frameworkid) {
// this.environmentVal.frameworkName = this.configSvc.orgReadData.frameworkid
this.getFrameworkInfo(this.configSvc.orgReadData.frameworkid)
} else {
this.createFreamwork()
Expand Down Expand Up @@ -135,7 +132,7 @@ export class DesignationsComponent implements OnInit {
} else {
setTimeout(() => {
this.getOrgReadData()
}, 10000)
}, _.get(this.designationConfig, 'refreshDelayTime', 10000))
}
// console.log('orgFramework Details', res)
})
Expand All @@ -153,9 +150,9 @@ export class DesignationsComponent implements OnInit {

this.getOrganisations()
},
error: (error: HttpErrorResponse) => {
error: () => {
this.showLoader = false
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.openSnackbar(errorMessage)
},

Expand All @@ -179,7 +176,7 @@ export class DesignationsComponent implements OnInit {
}

getDesignations() {
this.designationsList = this.getTermsByCode('designation')
this.designationsList = _.get(this.organisationsList, '[0].children')
this.designationsService.setCurrentOrgDesignationsList(this.designationsList)
this.filterDesignations()
}
Expand Down Expand Up @@ -217,26 +214,6 @@ export class DesignationsComponent implements OnInit {

//#region (ui interactions like click)

// openDesignationCreatPopup(event?: any) {
// console.log('event', event)
// const dialogData = {
// mode: 'create',
// columnInfo: {
// code: 'designation',
// name: 'Designation',
// children: this.designationsList,
// },
// frameworkId: 'organisation_fw',
// selectedDesignation: null
// }
// if (event && event.action) {
// dialogData.mode = event.action
// dialogData.selectedDesignation = event.row
// }
// }

// upload() { }

menuSelected(event: any) {
switch (event.action) {
// case 'edit':
Expand All @@ -252,7 +229,6 @@ export class DesignationsComponent implements OnInit {
}

openConformationPopup(event: any) {
// console.log('envent data', event)
const dialogData = {
dialogType: 'warning',
descriptions: [
Expand Down Expand Up @@ -314,9 +290,9 @@ export class DesignationsComponent implements OnInit {
this.showLoader = false
}
},
error: (error: HttpErrorResponse) => {
error: () => {
this.showLoader = false
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.openSnackbar(errorMessage)
},
})
Expand All @@ -328,15 +304,17 @@ export class DesignationsComponent implements OnInit {
this.designationsService.publishFramework(frameworkName).subscribe({
next: response => {
if (response) {
this.getFrameworkInfo(this.frameworkDetails.code)
if (action && action === 'delete') {
this.openSnackbar('Deleted Successfully')
}
setTimeout(() => {
this.getFrameworkInfo(this.frameworkDetails.code)
if (action && action === 'delete') {
this.openSnackbar(_.get(this.designationConfig, 'termRemoveMsg'))
}
}, _.get(this.designationConfig, 'refreshDelayTime', 10000))
}
},
error: (error: HttpErrorResponse) => {
error: () => {
this.showLoader = false
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.openSnackbar(errorMessage)
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { FormControl } from '@angular/forms'
import { catchError, delay, map } from 'rxjs/operators'
import { SelectedDesignationPopupComponent } from '../../dialog-boxes/selected-designation-popup/selected-designation-popup.component'
import { forkJoin, of, Subscription } from 'rxjs'
import { HttpErrorResponse } from '@angular/common/http'
import * as _ from 'lodash'
import { LoaderService } from '../../../../../../../../../../../src/app/services/loader.service'
import { ActivatedRoute, Router } from '@angular/router'
Expand Down Expand Up @@ -42,6 +41,7 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
designationsImportFailed: any = []
frameworkInfo: any = {}
dialogRef: any
progressDialogData: any

constructor(
private designationsService: DesignationsService,
Expand All @@ -51,14 +51,15 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
private snackBar: MatSnackBar,
private datePipe: DatePipe,
private activateRoute: ActivatedRoute
) { }
) {
this.getFrameWorkDetails()
}

ngOnInit() {
this.configSvc = this.activateRoute.snapshot.data['configService']
this.loadDesignations()
this.valudChangeSubscribers()

this.getFrameWorkDetails()
this.valueChangeSubscription()
this.getRoutesData()
}

getFrameWorkDetails() {
Expand Down Expand Up @@ -108,14 +109,20 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
return this.selectedDesignationsList
}

valudChangeSubscribers() {
valueChangeSubscription() {
if (this.searchControl) {
this.searchControl.valueChanges.pipe(delay(500)).subscribe((value: string) => {
this.loadDesignations(value)
})
}
}

getRoutesData() {
this.activateRoute.data.subscribe(data => {
this.designationConfig = data.pageData.data
})
}

selectDesignation(checked: Boolean, id: number) {
const index = this.igotDesignationsList.findIndex((e: any) => e.id === id)
const designation = this.igotDesignationsList[index]
Expand Down Expand Up @@ -224,22 +231,25 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
this.updateTerms(orgCategorie)
}
},
error: (error: HttpErrorResponse) => {
error: () => {
this.dialogRef.close()
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.openSnackbar(errorMessage)
},
})
}
}

updateTerms(orgCategorie: any) {
updateTerms(orgCategorie: any, retry = false) {
if (this.selectedDesignationsList.length === this.designationsImportFailed.length) {
this.dialogRef.close(false)
const errorMessage = 'Import failed'
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.openSnackbar(errorMessage)
this.designationsImportFailed = []
} else {
if (!retry) {
this.progressDialogData['subTitle'] = _.get(this.designationConfig, 'associationUpdateMsg')
}
const framework = _.get(this.frameworkInfo, 'code')
const category = _.get(orgCategorie, 'terms[0].category')
const categoryTermCode = _.get(orgCategorie, 'terms[0].code')
Expand All @@ -256,47 +266,55 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
this.publishFrameWork()
}
},
error: (error: HttpErrorResponse) => {
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
this.dialogRef.close()
this.openSnackbar(errorMessage)
error: () => {
if (retry) {
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.dialogRef.close()
this.openSnackbar(errorMessage)
} else {
this.progressDialogData['subTitle'] = _.get(this.designationConfig, 'associationRetryMsg')
const traiagain = true
this.updateTerms(orgCategorie, traiagain)
}
},
})
}
}

publishFrameWork() {
const frameworkName = _.get(this.frameworkInfo, 'code')
this.progressDialogData['subTitle'] = _.get(this.designationConfig, 'publishingMsg')
this.designationsService.publishFramework(frameworkName).subscribe({
next: response => {
if (response) {
setTimeout(() => {
this.dialogRef.close()
}, 10000)
this.dialogRef.close(true)
}, _.get(this.designationConfig, 'refreshDelayTime', 10000))
}
},
error: (error: HttpErrorResponse) => {
const errorMessage = _.get(error, 'error.message', 'Some thing went wrong')
error: () => {
const errorMessage = _.get(this.designationConfig, 'internalErrorMsg')
this.dialogRef.close()
this.openSnackbar(errorMessage)
},
})
}

openProcessingBox() {
const dialogData = {
this.progressDialogData = {
type: 'progress',
icon: 'vega',
title: 'Importing your designation.',
subTitle: 'Please wait a moment, your import is in progress.',
title: _.get(this.designationConfig, 'importingDesignation'),
subTitle: _.get(this.designationConfig, 'termCreationMsg'),
showLoader: true,
}
this.dialogRef = this.dialog.open(ConfirmationBoxComponent, {
disableClose: true,
data: dialogData,
data: this.progressDialogData,
autoFocus: false,
})

this.dialogRef.afterClosed().subscribe((res: boolean = true) => {
this.dialogRef.afterClosed().subscribe((res: boolean = false) => {
if (res) {
this.openConforamtionPopup()
}
Expand All @@ -318,33 +336,6 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
],
}
descriptions.push(description)
// if (this.importedDesignationNames.length > 0) {
// const designationNames = this.importedDesignationNames.join(', ')
// const description = {
// header: 'Designations imported successfully',
// messages: [
// {
// msgClass: 'textBold',
// msg: `${designationNames}`,
// },
// {
// msgClass: '',
// msg: ' are imported successfully',
// },
// ],
// }
// descriptions.push(description)
// }

// descriptions.push({

// messages: [
// {
// msgClass: '',
// msg: 'The changes will reflect shortly.',
// },
// ],
// })
const dialogData = {
descriptions,
dialogType: 'warning',
Expand All @@ -370,7 +361,7 @@ export class ImportDesignationComponent implements OnInit, OnDestroy {
this.navigateToMyDesignations()
})
} else {
const successMessage = 'Imported Successfully '
const successMessage = _.get(this.designationConfig, 'successMsg')
this.openSnackbar(successMessage, 10000)
this.navigateToMyDesignations()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,11 @@ const routes: Routes = [
{
path: 'import-designation',
pathMatch: 'full',
// data: {
// pageId: 'home/org-designations/import-designation',
// module: 'manage-designations',
// pageType: 'feature',
// pageKey: 'import-designations',
// },
data: {
pageId: 'home/odcs-mapping',
module: 'odcs-mapping',
pageType: 'feature',
pageKey: 'odcs',
pageKey: 'my_designations',
},
component: ImportDesignationComponent,
resolve: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,7 @@ export class DesignationsService {
category: a.category,
associations: a.associations,
// config: this.getConfig(a.code),
children: (a.terms || []).map((c: any) => {
const associations = c.associations || []
if (associations.length > 0) {
Object.assign(c, { children: associations })
}
const importedBy = _.get(c, 'additionalProperties.importedById', null) === _.get(this.userProfile, 'userId', '')
? 'You' : _.get(c, 'additionalProperties.importedByName', null)
c['importedByName'] = importedBy,
c['importedOn'] = _.get(c, 'additionalProperties.importedOn'),
c['importedById'] = _.get(c, 'additionalProperties.importedById')
return c
}),
children: this.formateChildren(a.terms || []),
})
})

Expand All @@ -163,6 +152,22 @@ export class DesignationsService {

}

formateChildren(terms: any[]): any[] {
return terms.map((c: any) => {
const associations = c.associations || []
if (associations.length > 0) {
Object.assign(c, { children: associations })
this.formateChildren(c.associations)
}
const importedBy = _.get(c, 'additionalProperties.importedById', null) === _.get(this.userProfile, 'userId', '')
? 'You' : _.get(c, 'additionalProperties.importedByName', null)
c['importedByName'] = importedBy,
c['importedOn'] = _.get(c, 'additionalProperties.importedOn'),
c['importedById'] = _.get(c, 'additionalProperties.importedById')
return c
})
}

get getUuid() {
return uuidv4()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
{{data?.subTitle}}
</div>
<div class="flex flex-1 flex-row progress-icon">
<img src="assets/icons/{{data?.icon}}.svg" />

<ng-container *ngIf="data?.showLoader; else progressIcon">
<mat-spinner [diameter]="30"></mat-spinner>
</ng-container>
<ng-template #progressIcon>
<img src="assets/icons/{{data?.icon}}.svg" />
</ng-template>
</div>
</div>

Expand Down
Loading

0 comments on commit b098b56

Please sign in to comment.