Commit 54f5a47a6295414dc777bd21914bdb5fd349e645
1 parent
3a22a50c
Schemata are now reloading after saving semantics.
Showing
10 changed files
with
114 additions
and
21 deletions
LICENSE
1 | -Copyright (c) 2012, Bartłomiej Nitoń | 1 | +Copyright (c) 2015, Bartłomiej Nitoń |
2 | All rights reserved. | 2 | All rights reserved. |
3 | 3 | ||
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
accounts/admin.py
@@ -39,7 +39,8 @@ class RealizedPhraseologyAdmin(admin.ModelAdmin): | @@ -39,7 +39,8 @@ class RealizedPhraseologyAdmin(admin.ModelAdmin): | ||
39 | readonly_fields = ('date',) | 39 | readonly_fields = ('date',) |
40 | search_fields = ('lemma__entry',) | 40 | search_fields = ('lemma__entry',) |
41 | 41 | ||
42 | -class RealizedSemanticsAdmin(admin.ModelAdmin): | 42 | +class RealizedSemanticsAdmin(admin.ModelAdmin): |
43 | + exclude = ('entry',) | ||
43 | list_filter = ('status', 'bonus',) | 44 | list_filter = ('status', 'bonus',) |
44 | search_fields = ('entry__name',) | 45 | search_fields = ('entry__name',) |
45 | 46 |
dictionary/ajax_lemma_view.py
@@ -3193,3 +3193,21 @@ def delete_user(request, user_id): | @@ -3193,3 +3193,21 @@ def delete_user(request, user_id): | ||
3193 | def deselect_preview_tab(request): | 3193 | def deselect_preview_tab(request): |
3194 | request.session['lemma_preview'] = False | 3194 | request.session['lemma_preview'] = False |
3195 | return {} | 3195 | return {} |
3196 | + | ||
3197 | +@ajax(method='get') | ||
3198 | +def get_schemata(request, lemma_id): | ||
3199 | + lemma = Lemma.objects.get(id=lemma_id) | ||
3200 | + schemata = lemma.frames.order_by('text_rep') | ||
3201 | + serialized_schemata = [frameObjToSerializableDict(lemma, schema, True) for schema in schemata] | ||
3202 | + json_schemata = json_encode(serialized_schemata) | ||
3203 | + return {'schemata': json_schemata, | ||
3204 | + 'can_modify': user_can_modify(lemma, request.user)} | ||
3205 | + | ||
3206 | +@ajax(method='get') | ||
3207 | +def get_examples(request, lemma_id): | ||
3208 | + lemma = Lemma.objects.get(id=lemma_id) | ||
3209 | + examples = lemma.nkjp_examples.all() | ||
3210 | + examples_js = nkjpExamplesObjToJs(examples, request.user, lemma) | ||
3211 | + json_examples = json_encode(examples_js) | ||
3212 | + return {'examples': json_examples, | ||
3213 | + 'can_modify': user_can_modify(lemma, request.user)} |
dictionary/saving.py
@@ -23,21 +23,22 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema, | @@ -23,21 +23,22 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema, | ||
23 | operations = [] | 23 | operations = [] |
24 | used_poss_ids = [] | 24 | used_poss_ids = [] |
25 | for js_position in js_schema['positions']: | 25 | for js_position in js_schema['positions']: |
26 | - position = get_position(schema, js_position, used_poss_ids) | ||
27 | - for js_phrase_type in js_position['arguments']: | ||
28 | - phrase_type = Argument.objects.get(text_rep=js_phrase_type['text_rep']) | ||
29 | - new_connection_target = {'schema': schema, | ||
30 | - 'position': position, | ||
31 | - 'phrase_type': phrase_type} | ||
32 | - for conn in js_phrase_type['connections']: | ||
33 | - operations.extend(reconnect_operations(frames, conn, new_connection_target)) | ||
34 | - conn_dict = next((conn_dict | ||
35 | - for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) | ||
36 | - if conn_dict: | ||
37 | - conn_dict['realizations'].extend(conn['realizations']) | ||
38 | - else: | ||
39 | - connections.append({'compl': conn['compl'], | ||
40 | - 'realizations': conn['realizations']}) | 26 | + if len(js_position['arguments']) > 0: |
27 | + position = get_position(schema, js_position, used_poss_ids) | ||
28 | + for js_phrase_type in js_position['arguments']: | ||
29 | + phrase_type = Argument.objects.get(text_rep=js_phrase_type['text_rep']) | ||
30 | + new_connection_target = {'schema': schema, | ||
31 | + 'position': position, | ||
32 | + 'phrase_type': phrase_type} | ||
33 | + for conn in js_phrase_type['connections']: | ||
34 | + operations.extend(reconnect_operations(frames, conn, new_connection_target)) | ||
35 | + conn_dict = next((conn_dict | ||
36 | + for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) | ||
37 | + if conn_dict: | ||
38 | + conn_dict['realizations'].extend(conn['realizations']) | ||
39 | + else: | ||
40 | + connections.append({'compl': conn['compl'], | ||
41 | + 'realizations': conn['realizations']}) | ||
41 | return operations | 42 | return operations |
42 | 43 | ||
43 | def get_position(schema, js_position, used_poss_ids): | 44 | def get_position(schema, js_position, used_poss_ids): |
dictionary/static/js/lemma-view.js
@@ -75,6 +75,15 @@ var nkjp_source_tab = ax_nkjp_source_vals; | @@ -75,6 +75,15 @@ var nkjp_source_tab = ax_nkjp_source_vals; | ||
75 | function alertUserNotAuthenticated() { | 75 | function alertUserNotAuthenticated() { |
76 | error_alert('Przed wykonaniem działania odśwież okno przeglądarki, a następnie zaloguj się ponownie do narzędzia.'); | 76 | error_alert('Przed wykonaniem działania odśwież okno przeglądarki, a następnie zaloguj się ponownie do narzędzia.'); |
77 | } | 77 | } |
78 | + | ||
79 | +function resetLemmaVersions() { | ||
80 | + window.frames_modif = new Array(); | ||
81 | + window.frames_modif_idx = 0; | ||
82 | + var lemma_version = new Lemma_Version(window.schemas, | ||
83 | + window.nkjp_examples, | ||
84 | + window.nkjp_lemma_examples); | ||
85 | + frames_modif.push(lemma_version); | ||
86 | +} | ||
78 | 87 | ||
79 | function initiateFrameFilters() | 88 | function initiateFrameFilters() |
80 | { | 89 | { |
@@ -437,7 +446,7 @@ function load_content(id) { | @@ -437,7 +446,7 @@ function load_content(id) { | ||
437 | window.notesNotSaved = false; | 446 | window.notesNotSaved = false; |
438 | window.lemmaExNotSaved = false; | 447 | window.lemmaExNotSaved = false; |
439 | 448 | ||
440 | - $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ | 449 | + $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ |
441 | window.lemma_id = id; | 450 | window.lemma_id = id; |
442 | createSplitter('framesSplit','new-frame-tables', 'tabs'); | 451 | createSplitter('framesSplit','new-frame-tables', 'tabs'); |
443 | if(window.can_modify) | 452 | if(window.can_modify) |
dictionary/static/js/semantics_coupling.js
1 | -function schemaGotAssignedSemantics(element_id) | ||
2 | -{ | 1 | +function schemaGotAssignedSemantics(element_id) { |
3 | var semanticsAssigned = true; | 2 | var semanticsAssigned = true; |
4 | var id_map = parseId(element_id); | 3 | var id_map = parseId(element_id); |
5 | var schema_id = id_map['frame_id']; | 4 | var schema_id = id_map['frame_id']; |
@@ -93,3 +92,63 @@ function clearPositionConnections(position) { | @@ -93,3 +92,63 @@ function clearPositionConnections(position) { | ||
93 | function clearPhraseTypeConnections(phraseType) { | 92 | function clearPhraseTypeConnections(phraseType) { |
94 | phraseType.connections = []; | 93 | phraseType.connections = []; |
95 | } | 94 | } |
95 | + | ||
96 | +function updateSchemataConnections() { | ||
97 | + $('#new-frame-tables').empty(); | ||
98 | + $("#show_nkjp_table").empty(); | ||
99 | + $.ajaxJSON({ | ||
100 | + method: 'get', | ||
101 | + url: ajax_get_schemata, | ||
102 | + data: { | ||
103 | + lemma_id: window.lemma_id | ||
104 | + }, | ||
105 | + | ||
106 | + callback: function(result) { | ||
107 | + window.schemas = serializedObjToObj(result['schemata']); | ||
108 | + resetLemmaVersions(); | ||
109 | + var frame_class = 'InactiveFrameTable'; | ||
110 | + if(result['can_modify']) { | ||
111 | + frame_class = 'ActiveFrameTable'; | ||
112 | + } | ||
113 | + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', | ||
114 | + 'frame_filter', window.nkjp_examples, frame_class, | ||
115 | + window.lemma_entry, window.lemma_entry); | ||
116 | + }, | ||
117 | + error_callback: function(xhr, status, error) { | ||
118 | + error_alert(status + ': ' + error); | ||
119 | + }, | ||
120 | + bad_data_callback: function(result) { | ||
121 | + return true; | ||
122 | + }, | ||
123 | + }); | ||
124 | +} | ||
125 | + | ||
126 | +function updateExamplesConnections() { | ||
127 | + $('#new-frame-tables').empty(); | ||
128 | + $("#show_nkjp_table").empty(); | ||
129 | + $.ajaxJSON({ | ||
130 | + method: 'get', | ||
131 | + url: ajax_get_examples, | ||
132 | + data: { | ||
133 | + lemma_id: window.lemma_id | ||
134 | + }, | ||
135 | + | ||
136 | + callback: function(result) { | ||
137 | + window.nkjp_examples = serializedNkjpToObj(result['examples']); | ||
138 | + resetLemmaVersions(); | ||
139 | + var frame_class = 'InactiveFrameTable'; | ||
140 | + if(result['can_modify']) { | ||
141 | + frame_class = 'ActiveFrameTable'; | ||
142 | + } | ||
143 | + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', | ||
144 | + 'frame_filter', window.nkjp_examples, frame_class, | ||
145 | + window.lemma_entry, window.lemma_entry); | ||
146 | + }, | ||
147 | + error_callback: function(xhr, status, error) { | ||
148 | + error_alert(status + ': ' + error); | ||
149 | + }, | ||
150 | + bad_data_callback: function(result) { | ||
151 | + return true; | ||
152 | + }, | ||
153 | + }); | ||
154 | +} |
dictionary/views.py
@@ -191,6 +191,8 @@ def lemma_view(request): | @@ -191,6 +191,8 @@ def lemma_view(request): | ||
191 | 'ajax_get_compatible_schema_chars' : reverse('get_compatible_schema_chars'), | 191 | 'ajax_get_compatible_schema_chars' : reverse('get_compatible_schema_chars'), |
192 | 192 | ||
193 | 'ajax_deselect_preview_tab': reverse('deselect_preview_tab'), | 193 | 'ajax_deselect_preview_tab': reverse('deselect_preview_tab'), |
194 | + 'ajax_get_schemata': reverse('get_schemata'), | ||
195 | + 'ajax_get_examples': reverse('get_examples'), | ||
194 | 196 | ||
195 | # powiazywanie hasel (nieczasownikowe) | 197 | # powiazywanie hasel (nieczasownikowe) |
196 | 'ajax_relate_entries' : reverse('relate_entries'), | 198 | 'ajax_relate_entries' : reverse('relate_entries'), |
semantics/static/js/semantics_frames.js
@@ -463,8 +463,8 @@ function saveFrames() { | @@ -463,8 +463,8 @@ function saveFrames() { | ||
463 | memorizeConnections(data.connections.connected, data.connections.connected_reverse); | 463 | memorizeConnections(data.connections.connected, data.connections.connected_reverse); |
464 | $("#semantic-frames-count").empty(); | 464 | $("#semantic-frames-count").empty(); |
465 | $("#semantic-frames-count").append(data.frames_count); | 465 | $("#semantic-frames-count").append(data.frames_count); |
466 | + updateSchemataConnections(); | ||
466 | }); | 467 | }); |
467 | frames_operations = []; | 468 | frames_operations = []; |
468 | } | 469 | } |
469 | } | 470 | } |
470 | - |
semantics/static/js/semantics_lexical_units.js
@@ -97,6 +97,7 @@ function saveMeanings() { | @@ -97,6 +97,7 @@ function saveMeanings() { | ||
97 | success: function(data){ | 97 | success: function(data){ |
98 | memorizeLexicalUnits(data.lexical_units); | 98 | memorizeLexicalUnits(data.lexical_units); |
99 | basicLexicalUnitsData(data.informations); | 99 | basicLexicalUnitsData(data.informations); |
100 | + updateExamplesConnections(); | ||
100 | }, | 101 | }, |
101 | async: false | 102 | async: false |
102 | }); | 103 | }); |
urls.py
@@ -121,6 +121,8 @@ urlpatterns += patterns('dictionary.ajax_lemma_view', | @@ -121,6 +121,8 @@ urlpatterns += patterns('dictionary.ajax_lemma_view', | ||
121 | url(r'^ajax/user_is_authenticated/$', 'user_is_authenticated'), | 121 | url(r'^ajax/user_is_authenticated/$', 'user_is_authenticated'), |
122 | 122 | ||
123 | url(r'^ajax/deselect_preview_tab/$', 'deselect_preview_tab'), | 123 | url(r'^ajax/deselect_preview_tab/$', 'deselect_preview_tab'), |
124 | + url(r'^ajax/get_schemata/$', 'get_schemata'), | ||
125 | + url(r'^ajax/get_examples/$', 'get_examples'), | ||
124 | 126 | ||
125 | # powiazywanie hasel (nieczasownikowe) | 127 | # powiazywanie hasel (nieczasownikowe) |
126 | url(r'^ajax/relate_entries/$', 'relate_entries'), | 128 | url(r'^ajax/relate_entries/$', 'relate_entries'), |