Skip to content

Commit

Permalink
Task #1 Create Schema and VC template
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratikshakhandagale committed Sep 15, 2022
1 parent 6e7f849 commit 9e9fc02
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/app/admin/create-entity/create-entity.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ <h3>{{usecaseSchema[activeMenuNo]?.title}}</h3>
<div class="">
<!-- <create-vc-template></create-vc-template> -->
<json-editor *ngIf="properties" [options]="editorOptions" [data]="properties"
[(ngModel)]="properties" (change)="getJsonData($event)"></json-editor>
[(ngModel)]="properties" (change)="readConvertJsonData($event)"></json-editor>
<footer class="footer fixed-bottom fixed-bottom-json">
<div class="container-fluid">
<div>
<button (change)="getJsonData($event)"
<button (click)="readConvertJsonData($event)"
class="btn text-capitalize float-end btn-primary btn-primary-sm px-3 my-2">Save</button>
<button (click)="hideJSon()"
class="btn btn-sec-bg float-end submit-button px-3 my-2">Cancel</button>
Expand Down
174 changes: 113 additions & 61 deletions src/app/admin/create-entity/create-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export class CreateEntityComponent implements OnInit {

this.activeRoute.params.subscribe(params => {
this.params = params;


if (this.params.hasOwnProperty('step')) {
this.currentTab = Number(params.step);
}else{
} else {
this.currentTab = 0;
}

Expand Down Expand Up @@ -168,12 +168,12 @@ export class CreateEntityComponent implements OnInit {
// this.entityListArr.push(res);
this.usecaseSchema.push(res);
this.defination.push(res);
// this.activeMenuNo = j;
// this.activeMenuNo = j;

// this.entityKey = res.title;
if (j == (this.entityList.length - 1)) {
this.getEntityProperties();
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.usecaseSchema[1].title);
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.usecaseSchema[1].title);
this.activeMenuNo = 1;
}
})
Expand All @@ -186,7 +186,7 @@ export class CreateEntityComponent implements OnInit {
// this.entityListArr.push(res);

// this.entityKey = "Common";
// this.activeMenuNo = j;
// this.activeMenuNo = j;

this.usecaseSchema.push(this.commonschemaDefination);
// this.properties = this.commonschemaDefination.definitions;
Expand All @@ -209,7 +209,7 @@ export class CreateEntityComponent implements OnInit {

getEntityPropertiesByIndex(j) {
let res = this.usecaseSchema[j];
this.activeMenuNo = j;
this.activeMenuNo = j;

if (this.usecaseSchema[j].title !== "Common" && this.usecaseSchema[j].title !== "common") {
let res = this.usecaseSchema[j];
Expand Down Expand Up @@ -241,7 +241,7 @@ this.activeMenuNo = j;
"data": this.readPropertyObj(this.properties)
};



} else {
let res = this.usecaseSchema[j];
Expand All @@ -250,7 +250,7 @@ this.activeMenuNo = j;
this.usecaseSchema[j].definitions = {
"propertyName": res.title,
"propertyKey": res.title,
"type": 'object',
"type": 'object',
"data": this.readPropertyObj(this.properties)
};

Expand All @@ -264,48 +264,106 @@ this.activeMenuNo = j;
convertIntoSBRCSchema(sProperties) {
let tempFieldObj = {};

for (let i = 0; i < sProperties.data.length; i++) {
if (sProperties.data[i].hasOwnProperty('propertyKey')) {
if (sProperties.hasOwnProperty('propertyKey')) {

tempFieldObj[sProperties.propertyKey] = {
"$id": sProperties['$id'],
"type": sProperties['type'],
"title": sProperties['propertyName'],
"properties": {}
}

let field = sProperties.data[i];
for (let i = 0; i < sProperties.data.length; i++) {
if (sProperties.data[i].hasOwnProperty('propertyKey')) {
let field = sProperties.data[i];

if((field['$ref'] != "" && field.type == 'array') && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common'))
{
tempFieldObj[field.propertyKey]= {
"type": "array",
"items" : {
"$ref" : field['$ref']
if ((field['$ref'] != "" && field.type == 'array') && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common')) {
tempFieldObj[field.propertyKey] = {
"type": "array",
"items": {
"$ref": field['$ref']
}
}
}
}else if((field['$ref'] != "" && field.type == 'object' ) && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common'))
{
tempFieldObj[field.propertyKey]= {
"$ref" : field['$ref']
} else if ((field['$ref'] != "" && field.type == 'object') && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common')) {
tempFieldObj[field.propertyKey] = {
"$ref": field['$ref']
}
}else{
} else {

tempFieldObj[field.propertyKey] = {
"$id": field['$id'],
"type": field['type'],
"title": field['propertyName'],
"properties": {}
}
tempFieldObj[field.propertyKey] = {
"$id": field['$id'],
"type": field['type'],
"title": field['propertyName'],
"properties": {}
}

if (field.hasOwnProperty('data')) {
for (let j = 0; j < field.data.length; j++) {
let property = field.data[j];
tempFieldObj[field.propertyKey]['properties'][property.key] = property.data
}
}
if (field.hasOwnProperty('data')) {
for (let j = 0; j < field.data.length; j++) {
let property = field.data[j];
tempFieldObj[field.propertyKey]['properties'][property.key] = property.data
}
}

}
}
}else{
let property = sProperties.data[i];
tempFieldObj[sProperties.propertyKey]['properties'][property.key] = property.data


}

}
}

/* for (let i = 0; i < sProperties.data.length; i++) {
if (sProperties.data[i].hasOwnProperty('propertyKey')) {
let field = sProperties.data[i];
if((field['$ref'] != "" && field.type == 'array') && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common'))
{
tempFieldObj[field.propertyKey]= {
"type": "array",
"items" : {
"$ref" : field['$ref']
}
}
}else if((field['$ref'] != "" && field.type == 'object' ) && (sProperties.propertyKey != 'Common' && sProperties.propertyKey != 'common'))
{
tempFieldObj[field.propertyKey]= {
"$ref" : field['$ref']
}
}else{
tempFieldObj[field.propertyKey] = {
"$id": field['$id'],
"type": field['type'],
"title": field['propertyName'],
"properties": {}
}
if (field.hasOwnProperty('data')) {
for (let j = 0; j < field.data.length; j++) {
let property = field.data[j];
tempFieldObj[field.propertyKey]['properties'][property.key] = property.data
}
}
}
}else if (sProperties.hasOwnProperty('propertyKey')) {
let field = sProperties.data[i];
tempFieldObj[field.propertyKey] = {
"$id": field['$id'],
"type": field['type'],
"title": field['propertyName'],
"properties": {}
}
}
}*/

return tempFieldObj;


Expand Down Expand Up @@ -386,16 +444,14 @@ this.activeMenuNo = j;
"data": self.readArraySchema(data)
});

if(self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common')
{
if (self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common') {
tempFieldObjSec[tempFieldObjSec.length - 1]['$ref'] = ((data.hasOwnProperty('$ref')) ? data['$ref'] : ((data.hasOwnProperty('items') && data.items.hasOwnProperty('$ref') ? data.items['$ref'] : '')));
}

} else if ((data.hasOwnProperty('$ref'))) {
tempFieldObjSec.push(self.readCommonSchema(data));

if(self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common')
{
if (self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common') {
tempFieldObjSec[tempFieldObjSec.length - 1]['$ref'] = data['$ref'];
}

Expand All @@ -415,14 +471,13 @@ this.activeMenuNo = j;
"propertyName": (data.hasOwnProperty('title') ? data.title : key),
"propertyKey": key,
"type": data.type,
"$ref": '',
"$ref": '',
"$id": (data.hasOwnProperty('$id')) ? data['$id'] : '',
"data": self.readPropertyObj(data.properties)

});

if(self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common')
{
if (self.usecaseSchema[self.activeMenuNo].title != 'Common' && self.usecaseSchema[self.activeMenuNo].title != 'common') {
tempFieldObjSec[tempFieldObjSec.length - 1]['$ref'] = data['$ref'];
}

Expand Down Expand Up @@ -478,7 +533,7 @@ this.activeMenuNo = j;
// return propertyObj;
// }

readCommonSchema(commonSchema) {
readCommonSchema(commonSchema) {
let refUrl, refKey;
let tempFieldObjSec = [];
let tempFieldObj = [];
Expand Down Expand Up @@ -536,14 +591,13 @@ readCommonSchema(commonSchema) {
this.isAddFormPg = false;
}

showJson()
{
showJson() {
this.isShowJson = !this.isShowJson;
this.getEntityJson();
}

getEntityJson() {

let tempProperty: any;
tempProperty = this.usecaseSchema[this.activeMenuNo];
tempProperty.definitions = this.convertIntoSBRCSchema(this.usecaseSchema[this.activeMenuNo].definitions);
Expand All @@ -569,10 +623,10 @@ readCommonSchema(commonSchema) {
this['active' + (this.currentTab - 1)] = false;


this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
}

this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);


}
Expand All @@ -588,9 +642,9 @@ readCommonSchema(commonSchema) {
this['active' + (this.currentTab - 1)] = true;


this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
}


}

Expand Down Expand Up @@ -626,10 +680,9 @@ readCommonSchema(commonSchema) {
this.an_menus[0].classList.add("activeMenu");
this.entityKey = entitykey;

this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);
this.location.replaceState('/create/' + this.currentTab + '/' + this.usecase + '/' + this.entityKey);

if(this.isShowJson)
{
if (this.isShowJson) {
this.getEntityJson();
}

Expand Down Expand Up @@ -730,7 +783,7 @@ readCommonSchema(commonSchema) {

}

getJsonData(event) {
readConvertJsonData(event) {
let value = this.jsonEditor.get();
this.usecaseSchema[this.activeMenuNo] = value;
this.getEntityPropertiesByIndex(this.activeMenuNo);
Expand Down Expand Up @@ -871,13 +924,12 @@ readCommonSchema(commonSchema) {
//alert(this.isActive);
if (this.isActive == 'createSchema') {

for(let i=0; i< this.usecaseSchema.length; i++)
{
for (let i = 0; i < this.usecaseSchema.length; i++) {
this.usecaseSchema[i].definitions = this.convertIntoSBRCSchema(this.usecaseSchema[i].definitions);

}
let schemaParams = {
'schema' : this.usecaseSchema
let schemaParams = {
'schema': this.usecaseSchema

}

Expand All @@ -888,5 +940,5 @@ readCommonSchema(commonSchema) {
}



}
6 changes: 3 additions & 3 deletions src/app/admin/edit-template/edit-template.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ <h3 class="heading-5">Save Document</h3>
<div class="container mt-4">
<div class="mb-4">
<p class="heading-4 font-700 mb-05">Name</p>
<input [(ngModel)]="templateName" ngDefaultControl class="w-100 input-field p14 p-3 inputField"
<input [(ngModel)]="templateName" class="w-100 input-field p14 p-3 inputField"
placeholder="Enter Document name" type="text" />
</div>

<div class="mt-2">
<p class="heading-4 font-700 mb-05">Description<span
class="text-muted">(optional)</span></p>
<textarea [(ngModel)]="description" ngDefaultControl
<textarea [(ngModel)]="description"
class="w-100 desc py-2 input-field p14 pl-3 inputField"
placeholder="Enter description"></textarea>
</div>
Expand All @@ -162,4 +162,4 @@ <h3 class="heading-5">Save Document</h3>

</div>

</div>
</div>
Loading

0 comments on commit 9e9fc02

Please sign in to comment.