Skip to content
Snippets Groups Projects
Commit de79440b authored by dcz's avatar dcz
Browse files

Add/remove unified frame argument

parent f2f7b5ec
Branches
Tags
No related merge requests found
......@@ -272,6 +272,61 @@ export default {
};
$.prompt(change_role_popup);
}
},
addArgument() {
var data = { 'unified_frame_id' : this.unified_frame.id};
$.ajax({
type : 'post',
url : '/' + lang + '/unifier/add_argument/',
dataType : 'json',
data : data,
timeout : 60000,
success : function(response) {
show_info('Nowy argument zosał dodany');
this.loadFrame();
}.bind(this),
error: function(request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
});
},
removeArgument() {
if (!this.active_unified_frame_argument) {
alert(gettext("Zaznacz argument, który chcesz usunąć."));
} else {
let hasSlowalFrameArgumentMapping = false;
for (var i in this.unified_frame.slowal_frame_mapping) {
var slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i];
for (var j in slowal_frame_mapping.slowal_frame_argument_mapping) {
var slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j];
if (slowal_frame_argument_mapping.unified_frame_agrument_id == this.active_unified_frame_argument.id) {
hasSlowalFrameArgumentMapping = true;
break;
}
}
}
if (hasSlowalFrameArgumentMapping) {
alert(gettext("Zaznaczony argument nie może zostać usunięty - podpięte ramy posiadają do niego dowiązania."));
} else {
var data = {'unified_frame_id': this.unified_frame.id, 'complement_id': this.active_unified_frame_argument.id};
$.ajax({
type: 'post',
url: '/' + lang + '/unifier/remove_argument/',
dataType: 'json',
data: data,
timeout: 60000,
success: function (response) {
show_info('Wybrany argument zosał usunięty');
this.loadFrame();
}.bind(this),
error: function (request, errorType, errorMessage) {
show_error(errorType + ' (' + errorMessage + ')');
$.prompt.close();
}
});
}
}
}
},
mounted () {
......@@ -292,14 +347,14 @@ export default {
<table 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>
<td id="add-arg" style="padding: 10px 15px 10px 15px; color: #000000;">Dodaj argum.</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 id="merge" style="padding: 10px 15px 10px 15px; color: #000000;">Scal</td>
<td style="padding: 10px 15px 10px 15px; color: #000000;" @click="$emit('goToDisplay')">Gotowe</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" style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argum.</td>
<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;">Zamień okna</td>
<td id="duplicates" style="padding: 10px 15px 10px 15px; color: #000000;">Duplikuj</td>
<td id="save-changes" style="padding: 10px 15px 10px 15px; color: #000000;">Zapisz</td>
......
......@@ -5,9 +5,16 @@ from django.core.management.base import BaseCommand
import os, logging
from xml.sax import handler, make_parser
from django.db.models import Max
from importer.unification.UnificationPreprocessXML import UnificationPreprocessHandler
from shellvalier.settings import BASE_DIR
from common.models import ImportInProgress
from django.db import connection
from unifier.models import UnifiedFrameArgument
class Command(BaseCommand):
args = 'none'
......@@ -30,4 +37,10 @@ def import_unification():
parser.setContentHandler(UnificationPreprocessHandler())
parser.parse(xml_path)
max_id = UnifiedFrameArgument.objects.aggregate(Max('id'))['id__max']+1
trigger_sql = "ALTER SEQUENCE unifier_unifiedframeargument_id_seq RESTART "+str(max_id)+";"
cursor = connection.cursor()
cursor.execute(trigger_sql)
ImportInProgress.objects.all().delete()
......@@ -79,7 +79,7 @@ class UnifiedFrame(models.Model):
class UnifiedFrameArgument(models.Model):
role_type = models.ForeignKey(RoleType, on_delete=models.PROTECT)
role_type = models.ForeignKey(RoleType, on_delete=models.PROTECT, default=None, blank=True, null=True)
#rola - wybrana przez użytkownika
role = models.ForeignKey(ArgumentRole, on_delete=models.PROTECT, default=None, blank=True, null=True)
#role zaproponowane przez system unifikacyjny
......
......@@ -16,5 +16,7 @@ urlpatterns = [
path('save_unified_frame_title/', views.save_unified_frame_title, name='save_unified_frame_title'),
path('save_selected_role/', views.save_selected_role, name='save_selected_role'),
path('save_new_role/', views.save_new_role, name='save_new_role'),
path('add_argument/', views.add_argument, name='add_argument'),
path('remove_argument/', views.remove_argument, name='remove_argument'),
]
......@@ -104,7 +104,7 @@ def unifiedFrame2dict(frame):
'str': '{}{}'.format(a.role.role.role.lower(), ' ' + a.role.attribute.attribute.lower() if a.role.attribute else '') if a.role is not None else None,
'id': str(a.role.id)
} if a.role is not None else None,
'role_type' : a.role_type.type.lower(),
'role_type' : a.role_type.type.lower() if a.role_type is not None else '',
'preferences' : get_prefs_list(a),
'proposed_roles': [{
'str': '{}{}'.format(r.role.role.lower(), ' ' + r.attribute.attribute.lower() if r.attribute else ''),
......@@ -318,3 +318,25 @@ def save_new_role(request):
unifiedFrameArgument.role = argumentRole
unifiedFrameArgument.save()
return JsonResponse({})
@ajax_required
@transaction.atomic
def add_argument(request):
if request.method == 'POST':
unified_frame_id = request.POST['unified_frame_id']
unifiedFrame = UnifiedFrame.objects.get(pk=unified_frame_id)
newUnifiedFrameArgument = UnifiedFrameArgument.objects.create(unified_frame=unifiedFrame)
newUnifiedFrameArgument.save()
return JsonResponse({})
@ajax_required
@transaction.atomic
def remove_argument(request):
if request.method == 'POST':
unified_frame_id = request.POST['unified_frame_id']
complement_id = request.POST['complement_id']
newUnifiedFrameArgument = UnifiedFrameArgument.objects.get(id=complement_id)
newUnifiedFrameArgument.delete()
return JsonResponse({})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment