diff --git a/entries/static/entries/css/unification_frames.css b/entries/static/entries/css/unification_frames.css index a4e070bae51ac8f98aaa2b22dfb994ebe18bfa8e..7946523a1ae59a380d2bcb10d9754edd1660132a 100644 --- a/entries/static/entries/css/unification_frames.css +++ b/entries/static/entries/css/unification_frames.css @@ -6,7 +6,7 @@ table.table-button-menu { width: 100% } -table.table-button-menu td { +.table-button-menu-td { border-style:solid; border-width:1px; border-right: 1px solid #000; @@ -14,7 +14,7 @@ table.table-button-menu td { } -table.table-button-menu td:hover { +.table-button-menu-td:hover { background-color: #e8ebed; cursor: pointer; } diff --git a/entries/static/entries/js/unification_entries_list.js b/entries/static/entries/js/unification_entries_list.js index aebeefdd1fbac726863f3593aff0985448ebf42b..39de36125227e0fa338e445bdcc00b1b186c95ec 100644 --- a/entries/static/entries/js/unification_entries_list.js +++ b/entries/static/entries/js/unification_entries_list.js @@ -97,7 +97,8 @@ function show_notes_form($container, pk, model, refreshFunction, type, title, bo data: { title: $('.note-form input[name=title]').val(), note: $('.note-form textarea[name=note]').val(), - super: $('.note-form input[name=super]').val() + super: $('.note-form input[name=super]').val(), + for_all: $('.note-form input[name=for_all]').val() }, timeout: 5000, success: function (response) { diff --git a/entries/static/entries/js/unification_frames_list.js b/entries/static/entries/js/unification_frames_list.js index 458283519b34df00aa6a6fc79aa6d9219d88a492..45c2e258dba96a7f1039e64eae973200337471bf 100644 --- a/entries/static/entries/js/unification_frames_list.js +++ b/entries/static/entries/js/unification_frames_list.js @@ -21,7 +21,7 @@ function setup_frames_list(options) { ], hidden_columns: can_see_assignees ? [3] : [2,3], selectEntryId: options.selectEntryId, - setup_hierarchy_marking: true + setup_hierarchy_marking: options.setupHierarchyMarking }); datatable.on('click', 'tr.entry', function () { const data = datatable.row(this).data(); diff --git a/entries/views.py b/entries/views.py index acd28b7980106d587edd515865cccdb704f8d910..e9be91948c4b80a2c05d85fe84aa818b7e86a1a1 100644 --- a/entries/views.py +++ b/entries/views.py @@ -476,6 +476,10 @@ def get_entries(request): continue else: yield lu + import datetime + now = datetime.datetime.now() + print("1 Current date and time : ") + print(now.strftime("%Y-%m-%d %H:%M:%S")) result = { 'draw' : scroller_params['draw'], @@ -509,6 +513,10 @@ def get_entries(request): ], } + now = datetime.datetime.now() + print("2 Current date and time : ") + print(now.strftime("%Y-%m-%d %H:%M:%S")) + if with_lexical_units: filteredData = [] for entry in result['data']: @@ -525,6 +533,10 @@ def get_entries(request): result['data'] = filteredData[first_index:last_index] + now = datetime.datetime.now() + print("3 Current date and time : ") + print(now.strftime("%Y-%m-%d %H:%M:%S")) + return JsonResponse(result) return JsonResponse({}) diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue index 41aa644b53f8d5c95fb89447893c1421178ae386..891426a78e33fb18abbb45bb8027e6506cfff6d7 100644 --- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue +++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue @@ -42,7 +42,6 @@ Object.assign(LexicalUnitEdit, { internalForceRefresh: this.forceRefresh, statusButtonTitle: '', active_slowal_frame: null, - showVerifiedFrames: false, subentries: null, alternations: null, realisation_phrases: null, @@ -53,7 +52,8 @@ Object.assign(LexicalUnitEdit, { selectedLus: null, selectedSchemas: null, selectedExamples: null, - hidden_frames: [], + hidden_frame_ids: [], + hidden_frame_status_set: [], lexicalUnitsVisible: true, selectionalPreferenciesVisible: true } @@ -739,27 +739,34 @@ Object.assign(LexicalUnitEdit, { this.select_slowal_frame_req(() => { let frame = this.active_slowal_frame; const isSuperLeksykograf = this.isSuperLeksykograf(); - let status = null; - if (!isSuperLeksykograf && frame.status === 'G') { - //przywracamy O - status = 'O'; - } else if (!isSuperLeksykograf && frame.status === 'O') { - //ustawiany na Gotowe - status = 'G'; - } else if (isSuperLeksykograf && frame.status === 'S') { - //ustawiany Sprawdzone - status = 'G'; - } else if (isSuperLeksykograf) { - status = 'S'; + if(!isSuperLeksykograf && this.unified_frame.status === 'G') { + alert(gettext("Nie można zmienić statusu ramy, kiedy rama zunifikowana posiada status 'Gotowa'.")); } else { - alert(gettext("Nie można zmienić statusu ramy.")); - } + let status = null; + if (!isSuperLeksykograf && frame.status === 'G') { + //przywracamy O + status = 'O'; + } else if (!isSuperLeksykograf && frame.status === 'O') { + //ustawiany na Gotowe + status = 'G'; + } else if (isSuperLeksykograf && frame.status === 'S') { + //ustawiany Sprawdzone + status = 'G'; + } else if (isSuperLeksykograf) { + status = 'S'; + } else { + alert(gettext("Nie można zmienić statusu ramy.")); + } - this.change_slowal_frame_status(status); + if (status != null) { + this.change_slowal_frame_status(status); + } + } }); }, - isFrameVisible(status) { - return (status != 'B' && status != 'C') || this.isSuperLeksykograf(); + isFrameVisible(frame) { + return !this.hidden_frame_ids.includes(frame.id) && !this.hidden_frame_status_set.includes(frame.status) && + ((frame.status != 'B' && frame.status != 'C') || this.isSuperLeksykograf()); }, changeStatusButtonTitleToDefault() { const isSuperLeksykograf = this.isSuperLeksykograf(); @@ -895,9 +902,17 @@ Object.assign(LexicalUnitEdit, { this.$emit("swapFrames", this.currentPreviewedUnifiedFrameId); } }, - changeShowVerifiedFrames(val) { - this.showVerifiedFrames = val; - this.hidden_frames = []; + hideFrameOfStatus(status, event) { + if(event) { + if (event.target.checked === true) { + this.hidden_frame_status_set.push(status); + } else { + var index = this.hidden_frame_status_set.indexOf(status); + if (index !== -1) { + this.hidden_frame_status_set.splice(index, 1); + } + } + } }, getArgumentCSS(argument) { return (argument.role ? argument.role.str + ' ' : '') + (argument == this.active_unified_frame_argument ? 'active' : ''); @@ -935,21 +950,16 @@ Object.assign(LexicalUnitEdit, { return (this.isSuperLeksykograf() && this.unified_frame.status === 'O') && this.unified_frame.assignee_username !== window.USER_USERNAME; }, hideFrame(frame) { - this.hidden_frames.push(frame); - }, - getSlowalReadyFrameCnt() { - const readyFrames = this.frames.filter(frame => frame.status == 'G'); - return readyFrames.length; + this.hidden_frame_ids.add(frame.id); }, - getSlowalVerifiedFrameCnt() { - const readyFrames = this.frames.filter(frame => frame.status == 'S'); - return readyFrames.length; - }, - createSlowalVerifiedButtonLabel() { - return 'Ukryj ' +(!this.isSuperLeksykograf() ? 'gotowe' : 'sprawdzone') + - (this.showVerifiedFrames ? '' : - !this.isSuperLeksykograf() ? (this.getSlowalReadyFrameCnt() > 0 ? ' (ukrytych: ' + this.getSlowalReadyFrameCnt() + ')' : '') : - (this.getSlowalVerifiedFrameCnt() > 0 ? ' (ukrytych: ' + this.getSlowalVerifiedFrameCnt() + ')' : '')); + resetFrameVisibilityRestictions() { + this.hidden_frame_ids = []; + this.hidden_frame_status_set = []; + $( 'input[id="checkbox-status-o"]' ).prop('checked', false); + $( 'input[id="checkbox-status-c"]' ).prop('checked', false); + $( 'input[id="checkbox-status-g"]' ).prop('checked', false); + $( 'input[id="checkbox-status-s"]' ).prop('checked', false); + $( 'input[id="checkbox-status-b"]' ).prop('checked', false); }, createSlowalContestedStatusButtonLabel() { return this.isSuperLeksykograf() ? this.active_slowal_frame && this.active_slowal_frame.status === 'C' ? 'Potwierdź niepasująca' : 'Nowa' : 'Niepasująca'; @@ -1093,7 +1103,7 @@ Object.assign(LexicalUnitEdit, { }, }); }, - frame_reject_as_not_matching_unified_frame() { + reject_slowal_frame_ready_status() { this.select_slowal_frame_req(() => { let selectedFrame = this.active_slowal_frame; send_post_request(`/unifier/reject_unified_frame_ready_status/`, @@ -1107,10 +1117,26 @@ Object.assign(LexicalUnitEdit, { }, (request, errorType, errorMessage) => { show_error(errorType + ' (' + errorMessage + ')'); - alert(gettext("Status ramy niew został zmieniony. Błąd: " + errorType + ' (' + errorMessage + ')')); + alert(gettext("Status ramy nie został zmieniony. Błąd: " + errorType + ' (' + errorMessage + ')')); $.prompt.close(); }) }); + }, + reject_unified_frame_ready_status() { + send_post_request(`/unifier/reject_unified_frame_ready_status/`, + {"slowal_frame_id" : -1, "unified_frame_id" : this.unified_frame.id}, + (reponse) => { + show_info('Zunifikowana rama została zwrócona do obróbki.'); + alert(gettext("Zunifikowana rama została zwrócona do obróbki.")); + this.$emit('refreshEntriesList'); + this.loadFrame(); + $.prompt.close(); + }, + (request, errorType, errorMessage) => { + show_error(errorType + ' (' + errorMessage + ')'); + alert(gettext("Status ramy nie został zmieniony. Błąd: " + errorType + ' (' + errorMessage + ')')); + $.prompt.close(); + }) } }, mounted() { @@ -1156,19 +1182,27 @@ export default LexicalUnitEdit; <div :id="'semantics-unified-frame-pane' + (readOnly ? '-preview' : '')" class="col w-100 p-0 overflow-auto"> <table v-if="!readOnly && !isReadOnlyForSuperLeksykograf()" class="table-button-menu sticky-top" cellspacing="1"> <tr style="background-color: white;"> - <td id="change-title" @click="changeTitle" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień nazwę</td> - <td id="add-arg" @click="addArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Dodaj argum.</td> - <td style="padding: 10px 15px 10px 15px; color: #000000;" @click="addSelectivePreference">Dodaj prefer.</td> - <td style="padding: 10px 15px 10px 15px; color: #000000;" @click="changeUnifiedFrameStatusToReadyOrVerified">{{isSuperLeksykograf() ? 'Sprawdzone' : 'Gotowe'}}</td> - <td id="duplicates" @click="duplicate" style="padding: 10px 15px 10px 15px; color: #000000;">Duplikuj</td> + <td class="table-button-menu-td" id="change-title" @click="changeTitle" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień nazwę</td> + <td class="table-button-menu-td" id="add-arg" @click="addArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Dodaj argum.</td> + <td class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="addSelectivePreference">Dodaj prefer.</td> + <td class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="changeUnifiedFrameStatusToReadyOrVerified">{{isSuperLeksykograf() ? 'Sprawdzone' : 'Gotowe'}}</td> + <td class="table-button-menu-td" id="duplicates" @click="duplicate" style="padding: 10px 15px 10px 15px; color: #000000;">Duplikuj</td> + + <td class="table-button-menu-td" v-if="isSuperLeksykograf()" id="return-to-process" style="padding: 10px 15px 10px 15px; color: #000000;" @click="reject_unified_frame_ready_status">Zwróć</td> + </tr> <tr style="background-color: white;"> - <td id="change-role" @click="changeRole" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień rolę</td> - <td id="remove-arg" @click="removeArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argum.</td> - <td id="remove-sel-pref" style="padding: 10px 15px 10px 15px; color: #000000;" @click="removeSelectionalPreference">Usuń prefer.</td> - <td id="change-windows" style="padding: 10px 15px 10px 15px; color: #000000;" @click="swapUnifiedFrames">Zamień okna</td> - <td v-if="frames.length == 0 || isSuperLeksykograf()" id="delete-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="deleteUnifiedFrames">Usuń ramę</td> - <td v-else id="empty-1" style="padding: 10px 15px 10px 15px; color: #000000;"></td> + <td class="table-button-menu-td" id="change-role" @click="changeRole" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień rolę</td> + <td class="table-button-menu-td" id="remove-arg" @click="removeArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argum.</td> + <td class="table-button-menu-td" id="remove-sel-pref" style="padding: 10px 15px 10px 15px; color: #000000;" @click="removeSelectionalPreference">Usuń prefer.</td> + <td class="table-button-menu-td" id="change-windows" style="padding: 10px 15px 10px 15px; color: #000000;" @click="swapUnifiedFrames">Zamień okna</td> + + <td class="table-button-menu-td" v-if="frames.length == 0 || isSuperLeksykograf()" id="delete-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="deleteUnifiedFrames">Usuń ramę</td> + <td class="table-button-menu-td" v-else id="empty-1" style="padding: 10px 15px 10px 15px; color: #000000;"></td> + + <td class="table-button-menu-td" v-if="isSuperLeksykograf()" id="empty-3" style="padding: 10px 15px 10px 15px; color: #000000;"></td> + + </tr> </table> @@ -1265,14 +1299,14 @@ export default LexicalUnitEdit; v-if="lexicalUnitsVisible" v-for='lexical_unit in lexical_units' > - <template v-if="isFrameVisible(lexical_unit.frame_status)"> +<!-- <template v-if="isFrameVisible(lexical_unit.frame_status)">--> <td class="argument py-2 px-1 border-top border-left border-secondary">{{ lexical_unit.str }}</td> <td class="argument py-2 px-1 border-top border-left border-secondary"> <img v-bind:src="img_prefix + 'entries/img/' +lexical_unit.opinion_key + '.svg'" width="12" height="12" v-bind:alt="lexical_unit.opinion"> {{ lexical_unit.opinion }} </td> <td class="argument py-2 px-1 border-top border-left border-secondary">[{{ lexical_unit.frame_status }}]</td> - </template> +<!-- </template>--> </tr> </tbody> </table> @@ -1288,29 +1322,38 @@ export default LexicalUnitEdit; <div :id="'semantics-slowal-frames-pane' + (readOnly ? '-preview' : '')" class="col w-100 p-0 overflow-auto"> <table v-if="!readOnly && unified_frame.id && !isReadOnlyForSuperLeksykograf()" class="table-button-menu sticky-top" cellspacing="1"> <tr style="background-color: white;"> - <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('B') : slowal_frame_status_change_with_confirmation('frame_confirm_invalid')">{{createSlowalBadStatusButtonLabel()}}</td> - <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="changeShowVerifiedFrames(false)">{{createSlowalVerifiedButtonLabel()}}</td> - <td id="ready-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="slowal_frame_ready_rollback">{{ statusButtonTitle }}</td> - <td id="attach-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="attachSlowalFrame">Podepnij</td> + <td id="wrong-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('B') : this.active_slowal_frame && this.active_slowal_frame.status === 'B' ? slowal_frame_status_change_with_confirmation('frame_confirm_invalid') : change_slowal_frame_status('B')">{{createSlowalBadStatusButtonLabel()}}</td> + <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"> + <div class="d-flex"> + Ukryj: + O <input id="checkbox-status-o" type="checkbox" @change="hideFrameOfStatus('O', $event)" class="custom-control custom-checkbox mr-1"> + <template v-if="this.isSuperLeksykograf()">B <input id="checkbox-status-b" type="checkbox" @change="hideFrameOfStatus('B', $event)" class="custom-control custom-checkbox mr-1"></template> + <template v-if="this.isSuperLeksykograf()">C <input id="checkbox-status-c" type="checkbox" @change="hideFrameOfStatus('C', $event)" class="custom-control custom-checkbox mr-1"></template> + G <input id="checkbox-status-g" type="checkbox" @change="hideFrameOfStatus('G', $event)" class="custom-control custom-checkbox mr-1"> + <template v-if="this.isSuperLeksykograf()">S <input id="checkbox-status-s" type="checkbox" @change="hideFrameOfStatus('S', $event)" class="custom-control custom-checkbox mr-1"></template> + </div> + </td> + <td id="ready-slowal-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="slowal_frame_ready_rollback">{{ statusButtonTitle }}</td> + <td id="attach-slowal-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="attachSlowalFrame">Podepnij</td> </tr> <tr style="background-color: white;"> - <td id="inccorect-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('C') : slowal_frame_status_change_with_confirmation('frame_confirm_as_not_matching_unified_frame')"> + <td id="inccorect-slowal-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('C') : this.active_slowal_frame && this.active_slowal_frame.status === 'C' ? slowal_frame_status_change_with_confirmation('frame_confirm_as_not_matching_unified_frame') : change_slowal_frame_status('C')"> {{createSlowalContestedStatusButtonLabel()}} </td> - <td id="show-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="changeShowVerifiedFrames(true)"> - Pokaż wszystkie {{this.hidden_frames.length > 0 ? '(ukrytych: ' + this.hidden_frames.length + ')' : ''}} + <td id="show-slowal-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="resetFrameVisibilityRestictions()"> + Pokaż wszystkie </td> - <td id="move-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" + <td id="move-slowal-frame" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;" @click="extract_frame_to_preview_frame"> Przerzuć </td> - <td v-if="this.isSuperLeksykograf() && this.active_slowal_frame && (this.active_slowal_frame.status === 'B' || this.active_slowal_frame.status === 'C')" id="reject-button" @click="frame_reject_as_not_matching_unified_frame" style="padding: 10px 15px 10px 15px; color: #000000;">Zwróć</td> + <td v-if="this.isSuperLeksykograf() && this.active_slowal_frame && (this.active_slowal_frame.status === 'B' || this.active_slowal_frame.status === 'C' || this.active_slowal_frame.status === 'G')" id="reject-button" @click="reject_slowal_frame_ready_status" class="table-button-menu-td" style="padding: 10px 15px 10px 15px; color: #000000;">Zwróć</td> <td v-else id="empty-2" style="padding: 10px 15px 10px 15px; color: #000000;"></td> </tr> </table> <div id="semantics-frames"> <template v-for="frame in frames"> - <div class="row pt-3" style="flex-wrap: nowrap;" v-if="!hidden_frames.includes(frame) && (!isFrameVerified(frame) || showVerifiedFrames) && isFrameVisible(frame.status)"> + <div class="row pt-3" style="flex-wrap: nowrap;" v-if="isFrameVisible(frame)"> <div class="col pl-5 pr-4"> <div class="row"> <div class="col frame px-0" id="lexical-unit"> diff --git a/frontend/src/components/unification/Unification/SelectionalPreference.js b/frontend/src/components/unification/Unification/SelectionalPreference.js index 4adb459c2cb91feca49c4cfaf0bbd70609799912..58d0867d5fbb63f2180ca41ae1b940af456ee1d3 100644 --- a/frontend/src/components/unification/Unification/SelectionalPreference.js +++ b/frontend/src/components/unification/Unification/SelectionalPreference.js @@ -72,7 +72,7 @@ export default class SelectionalPreference { let i; for (i = 0; i < this.predefined.length; i++) { - display += "<input type = \"checkbox\" name = \"predef\" value = \"" + this.predefined[i].id + "\">" + this.predefined[i].content + "<br>"; + display += "<input type = \"checkbox\" name = \"predef\" value = \"" + this.predefined[i].id + "\"> " + this.predefined[i].content + "<br>"; } return display; @@ -277,20 +277,28 @@ export default class SelectionalPreference { } if (v == 1) { e.preventDefault(); + const synsetPreferencies = []; + const predefinedSelectionalPreferencies = []; normalizeFormData(f.existing).map(choice => { let [type, id] = choice.split(':'); switch (type) { case 'meanings.Synset': - this.saveSynsetPreference(unified_frame_id, complement_id, id); + synsetPreferencies.push(parseInt(id)); + // this.saveSynsetPreference(unified_frame_id, complement_id, id); break; case 'semantics.PredefinedSelectionalPreference': - this.savePredefinedPreference(unified_frame_id, complement_id, id); + predefinedSelectionalPreferencies.push(parseInt(id)); + // this.savePredefinedPreference(unified_frame_id, complement_id, id); break; case 'semantics.RelationalSelectionalPreference': - this.saveRelationalSelectionalPreference(unified_frame_id, complement_id, null, null); // TODO + alert("Operacja niedozwolona dla RelationalSelectionalPreference!") + // this.saveRelationalSelectionalPreference(unified_frame_id, complement_id, null, null); // TODO break; } }); + + this.saveBunchOfPreferencies(unified_frame_id, complement_id, predefinedSelectionalPreferencies, synsetPreferencies) + $.prompt.goToState('state0'); } } @@ -349,6 +357,30 @@ export default class SelectionalPreference { }) } + saveBunchOfPreferencies(frame_id, complement_id, predefined_preference_ids, synset_preference_ids) { + const data = { + 'frame_id': frame_id, + 'complement_id': complement_id, + 'predefined_preference_ids': JSON.stringify(predefined_preference_ids), + 'synset_preference_ids': JSON.stringify(synset_preference_ids) + }; + + send_post_request('/unifier/save_bunch_of_preferences/', + data, + (response) => { + const succ = response.succ; + if(succ) { + show_info('Preferencje zosały zapisane'); + } else { + this.synset_hierarchy_conflict_alert(response); + } + }, + (request, errorType, errorMessage) => { + show_error(errorType + ' (' + errorMessage + ')'); + }) + } + + synset_hierarchy_conflict_alert(response) { const conflict_exists = response.conflict_exists; if (conflict_exists != null) { diff --git a/frontend/src/components/unification/Unification/UnificationFramesList.vue b/frontend/src/components/unification/Unification/UnificationFramesList.vue index 23fda43917c61359f91b33e1e673c69386ebf037..47be0f750d0176e8cdfb1fc950a8e47a7a01127e 100644 --- a/frontend/src/components/unification/Unification/UnificationFramesList.vue +++ b/frontend/src/components/unification/Unification/UnificationFramesList.vue @@ -3,6 +3,7 @@ export default { props: { initialUnifiedFrameId: Number, unificationEntriesListRefreshKey: Number, + setupHierarchyMarking: Boolean, }, data() { return { @@ -19,6 +20,7 @@ export default { this.$emit('unifiedFrameSelected', unifiedFrameId); }, selectEntryId: this.initialUnifiedFrameId, + setupHierarchyMarking: this.setupHierarchyMarking }); } }, @@ -32,6 +34,7 @@ export default { this.$emit('unifiedFrameSelected', unifiedFrameId); }, selectEntryId: this.initialUnifiedFrameId, + setupHierarchyMarking: this.setupHierarchyMarking }); } }, @@ -44,6 +47,7 @@ export default { this.$emit('unifiedFrameSelected', unifiedFrameId); }, selectEntryId: this.initialUnifiedFrameId, + setupHierarchyMarking: this.setupHierarchyMarking }); }, }; diff --git a/frontend/src/components/unification/Unification/UnificationSwitchableList.vue b/frontend/src/components/unification/Unification/UnificationSwitchableList.vue index 68de141368ec852846985c5fa45c41bce67285bf..ec3870b26c78db69b10c69d91ee7d53a40a3c46a 100644 --- a/frontend/src/components/unification/Unification/UnificationSwitchableList.vue +++ b/frontend/src/components/unification/Unification/UnificationSwitchableList.vue @@ -38,6 +38,7 @@ export default { /></div> <div v-else class="h-100"><unification-frames-list :unificationEntriesListRefreshKey="unificationEntriesListRefreshKey" + :setupHierarchyMarking="false" @unified-frame-selected="unifiedFrameSelected" /></div> </template> diff --git a/frontend/src/components/unification/hierarchy/Hierarchy.vue b/frontend/src/components/unification/hierarchy/Hierarchy.vue index af652e5970f5e7ad212c847c65304efcc8445880..5f501f6854c2cf410ea551e0dccc8fe7e9609007 100644 --- a/frontend/src/components/unification/hierarchy/Hierarchy.vue +++ b/frontend/src/components/unification/hierarchy/Hierarchy.vue @@ -55,15 +55,9 @@ export default { <unification-frames-list :unificationEntriesListRefreshKey="unificationEntriesListRefreshKey" :initialUnifiedFrameId="initial_unified_frame_id" + :setupHierarchyMarking="true" @unified-frame-selected="unifiedFrameSelected" /> -<!-- <unification-switchable-list--> -<!-- :unificationEntriesListRefreshKey="unificationEntriesListRefreshKey"--> -<!-- :initialLexicalUnitId="lexicalUnitId ? lexicalUnitId : initialLexicalUnitId"--> -<!-- :initialEntryId="entryId ? entryId : initialEntryId"--> -<!-- @lexical-unit-selected="lexicalUnitSelected"--> -<!-- @unified-frame-selected="unifiedFrameSelected"--> -<!-- />--> </div> </div> <div id="entry-display" class="col h-100 p-0 overflow-hidden"> diff --git a/syntax/management/commands/add_predefined_preferences.py b/syntax/management/commands/add_predefined_preferences.py index 343ad3f6677f48c197775dcc00a9c68773c10684..cee1119162a9f8c7b5f42cd4536ecaed594ef0fa 100644 --- a/syntax/management/commands/add_predefined_preferences.py +++ b/syntax/management/commands/add_predefined_preferences.py @@ -44,7 +44,7 @@ def create_predefined_preferences(): # ISTOTY: osoba-1, istota żywa-1, grupa istot-1 istoty_members = SelectivePreference() istoty_members.save() - istoty_members.synsets.add(osoba_1) + # istoty_members.synsets.add(osoba_1) istota_zywa_1 = LexicalUnit.objects.get(base='istota żywa', sense='1', pos='noun').synset diff --git a/unifier/apps.py b/unifier/apps.py index 5bbe9c03b9b9f43805a63fe1923467df9bfa3350..a284a2fa9f50a64f28b6b224d7080a733c417249 100644 --- a/unifier/apps.py +++ b/unifier/apps.py @@ -1,3 +1,5 @@ +import os + from django.apps import AppConfig @@ -19,38 +21,42 @@ class UnifierConfig(AppConfig): name = 'unifier' def ready(self): - print("Loading the slowosiec ontology hierarchy...") - from meanings.models import Synset - from django.db.models import Prefetch - i = 0 - objs = Synset.objects - objs = objs.prefetch_related( - Prefetch( - "hypernyms", + LOADING_THE_SLOWOSIEC_ONTOLOGY_HIERARCHY_DISABLED = os.getenv('LOADING_THE_SLOWOSIEC_ONTOLOGY_HIERARCHY_DISABLED') + + if LOADING_THE_SLOWOSIEC_ONTOLOGY_HIERARCHY_DISABLED != 'true': + print("Loading the slowosiec ontology hierarchy...") + from meanings.models import Synset + from django.db.models import Prefetch + i = 0 + objs = Synset.objects + objs = objs.prefetch_related( + Prefetch( + "hypernyms", + + ) ) - ) - for synset in objs.all(): - if i % 10000 == 0: - print("i: "+str(i)) - i = i + 1 - curr = None - if synset.id not in synset_hierarchy_dict: - curr = SynsetHierarchy(id=synset.id) - synset_hierarchy_dict[synset.id] = curr - else: - curr = synset_hierarchy_dict[synset.id] - - for hypernym in synset.hypernyms.all(): - curr_hypernym = None - if hypernym.id not in synset_hierarchy_dict: - curr_hypernym = SynsetHierarchy(id=hypernym.id) - synset_hierarchy_dict[hypernym.id] = curr_hypernym + for synset in objs.all(): + if i % 10000 == 0: + print("i: "+str(i)) + i = i + 1 + curr = None + if synset.id not in synset_hierarchy_dict: + curr = SynsetHierarchy(id=synset.id) + synset_hierarchy_dict[synset.id] = curr else: - curr_hypernym = synset_hierarchy_dict[hypernym.id] + curr = synset_hierarchy_dict[synset.id] + + for hypernym in synset.hypernyms.all(): + curr_hypernym = None + if hypernym.id not in synset_hierarchy_dict: + curr_hypernym = SynsetHierarchy(id=hypernym.id) + synset_hierarchy_dict[hypernym.id] = curr_hypernym + else: + curr_hypernym = synset_hierarchy_dict[hypernym.id] - curr.hyperonyms.append(curr_hypernym) - curr_hypernym.hyponyms.append(curr) + curr.hyperonyms.append(curr_hypernym) + curr_hypernym.hyponyms.append(curr) - print("Slowosiec ontology hierarchy loaded.") + print("Slowosiec ontology hierarchy loaded.") diff --git a/unifier/urls.py b/unifier/urls.py index b7ecbf783deba80e5110ee1c3feb453962c1c456..c1289dc41bd744b5fa69139dd2d1e5b5321692c0 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -7,6 +7,7 @@ app_name = 'unifier' urlpatterns = [ path('save_synset_preference/', views.save_synset_preference, name='save_synset_preference'), path('save_predefined_preference/', views.save_predefined_preference, name='save_predefined_preference'), + path('save_bunch_of_preferences/', views.save_bunch_of_preferences, name='save_bunch_of_preferences'), path('save_relational_selectional_preference/', views.save_relational_selectional_preference, name='save_relational_selectional_preference'), path('get_unified_frames/', views.get_unified_frames, name='get_unified_frames'), path('get_unified_frame/', views.get_unified_frame, name='get_unified_frame'), diff --git a/unifier/views.py b/unifier/views.py index 0942c6af9e2e79f4985debac241f06bf29b6154b..b9f4fe9471db85e3666898a70fbf417bf68915b5 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -56,20 +56,27 @@ def save_synset_preference(request): complement_id = request.POST['complement_id'] synset_preference_id = request.POST['synset_preference_id'] - unified_frame_argument = UnifiedFrameArgument.objects.get(unified_frame_id=int(frame_id), id=int(complement_id)) - - check_sysnet_hierarchy_constraints_ret = check_sysnet_hierarchy_constraints([synset_preference_id], unified_frame_argument) - - if check_sysnet_hierarchy_constraints_ret['succ'] is True: - unified_frame_argument.synsets.add(int(synset_preference_id)) - unified_frame_argument.save() - update_argument_preferences_count(unified_frame_argument) + check_sysnet_hierarchy_constraints_ret = save_synset_preference(frame_id, complement_id, synset_preference_id) return JsonResponse(check_sysnet_hierarchy_constraints_ret) return JsonResponse({}) +def save_synset_preference(frame_id, complement_id, synset_preference_id): + + unified_frame_argument = UnifiedFrameArgument.objects.get(unified_frame_id=int(frame_id), id=int(complement_id)) + + check_sysnet_hierarchy_constraints_ret = check_sysnet_hierarchy_constraints([synset_preference_id], unified_frame_argument) + + if check_sysnet_hierarchy_constraints_ret['succ'] is True: + unified_frame_argument.synsets.add(int(synset_preference_id)) + unified_frame_argument.save() + update_argument_preferences_count(unified_frame_argument) + + return check_sysnet_hierarchy_constraints_ret + + def check_sysnet_hierarchy_constraints(synset_preference_ids, unified_frame_argument): synset_ids_map = map(lambda s: s.id, unified_frame_argument.synsets.all()) predefined_synset_ids = [] @@ -100,6 +107,43 @@ def conflict_lu_to_str(conflict_lu): map(lambda s: str(s), conflict_hyponym_lu.all())) if conflict_lu is not None else None +# class MyException(Exception): +# def __init__(self, message, errors): +# super().__init__(message) +# self.errors = errors + + +@ajax_required +@transaction.atomic +def save_bunch_of_preferences(request): + if request.method == 'POST': + frame_id = request.POST['frame_id'] + complement_id = request.POST['complement_id'] + predefined_preference_ids = json.loads(request.POST['predefined_preference_ids']) + synset_ids = json.loads(request.POST['synset_preference_ids']) + + check_sysnet_hierarchy_constraints_ret = save_bunch_of_preferences_base(frame_id, complement_id, predefined_preference_ids, synset_ids) + return JsonResponse(check_sysnet_hierarchy_constraints_ret) + + return JsonResponse({}) + + +@transaction.atomic +def save_bunch_of_preferences_base(frame_id, complement_id, predefined_preference_ids, synset_ids): + for predefined_preference_id in predefined_preference_ids: + check_sysnet_hierarchy_constraints_ret = save_predefined_preference_base(frame_id, complement_id, predefined_preference_id) + if check_sysnet_hierarchy_constraints_ret['succ'] is False: + transaction.set_rollback(True) + return check_sysnet_hierarchy_constraints_ret + + for synset_id in synset_ids: + check_sysnet_hierarchy_constraints_ret = save_synset_preference(frame_id, complement_id, synset_id) + if not check_sysnet_hierarchy_constraints_ret['succ'] is False: + transaction.set_rollback(True) + return check_sysnet_hierarchy_constraints_ret + + return {'succ': True} + @ajax_required @transaction.atomic def save_predefined_preference(request): @@ -108,27 +152,34 @@ def save_predefined_preference(request): complement_id = request.POST['complement_id'] predefined_preference_id = request.POST['predefined_preference_id'] - unified_frame_argument = UnifiedFrameArgument.objects.get(unified_frame_id=int(frame_id), id=int(complement_id)) + check_sysnet_hierarchy_constraints_ret = save_predefined_preference_base(frame_id, complement_id, predefined_preference_id) - predefined_synset_ids = [] - pred_sel_pref = PredefinedSelectionalPreference.objects.get(id=predefined_preference_id) - if pred_sel_pref.name == 'ALL' and len(unified_frame_argument.predefined.all()) > 0: - return JsonResponse({"succ": False, "conflict_hyponym": None, - "conflict_hyperonym": None, - "conflict_exists": "Predefiniowana preferencja selekcyjna ALL może być dodana tylko, gdy nie na liście nie widnieją inne preferencje selekcyjne."}) - else: - get_predefined_preference_synsets([pred_sel_pref], predefined_synset_ids) + return JsonResponse(check_sysnet_hierarchy_constraints_ret) - check_sysnet_hierarchy_constraints_ret = check_sysnet_hierarchy_constraints(predefined_synset_ids, unified_frame_argument) + return JsonResponse({}) - if check_sysnet_hierarchy_constraints_ret['succ'] is True: - unified_frame_argument.predefined.add(int(predefined_preference_id)) - unified_frame_argument.save() - update_argument_preferences_count(unified_frame_argument) - return JsonResponse(check_sysnet_hierarchy_constraints_ret) +@transaction.atomic +def save_predefined_preference_base(frame_id, complement_id, predefined_preference_id): + unified_frame_argument = UnifiedFrameArgument.objects.get(unified_frame_id=int(frame_id), id=int(complement_id)) - return JsonResponse({}) + predefined_synset_ids = [] + pred_sel_pref = PredefinedSelectionalPreference.objects.get(id=predefined_preference_id) + if pred_sel_pref.name == 'ALL' and len(unified_frame_argument.predefined.all()) > 0: + return {"succ": False, "conflict_hyponym": None, + "conflict_hyperonym": None, + "conflict_exists": "Predefiniowana preferencja selekcyjna ALL może być dodana tylko, gdy nie na liście nie widnieją inne preferencje selekcyjne."} + else: + get_predefined_preference_synsets([pred_sel_pref], predefined_synset_ids) + + check_sysnet_hierarchy_constraints_ret = check_sysnet_hierarchy_constraints(predefined_synset_ids, unified_frame_argument) + + if check_sysnet_hierarchy_constraints_ret['succ'] is True: + unified_frame_argument.predefined.add(int(predefined_preference_id)) + unified_frame_argument.save() + update_argument_preferences_count(unified_frame_argument) + + return check_sysnet_hierarchy_constraints_ret @ajax_required @@ -594,14 +645,26 @@ def change_unified_frame_status_to_ready(request): def reject_unified_frame_ready_status(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] - slowal_frame_id = request.POST['slowal_frame_id'] + slowal_frame_id = int(request.POST['slowal_frame_id']) unified_frame = UnifiedFrame.objects.get(pk=unified_frame_id) unified_frame.status = UnifiedFrameStatus.PROCESSING unified_frame.save() - slowal_frame = Frame.objects.get(pk=slowal_frame_id) - slowal_frame.status = FrameStatus.PROCESSING - slowal_frame.save() + if slowal_frame_id != -1: + # Gdy -1 to zmieniamy tylko status ramy zunikowanej pozwalajac leksykografai na dlasza prace nad nia + slowal_frame = Frame.objects.get(pk=slowal_frame_id) + slowal_frame.status = FrameStatus.PROCESSING + slowal_frame.save() + + mappings = UnifiedFrame2SlowalFrameMapping.objects.filter(unified_frame=unified_frame) + for mapping in mappings.all(): + id = mapping.slowal_frame.id + if id != mapping.slowal_frame.id and mapping.slowal_frame.status == 'S': + # Umozliwiamy ponowna prace nad rama dla leksykografa + loaded_slowal_frame = Frame.objects.get(pk=id) + loaded_slowal_frame.status = FrameStatus.READY + loaded_slowal_frame.save() + return JsonResponse({}) diff --git a/users/forms.py b/users/forms.py index 6400b8c51347e4183957f02cc0ab7ccf812c5d91..9e872e6ffb95381c0d543bec74b86a00f4c75ddc 100644 --- a/users/forms.py +++ b/users/forms.py @@ -109,4 +109,4 @@ password_reset_set_password_form_helper.layout = Layout( class NoteForm(forms.ModelForm): class Meta: model = Note - fields = ["title", "note", "super"] + fields = ["title", "note", "super", "for_all"] diff --git a/users/models.py b/users/models.py index d289bd9cfaf4d06f1b029ccf2545ef80435d5760..b7f4cc76c48ee37339d9c733b58aa659e0c33fe8 100644 --- a/users/models.py +++ b/users/models.py @@ -36,6 +36,9 @@ class NoteQuerySet(models.QuerySet): notes = ( self.filter(author=user) ) + notes |= ( + self.exclude(author=user).filter(for_all=True).annotate(owner_label=models.F('author__username')) + ) if user.has_perm('users.view_all_notes'): notes |= ( self.exclude(author=user).annotate(owner_label=models.F('author__username')) @@ -63,5 +66,6 @@ class Note(models.Model): created_at = models.DateTimeField(auto_now_add=True) type = models.CharField(max_length=100, default=None, blank=True, null=True) super = models.BooleanField(default=False) + for_all = models.BooleanField(default=False) objects = models.Manager.from_queryset(NoteQuerySet)() diff --git a/users/templates/notes.html b/users/templates/notes.html index 40276a51c4e49d848d825b805e6f41e812d3dc1d..d58844e5f4dcf3d0fa644447ae48e7b04ff9135e 100644 --- a/users/templates/notes.html +++ b/users/templates/notes.html @@ -15,6 +15,8 @@ Superleksykograf {% endif %} <input id="super" name="super" type="checkbox" title="{% if is_superlexicograf %} {% trans 'Notatka widoczna dla użytkownika' %} {% else %} {% trans 'Notatka widoczna dla superleksykografa' %} {% endif %}" /> + Widoczna dla wszystkich + <input id="for_all" name="for_all" type="checkbox" title="Notatka widoczna dla wszystkich" /> <input id="title" name="title" class="form-control mb-2" placeholder="{% trans 'Tytuł notatki' %}" /> <textarea id="note" name="note" class="form-control" placeholder="{% trans 'Treść notatki' %}"></textarea> </div> diff --git a/users/views.py b/users/views.py index 6631c4a9044d2fffbf81b686239d4f64e3549561..95ae268dc76d4daff6757364fc98f18f3054fa24 100644 --- a/users/views.py +++ b/users/views.py @@ -8,7 +8,6 @@ from django.shortcuts import get_object_or_404, render, redirect from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_http_methods -from common.decorators import ajax from users.forms import UserForm, UserProfileForm, NoteForm from users.models import Note from users.utils import send_new_user_email