diff --git a/src/app/admin/create-entity/create-entity.component.html b/src/app/admin/create-entity/create-entity.component.html index 214025f..316c7e7 100644 --- a/src/app/admin/create-entity/create-entity.component.html +++ b/src/app/admin/create-entity/create-entity.component.html @@ -485,6 +485,8 @@

{{'SAVE_CONFIGURATION' | translate}}

  +   diff --git a/src/app/admin/create-entity/create-entity.component.ts b/src/app/admin/create-entity/create-entity.component.ts index 0b9b2cb..acf29ea 100644 --- a/src/app/admin/create-entity/create-entity.component.ts +++ b/src/app/admin/create-entity/create-entity.component.ts @@ -1945,8 +1945,8 @@ export class CreateEntityComponent implements OnInit, AfterContentChecked { } saveOwnershipAttributes(moveNext = false) { - this.OwnershipComp.submitOwnershipForm(); - moveNext ? this.nextStep() : this.saveAsDraftMsg(); + let toMoveNext = this.OwnershipComp.submitOwnershipForm(moveNext); + (moveNext ? (toMoveNext ? this.nextStep() : undefined) : (toMoveNext ? undefined : this.saveAsDraftMsg())); } saveConfigWorkflow(moveNext = false) { diff --git a/src/app/admin/ownership/ownership.component.html b/src/app/admin/ownership/ownership.component.html index f2f2743..e483340 100644 --- a/src/app/admin/ownership/ownership.component.html +++ b/src/app/admin/ownership/ownership.component.html @@ -14,7 +14,7 @@
{{'FIELD_MAPPING' | translate}}
-
+
@@ -22,16 +22,16 @@
- +
@@ -44,7 +44,7 @@
+ id="flexCheckEmail" formControlName="emailCheckbox" (change)="onCheckboxChange($event)"> @@ -53,7 +53,7 @@
@@ -67,7 +67,7 @@
+ id="flexCheckMobile" formControlName="mobilenumberCheckbox" (change)="onCheckboxChange($event)"> @@ -75,7 +75,7 @@
@@ -87,7 +87,7 @@
+ id="flexCheckPassword" formControlName="passwordCheckbox" (change)="onCheckboxChange($event)"> @@ -95,7 +95,7 @@
@@ -120,29 +120,30 @@
+ value="anonymous" formControlName="issuer" [defaultChecked]="true" (change)="onIssuerRadioChange($event)">
+ formControlName="issuer" (change)="onIssuerRadioChange($event)">
-
{{'SELECT_ROLE' | translate}}
+
- + +
@@ -159,28 +160,29 @@
+ value="anonymous" formControlName="invitee" [defaultChecked]="true" (change)="onInviteRadioChange($event)">
+ formControlName="invitee" (change)="onInviteRadioChange($event)"> -
-
+
{{'SELECT_ROLE' | translate}}
+
- + +
diff --git a/src/app/admin/ownership/ownership.component.ts b/src/app/admin/ownership/ownership.component.ts index 791dea2..765157d 100644 --- a/src/app/admin/ownership/ownership.component.ts +++ b/src/app/admin/ownership/ownership.component.ts @@ -2,6 +2,7 @@ import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/cor import { FormBuilder, FormGroup } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; +import { ToastMessageService } from '../../services/toast-message/toast-message.service'; import { GeneralService } from 'src/app/services/general/general.service'; @Component({ @@ -14,35 +15,50 @@ export class OwnershipComponent implements OnInit, OnChanges { params: any; isSettingMenu: boolean = false; ownershipForm: FormGroup; - items: any = []; + useCaseSchema: any = []; entityName: any; propertyList = []; propertyNames = []; selectedProperty: any; entityList: any[]; schemaStatus: any; + passwordCheck: boolean; + issuerCheck: string; + inviteCheck: string; + email: any; + emailCheck: boolean; + userID: any; + userIDCheck: boolean; + mobile: any; + mobileCheck: boolean; + password: any; + issuerRole: any; + inviteRole: any; + defaultOptionValue: string = ''; constructor( private activeRoute: ActivatedRoute, public translate: TranslateService, + public toastMsg: ToastMessageService, private fb: FormBuilder, public generalService: GeneralService ) { this.ownershipForm = this.fb.group({ primaryLogin: this.fb.group({ - userIDCheckbox : false, - userIDField : '', + userIDCheckbox: false, + userIDField: '', emailCheckbox: false, emailField: '', mobilenumberCheckbox: false, mobilenumberField: '', - passwordCheckbox:false, + passwordCheckbox: false, passwordField: '' }), issuer: 'anonymous', issuerRole: '', - invitee:'anonymous', - inviteRole:'' + invitee: 'anonymous', + inviteRole: '', + newRole: '' }) } @@ -56,9 +72,16 @@ export class OwnershipComponent implements OnInit, OnChanges { }); this.generalService.getData('/Schema').subscribe((res) => { - this.readSchema(res); - + for (let i = 0; i < res.length; i++) { + if (typeof (res[i].schema) == 'string') { + res[i].schema = JSON.parse(res[i].schema); + if (!res[i].schema.hasOwnProperty('isRefSchema') && !res[i].schema.isRefSchema) { + this.useCaseSchema.push(res[i]); + } + } + } this.populateFields(); + this.readSchema(); }); } @@ -67,122 +90,237 @@ export class OwnershipComponent implements OnInit, OnChanges { if (latestRequest.currentValue) { this.entityName = latestRequest.currentValue; this.populateFields(); + this.readSchema(); } } - readSchema(res) { - for (let i = 0; i < res.length; i++) { - if (typeof (res[i].schema) == 'string') { - res[i].schema = JSON.parse(res[i].schema); - if (!res[i].schema.hasOwnProperty('isRefSchema') && !res[i].schema.isRefSchema) { - this.items.push(res[i]); + readSchema() { + for (let i = 0; i < this.useCaseSchema.length; i++) { + if (this.useCaseSchema[i]["name"] == this.entityName) { + if (this.useCaseSchema[i].schema._osConfig['ownershipAttributes'].length || this.useCaseSchema[i].schema._osConfig['roles'].length || this.useCaseSchema[i].schema._osConfig['inviteRoles'] != 'anonymous') { + if (this.useCaseSchema[i].schema._osConfig['ownershipAttributes'].length) { + this.email = this.useCaseSchema[i].schema._osConfig['ownershipAttributes'][0].email; + this.email = this.email.substring(1); + this.email == '' ? this.emailCheck = false : this.emailCheck = true; + + this.userID = this.useCaseSchema[i].schema._osConfig['ownershipAttributes'][0].userID; + this.userID = this.userID.substring(1); + this.userID == '' ? this.userIDCheck = false : this.userIDCheck = true; + + this.mobile = this.useCaseSchema[i].schema._osConfig['ownershipAttributes'][0].mobile; + this.mobile = this.mobile.substring(1); + this.mobile == '' ? this.mobileCheck = false : this.mobileCheck = true; + + this.password = this.useCaseSchema[i].schema._osConfig['ownershipAttributes'][0].password ? this.useCaseSchema[i].schema._osConfig['ownershipAttributes'][0].password : ''; + this.password = this.password.substring(1); + this.password == '' ? this.passwordCheck = false : this.passwordCheck = true; + } + if (this.useCaseSchema[i].schema._osConfig['roles'] && this.useCaseSchema[i].schema._osConfig['roles'].length) { + this.issuerRole = this.useCaseSchema[i].schema._osConfig['roles'][0]; + this.issuerRole ? this.issuerCheck = 'role' : this.issuerCheck = 'anonymous'; + if(!this.entityList.includes(this.issuerRole)){ + this.entityList.push(this.issuerRole); + } + } + + if (this.useCaseSchema[i].schema._osConfig['inviteRoles'] && this.useCaseSchema[i].schema._osConfig['inviteRoles'].length) { + this.inviteRole = this.useCaseSchema[i].schema._osConfig['inviteRoles'][0]; + this.inviteRole ? this.inviteCheck = 'inviteRoles' : this.issuerCheck = 'anonymous' + if(!this.entityList.includes(this.inviteRole)){ + this.entityList.push(this.inviteRole); + } + } + + this.ownershipForm.patchValue({ + primaryLogin: { + userIDCheckbox: this.userIDCheck, + userIDField: this.userID, + emailCheckbox: this.emailCheck, + emailField: this.email, + mobilenumberField: this.mobile, + mobilenumberCheckbox: this.mobileCheck, + passwordCheckbox: this.passwordCheck, + passwordField: this.password + }, + issuer: this.issuerCheck, + issuerRole: this.issuerRole, + invitee: this.inviteCheck, + inviteRole: this.inviteRole + }); } + if (!this.useCaseSchema[i].schema._osConfig['ownershipAttributes'].length && !this.useCaseSchema[i].schema._osConfig['roles'].length && this.useCaseSchema[i].schema._osConfig['inviteRoles'] == 'anonymous') { + this.ownershipForm.patchValue({ + primaryLogin: { + userIDCheckbox: false, + userIDField: '', + emailCheckbox: false, + emailField: '', + mobilenumberCheckbox: false, + mobilenumberField: '', + passwordCheckbox: false, + passwordField: '' + }, + issuer: 'anonymous', + issuerRole: '', + invitee: 'anonymous', + inviteRole: '' + }); + } + + } } + } populateFields() { this.propertyList = []; - this.propertyNames = []; + let propertyName = new Set(); this.entityList = []; - for (let i = 0; i < this.items.length; i++) { - this.entityList.push(this.items[i].name); - if (this.items[i]["name"] == this.entityName) { - this.schemaStatus = this.items[i].status; - let properties = this.items[i]["schema"]["definitions"][this.entityName]["properties"]; - let requiredProperties = this.items[i]["schema"]["definitions"][this.entityName]["required"]; - for(let j=0; j< requiredProperties.length; j++){ - this.propertyNames.push(requiredProperties[j]); + for (let i = 0; i < this.useCaseSchema.length; i++) { + let entityListItem = this.useCaseSchema[i].name; + if (!this.entityList.includes(entityListItem)) { + this.entityList.push(entityListItem); + } + if (this.useCaseSchema[i]["name"] == this.entityName) { + this.schemaStatus = this.useCaseSchema[i].status; + let properties = this.useCaseSchema[i]["schema"]["definitions"][this.entityName]["properties"]; + let requiredProperties = this.useCaseSchema[i]["schema"]["definitions"][this.entityName]["required"]; + if (this.useCaseSchema[i]["schema"]["definitions"][this.entityName]?.properties) { + var nestedFields = this.useCaseSchema[i]["schema"]["definitions"][this.entityName].properties; + for (var c in nestedFields) { + if (nestedFields.hasOwnProperty(c)) { + if (nestedFields[c].required) { + for (let k = 0; k < nestedFields[c].required.length; k++) { + requiredProperties.push(nestedFields[c].required[k]) + } + } + } + } } + for (let j = 0; j < requiredProperties.length; j++) { + propertyName.add(requiredProperties[j]); + } + this.propertyNames = Array.from(propertyName); const keys = Object.keys(properties); keys.forEach((key, index) => { properties[key] = { ...properties[key], "key": key } - this.propertyList.push(properties[key]); + this.propertyList.push(properties[key]); }); - + } } } - submitOwnershipForm() { - if (this.ownershipForm.value.uniqueField == undefined || this.ownershipForm.value.uniqueField.length === 0) { - return; + onCheckboxChange(event: Event) { + const checkbox = event.target as HTMLInputElement; + const controlName = checkbox.id; + if (!checkbox.checked) { + switch (controlName) { + case 'flexCheckUserID': + this.ownershipForm.get('primaryLogin.userIDField').setValue(this.defaultOptionValue); + break; + case 'flexCheckEmail': + this.ownershipForm.get('primaryLogin.emailField').setValue(this.defaultOptionValue); + break; + case 'flexCheckMobile': + this.ownershipForm.get('primaryLogin.mobilenumberField').setValue(this.defaultOptionValue); + break; + case 'flexCheckPassword': + this.ownershipForm.get('primaryLogin.passwordField').setValue(this.defaultOptionValue); + break; + } } + } - for (let i = 0; i < this.propertyNames.length; i++) { - if (this.ownershipForm.value.uniqueField === this.propertyNames[i]) { - this.selectedProperty = this.propertyList[i]; + onIssuerRadioChange(event: Event) { + const radio = event.target as HTMLInputElement; + radio.id !='customRadio2'? this.ownershipForm.get('issuerRole').setValue(this.defaultOptionValue) : null; + } + + onInviteRadioChange(event: Event) { + const radio = event.target as HTMLInputElement; + radio.id !='inviteCustomRadio2'? this.ownershipForm.get('inviteRole').setValue(this.defaultOptionValue) : null; + } + + createRole() { + if (this.ownershipForm.value['newRole']) { + if (!this.entityList.includes(this.ownershipForm.value['newRole'])) { + this.entityList.push(this.ownershipForm.value['newRole']); } + this.toastMsg.success('success', this.ownershipForm.value['newRole'] + ' Role is created Sucessfully!'); + this.ownershipForm.patchValue({ newRole: '' }); } + } - for (let i = 0; i < this.items.length; i++) { - if (this.entityName === this.items[i].name) { + submitOwnershipForm(toMoveNext) { + for (let i = 0; i < this.useCaseSchema.length; i++) { + if (this.entityName === this.useCaseSchema[i].name) { let ownershipObj = {}; - let alternateOwnershipObj = {}; - let editSchema = this.items[i]["schema"]; - editSchema["_osConfig"]["ownershipAttributes"] = []; - editSchema["_osConfig"]["uniqueIndexFields"] = []; + let entitySchema = this.useCaseSchema[i]["schema"]; + entitySchema["_osConfig"]["ownershipAttributes"] = []; + entitySchema["_osConfig"]["roles"] = []; + entitySchema["_osConfig"]["inviteRoles"] = []; if (this.ownershipForm.value.primaryLogin['userIDCheckbox']) { ownershipObj = { ...ownershipObj, - "userID": "/" + this.selectedProperty?.key + "/userID" + "userID": "/" + this.ownershipForm.value.primaryLogin['userIDField'] } } if (this.ownershipForm.value.primaryLogin['emailCheckbox']) { ownershipObj = { ...ownershipObj, - "email": "/" + this.selectedProperty?.key + "/email" + "email": "/" + this.ownershipForm.value.primaryLogin['emailField'] } } if (this.ownershipForm.value.primaryLogin['mobilenumberCheckbox']) { ownershipObj = { ...ownershipObj, - "mobile": "/" + this.selectedProperty?.key + "/contact" + "mobile": "/" + this.ownershipForm.value.primaryLogin['mobilenumberField'] } } if (this.ownershipForm.value.primaryLogin['passwordCheckbox']) { ownershipObj = { ...ownershipObj, - "password": "/" + this.selectedProperty?.key + "/password" + "password": "/" + this.ownershipForm.value.primaryLogin['passwordField'] } } - if (Object.keys(ownershipObj).length !== 0) { - editSchema["_osConfig"]["ownershipAttributes"].push(ownershipObj); - editSchema["_osConfig"]["uniqueIndexFields"].push(this.selectedProperty.key); - } - - if (this.ownershipForm.value.alternateLoginCheckbox && this.ownershipForm.value.alternateLogin['emailCheckbox']) { - alternateOwnershipObj = { - ...alternateOwnershipObj, - "email": "/" + this.selectedProperty?.key + "/email" + if (this.ownershipForm.value.primaryLogin['userIDField'] == '' || this.ownershipForm.value.primaryLogin['emailField'] == '' || this.ownershipForm.value.primaryLogin['mobilenumberField'] == '') { + const emptyFields = []; + this.ownershipForm.value.primaryLogin['userIDField'] === '' ? emptyFields.push('User ID') : null; + this.ownershipForm.value.primaryLogin['emailField'] === '' ? emptyFields.push('Email') : null; + this.ownershipForm.value.primaryLogin['mobilenumberField'] === '' ? emptyFields.push('Mobile Number') : null; + var mandatoryFields = emptyFields.join(', '); + this.toastMsg.error('Error', mandatoryFields + ' is Mandatory!'); + toMoveNext = false; + } else { + if (Object.keys(ownershipObj).length !== 0) { + entitySchema["_osConfig"]["ownershipAttributes"].push(ownershipObj); } - } - if (this.ownershipForm.value.alternateLoginCheckbox && this.ownershipForm.value.alternateLogin['mobilenumberCheckbox']) { - alternateOwnershipObj = { - ...alternateOwnershipObj, - "mobile": "/" + this.selectedProperty?.key + "/contact" + if (this.ownershipForm.value['issuerRole']) { + entitySchema["_osConfig"]["roles"].push(this.ownershipForm.value['issuerRole']) } - } - if (Object.keys(alternateOwnershipObj).length !== 0) { - editSchema["_osConfig"]["ownershipAttributes"].push(alternateOwnershipObj); - editSchema["_osConfig"]["uniqueIndexFields"].push(this.selectedProperty.key); - } + if (this.ownershipForm.value['inviteRole']) { + entitySchema["_osConfig"]["inviteRoles"].push(this.ownershipForm.value['inviteRole']) + } + - let payload = { - ...this.items[i], - "schema": JSON.stringify(editSchema) + let schemaOsid = this.useCaseSchema[i].osid; + let payload = { + "schema": JSON.stringify(entitySchema) + } + this.generalService.putData('/Schema', schemaOsid, payload).subscribe((res) => { + console.log("Post data in ownership", res); + }); + toMoveNext = true; } - this.generalService.putData('/Schema', this.items[i].osid, payload).subscribe((res) => { - console.log("Post data in ownership", res); - }) } } - console.log(this.ownershipForm); + return toMoveNext; } - } diff --git a/src/assets/i18n/global/en-global.json b/src/assets/i18n/global/en-global.json index 8762029..cc87b70 100644 --- a/src/assets/i18n/global/en-global.json +++ b/src/assets/i18n/global/en-global.json @@ -146,6 +146,7 @@ "EDUCATION_RC": "Education RC", "COMING_SOON": "Coming Soon", + "CREATE_NEW_ROLE": "Create Role", "WHO_IS_AUTHORISED_FOR_ISSUANCE": "Who is authorised for issuance?", "WHO_IS_AUTHORISED_TO_INVITE_ROLES": "Who Is Authorized to Invite Roles?", "ANONYMOUS": "Anonymous", diff --git a/src/assets/i18n/global/hi-global.json b/src/assets/i18n/global/hi-global.json index d0b9b0e..6c3e41b 100644 --- a/src/assets/i18n/global/hi-global.json +++ b/src/assets/i18n/global/hi-global.json @@ -149,6 +149,7 @@ "WHO_IS_AUTHORISED_FOR_ISSUANCE" : "जारी करने के लिए कौन अधिकृत है?", "WHO_IS_AUTHORISED_TO_INVITE_ROLES":"भूमिकाएँ आमंत्रित करने के लिए कौन अधिकृत है?", "COMING_SOON" : "जल्द आ रहा है", + "CREATE_NEW_ROLE":"भूमिका बनाएँ", "ANONYMOUS" : "बेनामी", "ROLE" : "भूमिका", "INVITE_ROLES": "भूमिकाएँ आमंत्रित करें",