Skip to content

Commit

Permalink
Task #1: Read schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratikshakhandagale committed Aug 22, 2022
1 parent 7fc2032 commit c115c8d
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 51 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 @@ -49,7 +49,7 @@

<ul id="sideMenu" class="list-unstyled components">

<li class="menu" (click)="openEntity(i)" *ngFor="let menuItem of apiEntityName; let i = index">
<li class="menu" (click)="openEntity(i)" *ngFor="let menuItem of entityList; let i = index">
<a class="a-menu"> {{menuItem?.entityName}}
<i *ngIf="active0" class="fa fa-ellipsis-h text-grey-color float-end mt-1 p14"
aria-hidden="true"></i>
Expand Down Expand Up @@ -257,4 +257,4 @@ <h3 class="heading-5">Add Entity</h3>
</div>
</footer>
</div>
<!-- Modal End : Save Entity Name -->
<!-- Modal End : Save Entity Name -->
61 changes: 52 additions & 9 deletions src/app/admin/create-entity/create-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CreateEntityComponent implements OnInit {
entityName: string;
description: string;


entityList: any;
apiEntityName: any = [
{
'entityName': "Education Board",
Expand Down Expand Up @@ -80,7 +80,7 @@ export class CreateEntityComponent implements OnInit {
currentMenu: number = 0;
menus: any;
an_menus: any;
// entityFieldList: any = [];
entityProperties: any = [];

constructor(
private activeRoute: ActivatedRoute,
Expand All @@ -94,10 +94,6 @@ export class CreateEntityComponent implements OnInit {
this.editorOptions.history = true;
this.editorOptions.onChange = () => this.jsonEditor.get();





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

Expand All @@ -111,7 +107,7 @@ export class CreateEntityComponent implements OnInit {

this.entityFields = this.apiEntityName[0]

//this.getSchemaJSON();
this.getSchemaJSON();

console.log(this.entityFields);

Expand All @@ -137,12 +133,59 @@ export class CreateEntityComponent implements OnInit {

getSchemaJSON() {
this.schemaService.getEntitySchemaJSON().subscribe((data) => {
this.SchemaUrl = data.entitySchema[this.usecase + "SchemaUrl"];
console.log(this.SchemaUrl);
this.SchemaUrl = data['usecase'][this.usecase];
this.entityList = data['usecase'][this.usecase]['entity'];
this.getEntityFields();

console.log({ data });
})
}

async getEntityFields() {
//let url = "https://raw.githubusercontent.com/Sunbird-RC/demo-education-registry/main/schemas/Institute.json";
// await fetch(this.entityList[0].schemaUrl)
// //await fetch(url)
// .then(res => res.json())
// .then(data => {
// console.log({ data });
// let properties = data.definitions[this.entityList[0].entityName].properties;
// this.entityProperties = this.createObjectFormat(properties);
// // data = JSON.parse(data);

// console.log(this.entityProperties);

// });

this.schemaService.getJSONData(this.entityList[0].schemaUrl).subscribe((res)=>{
console.log({ res });
let properties = res.definitions[this.entityList[0].entityName].properties;
this.entityProperties = this.createObjectFormat(properties);
console.log(this.entityProperties);
})

}

createObjectFormat(entityProperties) {

console.log({ entityProperties });
let tempFieldObj = [];

Object.keys(entityProperties).forEach(function (key) {

if (typeof (entityProperties[key]) == 'object') {
let data = entityProperties[key];

tempFieldObj.push(
{
"key": key,
data
})
}
});

return tempFieldObj;

}

showAddForm() {
this.isAddFormPg = true;
Expand Down
2 changes: 0 additions & 2 deletions src/app/admin/get-started/get-started.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { getAllReferenceSchemas } from '../../../schemas';
import { Route } from '@angular/router';
@Component({
selector: 'get-started',
Expand All @@ -11,7 +10,6 @@ export class GetStartedComponent implements OnInit {
constructor() { }

ngOnInit(): void {
console.log(getAllReferenceSchemas());
}

status: boolean = false;
Expand Down
13 changes: 12 additions & 1 deletion src/app/services/data/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class SchemaService {

schemaUrl = this.config.getEnv('schemaUrl');
configFolder = this.config.getEnv('configFolder');
referanceSchema = this.config.getEnv('referanceSchema');


constructor(public dataService: DataService,private config: AppConfig) {
}
Expand Down Expand Up @@ -84,7 +86,7 @@ export class SchemaService {
}

getEntitySchemaJSON() {
let url = `.${this.configFolder}/entityConfig.json`;
let url = `.${this.referanceSchema}/entityConfig.json`;
url.replace('//', '/');
const req = {
url: url
Expand All @@ -93,6 +95,15 @@ export class SchemaService {
return this.dataService.get(req);
}

getJSONData(fileUrl) {
let url = fileUrl;
const req = {
url: url
};

return this.dataService.get(req);
}


}

5 changes: 3 additions & 2 deletions src/assets/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"realm": "sunbird-rc"
},
"configFolder": "/assets/config/ui-config",
"referanceSchema" : "/assets/config",
"languageFolder": "/assets/i18n",
"title": "Education-Sunbird",
"title": "Admin Portal",
"baseUrl": "http://localhost:4200/registry/api/v1",
"schemaUrl": "http://localhost:4200/registry/api/docs/swagger.json",
"footerText": "Education-Sunbird",
"footerText": "Admin Portal",
"languages": [
"en",
"hi"
Expand Down
10 changes: 5 additions & 5 deletions src/assets/config/entityConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"entity": [
{
"entityName": "Institute",
"schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-education-registry/main/schemas/Institute.json",
"schemaUrl": "/assets/schemas/education/Institute.json",
"config" : {

}
},
{
"entityName": "Teacher",
"entityUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-education-registry/main/schemas/Teacher.json"
"entityUrl": "/assets/schemas/education/Teacher.json"
},
{
"entityName": "Student",
"schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-education-registry/main/schemas/Student.json",
"schemaUrl": "/assets/schemas/education/Student.json",
"config" : {

}
Expand All @@ -28,11 +28,11 @@
"entity": [
{
"entityName": "Skill Certificate",
"entischemaUrltyUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/schemas/SkillCertificate.json"
"entischemaUrltyUrl": "/assets/schemas/certificate-issuance/SkillCertificate.json"
},
{
"entityName": "Training Certificate",
"entityUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/schemas/TrainingCertificate.json"
"entityUrl": "/assets/schemas/certificate-issuance/TrainingCertificate.json"
}
]
}
Expand Down
68 changes: 68 additions & 0 deletions src/assets/schemas/certificate-issuance/SkillCertificate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"SkillCertificate": {
"$ref": "#/definitions/SkillCertificate"
}
},
"required": [
"SkillCertificate"
],
"title": "SkillCertificate",
"definitions": {
"SkillCertificate": {
"$id": "#/properties/SkillCertificate",
"type": "object",
"title": "The SkillCertificate Schema",
"required": [
"name",
"contact"
],
"properties": {
"name": {
"type": "string"
},
"trainingTitle": {
"type": "string"
},
"contact": {
"type": "string"
},
"date": {
"type": "string",
"format": "date"
},
"note": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"type": "object",
"properties": {
"skill": {
"type": "string"
},
"certifiedOn": {
"type": "string"
}
}
}
}
}
}
},
"_osConfig": {
"uniqueIndexFields": [
"contact"
],
"ownershipAttributes": [],
"roles": [],
"inviteRoles": [
"anonymous"
],
"enableLogin": false,
"credentialTemplate": "https://gist.githubusercontent.com/tejash-jl/550aa1365c37e09065f1f134c936530d/raw/54f10668f8cad3953d9b09c09212d4ec4434ae7f/SkillExternalCredentialTemplate.json"
}
}
69 changes: 69 additions & 0 deletions src/assets/schemas/certificate-issuance/TrainingCertificate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"TrainingCertificate": {
"$ref": "#/definitions/TrainingCertificate"
}
},
"required": [
"TrainingCertificate"
],
"title": "TrainingCertificate",
"definitions": {
"TrainingCertificate": {
"$id": "#/properties/TrainingCertificate",
"type": "object",
"title": "The TrainingCertificate Schema",
"required": [
"name",
"contact"
],
"properties": {
"name": {
"type": "string"
},
"trainingTitle": {
"type": "string"
},
"contact": {
"type": "string"
},
"date": {
"type": "string",
"format": "date"
},
"note": {
"type": "string"
}
}
}
},
"_osConfig": {
"uniqueIndexFields": [
"contact"
],
"ownershipAttributes": [],
"roles": [],
"inviteRoles": [
"anonymous"
],
"enableLogin": false,
"credentialTemplate": {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://gist.githubusercontent.com/dileepbapat/eb932596a70f75016411cc871113a789/raw/498e5af1d94784f114b32c1ab827f951a8a24def/skill"
],
"type": [
"VerifiableCredential"
],
"issuanceDate": "2021-08-27T10:57:57.237Z",
"credentialSubject": {
"type": "Person",
"name": "{{name}}",
"trainedOn": "{{trainingTitle}}"
},
"issuer": "did:web:sunbirdrc.dev/vc/skill"
}
}
}
1 change: 0 additions & 1 deletion src/schemas/certificate-issuance
Submodule certificate-issuance deleted from 1ec925
1 change: 0 additions & 1 deletion src/schemas/education
Submodule education deleted from c95422
28 changes: 0 additions & 28 deletions src/schemas/index.js

This file was deleted.

0 comments on commit c115c8d

Please sign in to comment.