From 1e82fe0cc19599f5e94efb24f9c9bbd66a54f1cb Mon Sep 17 00:00:00 2001
From: dcz <dcz@ipipan.waw.pl>
Date: Mon, 2 Oct 2023 12:59:20 +0200
Subject: [PATCH] Additional synsets for predefined selectional preferencies.
 Add the "status" field to the filtering to slowal frame form. Show all
 entries for super users in the unification view. Reload the unified
 entries/fam list after filter form apply.

---
 ...defined_selectional_preferences_update.txt | 13 ++++++++
 entries/forms.py                              | 17 ++++++++++
 .../js/unification_entries_for_frames_list.js |  4 ++-
 .../Unification/LexicalUnitEdit.vue           | 32 +++++++++++++++----
 .../UnificationEntriesForFramesList.vue       | 18 ++++++++++-
 5 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/data/db_manual_updates/predefined_selectional_preferences_update.txt b/data/db_manual_updates/predefined_selectional_preferences_update.txt
index 173b233..f22f420 100644
--- a/data/db_manual_updates/predefined_selectional_preferences_update.txt
+++ b/data/db_manual_updates/predefined_selectional_preferences_update.txt
@@ -49,3 +49,16 @@ select base, synset_id from meanings_lexicalunit where base='CZASOWNIK' and sens
 insert into semantics_selectivepreference (id) values (19);
 insert into semantics_selectivepreference_synsets (selectivepreference_id, synset_id) values (19, 10765),(19, 6526),(19, 247969),(19, 47401),(19, 55268);
 update semantics_predefinedselectionalpreference set members_id=19 where id=17;
+
+CZYNNOŚĆ
+<czynność-1, czyn-1, czynności-1, robić-1>
+
+select base, synset_id from meanings_lexicalunit where base='czyn' and sense='1';
+50840
+select base, synset_id from meanings_lexicalunit where base='czynności' and sense='1';
+105438
+select base, synset_id from meanings_lexicalunit where base='robić' and sense='1';
+55305
+
+insert into semantics_selectivepreference_synsets (selectivepreference_id, synset_id) values (13, 50840),(13, 105438),(13, 55305);
+
diff --git a/entries/forms.py b/entries/forms.py
index 5969c9c..919b9c7 100644
--- a/entries/forms.py
+++ b/entries/forms.py
@@ -14,6 +14,7 @@ import crispy_forms.bootstrap as bootstrap
 import crispy_forms.layout as layout
 
 from connections.models import Entry, POS, Status, SchemaHook
+from semantics.choices import FrameStatus
 from syntax.models import (
     Schema, SchemaOpinion, InherentSie, Negativity, Predicativity, Aspect,
     Position, SyntacticFunction, Control, PredicativeControl,
@@ -593,6 +594,22 @@ class FrameFormFactory(FormFactory):
                 lookup='opinion',
             ), None,
         ),
