Skip to content

Commit

Permalink
More corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
silvae86 committed May 8, 2020
1 parent 4cf1033 commit cc22189
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 62 deletions.
7 changes: 6 additions & 1 deletion frontend/src/app/combo-box/combo-box.component.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.combobox-options {

position: absolute;
text-align: center;
background-color: white;
Expand All @@ -10,6 +9,12 @@
z-index: 1;
}

input.combobox-input {
border-style: none;
padding: 0px;
}



list-item{

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/components/edit-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class EditEntityComponent implements OnInit {

sendNode(data) {
this.load = false;
this.service.sendNode(data)
this.service.sendNode(data, this.template)
.subscribe(result => {
this.form.data[this.uid] = result;
console.log(result);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/components/search.component.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#search {
font-family: "Trebuchet MS", Arial, "Helvetica Neue", sans-serif;
border-collapse: collapse;
width: 100%;
}

Expand Down
75 changes: 38 additions & 37 deletions frontend/src/app/components/search.component.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<div style="margin-left: 35px;">
<p>Search</p>
</div>

<div style="margin-left: 35px;padding: 3px; display: inline-block;">
<input style="width: 300px" #search_box (keyup.enter)="searchDatabase(search_box.value)">
</div>
<div style="padding: 3px; display: inline-block;">
<app-combo-box [list]="itemList"></app-combo-box>
</div>
<div style="padding: 3px; display: inline-block;">
<button type="button" (click)="searchDatabase(search_box.value)"> Search </button>
</div>
<div class="container">

<h1>Search</h1>
<p class="lead">Search for entities according to their classes and associated property values</p>

<div class="form-inline">
<div>
<input class="form-control" style="width: 300px" #search_box (keyup.enter)="searchDatabase(search_box.value)">
</div>
<div>
<app-combo-box [list]="itemList" class="form-control"></app-combo-box>
</div>
<div>
<button class="form-control" type="button" (click)="searchDatabase(search_box.value)" class="btn btn-primary">Search</button>
</div>
</div>

<div *ngIf="loadSearch" style="margin: 35px">
<table id="search" >
<thead>
<tr>
<th>UID</th>
<th>Name</th>
<th>Labels</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of searchResultArray; let i = index">
<td><nav>
<a [routerLink]="['/viewtemplate', item.uid]">{{item.uid}}</a>
</nav></td>
<td>{{ item.name }}</td>
<td><ul>
<li *ngFor="let label of item.labels">
{{ label }}
</li>
</ul></td>
</tr>
</tbody>
</table>
<div *ngIf="loadSearch" style="margin: 35px">
<table id="search" >
<thead>
<tr>
<th>UID</th>
<th>Name</th>
<th>Labels</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of searchResultArray; let i = index">
<td><nav>
<a [routerLink]="['/viewtemplate', item.uid]">{{item.uid}}</a>
</nav></td>
<td>{{ item.name }}</td>
<td><ul>
<li *ngFor="let label of item.labels">
{{ label }}
</li>
</ul></td>
</tr>
</tbody>
</table>

</div>
</div>

9 changes: 7 additions & 2 deletions frontend/src/app/service/my-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ export class MyServiceService {
return this.http.post<Schema>(this.baseUrl + 'schemawithtemplate' + '/' + uid, template);
}

sendNode(data): Observable<any> {
sendNode(data, template): Observable<any> {
const uid = Object.keys(data)[0];
return this.http.post<any>(this.baseUrl + uid, data[uid]);
const body = {
template,
data: data[uid]
};

return this.http.post<any>(this.baseUrl + uid, body);
}

constructor(private http: HttpClient) {
Expand Down
31 changes: 14 additions & 17 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
from pathlib import Path
import os, sys
import argparse
from src.Utils.Utils import read_file

# returns the project root path (assumes that the script is started from src/Routes/routes.py)
def get_project_root():
"""Returns project root folder."""
return Path(__file__).parent.parent.parent

# append project root to sys paths so that src.** modules can be found by Python when running the app from a script
# From https://leemendelowitz.github.io/blog/how-does-python-find-packages.html
print("Archgraph running at " + get_project_root().as_posix())
sys.path.append(get_project_root().as_posix())

from src.Routes.mongo import insert_template_in_mongo, get_all_records_from_collection, update_data_in_mongo, \
get_record_from_collection, add_record_to_collection, get_schema_from_mongo, \
Expand All @@ -16,18 +25,6 @@

args = parser.parse_args()


# returns the project root path (assumes that the script is started from src/Routes/routes.py)
def get_project_root():
"""Returns project root folder."""
return Path(__file__).parent.parent.parent


# append project root to sys paths so that src.** modules can be found by Python when running the app from a script
# From https://leemendelowitz.github.io/blog/how-does-python-find-packages.html
print("Archgraph running at " + get_project_root().as_posix())
sys.path.append(get_project_root().as_posix())

from flask import Flask, Response, jsonify, make_response, request, send_from_directory

from flask_cors import CORS, cross_origin
Expand Down Expand Up @@ -98,8 +95,8 @@ def get_record(uid):
node = get_node_by_uid(uid)
if node is not None:
data = nested_json(node, template)
print(data)
add_record_to_collection(uid, data, "data")
# print(data)
# add_record_to_collection(uid, data, "data")
get_all_records_from_collection("data")
if data is not None:
return make_response(jsonify(data), 201)
Expand Down Expand Up @@ -202,11 +199,11 @@ def response_update(uid):
if node is not None:
#todo meter o template no body tambem
data = request.json
merged = updated_node(node, data, template)
merged = updated_node(node, data['data'], data['template'])
if merged:
#update_data_in_mongo(uid, node.encodeJSON())
#get_all_records_from_collection("data")
new_data = nested_json(node, template)
new_data = nested_json(node, data['template'])
return make_response(jsonify(new_data), 201)
else:
return make_response(jsonify(message="Unsaved node"), 404)
Expand Down
12 changes: 9 additions & 3 deletions src/Utils/Utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import datetime
import marshmallow.fields as fields

from neo4j import GraphDatabase
from neomodel import db
Expand Down Expand Up @@ -178,20 +180,23 @@ def updated_node_aux(current_node, data, template):
# add_new_node(new_node['relationships'][relationship_name], relationship_of_node, None, template[relationship_name])
if relationship_name in new_node['relationships']:
new_relationships = new_node['relationships'][relationship_name]
if add_all_relationships(new_relationships, relationship_of_node) is None:
if add_all_relationships(new_relationships, relationship_of_node, current_node.schema) is None:
return None
return True
else:
return None


def add_all_relationships(relationships, node):
def add_all_relationships(relationships, node, node_schema):
for nested_node in relationships:
if "uid" not in nested_node:
range_class = node.definition["node_class"]
new_instance = range_class()
for attr in nested_node:
setattr(new_instance, attr, nested_node[attr])
if node_schema.fields[attr].__class__ == fields.Date:
setattr(new_instance, attr, datetime.datetime.strptime(nested_node[attr], "%Y-%m-%d"))
else:
setattr(new_instance, attr, nested_node[attr])
new_instance.save()
node.connect(new_instance)
else:
Expand All @@ -206,6 +211,7 @@ def add_all_relationships(relationships, node):
node.connect(nested_node)
except:
return None

#result = updated_node_aux(node, nested_node, template)
# if result is None:
# new_result["error"] = None
Expand Down

0 comments on commit cc22189

Please sign in to comment.