Commit 1f77b82b authored by Romain Loth's avatar Romain Loth

[GRAPH] better messages between client and server + clickable links in messages

parent f4c42b8f
...@@ -48,6 +48,13 @@ def compress_graph(graphdata): ...@@ -48,6 +48,13 @@ def compress_graph(graphdata):
return graphdata return graphdata
def format_html(link):
"""
Build an html link adapted to our json message format
"""
return "<a class='msglink' href='%s'>%s</a>" % (link, link)
# TODO check authentication # TODO check authentication
class Graph(APIView): class Graph(APIView):
...@@ -146,7 +153,7 @@ class Graph(APIView): ...@@ -146,7 +153,7 @@ class Graph(APIView):
# data :: Either (Dic Nodes Links) (Dic State Length) # data :: Either (Dic Nodes Links) (Dic State Length)
# data_test :: Either String Bool # data_test :: Either String Bool
data_test = data.get("state", True) data_test = data.get("state", True)
...@@ -158,70 +165,71 @@ class Graph(APIView): ...@@ -158,70 +165,71 @@ class Graph(APIView):
status=200 status=200
) )
# -------------------------------------------- # --------------------------------------------
else: else:
# All other cases (more probable are higher in the if list) # All other cases (more probable are higher in the if list)
if data["state"] == "saveOnly": if data["state"] == "saveOnly":
# async data case # async data case
link = "http://%s/projects/%d/corpora/%d/myGraphs" % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({ return JsonHttpResponse({
'msg': '''Your graph is saved: 'msg': '''Your graph is saved:
http://%sgargantext.org/projects/%d/corpora/%d/myGraphs %s
''' % ("dev.", corpus.parent_id, corpus.id), ''' % format_html(link),
}, status=400) }, status=200)
elif data["state"] == "corpusMin": elif data["state"] == "corpusMin":
# async data case # async data case
link = "http://%s/projects/%d/" % (request.get_host(), corpus.parent_id)
return JsonHttpResponse({ return JsonHttpResponse({
'msg': '''Problem: your corpus is too small (only %d documents). 'msg': '''Problem: your corpus is too small (only %d documents).
Solution: Add more documents (more than %d documents) Solution: Add more documents (more than %d documents)
in order to get a graph. in order to get a graph.
You can manage your corpus here: You can manage your corpus here:
http://%sgargantext.org/projects/%d/ %s
''' % ( data["length"] ''' % ( data["length"]
, graph_constraints['corpusMin'] , graph_constraints['corpusMin']
, "dev." , format_html(link)
, corpus.parent_id
), ),
}, status=400) }, status=400)
elif data["state"] == "mapListError": elif data["state"] == "mapListError":
# async data case # async data case
link = 'http://%s/projects/%d/corpora/%d/terms' % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({ return JsonHttpResponse({
'msg': '''Problem: your map list is too small (currently %d terms). 'msg': '''Problem: your map list is too small (currently %d terms).
Solution: Add some terms (more than %d terms) Solution: Add some terms (more than %d terms)
in order to get a graph. in order to get a graph.
You can manage your map terms here: You can manage your map terms here:
http://%sgargantext.org/projects/%d/corpora/%d/terms %s
''' % ( data["length"] ''' % ( data["length"]
, graph_constraints['mapList'] , graph_constraints['mapList']
, "dev." , format_html(link)
, corpus.parent_id
, corpus.id
), ),
}, status=400) }, status=400)
elif data["state"] == "corpusMax": elif data["state"] == "corpusMax":
# async data case # async data case
link = 'http://%s/projects/%d/corpora/%d/myGraphs' % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({ return JsonHttpResponse({
'msg': '''Warning: Async graph generation since your corpus is 'msg': '''Warning: Async graph generation since your corpus is
big (about %d documents). big (about %d documents).
Wait a while and discover your graph very soon. Wait a while and discover your graph very soon.
Click on the link below and see your current graph Click on the link below and see your current graph
processing on top of the list: processing on top of the list:
http://%sgargantext.org/projects/%d/corpora/%d/myGraphs %s
''' % (data["length"], "dev.", corpus.parent_id, corpus.id), ''' % (data["length"], format_html(link)),
}, status=400) }, status=200)
else : else :
......
...@@ -357,17 +357,19 @@ ...@@ -357,17 +357,19 @@
</div> </div>
</div> </div>
<div id="errormodal" class="modal fade"> <div id="msgmodal" class="modal fade">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Graph generation error</h4> <h4 id="msgtitle" class="modal-title">
Graph generation message
</h4>
</div> </div>
<div class="modal-body form-horizontal"> <div class="modal-body form-horizontal">
<div id="errormsg"></div> <div id="msgcontent"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
......
...@@ -89,16 +89,24 @@ $.ajax({ ...@@ -89,16 +89,24 @@ $.ajax({
}); });
function showDialog(url, hasError, status, msg) { function showDialog(url, hasError, status, msg) {
console.log('FUN t.main:showErrorDialog') console.log('FUN t.main:showDialog' + 'hasError:'+hasError)
// hide loader gif etc // hide loader gif etc
$("#semLoader").hide(); $("#semLoader").hide();
$("#closeloader").click(); $("#closeloader").click();
if (hasError) {
$('#msgtitle').html('Graph generation error')
$('#msgtitle').css('color', 'red')
}
else {
$('#msgtitle').html('Graph generation info')
}
// copy message content // copy message content
$('#errormsg').html(msg.replace(/\n/g, '<br/>')) $('#msgcontent').html(msg.replace(/\n/g, '<br/>'))
// show the dialog box // show the dialog box
$('#errormodal').modal('show'); $('#msgmodal').modal('show');
} }
function MainFunction( RES ) { function MainFunction( RES ) {
......
...@@ -372,17 +372,19 @@ ...@@ -372,17 +372,19 @@
</div> </div>
</div> </div>
<div id="errormodal" class="modal fade"> <div id="msgmodal" class="modal fade">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Graph generation error</h4> <h4 id="msgtitle" class="modal-title">
Graph generation message
</h4>
</div> </div>
<div class="modal-body form-horizontal"> <div class="modal-body form-horizontal">
<div id="errormsg"></div> <div id="msgcontent"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
......
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