Skip to content

Commit

Permalink
chore(semantics): adapt adding nodes functions in semantics module
Browse files Browse the repository at this point in the history
* fix: bug fix sidebar change on loading semantics app

* chore: add relationship info on Add Entity

* chore: change default relationship name

* fix: error handling in entity create view

---------

Co-authored-by: JunsongDu <[email protected]>
  • Loading branch information
sbanoeon and djs0109 authored Jul 18, 2024
1 parent 680c685 commit b5554f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
34 changes: 20 additions & 14 deletions app/Entirety/entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,24 @@ class Create(ProjectContextMixin, TemplateView):

def get_context_data(self, **kwargs):
basic_info = EntityForm(self.project)

# Extract query parameters for the attributes formset
attributes_data = self.request.GET.getlist("attributes", [])
attributes_initial_data = []
for attribute in attributes_data:
attr_parts = attribute.split(";")
if len(attr_parts) == 4:
attributes_initial_data.append(
{
"name": attr_parts[0],
"type": attr_parts[1],
"value": attr_parts[2],
# 'metadata': attr_parts[3],
}
)

attributes_form_set = formset_factory(AttributeForm, max_num=0)
attributes = attributes_form_set(prefix="attr")
attributes = attributes_form_set(prefix="attr", initial=attributes_initial_data)
smart_data_model_form = SmartDataModelQueryForm(initial={"data_model": ".."})

context = super(Create, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -210,7 +226,7 @@ def post(self, request, *args, **kwargs):
basic_info = EntityForm(initial=request.POST, project=self.project)
attributes_form_set = formset_factory(AttributeForm, max_num=0)
attributes = attributes_form_set(request.POST, prefix="attr")
context = super(Create, self).get_context_data(**kwargs)
context = self.get_context_data(**kwargs)
context["basic_info"] = basic_info
context["attributes"] = attributes
try:
Expand Down Expand Up @@ -248,23 +264,13 @@ def post(self, request, *args, **kwargs):
i = i + 1
j = j + 1
res = post_entity(self, entity, False, self.project)
if res:
messages.error(
self.request,
f"Entity not created. Reason: {res}",
)
else:
return redirect(
"projects:entities:list", project_id=self.project.uuid
)
# handel the error from server
except ValidationError as e:
messages.error(request, e.raw_errors[0].exc.__str__())
if res:
messages.error(
self.request,
"Entity not created. Reason: "
+ json.loads(res.response.text).get("description"),
"Entity not created. Reason: " + res,
)
logger.error(
str(
Expand All @@ -275,7 +281,7 @@ def post(self, request, *args, **kwargs):
+ " tried creating the entity with id "
+ entity.id
+ " but failed with error "
+ json.loads(res.response.text).get("description")
+ res
+ f" in project {self.project.name}"
)
return render(request, self.template_name, context)
Expand Down
19 changes: 16 additions & 3 deletions app/Entirety/static/js/semantics.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,24 @@ var selectionmenu = {
},
{
content: 'Add entity',
select: function () {
select: function (ele) {
createUrl = currentUrl.split('/semantics/')[0]
var newUrl = createUrl + "/entities/create/";

let attributes = [
{
name: 'refEntity (replace it with relationship name)',
type: 'Relationship',
value: ele.id(),
// metadata: {}
}
];

attributes.forEach((attribute, index) => {
let attrString = `${attribute.name};${attribute.type};${attribute.value};${encodeURIComponent(JSON.stringify(attribute.metadata))}`;
newUrl += `?attributes=${encodeURIComponent(attrString)}`;
});

window.location.href = newUrl;
}
},
Expand Down Expand Up @@ -1079,5 +1094,3 @@ function scrollToDetail() {
function scrollToMain() {
window.scrollTo({top: 0, behavior: "smooth"});
}


15 changes: 7 additions & 8 deletions app/Entirety/static/semantics/css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@
cursor: pointer;
}

* {
box-sizing: border-box;
}

body {
font: 16px Arial;
}
//* {
// box-sizing: border-box;
//}
//
//body {
// font: 16px Arial;
//}

.autocomplete {
/*the container must be positioned relative:*/
Expand Down Expand Up @@ -161,4 +161,3 @@ body {
background-color: #297797 !important;
color: #ffffff;
}

0 comments on commit b5554f2

Please sign in to comment.