From 339ce60d8cecf9c53404df242ff5ca9aac6d74c5 Mon Sep 17 00:00:00 2001 From: dcz <dcz@ipipan.waw.pl> Date: Wed, 29 Jun 2022 11:54:12 +0200 Subject: [PATCH] Go to edit from preview window Correct refresh after preferencies selection Set Ready status for unified frame --- .../js/components/LexicalUnitDisplay.js | 5 +- .../entries/js/components/LexicalUnitEdit.js | 73 ++++++++++++++----- .../entries/js/selectional_preference.js | 11 ++- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/entries/static/entries/js/components/LexicalUnitDisplay.js b/entries/static/entries/js/components/LexicalUnitDisplay.js index b1b5583..541c634 100644 --- a/entries/static/entries/js/components/LexicalUnitDisplay.js +++ b/entries/static/entries/js/components/LexicalUnitDisplay.js @@ -42,6 +42,9 @@ export default { dataType: 'json', timeout: 60000, }).then(() => { this.$emit('refresh'); }); + }, + isReadyToProcess() { + return (this.frame?.status === 'O' || this.frame?.status === 'G') && this.unifiedFrame?.status === 'O'; } }, created () { @@ -74,7 +77,7 @@ export default { <a class="btn btn-sm btn-outline-dark mr-2" v-if="frame?.status === 'N'" @click="take">{{ gettext('Pobierz') }}</a> <a class="btn btn-sm btn-outline-dark mr-2" - v-if="frame?.status === 'O' || frame?.status === 'G' && unifiedFrame?.status === 'O'" + v-if="isReadyToProcess()" @click="$emit('goToEdit', this.unifiedFrame.pk)" > {{ gettext('Obrabiaj') }} diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js index 122a2e0..d70808f 100644 --- a/entries/static/entries/js/components/LexicalUnitEdit.js +++ b/entries/static/entries/js/components/LexicalUnitEdit.js @@ -14,7 +14,12 @@ const FramePreview = { }; }, components: {LexicalUnitEdit}, - emits: ['changeFrame'], + emits: ['changeFrame', 'changePreviewToEdit'], + methods: { + changePreviewToEditLocal(unifiedFrameId) { + this.$emit('changePreviewToEdit', unifiedFrameId); + } + }, mounted () { Split(['#frame-preview-left-pane', '#frame-preview-right-pane'], { sizes: [60, 40], @@ -35,6 +40,7 @@ const FramePreview = { :readOnly="true" :unifiedFrameId="unifiedFrameId" :forceRefresh="forceRefresh" + @change-preview-to-edit="changePreviewToEditLocal" /> <div v-else class="h-100"> Brak ramy do wyświetlenia @@ -78,7 +84,7 @@ Object.assign(LexicalUnitEdit, { } }, components: {InfoTooltip, Spinner, FramePreview}, - emits: ['goToDisplay', 'refresh', 'swapFrames'], + emits: ['goToDisplay', 'refresh', 'swapFrames', 'changePreviewToEdit'], watch: { forceRefresh(newVal, oldVal) { console.log("forceRefresh exec") @@ -173,7 +179,9 @@ Object.assign(LexicalUnitEdit, { 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); + window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames, function () { + this.loadFrame(); + }.bind(this)); } }, changeTitle() { @@ -462,21 +470,38 @@ Object.assign(LexicalUnitEdit, { 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 + ')'); + let roleDict = {}; + let hasPreferenceSelected = true; + for (var i in this.unified_frame_arguments) { + var argument = this.unified_frame_arguments[i]; + if(argument.role) { + roleDict[argument.role.str] = argument.role; } - }); + if(!argument.preferences || argument.preferences.length == 0) { + hasPreferenceSelected = false; + } + } + if(Object.keys(roleDict).length === this.unified_frame_arguments.length && hasPreferenceSelected) { + //all roles are set, and are uniq + //TODO: aktywne preferencje w argumencie nie znajdują się w relacji hipo-/hiperonimii. + 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 + ')'); + } + }); + } else { + alert(gettext("Role dla wszystkich argumentów powinny być ustawione oraz unikalne. Preferencje selekcyjne dla wszystkich argumentów powinny być ustawione.")); + } } }, change_slowal2unified_frame_argument_mapping(slowal_frame_id) { @@ -623,7 +648,10 @@ Object.assign(LexicalUnitEdit, { if (this.currentPreviewedUnifiedFrameId !== -1 && this.unified_frame.id !== this.currentPreviewedUnifiedFrameId) { this.$emit("swapFrames", this.currentPreviewedUnifiedFrameId); } - } + }, + changePreviewToEditClick () { + this.$emit("changePreviewToEdit", this.unified_frame.id); + }, }, mounted() { !this.readOnly && Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { @@ -640,6 +668,13 @@ Object.assign(LexicalUnitEdit, { }, template: ` <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-frames-pane"> + + <table v-if="readOnly" class="table-button-menu" style="max-width: 50px" cellspacing="1"> + <tr style="background-color: white;"> + <td id="change-title" @click="changePreviewToEditClick" style="padding: 10px 15px 10px 15px; color: #000000;">Edytuj</td> + </tr> + </table> + <table v-if="!readOnly" class="table-button-menu" cellspacing="1"> <tr style="background-color: white;"> <td id="change-title" @click="changeTitle" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień nazwę</td> @@ -653,7 +688,6 @@ Object.assign(LexicalUnitEdit, { <td id="remove-arg" @click="removeArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argum.</td> <td id="change-windows" style="padding: 10px 15px 10px 15px; color: #000000;" @click="swapUnifiedFrames">Zamień okna</td> <td id="duplicates" @click="duplicate" style="padding: 10px 15px 10px 15px; color: #000000;">Duplikuj</td> - <td id="save-changes" style="padding: 10px 15px 10px 15px; color: #000000;">Zapisz</td> </tr> </table> <spinner /> @@ -819,6 +853,7 @@ Object.assign(LexicalUnitEdit, { :key="currentPreviewedUnifiedFrameId" :initialUnifiedFrameId="currentPreviewedUnifiedFrameId" @change-frame="changePreviewedUnifiedFrameId" + @change-preview-to-edit="swapUnifiedFrames" :forceRefresh="internalForceRefresh" /> </div> <div v-if="right_pane_tab === 'notes'">notateczki</div> diff --git a/entries/static/entries/js/selectional_preference.js b/entries/static/entries/js/selectional_preference.js index acb0bf2..d0cc544 100644 --- a/entries/static/entries/js/selectional_preference.js +++ b/entries/static/entries/js/selectional_preference.js @@ -119,12 +119,12 @@ function attachPlWNContextAutocomplete() { }); } -function addSelectivePreference(unified_frame, unified_frame_active_argument_id, frames) { +function addSelectivePreference(unified_frame, unified_frame_active_argument_id, frames, callbackFunction) { if (!unified_frame_active_argument_id) return; - addSelectivePreferenceBase(unified_frame, frames, unified_frame_active_argument_id); + addSelectivePreferenceBase(unified_frame, frames, unified_frame_active_argument_id, callbackFunction); } -function addSelectivePreferenceBase(unified_frame, frames, complement_id) { +function addSelectivePreferenceBase(unified_frame, frames, complement_id, callbackFunction) { let unified_frame_id = unified_frame.id; var submitSynsetSelection = function(e,v,m,f){ @@ -163,10 +163,9 @@ function addSelectivePreferenceBase(unified_frame, frames, complement_id) { submit: function(e,v,m,f){ if (v == -1) { e.preventDefault(); - - get_unified_frame(curr_entry, false); - $.prompt.close(); + + callbackFunction(); } if (v === 0) { e.preventDefault(); -- GitLab