From 7d7533ef2d6e16edcace7fb35101e01fb6542266 Mon Sep 17 00:00:00 2001 From: dcz <dcz@ipipan.waw.pl> Date: Wed, 25 May 2022 14:49:05 +0200 Subject: [PATCH] Listing unified frames --- entries/static/entries/js/entries.js | 6 ++- .../entries/js/unification_frames_list.js | 33 +++++++++++++++ entries/templates/entries_base.html | 1 + .../templates/unification_entries_list.html | 3 -- entries/templates/unification_frames.html | 15 +++++++ .../templates/unification_frames_list.html | 18 +++++++++ entries/urls.py | 1 + entries/views.py | 11 +++++ unifier/urls.py | 2 + unifier/views.py | 40 ++++++++++++++++++- 10 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 entries/static/entries/js/unification_frames_list.js create mode 100644 entries/templates/unification_frames.html create mode 100644 entries/templates/unification_frames_list.html diff --git a/entries/static/entries/js/entries.js b/entries/static/entries/js/entries.js index 1bda208..19231a0 100644 --- a/entries/static/entries/js/entries.js +++ b/entries/static/entries/js/entries.js @@ -959,7 +959,11 @@ function setup_datatable(options) { { searchable: false, targets: [1, 2] - } + }, + { + visible: false, + targets: options.hidden_columns, + } ], createdRow: function(row, data, dataIndex, cells) { $(row).addClass('entry'); diff --git a/entries/static/entries/js/unification_frames_list.js b/entries/static/entries/js/unification_frames_list.js new file mode 100644 index 0000000..a85b04b --- /dev/null +++ b/entries/static/entries/js/unification_frames_list.js @@ -0,0 +1,33 @@ +function update_entries() { + const can_see_assignees = has_permission("auth.view_user"); + + function is_assigned_to_user_renderer (data) { + return ( + data + && data.assignee_username === window.USER_USERNAME + ) ? gettext("tak") : gettext("nie"); + } + + var datatable = setup_datatable({ + url: '/' + lang + '/unifier/get_unified_frames/', + columns: [ + { data: 'title' }, + { data: 'status' }, + can_see_assignees ? { data: 'assignee_username' } : { render: is_assigned_to_user_renderer }, + { data: 'id' }, + ], + hidden_columns: [3] + }); + datatable.on('click', 'tr.entry', function () { + var selected_entry = $(this).data('entry'); + var data = datatable.row(this).data(); + if (!data) return; + var related = data.related === true; + if (selected_entry !== curr_entry) { + $('.entry[data-entry="' + curr_entry + '"]').removeClass('table-primary'); + //TODO: zastapic etoda pobierajaca rame za po jej id + get_entry(selected_entry, related); + $(this).addClass('table-primary'); + } + }); +} diff --git a/entries/templates/entries_base.html b/entries/templates/entries_base.html index c0c2003..3ab1544 100644 --- a/entries/templates/entries_base.html +++ b/entries/templates/entries_base.html @@ -32,6 +32,7 @@ {% block additional-nav-items %} {% if request.user.is_authenticated %} <li class="nav-item"><a href="{% url 'entries:unification' %}" class="nav-link">{% trans "Unifikacja" %}</a></li> + <li class="nav-item"><a href="{% url 'entries:unification_frames' %}" class="nav-link">{% trans "Unifikacja - ramy" %}</a></li> {% endif %} <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="nav-filters" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> diff --git a/entries/templates/unification_entries_list.html b/entries/templates/unification_entries_list.html index 5c5df3e..48b7373 100644 --- a/entries/templates/unification_entries_list.html +++ b/entries/templates/unification_entries_list.html @@ -1,7 +1,4 @@ {% load i18n %} -<!--dupa--> -<!--chcekcbox--> -<!--update_entries()--> <table id="entries-table" class="table table-sm table-hover text-dark"> <thead> diff --git a/entries/templates/unification_frames.html b/entries/templates/unification_frames.html new file mode 100644 index 0000000..cb4fd55 --- /dev/null +++ b/entries/templates/unification_frames.html @@ -0,0 +1,15 @@ +{% extends "entries_base.html" %} + +{% load i18n %} +{% load static %} + +{% block title %}{% trans "Hasła" %}{% endblock %} + +{% block scripts %} + {{ block.super }} + <script src="{% static 'entries/js/unification_frames_list.js' %}"></script> +{% endblock %} + +{% block left_pane %}{% include "unification_frames_list.html" %}{% endblock %} + +{% block right_pane %}{% include "entry_display.html" %}{% endblock %} diff --git a/entries/templates/unification_frames_list.html b/entries/templates/unification_frames_list.html new file mode 100644 index 0000000..87b3b4a --- /dev/null +++ b/entries/templates/unification_frames_list.html @@ -0,0 +1,18 @@ +{% load i18n %} + +<table id="entries-table" class="table table-sm table-hover text-dark"> + <thead> + <tr> + <th class="p-1">{% trans "Rama" %}</th> + <th class="p-1">{% trans "Status" %}</th> + {% if perms.users.view_user %} + <th class="p-1">{% trans "Leksykograf" %}</th> + {% else %} + <th class="p-1">{% trans "Moje (w opracowaniu)" %}</th> + {% endif %} + <th class="p-1" hidden="true">{% trans "Id" %}</th> + </tr> + </thead> + <tbody id="entries"> + </tbody> +</table> diff --git a/entries/urls.py b/entries/urls.py index 697f591..47ea4be 100644 --- a/entries/urls.py +++ b/entries/urls.py @@ -16,6 +16,7 @@ urlpatterns = [ path('change_show_reals_desc/', views.change_show_reals_desc, name='change_show_reals_desc'), path('change_show_linked_entries/', views.change_show_linked_entries, name='change_show_linked_entries'), path('unification', views.unification, name='unification'), + path('unification_frames', views.unification_frames, name='unification_frames'), path('autocomplete/', autocompletes.autocomplete, name='autocomplete'), path('plWN_context_lookup/', ajax_plWN_context_lookup, name='plWN_context_lookup'), diff --git a/entries/views.py b/entries/views.py index fda744e..7ac820a 100644 --- a/entries/views.py +++ b/entries/views.py @@ -80,6 +80,17 @@ def unification(request): }, ) +@login_required +def unification_frames(request): + return render( + request, + 'unification_frames.html', + { + 'entries_form' : EntryForm(), + 'frames_form': FrameFormFactory.get_form(as_subform=False), + 'schemata_form': SchemaFormFactory.get_form(as_subform=False) + }, + ) FORM_TYPES = { 'entry' : EntryForm, diff --git a/unifier/urls.py b/unifier/urls.py index 2ababb7..56207b1 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -8,4 +8,6 @@ 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_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'), + ] diff --git a/unifier/views.py b/unifier/views.py index d992582..b138def 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -1,8 +1,10 @@ from django.http import JsonResponse from common.decorators import ajax_required +from entries.views import get_scroller_params from semantics.models import RelationalSelectionalPreference -from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference +from unifier.models import UnifiedFrameArgument, UnifiedRelationalSelectionalPreference, UnifiedFrame, \ + UnifiedFrame2SlowalFrameMapping @ajax_required @@ -44,3 +46,39 @@ def save_relational_selectional_preference(request): unifiedFrameArgument.save() return JsonResponse({}) + +@ajax_required +def get_unified_frames(request): + if request.method == 'POST': + errors_dict = dict() + + scroller_params = get_scroller_params(request.POST) + + unifiedFrame2SlowalFrameMappings = UnifiedFrame2SlowalFrameMapping.objects.all(); + + res = {} + for mapping in unifiedFrame2SlowalFrameMappings: + res[mapping.unified_frame.id] = res.get(mapping.unified_frame.id, []) + res[mapping.unified_frame.id].append(mapping) + + resProcessed = [] + for key, value in res.items(): + title = value[0].unified_frame.title if value[0].unified_frame.title is not None else '['+value[0].slowal_frame.lexical_units.first().base+']' + resProcessed.append({ + 'id': str(value[0].unified_frame.id), + 'title': title, + 'status': value[0].unified_frame.status, + 'assignee_username': ( + assignment.user.username if (assignment := value[0].slowal_frame.lexical_units.first().assignments.first()) else None + ), + }) + + ret = { + 'draw' : scroller_params['draw'], + 'recordsTotal': len(resProcessed), + 'recordsFiltered': len(resProcessed), + 'data': resProcessed + } + + return JsonResponse(ret) + return JsonResponse({}) -- GitLab