From 010ff5c1c4917cedeb41f82d9a28eab848ce8b05 Mon Sep 17 00:00:00 2001 From: dcz <dcz@ipipan.waw.pl> Date: Mon, 4 Sep 2023 14:34:20 +0200 Subject: [PATCH] Request api with slider utils. Status color bugfix (red for others). Roles assign bugfix (optional attributes) --- entries/static/entries/css/entries.css | 2 +- .../static/entries/img_status/NU_status.svg | 68 +++++++++++++++++ .../entries/js/unification_entries_list.js | 2 +- .../unification/Entries/Entries.vue | 5 ++ .../Unification/LexicalUnitEdit.vue | 59 ++++++++------- .../Unification/SelectionalPreference.js | 73 ++++++++++++------- .../unification/Unification/Unification.vue | 5 ++ .../unification/shared/LexicalUnitDisplay.vue | 45 +++++++----- .../components/unification/shared/utils.js | 29 +++++++- semantics/models.py | 2 +- unifier/views.py | 2 +- 11 files changed, 217 insertions(+), 75 deletions(-) create mode 100644 entries/static/entries/img_status/NU_status.svg diff --git a/entries/static/entries/css/entries.css b/entries/static/entries/css/entries.css index ea12caf..7f8243f 100644 --- a/entries/static/entries/css/entries.css +++ b/entries/static/entries/css/entries.css @@ -290,7 +290,7 @@ legend { #overlay{ position: fixed; top: 0; - z-index: 100; + z-index: 1030; width: 100%; height:100%; display: none; diff --git a/entries/static/entries/img_status/NU_status.svg b/entries/static/entries/img_status/NU_status.svg new file mode 100644 index 0000000..f360dfc --- /dev/null +++ b/entries/static/entries/img_status/NU_status.svg @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="10mm" + height="10mm" + viewBox="0 0 10 10" + version="1.1" + id="svg864" + inkscape:version="0.92.3 (2405546, 2018-03-11)" + sodipodi:docname="bad.svg"> + <defs + id="defs858" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="11.2" + inkscape:cx="-6.5679497" + inkscape:cy="19.041578" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:pagecheckerboard="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1853" + inkscape:window-height="1025" + inkscape:window-x="67" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata861"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-19.654762,-94.232147)"> + <circle + style="fill:#bf0000;fill-opacity:1;stroke:none;stroke-width:0.05232107;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path868" + cx="24.654762" + cy="99.232147" + r="5" /> + </g> +</svg> diff --git a/entries/static/entries/js/unification_entries_list.js b/entries/static/entries/js/unification_entries_list.js index c87cb07..aebeefd 100644 --- a/entries/static/entries/js/unification_entries_list.js +++ b/entries/static/entries/js/unification_entries_list.js @@ -46,7 +46,7 @@ function setup_lexical_units_table(drilldown, lexical_units, can_see_assignees, return $(` <tr class="lexical-unit"> <td class="p-1">${lexical_unit.display}</td> - <td class="p-1">${"<img src='/static/entries/img_status/"+lexical_unit.status+"_status.svg' width='10' height='10'> "+lexical_unit.status}</td> + <td class="p-1">${"<img src='/static/entries/img_status/"+(is_assigned_to_user || lexical_unit.status === 'N' || lexical_unit.status === 'S' ? lexical_unit.status : 'NU')+"_status.svg' width='10' height='10'> "+lexical_unit.status}</td> ` + ( can_see_assignees ? `<td class="p-1">${lexical_unit.assignee_username || ""}</td>` diff --git a/frontend/src/components/unification/Entries/Entries.vue b/frontend/src/components/unification/Entries/Entries.vue index fde7135..c21c31a 100644 --- a/frontend/src/components/unification/Entries/Entries.vue +++ b/frontend/src/components/unification/Entries/Entries.vue @@ -50,6 +50,11 @@ export default { </script> <template> + <div id="overlay"> + <div class="cv-spinner"> + <span class="spinner"></span> + </div> + </div> <div id="entries-list" class="col h-100 w-100 pr-0 overflow-hidden"> <div id="entries-list-div" class="h-100 w-100 overflow-hidden"> <entries-list diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue index 936b1ce..f67c273 100644 --- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue +++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue @@ -8,6 +8,7 @@ import MeaningComponent from "../shared/frame-components/MeaningComponent.vue"; import SelectionalPreference from "./SelectionalPreference.js"; import UnificationFramePreview from "./UnificationFramePreview.vue"; import { slowal_frames2selecional_preferencies } from "../shared/utils.js"; +import {send_post_request} from "../shared/utils"; let LexicalUnitEdit = {}; @@ -159,9 +160,6 @@ Object.assign(LexicalUnitEdit, { this.selectionalPreference.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames, function () { this.loadFrame(); }.bind(this)); - // window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames, function () { - // this.loadFrame(); - // }.bind(this)); } }, removeSelectionalPreference() { @@ -673,28 +671,39 @@ Object.assign(LexicalUnitEdit, { "za niedopasowana do zunifikowanej ramy (identyfikator) przez (Leksykograf)."); } - const data = { - 'unified_frame_id': this.unified_frame.id, - 'slowal_frame_id': frame.id, - 'status': status - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/change_slowal_frame_status/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Status ramy został zmieniony'); - alert(gettext("Status ramy został zmieniony.")); - this.$emit('refreshEntriesList'); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - alert(gettext("Status ramy niew został zmieniony. Błąd: "+errorType + ' (' + errorMessage + ')')); - } - }); + send_post_request('/unifier/change_slowal_frame_status/', + { + 'unified_frame_id': this.unified_frame.id, + 'slowal_frame_id': frame.id, + 'status': status + }, + (reponse) => { + show_info('Status ramy został zmieniony'); + alert(gettext("Status ramy został zmieniony.")); + this.$emit('refreshEntriesList'); + this.loadFrame(); + }, + (request, errorType, errorMessage) => { + show_error(errorType + ' (' + errorMessage + ')'); + alert(gettext("Status ramy niew został zmieniony. Błąd: "+errorType + ' (' + errorMessage + ')')); + }) + // $.ajax({ + // type: 'post', + // url: '/' + lang + '/unifier/change_slowal_frame_status/', + // dataType: 'json', + // data: data, + // timeout: 60000, + // success: function (response) { + // show_info('Status ramy został zmieniony'); + // alert(gettext("Status ramy został zmieniony.")); + // this.$emit('refreshEntriesList'); + // this.loadFrame(); + // }.bind(this), + // error: function (request, errorType, errorMessage) { + // show_error(errorType + ' (' + errorMessage + ')'); + // alert(gettext("Status ramy niew został zmieniony. Błąd: "+errorType + ' (' + errorMessage + ')')); + // } + // }); }); }, slowal_frame_ready_rollback(status) { diff --git a/frontend/src/components/unification/Unification/SelectionalPreference.js b/frontend/src/components/unification/Unification/SelectionalPreference.js index 338b66f..abde3b5 100644 --- a/frontend/src/components/unification/Unification/SelectionalPreference.js +++ b/frontend/src/components/unification/Unification/SelectionalPreference.js @@ -1,4 +1,5 @@ import {slowal_frames2selecional_preferencies} from "../shared/utils.js"; +import {send_post_request} from "../shared/utils"; export default class SelectionalPreference { @@ -331,19 +332,29 @@ export default class SelectionalPreference { 'complement_id': complement_id, 'predefined_preference_id': predefined_preference_id }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_predefined_preference/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Preferencja zosała zapisana'); - }, - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); + + send_post_request('/unifier/save_predefined_preference/', + data, + (response) => { + show_info('Preferencja zosała zapisana'); + }, + (request, errorType, errorMessage) => { + show_error(errorType + ' (' + errorMessage + ')'); + }) + + // $.ajax({ + // type: 'post', + // url: '/' + lang + '/unifier/save_predefined_preference/', + // dataType: 'json', + // data: data, + // timeout: 60000, + // success: function (response) { + // show_info('Preferencja zosała zapisana'); + // }, + // error: function (request, errorType, errorMessage) { + // show_error(errorType + ' (' + errorMessage + ')'); + // } + // }); } saveRelationalSelectionalPreference(frame_id, complement_id_from, complement_id_to, relation_id) { @@ -353,19 +364,29 @@ export default class SelectionalPreference { 'complement_id_to': complement_id_to, 'relation_id': relation_id }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_relational_selectional_preference/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Preferencja zosała zapisana'); - }, - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); + + send_post_request('/unifier/save_relational_selectional_preference/', + data, + (response) => { + show_info('Preferencja zosała zapisana'); + }, + (request, errorType, errorMessage) => { + show_error(errorType + ' (' + errorMessage + ')'); + }) + + // $.ajax({ + // type: 'post', + // url: '/' + lang + '/unifier/save_relational_selectional_preference/', + // dataType: 'json', + // data: data, + // timeout: 60000, + // success: function (response) { + // show_info('Preferencja zosała zapisana'); + // }, + // error: function (request, errorType, errorMessage) { + // show_error(errorType + ' (' + errorMessage + ')'); + // } + // }); } } diff --git a/frontend/src/components/unification/Unification/Unification.vue b/frontend/src/components/unification/Unification/Unification.vue index 2ab9367..be37d88 100644 --- a/frontend/src/components/unification/Unification/Unification.vue +++ b/frontend/src/components/unification/Unification/Unification.vue @@ -53,6 +53,11 @@ export default { </script> <template> + <div id="overlay"> + <div class="cv-spinner"> + <span class="spinner"></span> + </div> + </div> <div id="entries-list" class="col h-100 w-100 pr-0 overflow-hidden"> <div id="entries-list-div" class="col p-0 h-100 w-100 overflow-hidden"> <unification-switchable-list diff --git a/frontend/src/components/unification/shared/LexicalUnitDisplay.vue b/frontend/src/components/unification/shared/LexicalUnitDisplay.vue index e2ddde1..d72961c 100644 --- a/frontend/src/components/unification/shared/LexicalUnitDisplay.vue +++ b/frontend/src/components/unification/shared/LexicalUnitDisplay.vue @@ -4,6 +4,7 @@ import SemanticsSchemataComponent from "./frame-components/SemanticsSchemataComp import ExamplesComponent from "./frame-components/ExamplesComponent.vue"; import SlowalFrameComponent from "./frame-components/SlowalFrameComponent.vue"; import MeaningComponent from "./frame-components/MeaningComponent.vue"; +import {send_post_request_with_timeout} from "./utils"; export default { components: { Spinner, SemanticsSchemataComponent, ExamplesComponent, SlowalFrameComponent, MeaningComponent }, @@ -65,23 +66,36 @@ export default { if(response.exists === false) { const data = {'lu_id': this.lexicalUnitId, 'unified_frame_title': title, 'frame_id': this.frame.id}; - $("#overlay").fadeIn(300); - $.ajax({ - type : 'post', - url : `/${lang}/unifier/frame_assign/`, - dataType : 'json', - data: data, - timeout : 300000, - success: function (response) { - $("#overlay").fadeOut(300); + + send_post_request_with_timeout(`/unifier/frame_assign/`, + data, + (response) => { show_info('Rama została stworzona oraz przypisana użytkownikowi.'); this.goToEdit(response.unified_frame_id, this.entryId, this.lexicalUnitId); - }.bind(this), - error: function (request, errorType, errorMessage) { + }, + (request, errorType, errorMessage) => { $("#overlay").fadeOut(300); show_error(errorType + ' (' + errorMessage + ')'); - } - }); + }, + 300000) + + // $("#overlay").fadeIn(300); + // $.ajax({ + // type : 'post', + // url : `/${lang}/unifier/frame_assign/`, + // dataType : 'json', + // data: data, + // timeout : 300000, + // success: function (response) { + // $("#overlay").fadeOut(300); + // show_info('Rama została stworzona oraz przypisana użytkownikowi.'); + // this.goToEdit(response.unified_frame_id, this.entryId, this.lexicalUnitId); + // }.bind(this), + // error: function (request, errorType, errorMessage) { + // $("#overlay").fadeOut(300); + // show_error(errorType + ' (' + errorMessage + ')'); + // } + // }); } else { alert(gettext("Nazwa zunifikowanej ramy nie jest unikalna. Proszę wybrać inną nazwę.")); } @@ -212,11 +226,6 @@ export default { </script> <template> - <div id="overlay"> - <div class="cv-spinner"> - <span class="spinner"></span> - </div> - </div> <div class="col p-0 h-100 overflow-hidden"> <div id="main-frames-pane" class="row"> <div class="col h-100 pl-3 pr-1 pt-0 pb-2 overflow-auto" id="semantics-frames-pane"> diff --git a/frontend/src/components/unification/shared/utils.js b/frontend/src/components/unification/shared/utils.js index b3e21ba..2c69dd2 100644 --- a/frontend/src/components/unification/shared/utils.js +++ b/frontend/src/components/unification/shared/utils.js @@ -27,11 +27,36 @@ function slowal_frames2selecional_preferencies(unified_frame, slowal_frames) { value.sort((a,b) => -a.type.localeCompare(b.type)); } + return unified_argument_2_selecional_preferencies; +} +const DEFAUTL_TIMEOUT = 60000; - return unified_argument_2_selecional_preferencies; +function send_post_request(path, data, succ_func, err_func) { + send_post_request_with_timeout(path, data, succ_func, err_func, DEFAUTL_TIMEOUT); +} + +function send_post_request_with_timeout(path, data, succ_func, err_func, timeout) { + $("#overlay").fadeIn(300); + $.ajax({ + type: 'post', + url: '/' + lang + path, + dataType: 'json', + data: data, + timeout: timeout, + success: function (response) { + $("#overlay").fadeOut(300); + succ_func(response); + }.bind(this), + error: function (request, errorType, errorMessage) { + $("#overlay").fadeOut(300); + err_func(request, errorType, errorMessage); + } + }); } export { - slowal_frames2selecional_preferencies + slowal_frames2selecional_preferencies, + send_post_request, + send_post_request_with_timeout }; diff --git a/semantics/models.py b/semantics/models.py index e2c242c..6542ce3 100644 --- a/semantics/models.py +++ b/semantics/models.py @@ -57,7 +57,7 @@ class Argument(models.Model): class ArgumentRole(models.Model): role = models.ForeignKey('SemanticRole', on_delete=models.PROTECT) - attribute = models.ForeignKey('RoleAttribute', null=True, on_delete=models.PROTECT) + attribute = models.ForeignKey('RoleAttribute', default=None, blank=True, null=True, on_delete=models.PROTECT) sub_attribute = models.ForeignKey('RoleSubAttribute', default=None, blank=True, null=True, on_delete=models.PROTECT) def __str__(self): diff --git a/unifier/views.py b/unifier/views.py index 1a5e2be..417afec 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -481,7 +481,7 @@ def save_new_role(request): sub_attribute_id=sub_attribute_id).first() if argument_role is None: argument_role = ArgumentRole(role=SemanticRole.objects.get(pk=role_id), - attribute=RoleAttribute.objects.get(pk=attribute_id), + attribute=None if attribute_id is None else RoleAttribute.objects.get(pk=attribute_id), sub_attribute=RoleSubAttribute.objects.get(pk=sub_attribute_id)) argument_role.save() -- GitLab