From d172ab7da453768e9fa9e16e00140804fb98a10c Mon Sep 17 00:00:00 2001
From: dcz <dcz@ipipan.waw.pl>
Date: Wed, 13 Sep 2023 14:07:36 +0200
Subject: [PATCH] Minor bugfixes Add reject button to unification page

---
 .../Unification/LexicalUnitEdit.vue           | 34 +++++++++++++++----
 unifier/urls.py                               |  2 ++
 unifier/views.py                              | 17 ++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
index 48742de..7cfdf51 100644
--- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
+++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
@@ -704,8 +704,10 @@ Object.assign(LexicalUnitEdit, {
         } else if (isSuperLeksykograf && frame.status === 'S') {
           //ustawiany Sprawdzone
           status = 'G';
-        } else {
+        } else if (isSuperLeksykograf) {
           status = 'S';
+        } else {
+          alert(gettext("Nie można zmienić statusu ramy."));
         }
 
         this.change_slowal_frame_status(status);
@@ -996,6 +998,25 @@ Object.assign(LexicalUnitEdit, {
                   });
         },
       });
+    },
+    frame_reject_as_not_matching_unified_frame() {
+      this.select_slowal_frame_req(() => {
+        let selectedFrame = this.active_slowal_frame;
+        send_post_request(`/unifier/reject_unified_frame_ready_status/`,
+                {"slowal_frame_id" : selectedFrame.id, "unified_frame_id" : this.unified_frame.id},
+                (reponse) => {
+                  show_info('Rama została zwrócona do obróbki.');
+                  alert(gettext("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 niew został zmieniony. Błąd: " + errorType + ' (' + errorMessage + ')'));
+                  $.prompt.close();
+                })
+      });
     }
   },
   mounted() {
@@ -1131,8 +1152,8 @@ export default LexicalUnitEdit;
           </tbody>
             </table>
             </td><td style="vertical-align: text-top; padding-left: 10px; padding-top: 8px; min-width: 50px;">
-              <span class="cursor-pointer" @click.stop="hideSelectionalPreferencies()" title="Ukryj jednostki leksykalne">&#9652;</span> /
-              <span class="cursor-pointer" @click.stop="showSelectionalPreferencies()" title="Pokaż jednostki leksykalne">&#9662;</span>
+              <span class="cursor-pointer" @click.stop="hideSelectionalPreferencies()" title="Ukryj preferencje selekcyjne">&#9652;</span> /
+              <span class="cursor-pointer" @click.stop="showSelectionalPreferencies()" title="Pokaż preferencje selekcyjne">&#9662;</span>
             </td></tr>
         </table>
         </div>
@@ -1173,14 +1194,14 @@ 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="change_slowal_frame_status('B')">Błędna</td>
+            <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="change_slowal_frame_status('B')">{{this.isSuperLeksykograf() ? 'Zła' : 'Błędna'}}</td>
             <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"  @click="changeShowVerifiedFrames(false)">Ukryj gotowe {{showVerifiedFrames ? '' : getSlowalReadyFrameCnt() > 0 ? '(ukrytych: ' + getSlowalReadyFrameCnt() + ')' : ''}}</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>
           </tr>
           <tr style="background-color: white;">
             <td id="inccorect-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="change_slowal_frame_status('C')">
-                NiepasujÄ…ca
+              {{this.isSuperLeksykograf() ? 'Nowa' : 'NiepasujÄ…ca'}}
             </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 + ')' : ''}}
@@ -1189,7 +1210,8 @@ export default LexicalUnitEdit;
                 @click="extract_frame_to_preview_frame">
                 Przerzuć
             </td>
-            <td id="empty-2" style="padding: 10px 15px 10px 15px; color: #000000;"></td>
+            <td v-if="this.isSuperLeksykograf()" id="reject-button" @click="frame_reject_as_not_matching_unified_frame" 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">
diff --git a/unifier/urls.py b/unifier/urls.py
index a04cda7..fe76fed 100644
--- a/unifier/urls.py
+++ b/unifier/urls.py
@@ -34,4 +34,6 @@ urlpatterns = [
     path('check_unified_frame_title_uniq/', views.check_unified_frame_title_uniq, name='check_unified_frame_title_uniq'),
 
     path('attach_lu_to_unified_frame/', views.attach_lu_to_unified_frame, name='attach_lu_to_unified_frame'),
+    path('reject_unified_frame_ready_status/', views.reject_unified_frame_ready_status, name='reject_unified_frame_ready_status'),
+
 ]
diff --git a/unifier/views.py b/unifier/views.py
index 5297c76..e7c63b8 100644
--- a/unifier/views.py
+++ b/unifier/views.py
@@ -528,12 +528,23 @@ def change_unified_frame_status_to_ready(request):
         unified_frame_id = request.POST['unified_frame_id']
         unified_frame = UnifiedFrame.objects.get(pk=unified_frame_id)
         unified_frame.status = UnifiedFrameStatus.READY
+        unified_frame.save()
+    return JsonResponse({})
 
-        for mapping in unified_frame.unified_frame_2_slowal_frame.all():
-            mapping.verified = True
-            mapping.save()
 
+@ajax_required
+@transaction.atomic
+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']
+        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()
     return JsonResponse({})
 
 
-- 
GitLab