Commit b1e90ab8 authored by Romain Loth's avatar Romain Loth

fix "delete node" in graphexplorer view

parent ab2c76dd
...@@ -19,12 +19,15 @@ def explorer(request, project_id, corpus_id): ...@@ -19,12 +19,15 @@ def explorer(request, project_id, corpus_id):
# we pass our corpus # we pass our corpus
corpus = cache.Node[corpus_id] corpus = cache.Node[corpus_id]
# get the maplist_id for modifications
maplist_id = corpus.children(typename="MAPLIST").first().id
# and the project just for project.id in corpusBannerTop # and the project just for project.id in corpusBannerTop
project = cache.Node[project_id] project = cache.Node[project_id]
graphurl = "projects/" + str(project_id) + "/corpora/" + str(corpus_id) + "/node_link.json" graphurl = "projects/" + str(project_id) + "/corpora/" + str(corpus_id) + "/node_link.json"
# rendered page : journals.html # rendered page : explorer.html
return render( return render(
template_name = 'graphExplorer/explorer.html', template_name = 'graphExplorer/explorer.html',
request = request, request = request,
...@@ -35,9 +38,8 @@ def explorer(request, project_id, corpus_id): ...@@ -35,9 +38,8 @@ def explorer(request, project_id, corpus_id):
'date' : datetime.now(), 'date' : datetime.now(),
'project' : project, 'project' : project,
'corpus' : corpus, 'corpus' : corpus,
#'list_id' : maplist.id,\ 'maplist_id': maplist_id,
'graphfile' : graphurl,\ 'graphfile' : graphurl,
'view' : 'graph' 'view' : 'graph'
}, },
) )
...@@ -23,15 +23,11 @@ function modify_ngrams( classname ) { ...@@ -23,15 +23,11 @@ function modify_ngrams( classname ) {
console.clear() console.clear()
var corpus_id = getIDFromURL( "corpora" ) // not used var corpus_id = getIDFromURL( "corpora" ) // not used
var list_id = $("#list_id").val() var list_id = $("#maplist_id").val()
var selected_ngrams = $.extend({}, selections) var selected_ngrams = $.extend({}, selections)
console.log( selected_ngrams )
if(classname=="delete") { if(classname=="delete") {
CRUD( corpus_id , "/keep" , [] , selected_ngrams , "DELETE" , function(result) { CRUD(list_id, Object.keys(selected_ngrams), "DELETE", function(success) {
console.log(" Delete from Map-list: "+result)
CRUD( list_id , "" , Object.keys(selected_ngrams).map(Number) , [] , "DELETE", function(result) {
console.log(" Add to Stop-list "+result)
cancelSelection(false) cancelSelection(false)
for(var i in selected_ngrams) { for(var i in selected_ngrams) {
partialGraph.dropNode( i ) partialGraph.dropNode( i )
...@@ -40,8 +36,7 @@ function modify_ngrams( classname ) { ...@@ -40,8 +36,7 @@ function modify_ngrams( classname ) {
} }
partialGraph.refresh() partialGraph.refresh()
$("#lensButton").click() $("#lensButton").click()
}); }) ;
});
} }
// if(classname=="group") { // if(classname=="group") {
...@@ -53,33 +48,43 @@ function modify_ngrams( classname ) { ...@@ -53,33 +48,43 @@ function modify_ngrams( classname ) {
// } // }
} }
function CRUD( parent_id , action , nodes , args , http_method , callback) { function CRUD( list_id , ngram_ids , http_method , callback) {
var the_url = window.location.origin+"/api/node/"+parent_id+"/ngrams"+action+"/"+nodes.join("+"); // ngramlists/change?node_id=42&ngram_ids=1,2
the_url = the_url.replace(/\/$/, ""); //remove trailing slash var the_url = window.location.origin+"/api/ngramlists/change?list="+list_id+"&ngrams="+ngram_ids.join(",");
console.log( the_url )
console.log( args ) // debug
if(nodes.length>0 || Object.keys(args).length>0) { // console.log("starting CRUD AJAX => URL: " + the_url + " (" + http_method + ")")
if(ngram_ids.length>0) {
$.ajax({ $.ajax({
method: http_method, method: http_method,
url: the_url, url: the_url,
data: args, // data: args, // currently all data explicitly in the url (like a GET)
beforeSend: function(xhr) { beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken")); xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
}, },
success: function(data){ success: function(data){
console.log("-- CRUD ----------")
console.log(http_method + " ok!!") console.log(http_method + " ok!!")
console.log(nodes) console.log(JSON.stringify(data))
console.log(data) console.log("------------------")
callback("Success"); callback(true);
}, },
error: function(result) { error: function(result) {
console.log("-- CRUD ----------")
console.log("Data not found in #Save_All");
console.log(result) console.log(result)
callback("Fail"); console.log("------------------")
callback(false);
} }
}); });
} else callback(false); } else callback(false);
} }
// = = = = = = = = = = = [ Clusters Plugin ] = = = = = = = = = = = // // = = = = = = = = = = = [ Clusters Plugin ] = = = = = = = = = = = //
// Execution: ChangeGraphAppearanceByAtt( true ) // Execution: ChangeGraphAppearanceByAtt( true )
......
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
<li> <li>
<a> <a>
<div id="graphid" style="visibility: hidden;">{{graphfile}}</div> <div id="graphid" style="visibility: hidden;">{{graphfile}}</div>
<input type="hidden" id="list_id" value="{{ list_id }}"></input> <input type="hidden" id="maplist_id" value="{{ maplist_id }}"></input>
<div id="jquerytemplatenb" style="visibility: hidden;">{{user.id}}</div> <div id="jquerytemplatenb" style="visibility: hidden;">{{user.id}}</div>
</a> </a>
</li> </li>
......
Markdown is supported
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