+        (
+            'status',
+            lambda: MultipleChoiceFilter(
+                label=_('Status'),
+                choices=(
+                    (FrameStatus.NEW, (_('Nowa'), None)),
+                    (FrameStatus.PROCESSING, (_('W obróbce'), None)),
+                    (FrameStatus.READY,  (_('Gotowa'), None)),
+                    (FrameStatus.VERIFIED,  (_('Sprawdzona'), None)),
+                    (FrameStatus.INVALID,  (_('Błędna'), None)),
+                    (FrameStatus.NOT_MATCHING_UNIFIED_FRAME,  (_('NiepasujÄ…ca'), None)),
+                    (FrameStatus.BAD,  (_('Zła'), None)),
+                ),
+                lookup='status',
+            ), None,
+        ),
         (
             'num_arguments',
             lambda: RangeFilter(
diff --git a/entries/static/entries/js/unification_entries_for_frames_list.js b/entries/static/entries/js/unification_entries_for_frames_list.js
index e339bd5..80baebc 100644
--- a/entries/static/entries/js/unification_entries_for_frames_list.js
+++ b/entries/static/entries/js/unification_entries_for_frames_list.js
@@ -9,7 +9,9 @@ function setup_entries_for_frames_list(options) {
         ) ? gettext("tak") : gettext("nie");
     }
 
-    const ajaxURL = can_see_assignees ? '/' + window.lang + '/entries/get_entries/?with_lexical_units=true&has_unified_frame=true' : '/' + window.lang + '/entries/get_entries/?with_lexical_units=true&has_unified_frame=true&exclude_status=N&restrict_to_user='+window.USER_USERNAME;
+    user_restrict = options.is_super_user ? '&restrict_to_user='+window.USER_USERNAME : '';
+
+    const ajaxURL = can_see_assignees ? '/' + window.lang + '/entries/get_entries/?with_lexical_units=true&has_unified_frame=true' : '/' + window.lang + '/entries/get_entries/?with_lexical_units=true&has_unified_frame=true&exclude_status=N' + user_restrict;
 
     const datatable = setup_datatable({
         element: options.table,
diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
index 28b8106..985697b 100644
--- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
+++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
@@ -595,16 +595,22 @@ Object.assign(LexicalUnitEdit, {
       } else {
         let roleDict = {};
         let hasPreferenceSelected = true;
+        let argument_cnt = this.unified_frame_arguments.length;
         for (let i in this.unified_frame_arguments) {
           const argument = this.unified_frame_arguments[i];
-          if (argument.role) {
-            roleDict[argument.role.str] = argument.role;
-          }
-          if (!argument.preferences || argument.preferences.length == 0) {
-            hasPreferenceSelected = false;
+          const slowal_frame_stastuses = this.get_slowal_frame_stastuses_by_unified_frame_argument(argument.id);
+          if(slowal_frame_stastuses.has('G')) {
+            if (argument.role) {
+              roleDict[argument.role.str] = argument.role;
+            }
+            if (!argument.preferences || argument.preferences.length == 0) {
+              hasPreferenceSelected = false;
+            }
+          } else {
+            argument_cnt--;
           }
         }
-        if (Object.keys(roleDict).length === this.unified_frame_arguments.length && hasPreferenceSelected) {
+        if (Object.keys(roleDict).length === argument_cnt && hasPreferenceSelected) {
           //all roles are set, and are uniq
 
           if(!this.has_full_empty_arguments()) {
@@ -975,6 +981,20 @@ Object.assign(LexicalUnitEdit, {
       }
       return Object.keys(non_empty_unified_frame_arguments).length !== this.unified_frame.arguments.length;
     },
+    get_slowal_frame_stastuses_by_unified_frame_argument(unified_frame_argument_id) {
+      let slowal_frame_stastuses = new Set()
+      for (let i in this.unified_frame.slowal_frame_mapping) {
+        const slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i];
+        let slowal_frame = this.frames.find(o => o.id === slowal_frame_mapping.slowal_frame_id);
+        if(slowal_frame != null) {
+          let unified_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping.find(o => o.unified_frame_agrument_id === unified_frame_argument_id);
+          if (unified_frame_argument_mapping) {
+            slowal_frame_stastuses.add(slowal_frame.status);
+          }
+        }
+      }
+      return slowal_frame_stastuses;
+    },
     hideLexicalUnits() {
       this.lexicalUnitsVisible = false;
     },
diff --git a/frontend/src/components/unification/Unification/UnificationEntriesForFramesList.vue b/frontend/src/components/unification/Unification/UnificationEntriesForFramesList.vue
index a97c2eb..cf58c6d 100644
--- a/frontend/src/components/unification/Unification/UnificationEntriesForFramesList.vue
+++ b/frontend/src/components/unification/Unification/UnificationEntriesForFramesList.vue
@@ -21,12 +21,28 @@ export default {
           this.$emit('unifiedFrameSelected', lexicalUnitUnifiedFrameId, entryId, lexicalUnitId);
         },
         selectEntryId: this.initialEntryId,
-        secondarySelectEntryId: this.initialLexicalUnitId
+        secondarySelectEntryId: this.initialLexicalUnitId,
+        is_super_user: canViewAssignment
+      });
+    }
+  },
+  methods: {
+    reset_list() {
+      this.$emit('unifiedFrameSelected', null);
+      setup_entries_for_frames_list({
+        table: this.$refs.table,
+        lexicalUnitSelected: (lexicalUnitUnifiedFrameId, entryId, lexicalUnitId) => {
+          this.$emit('unifiedFrameSelected', null, null, null);
+        },
+        selectEntryId: this.initialEntryId,
+        secondarySelectEntryId: this.initialLexicalUnitId,
+        is_super_user: this.canViewAssignment
       });
     }
   },
   emits: ['unifiedFrameSelected'],
   mounted() {
+    this.$.appContext.config.globalProperties.$entries_list = this;
     setup_entries_for_frames_list({
       table: this.$refs.table,
       lexicalUnitSelected: (lexicalUnitUnifiedFrameId, entryId, lexicalUnitId) => {
-- 
GitLab