Skip to content

Commit

Permalink
show entity on browser with template
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarocosta committed May 7, 2020
1 parent fdd8fef commit 4cf1033
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 60 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/components/edit-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EditEntityComponent implements OnInit {
this.load = false;
//this.getSchemaNode(this.uid);
this.route.queryParamMap.subscribe(query => {
this.template = query.get('template');
this.template = JSON.parse(query.get('template'));
console.log(this.template)
this.getSchemaNodeWithTemplate(this.uid, this.template)
});
Expand All @@ -66,7 +66,7 @@ export class EditEntityComponent implements OnInit {
}

getDataNodeWithTemplate(uid) {
this.service.getDataNodeWithTemplate(uid)
this.service.getDataNodeWithTemplate(uid, this.template)
.subscribe(result => {
this.form.data[this.uid] = result;
console.log(result);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/components/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<tbody>
<tr *ngFor="let item of searchResultArray; let i = index">
<td><nav>
<a routerLink={{item.uid}}>{{item.uid}}</a>
<a [routerLink]="['/viewtemplate', item.uid]">{{item.uid}}</a>
</nav></td>
<td>{{ item.name }}</td>
<td><ul>
Expand Down
25 changes: 18 additions & 7 deletions frontend/src/app/components/view-template.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<select (change)="selectChangeHandler($event)">
<option *ngFor="let key of objectKeys(templates)" [ngValue]="templates[key]">{{ key }}</option>
</select>

<div *ngIf="hasTemplate">
<pre>{{templates[key] | json}}</pre>
</div>
<select (change)="selectChangeHandler($event)">
<option *ngFor="let key of objectKeys(templates)" [ngValue]="templates[key]">{{ key }}</option>
</select>

<pre>{{templates[key] | json}}</pre>

<div class="example-button-row">
<button type="button" class="btn btn-primary-outline pull-right" (click)="editEntity();"><i class="fa fa-plus"></i> Edit Entity</button>
<button type="button" class="btn btn-primary-outline pull-right" (click)="editEntity();"><i class="fa fa-plus"></i>
Edit Entity
</button>
</div>
</div>

<div class="row" *ngIf="!hasTemplate" style="align-content: center">
<div class="col-xs-12">
<p class="alert alert-danger">
<strong>Don't have templates</strong>

</p>
</div>
</div>
57 changes: 31 additions & 26 deletions frontend/src/app/components/view-template.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {Location} from "@angular/common";
import {ActivatedRoute} from "@angular/router";
import {MyServiceService} from "../service/my-service.service";
import { Router } from '@angular/router';
import {Router} from '@angular/router';


@Component({
Expand All @@ -17,12 +17,12 @@ export class ViewTemplateComponent implements OnInit {
private router: ActivatedRoute,
private service: MyServiceService,
private route: Router
) {
) {
}

uid = '';
objectKeys = Object.keys;
templates = {
};
templates = {};
key: any;
template: any;
hasTemplate = false
Expand All @@ -39,42 +39,47 @@ export class ViewTemplateComponent implements OnInit {


private getTemplatesFromEntity(uid: string) {
this.service.getTemplatesFromEntity(uid)
this.service.getTemplatesFromEntity(uid)
.subscribe(templates => {
let index = 1;

for(let template of templates){
let name = "template " + index;
this.templates[name] = template;
index++

}
if(templates.length >0){
this.key= "template 1"
this.hasTemplate = true
this.template = this.templates[this.key]
if (templates["message"]) {
this.hasTemplate = false
} else {
for (let template of templates) {
let name = "template " + index;
this.templates[name] = template;
index++
}
if (templates.length > 0) {
this.key = "template 1"
this.hasTemplate = true
this.template = this.templates[this.key]
}
}

let x = 1

});

}

selectChangeHandler($event) {
console.log($event.target.value);
this.key = $event.target.value
this.template = this.templates[this.key]

}

editEntity() {
//this.route.navigateByUrl(this.uid);
this.route.navigate([this.uid],
{queryParams :
{
template : JSON.stringify(this.template)
}}
);
//this.route.navigate([this.uid], { queryParams: { template: "this.template" }});
//this.route.navigateByUrl(this.uid);
this.route.navigate([this.uid],
{
queryParams:
{
template: JSON.stringify(this.template)
}
}
);
//this.route.navigate([this.uid], { queryParams: { template: "this.template" }});


}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/service/my-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class MyServiceService {
return this.http.get<any[]>(this.baseUrl + uid);
}

getDataNodeWithTemplate( uid: string): Observable<any[]> {
return this.http.get<any[]>(this.baseUrl + "withtemplate/" + uid);
getDataNodeWithTemplate( uid: string, template: object): Observable<any[]> {
return this.http.post<any[]>(this.baseUrl + "withtemplate/" + uid, template) ;
}

getTemplatesFromEntity( uid: string): Observable<any[]> {
Expand All @@ -45,10 +45,10 @@ export class MyServiceService {
return this.http.get<Schema>(this.baseUrl + 'schema' + '/' + uid);
}

getSchemaNodeWithTemplate(uid: string, template: string): Observable<Schema> {
getSchemaNodeWithTemplate(uid: string, template: object): Observable<Schema> {
// const headers = new HttpHeaders();
// headers.append('template', template)
return this.http.get<Schema>(this.baseUrl + 'schemawithtemplate' + '/' + uid + '/' + template);
return this.http.post<Schema>(this.baseUrl + 'schemawithtemplate' + '/' + uid, template);
}

sendNode(data): Observable<any> {
Expand Down
2 changes: 1 addition & 1 deletion src/Routes/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def delete_collection(collection):
#
# print("get all records")
# get_all_records_from_collection("createdTemplate")
get_all_records_from_collection("defaultTemplate")
#get_all_records_from_collection("defaultTemplate")
# delete_collection("createdTemplate")
# delete_collection("defaultTemplate")
# get_all_records_from_collection("data")
31 changes: 15 additions & 16 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def default_template(uid):
return make_response(jsonify(message="Node doesn't exists"), 404)


@app.route("/withtemplate/<uid>", methods=["GET"])
@app.route("/withtemplate/<uid>", methods=["POST"])
@cross_origin()
def get_record(uid):
template = {
"E52_Time_Span": {
"has_value": "DataObject"}
}
# template = {
# "E52_Time_Span": {
# "has_value": "DataObject"}
# }
# template = {
# "E52_Time_Span": {
# "P86_falls_within": "E52_Time_Span"}
Expand All @@ -92,6 +92,9 @@ def get_record(uid):
# if record is not None:
# return make_response(jsonify(json.loads(record["data"])), 201)
# else:
#template = json.loads(template_str)
template = request.json

node = get_node_by_uid(uid)
if node is not None:
data = nested_json(node, template)
Expand Down Expand Up @@ -141,14 +144,14 @@ def insert_template_in_mongodb(uid):
return make_response(jsonify(message="Node doesn't exists"), 404)


@app.route("/schemawithtemplate/<uid>/<template_str>", methods=["GET"])
@app.route("/schemawithtemplate/<uid>", methods=["POST"])
@cross_origin()
def get_schema(uid, template_str):
def get_schema(uid):
node = get_node_by_uid(uid)
template = {
"E52_Time_Span": {
"has_value": "DataObject"}
}
# template = {
# "E52_Time_Span": {
# "has_value": "DataObject"}
# }
# todo descomentar isto
#template = json.loads(template_str)

Expand All @@ -157,6 +160,7 @@ def get_schema(uid, template_str):
# "E52_Time_Span": {
# "P86_falls_within": "E52_Time_Span"}
# }
template = request.json
print(template)
if node is not None:
result = get_schema_from_mongo(template)
Expand Down Expand Up @@ -194,11 +198,6 @@ def get_templates_from_entity(uid):
@cross_origin()
def response_update(uid):

template = {
"E52_Time_Span": {
"has_value": "DataObject",
}
}
node = get_node_by_uid(uid)
if node is not None:
#todo meter o template no body tambem
Expand Down
27 changes: 24 additions & 3 deletions test/Unit/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,34 @@ def test_schema_with_template(self):
def test_generate_schema(self):
delete_collection("defaultTemplate")
templates = []
classes_schema = find_name_of_classes_schema_in_project(classes_name)
for class_schema in classes_schema:
templates.append(class_schema().generate_template())
# classes_schema = find_name_of_classes_schema_in_project(classes_name)
# for class_schema in classes_schema:
# templates.append(class_schema().generate_template())
# insert_default_templates(templates)
# get_all_records_from_collection("defaultTemplate")

def test_insert_template(self):
delete_collection("defaultTemplate")
template = {
"E52_Time_Span": {
"has_value": "DataObject",
}
}
template2 = {'E52_Time_Span': {'P86_falls_within': 'E52_Time_Span'}}
template3 = {'E52_Time_Span': {}}
class_name =['E52_Time_Span', 'E1_CRM_Entity']
schema = e52.get_schema_with_template(template)
schema2 = e52.get_schema_with_template(template2)
schema3 = e52.get_schema_with_template(template3)
templates = [{"classes_name": class_name, "template": template, "schema": json.dumps(schema) },
{"classes_name": class_name, "template": template2, "schema": json.dumps(schema2) },
{"classes_name": class_name, "template": template3, "schema": json.dumps(schema3) }]
insert_default_templates(templates)
get_all_records_from_collection("defaultTemplate")




var = {'$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': {
'E2_Temporal_EntitySchema': {'type': 'object', 'properties': {'name': {'title': 'name', 'type': 'string'},
'uid': {'title': 'uid', 'type': 'string'},
Expand Down

0 comments on commit 4cf1033

Please sign in to comment.