From 429b8926317919d73228e3d37817e9db5a2f652d Mon Sep 17 00:00:00 2001 From: dcz <dcz@ipipan.waw.pl> Date: Tue, 28 Jun 2022 14:59:06 +0200 Subject: [PATCH] Vue version of slowal frame in edit view. --- .../entries/js/components/LexicalUnitEdit.js | 854 ++++++++++-------- entries/static/entries/js/entries.js | 36 +- entries/static/entries/js/unification.js | 150 --- 3 files changed, 501 insertions(+), 539 deletions(-) diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js index 540da90..0f3948b 100644 --- a/entries/static/entries/js/components/LexicalUnitEdit.js +++ b/entries/static/entries/js/components/LexicalUnitEdit.js @@ -2,420 +2,496 @@ import InfoTooltip from "./InfoTooltip.js"; import Spinner from "./Spinner.js"; export default { - props: { - unifiedFrameId: Number - }, - data() { - return { - gettext: window.gettext, - unified_frame: Object, - unified_frame_title: Object, - unified_frame_arguments: [], - active_unified_frame_argument: null, - slowal_frames2selecional_preferencies_mapping: {}, - lexical_units: [], - img_prefix: String, - frames: [] - } - }, - components: { InfoTooltip, Spinner }, - emits: ['goToDisplay', 'refresh'], - watch: { - unifiedFrameId: function () { - this.loadFrame(); - } - }, - methods: { - hasWhiteSpace(s) { - return /\s/g.test(s); + props: { + unifiedFrameId: Number }, - async loadFrame() { - try { - var data = {'unified_frame_id': this.unifiedFrameId}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/get_unified_frame/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { + data() { + return { + gettext: window.gettext, + unified_frame: Object, + unified_frame_title: Object, + unified_frame_arguments: [], + active_unified_frame_argument: null, + slowal_frames2selecional_preferencies_mapping: {}, + lexical_units: [], + img_prefix: String, + frames: [] + } + }, + components: {InfoTooltip, Spinner}, + emits: ['goToDisplay', 'refresh'], + watch: { + unifiedFrameId: function () { + this.loadFrame(); + } + }, + methods: { + hasWhiteSpace(s) { + return /\s/g.test(s); + }, + slowal_frame_html(frame) { + let ret = frame2dom(frame); + return ret.outerHTML; + }, + show_semantics_unified_view(frames, subentries) { + $('#semantics-no-examples').hide(); + var schemata_dom = subentries2dom(subentries); + $('#semantics-schemata').append($(schemata_dom)); + }, + async loadFrame() { + try { + var data = {'unified_frame_id': this.unifiedFrameId}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/get_unified_frame/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { - this.img_prefix = window.STATIC_URL; + this.img_prefix = window.STATIC_URL; - this.lexical_units = frames2lexical_units(response.frames); + this.lexical_units = frames2lexical_units(response.frames); - this.unified_frame = response.unified_frame; - this.unified_frame_title = this.unified_frame.title || lexical_units2dom(this.lexical_units) - this.unified_frame_arguments = this.unified_frame.arguments; - this.frames = response.frames; + this.unified_frame = response.unified_frame; + this.unified_frame_title = this.unified_frame.title || lexical_units2dom(this.lexical_units) + this.unified_frame_arguments = this.unified_frame.arguments; + this.frames = response.frames; - // $('#lexical-unit').html(this.unified_frame_title); + // $('#lexical-unit').html(this.unified_frame_title); - this.slowal_frames2selecional_preferencies_mapping = slowal_frames2selecional_preferencies(this.unified_frame, response.frames); + this.slowal_frames2selecional_preferencies_mapping = slowal_frames2selecional_preferencies(this.unified_frame, response.frames); - // unified_view_frame_content = response.frames - curr_entry = this.unifiedFrameId; - // curr_no_filters = related; - clear_info(); - curr_alternations = response.alternations; - curr_realisation_phrases = response.realisation_phrases; - curr_realisation_descriptions = response.realisation_descriptions; - curr_examples = response.examples; - curr_examples_by_id = Object(); - for (var i in curr_examples) { - curr_examples_by_id[curr_examples[i].id] = curr_examples[i]; - } - unified_frame_active_frame = this.unified_frame; - show_unified_frame_lexical_units(response.frames) - fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames) - show_semantics_unified_view(response.frames, response.subentries); - // show_unmatched_examples(); + // unified_view_frame_content = response.frames + curr_entry = this.unifiedFrameId; + // curr_no_filters = related; + clear_info(); + curr_alternations = response.alternations; + curr_realisation_phrases = response.realisation_phrases; + curr_realisation_descriptions = response.realisation_descriptions; + curr_examples = response.examples; + curr_examples_by_id = Object(); + for (var i in curr_examples) { + curr_examples_by_id[curr_examples[i].id] = curr_examples[i]; + } + show_unified_frame_lexical_units(response.frames) + fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames) + this.show_semantics_unified_view(response.frames, response.subentries); + // show_unmatched_examples(); - // tooltips with meaning gloss - activate_tooltips($('#semantics-frames-pane')); - update_last_visited(response.last_visited); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); + // tooltips with meaning gloss + activate_tooltips($('#semantics-frames-pane')); + update_last_visited(response.last_visited); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); - } catch (error) { - console.log(error); - } - }, - unifiedFrameArgumentSelected (argument) { - if (this.active_unified_frame_argument === argument) { - this.active_unified_frame_argument = null; - } else { - this.active_unified_frame_argument = argument; - } - this.unifiedFrameArgumentHovered(argument); - }, - unifiedFrameArgumentHovered (argument) { - clear_info(); - if (argument && this.active_unified_frame_argument === argument) { - show_info(gettext('Kliknij, aby cofnąć wybór kolumny do edycji.')); - } - if (argument && this.active_unified_frame_argument !== argument) { - show_info(gettext('Kliknij, aby wybrać kolumnę do edycji.')); - } - }, - addSelectivePreference () { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); - } else { - window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames); - } - }, - changeTitle() { - let title = this.unified_frame.title != null ? this.unified_frame.title : ''; - var change_title_popup = { - state0: { - title: 'Zmiana nazwy ramy', - html: '<input type="text" size="32" value="' + title + '" name="title" />', - buttons: { Anuluj: 0, Zapisz: 1}, - focus: -1, - submit: function(e,v,m,f){ - if (v == 0) { - $.prompt.close(); + } catch (error) { + console.log(error); + } + }, + unifiedFrameArgumentSelected(argument) { + if (this.active_unified_frame_argument === argument) { + this.active_unified_frame_argument = null; + } else { + this.active_unified_frame_argument = argument; + } + this.unifiedFrameArgumentHovered(argument); + }, + unifiedFrameArgumentHovered(argument) { + clear_info(); + if (argument && this.active_unified_frame_argument === argument) { + show_info(gettext('Kliknij, aby cofnąć wybór kolumny do edycji.')); } - if (v === 1) { - e.preventDefault(); - var title = f.title; + if (argument && this.active_unified_frame_argument !== argument) { + show_info(gettext('Kliknij, aby wybrać kolumnę do edycji.')); + } + }, + addSelectivePreference() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); + } else { + window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames); + } + }, + changeTitle() { + let title = this.unified_frame.title != null ? this.unified_frame.title : ''; + var change_title_popup = { + state0: { + title: 'Zmiana nazwy ramy', + html: '<input type="text" size="32" value="' + title + '" name="title" />', + buttons: {Anuluj: 0, Zapisz: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + $.prompt.close(); + } + if (v === 1) { + e.preventDefault(); + var title = f.title; - if(this.hasWhiteSpace(title)) { - alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id, 'unified_frame_title': title}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_unified_frame_title/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Tytuł ramy zosał zapisany'); - $.prompt.close(); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } + if (this.hasWhiteSpace(title)) { + alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); + } else { + var data = {'unified_frame_id': this.unified_frame.id, 'unified_frame_title': title}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/save_unified_frame_title/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Tytuł ramy zosał zapisany'); + $.prompt.close(); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } + } + }.bind(this) + } } - }.bind(this) - } - } - $.prompt(change_title_popup); - }, - changeRole() { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, dla którego chcesz wybrać rolę.")); - } else { - var existingSelect = function () { - let selected_unified_frame_argument = this.unified_frame_arguments.find(o => o.id === this.active_unified_frame_argument.id); - if (!selected_unified_frame_argument.proposed_roles) { - return gettext('Brak ról do wyboru.') - } - return selected_unified_frame_argument.proposed_roles.map(role => { - return `<label><input type="radio" name="roles" value="${role.id}" /> ${role.str}</label><br />`; - }).join(""); - }.bind(this); + $.prompt(change_title_popup); + }, + changeRole() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, dla którego chcesz wybrać rolę.")); + } else { + var existingSelect = function () { + let selected_unified_frame_argument = this.unified_frame_arguments.find(o => o.id === this.active_unified_frame_argument.id); + if (!selected_unified_frame_argument.proposed_roles) { + return gettext('Brak ról do wyboru.') + } + return selected_unified_frame_argument.proposed_roles.map(role => { + return `<label><input type="radio" name="roles" value="${role.id}" /> ${role.str}</label><br />`; + }).join(""); + }.bind(this); - var newSelect = function () { - let rolesHTML = roles.map(role => { - return `<label><input type="radio" name="role" value="${role.id}" /> ${role.role}</label><br />`; - }).join(""); - let attributesHTML = role_attributes.map(attribute => { - return `<label><input type="radio" name="attribute" value="${attribute.id}" /> ${attribute.attribute}</label><br />`; - }).join(""); - return '<div class="row"><div class="column"><div class="role_select_header">Role</div>' + rolesHTML + '</div><div class="column"><div class="role_select_header">Atrybuty</div>' + attributesHTML +'</div></div>'; - }.bind(this); + var newSelect = function () { + let rolesHTML = roles.map(role => { + return `<label><input type="radio" name="role" value="${role.id}" /> ${role.role}</label><br />`; + }).join(""); + let attributesHTML = role_attributes.map(attribute => { + return `<label><input type="radio" name="attribute" value="${attribute.id}" /> ${attribute.attribute}</label><br />`; + }).join(""); + return '<div class="row"><div class="column"><div class="role_select_header">Role</div>' + rolesHTML + '</div><div class="column"><div class="role_select_header">Atrybuty</div>' + attributesHTML + '</div></div>'; + }.bind(this); - let change_role_popup = { - state0: { - title: 'Wybór roli', - html: 'Wybierz lub dodaj rolę', - buttons: { Wybierz: 0, Dodaj: 1, Koniec: -1 }, - focus: -1, - submit: function(e,v,m,f){ - if (v == -1) { - e.preventDefault(); + let change_role_popup = { + state0: { + title: 'Wybór roli', + html: 'Wybierz lub dodaj rolę', + buttons: {Wybierz: 0, Dodaj: 1, Koniec: -1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); - this.loadFrame(); + this.loadFrame(); - $.prompt.close(); - } - if (v === 0) { - e.preventDefault(); - $.prompt.goToState('state1'); - } - if (v == 1) { - e.preventDefault(); - $.prompt.goToState('state2'); - } - }.bind(this) - }, - state1: { - title: 'Wybierz rolę', - html: existingSelect(), - buttons: {Anuluj: -1, Zatwierdź: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == -1) { - e.preventDefault(); - $.prompt.goToState('state0'); - } - if (v == 1) { - e.preventDefault(); - normalizeFormData(f.roles).map(role_id => { - var data = { 'unified_frame_id' : this.unified_frame.id, 'complement_id' : this.active_unified_frame_argument.id, 'role_id' : role_id }; - $.ajax({ - type : 'post', - url : '/' + lang + '/unifier/save_selected_role/', - dataType : 'json', - data : data, - timeout : 60000, - success : function(response) { - show_info('Wybrana rola zosała zapisana'); - $.prompt.goToState('state0'); - }.bind(this), - error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - }); - } - }.bind(this) - }, - state2: { - title: 'Dodaj rolę', - html: newSelect(), - buttons: {Anuluj: -1, Zatwierdź: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == -1) { - e.preventDefault(); - $.prompt.goToState('state0'); - } - if (v == 1) { - e.preventDefault(); + $.prompt.close(); + } + if (v === 0) { + e.preventDefault(); + $.prompt.goToState('state1'); + } + if (v == 1) { + e.preventDefault(); + $.prompt.goToState('state2'); + } + }.bind(this) + }, + state1: { + title: 'Wybierz rolę', + html: existingSelect(), + buttons: {Anuluj: -1, Zatwierdź: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); + $.prompt.goToState('state0'); + } + if (v == 1) { + e.preventDefault(); + normalizeFormData(f.roles).map(role_id => { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'complement_id': this.active_unified_frame_argument.id, + 'role_id': role_id + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/save_selected_role/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Wybrana rola zosała zapisana'); + $.prompt.goToState('state0'); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + }); + } + }.bind(this) + }, + state2: { + title: 'Dodaj rolę', + html: newSelect(), + buttons: {Anuluj: -1, Zatwierdź: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); + $.prompt.goToState('state0'); + } + if (v == 1) { + e.preventDefault(); - var role_id = normalizeFormData(f.role)[0]; + var role_id = normalizeFormData(f.role)[0]; - if(role_id != null) { - var attribute_id = normalizeFormData(f.attribute)[0]; + if (role_id != null) { + var attribute_id = normalizeFormData(f.attribute)[0]; - var data = { - 'unified_frame_id': this.unified_frame.id, - 'complement_id': this.active_unified_frame_argument.id, - 'role_id': role_id, - 'attribute_id': attribute_id - }; - $.ajax({ + var data = { + 'unified_frame_id': this.unified_frame.id, + 'complement_id': this.active_unified_frame_argument.id, + 'role_id': role_id, + 'attribute_id': attribute_id + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/save_new_role/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Nowa rola zosała zapisana'); + $.prompt.goToState('state0'); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } else { + alert(gettext("Musisz wybrać pzynajmniej rolę.")); + } + } + }.bind(this) + } + }; + $.prompt(change_role_popup); + } + }, + addArgument() { + var data = {'unified_frame_id': this.unified_frame.id}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/add_argument/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Nowy argument zosał dodany'); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + }, + removeArgument() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, który chcesz usunąć.")); + } else { + let hasSlowalFrameArgumentMapping = false; + for (var i in this.unified_frame.slowal_frame_mapping) { + var slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i]; + for (var j in slowal_frame_mapping.slowal_frame_argument_mapping) { + var slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j]; + if (slowal_frame_argument_mapping.unified_frame_agrument_id == this.active_unified_frame_argument.id) { + hasSlowalFrameArgumentMapping = true; + break; + } + } + } + if (hasSlowalFrameArgumentMapping) { + alert(gettext("Zaznaczony argument nie może zostać usunięty - podpięte ramy posiadają do niego dowiązania.")); + } else { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'complement_id': this.active_unified_frame_argument.id + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/remove_argument/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Wybrany argument zosał usunięty'); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } + } + }, + duplicate() { + let title = this.unified_frame.title != null ? this.unified_frame.title : ''; + var duplicate_popup = { + state0: { + title: 'Podaj nazwę zduplikowanej ramy', + html: '<input type="text" size="32" value="KOPIA_' + title + '" name="title" />', + buttons: {Anuluj: 0, Zapisz: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + e.preventDefault(); + $.prompt.close(); + } + if (v === 1) { + e.preventDefault(); + var title = f.title; + + if (this.hasWhiteSpace(title)) { + alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); + } else { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'target_unified_frame_title': title + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/duplicate_unified_frame/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Zunifikowana rama została zduplikowana.'); + $.prompt.close(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } + } + }.bind(this) + } + } + $.prompt(duplicate_popup); + }, + changeUnifiedFrameStatusToReady() { + let foundNotVerifiedFrame = this.frames.find(frame => !frame.verified); + if (foundNotVerifiedFrame) { + alert(gettext("Wszystkie podpięte ramy powinny być zweryfikowane.")); + } else { + var data = {'unified_frame_id': this.unified_frame.id}; + $.ajax({ type: 'post', - url: '/' + lang + '/unifier/save_new_role/', + url: '/' + lang + '/unifier/change_unified_frame_status_to_ready/', dataType: 'json', data: data, timeout: 60000, success: function (response) { - show_info('Nowa rola zosała zapisana'); - $.prompt.goToState('state0'); + show_info('Status ramy został zmieniony'); + this.$emit('goToDisplay') }.bind(this), error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); + show_error(errorType + ' (' + errorMessage + ')'); } - }); - } else { - alert(gettext("Musisz wybrać pzynajmniej rolę.")); - } - } - }.bind(this) - } - }; - $.prompt(change_role_popup); - } - }, - addArgument() { - var data = { 'unified_frame_id' : this.unified_frame.id}; - $.ajax({ - type : 'post', - url : '/' + lang + '/unifier/add_argument/', - dataType : 'json', - data : data, - timeout : 60000, - success : function(response) { - show_info('Nowy argument zosał dodany'); - this.loadFrame(); - }.bind(this), - error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - }, - removeArgument() { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, który chcesz usunąć.")); - } else { - let hasSlowalFrameArgumentMapping = false; - for (var i in this.unified_frame.slowal_frame_mapping) { - var slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i]; - for (var j in slowal_frame_mapping.slowal_frame_argument_mapping) { - var slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j]; - if (slowal_frame_argument_mapping.unified_frame_agrument_id == this.active_unified_frame_argument.id) { - hasSlowalFrameArgumentMapping = true; - break; + }); } + }, + change_slowal2unified_frame_argument_mapping(slowal_frame_id) { + var argument_ids = []; + $('.argument.active').each(function() { + var id = $(this).data('argument_id').split('-')[1]; + if(id.startsWith('_')) { + id = -parseInt(id.split('_')[1]) + } else { + id = parseInt(id) + } + argument_ids.push(id); + }); + var choosed_slowal_frame_id = null; + $('.frame.active').each(function() { + choosed_slowal_frame_id = $(this).data('frame_id'); + }); + if(choosed_slowal_frame_id == slowal_frame_id && argument_ids.length == 2) { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'slowal_frame_id': choosed_slowal_frame_id, + 'slowal_frame_selected_arguments': JSON.stringify(argument_ids) + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/change_slowal2unified_fram_argument_mapping/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); } - } - if (hasSlowalFrameArgumentMapping) { - alert(gettext("Zaznaczony argument nie może zostać usunięty - podpięte ramy posiadają do niego dowiązania.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id, 'complement_id': this.active_unified_frame_argument.id}; + }, + change_slowal2unified_mapping_verification(slowal_frame_id, verified) { + // check_import_status(); + // show_entry_spinners(); + var data = { + 'unified_frame_id': this.unified_frame.id, + 'slowal_frame_id': slowal_frame_id, + 'verified': verified + }; $.ajax({ type: 'post', - url: '/' + lang + '/unifier/remove_argument/', + url: '/' + lang + '/unifier/change_slowal2unified_mapping_verification/', dataType: 'json', data: data, timeout: 60000, success: function (response) { - show_info('Wybrany argument zosał usunięty'); this.loadFrame(); }.bind(this), error: function (request, errorType, errorMessage) { show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); } }); - } - } - }, - duplicate() { - let title = this.unified_frame.title != null ? this.unified_frame.title : ''; - var duplicate_popup = { - state0: { - title: 'Podaj nazwę zduplikowanej ramy', - html: '<input type="text" size="32" value="KOPIA_' + title + '" name="title" />', - buttons: { Anuluj: 0, Zapisz: 1}, - focus: -1, - submit: function(e,v,m,f){ - if (v == 0) { - e.preventDefault(); - $.prompt.close(); - } - if (v === 1) { - e.preventDefault(); - var title = f.title; - - if(this.hasWhiteSpace(title)) { - alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id, 'target_unified_frame_title': title}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/duplicate_unified_frame/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Zunifikowana rama została zduplikowana.'); - $.prompt.close(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } - } - }.bind(this) - } - } - $.prompt(duplicate_popup); + }, }, - changeUnifiedFrameStatusToReady() { - let foundNotVerifiedFrame = this.frames.find(frame => !frame.verified); - if(foundNotVerifiedFrame) { - alert(gettext("Wszystkie podpięte ramy powinny być zweryfikowane.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/change_unified_frame_status_to_ready/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Status ramy został zmieniony'); - this.$emit('goToDisplay') - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } + mounted() { + Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { + sizes: [40, 60], + minSize: 400, + gutterSize: 4, + elementStyle: (dimension, size, gutterSize) => { + return { + 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' + } + }, }); - } - } - }, - mounted () { - Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { - sizes: [40, 60], - minSize: 400, - gutterSize: 4, - elementStyle: (dimension, size, gutterSize) => { - return { - 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' - } - }, - }); - this.loadFrame(); - }, - template: ` + this.loadFrame(); + }, + template: ` <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-frames-pane"> <table class="table-button-menu" cellspacing="1"> <tr style="background-color: white;"> @@ -545,7 +621,41 @@ export default { <td id="empty" style="padding: 10px 15px 10px 15px; color: #000000;"></td> </tr> </table> - <div id="semantics-frames"></div> + <div id="semantics-frames"> + + <table class="table m-0 table-borderless border border-secondary text-dark" + v-for="frame in frames" + :key="frame.id" + > + <tbody> + <tr> + <th scope="row"> + <div v-html="slowal_frame_html(frame)"></div> + </th> + <th scope="row"> + <div> + + <label v-bind:for="frame.id"> + <div><input + :id="frame.id" + type="checkbox" + + v-model="frame.verified" + :checked="frame.verified" + class="custom-control custom-checkbox" + @change="change_slowal2unified_mapping_verification(frame.id, frame.verified)" + > + <span>Zweryfikowane</span></div> + </label> + <br><br> <a href="#" class="btn btn-sm btn-dark" role="button" + @click="change_slowal2unified_frame_argument_mapping(frame.id)">Z</a> + </div> + </th> + </tr> + </tbody> + </table> + + </div> </div> <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-schemata-pane"> <ul class="nav nav-pills nav-justified p-1" id="entryTabs" role="tablist"> diff --git a/entries/static/entries/js/entries.js b/entries/static/entries/js/entries.js index 9a72eb8..ef204bb 100644 --- a/entries/static/entries/js/entries.js +++ b/entries/static/entries/js/entries.js @@ -141,6 +141,25 @@ function frame2dom(frame) { div.className = 'frame mb-3'; div.setAttribute('data-frame_id', frame.id); + div.setAttribute("onmouseenter", "\ + var frame = $(this); \ + if (!frame.hasClass('active')) { \ + $(this).addClass('highlight bg-highlight'); \ + show_info(gettext('Kliknij, aby wyświetlić przykłady dla tej ramy oraz jej realizacje składniowe.')); \ + } \ + "); + div.setAttribute("onmouseleave", " \ + $(this).removeClass('highlight bg-highlight'); \ + clear_info(); \ + "); + div.setAttribute("onclick", "\ + var frame = $(this); \ + if (!frame.hasClass('active')) { \ + select_frame(frame); \ + } \ + clear_info(); \ + "); + var lexical_units_html = lexical_units2dom(frame.lexical_units); var p = document.createElement('p'); p.className = 'mb-1' @@ -357,23 +376,6 @@ function show_semantics(frames, subentries) { $('#semantics-frames').append($(frames_dom)); - $('.frame').mouseenter(function() { - var frame = $(this); - if (!frame.hasClass('active')) { - $(this).addClass('highlight bg-highlight'); - show_info(gettext('Kliknij, aby wyświetlić przykłady dla tej ramy oraz jej realizacje składniowe.')); - } - }).mouseleave(function() { - $(this).removeClass('highlight bg-highlight'); - clear_info(); - }).click(function() { - var frame = $(this); - if (!frame.hasClass('active')) { - select_frame(frame); - } - clear_info(); - }); - /*$('.plwn-url').click(function() { $(this).tooltip('hide'); });*/ diff --git a/entries/static/entries/js/unification.js b/entries/static/entries/js/unification.js index b31f3fb..d55eb8a 100644 --- a/entries/static/entries/js/unification.js +++ b/entries/static/entries/js/unification.js @@ -1,155 +1,5 @@ "use strict"; -var unified_view_frame_content; -var unified_frame_active_frame; - -function change_slowal2unified_frame_argument_mapping(slowal_frame_id) { - var argument_ids = []; - $('.argument.active').each(function() { - var id = $(this).data('argument_id').split('-')[1]; - if(id.startsWith('_')) { - id = -parseInt(id.split('_')[1]) - } else { - id = parseInt(id) - } - argument_ids.push(id); - }); - var choosed_slowal_frame_id = null; - $('.frame.active').each(function() { - choosed_slowal_frame_id = $(this).data('frame_id'); - }); - if(choosed_slowal_frame_id == slowal_frame_id && argument_ids.length == 2) { - change_slowal2unified_fram_argument_mapping_post(unified_frame_active_frame.id, choosed_slowal_frame_id, argument_ids); - get_unified_frame(unified_frame_active_frame.id); - } -} - -function frames2dom_unidief_view(frames) { - var fragment = document.createDocumentFragment(); - for (var i in frames) { - let frameDiv = frame2dom(frames[i]); - var table = document.createElement('table'); - table.className = 'table m-0 table-borderless border border-secondary text-dark'; - var tbody = document.createElement('tbody'); - - var roles_row = document.createElement('tr'); - - var frame_col = document.createElement('th'); - frame_col.scope = 'row'; - frame_col.class = 'py-0 px-1 text-secondary'; - frame_col.append(frameDiv) - - var button_col = document.createElement('th'); - button_col.scope = 'row'; - button_col.class = 'py-0 px-1 text-secondary'; - - var button_col_div = document.createElement('div'); - button_col_div.innerHTML = '<div class="custom-control custom-checkbox">\n' + - ' <input type="checkbox" id="slowal-verification-'+frames[i].id+'" class="custom-control-input" '+(frames[i].verified ? 'checked' : '')+' onclick="change_slowal2unified_mapping_verification('+frames[i].id+', this.checked)">\n' + - ' <label class="custom-control-label" for="slowal-verification-'+frames[i].id+'">Zweryfikowane</label>\n' + - ' <br><br>' + - ' <a href="#" class="btn btn-sm btn-dark" role="button" onclick="change_slowal2unified_frame_argument_mapping('+frames[i].id+')">Z</a>' + - '</div>'; - - button_col.append(button_col_div); - - roles_row.append(frame_col); - roles_row.append(button_col); - tbody.append(roles_row); - table.append(tbody); - - fragment.append(table); - - } - if (fragment.childNodes.length === 0) { - return '<p>(' + gettext('brak ram') + ')</p>'; - } - return fragment; -} - -function show_semantics_unified_view(frames, subentries) { - $('#semantics-no-examples').hide(); - var schemata_dom = subentries2dom(subentries); - $('#semantics-schemata').append($(schemata_dom)); - var frames_dom = frames2dom_unidief_view(frames); - - $('#semantics-frames').append($(frames_dom)); - - $('.frame').mouseenter(function() { - var frame = $(this); - if (!frame.hasClass('active')) { - $(this).addClass('highlight bg-highlight'); - show_info(gettext('Kliknij, aby wyświetlić przykłady dla tej ramy oraz jej realizacje składniowe.')); - } - }).mouseleave(function() { - $(this).removeClass('highlight bg-highlight'); - clear_info(); - }).click(function() { - var frame = $(this); - if (!frame.hasClass('active')) { - select_frame(frame); - } - clear_info(); - }); - - $('.lu-plwn, .synset-plwn').click(function(event) { - // don’t make link click select the frame - event.stopPropagation(); - }); - - // if there’s one frame, select it immediately - if ($('.frame').length === 1) { - select_frame($('.frame').first()); - } - - // if there’s no frames, disable the tab - if ($('.frame').length === 0) { - $('#semantics-tab').addClass('disabled'); - } else { - $('#semantics-tab').removeClass('disabled'); - } -} - - -function change_slowal2unified_fram_argument_mapping_post(unified_frame_id, slowal_frame_id, slowal_frame_selected_arguments) { - check_import_status(); - show_entry_spinners(); - var data = { 'unified_frame_id' : unified_frame_id, 'slowal_frame_id' : slowal_frame_id, 'slowal_frame_selected_arguments' : JSON.stringify(slowal_frame_selected_arguments) }; - $.ajax({ - type : 'post', - url : '/' + lang + '/unifier/change_slowal2unified_fram_argument_mapping/', - dataType : 'json', - data : data, - timeout : 60000, - success : function(response) { - - }, - error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); -} - -function change_slowal2unified_mapping_verification(slowal_frame_id, verified) { - check_import_status(); - show_entry_spinners(); - var data = { 'unified_frame_id' : unified_frame_active_frame.id, 'slowal_frame_id' : slowal_frame_id, 'verified' : verified }; - $.ajax({ - type : 'post', - url : '/' + lang + '/unifier/change_slowal2unified_mapping_verification/', - dataType : 'json', - data : data, - timeout : 60000, - success : function(response) { - - }, - error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); -} - - function get_unified_frame(unified_frame_id, related) { check_import_status(); clear_entry(); -- GitLab