Commit 69ab91ec authored by Romain Loth's avatar Romain Loth

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

parent 4fdf77b1
......@@ -48,6 +48,13 @@ def compress_graph(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
class Graph(APIView):
......@@ -164,15 +171,17 @@ class Graph(APIView):
if data["state"] == "saveOnly":
# async data case
link = "http://%s/projects/%d/corpora/%d/myGraphs" % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({
'msg': '''Your graph is saved:
http://%sgargantext.org/projects/%d/corpora/%d/myGraphs
''' % ("dev.", corpus.parent_id, corpus.id),
}, status=400)
%s
''' % format_html(link),
}, status=200)
elif data["state"] == "corpusMin":
# async data case
link = "http://%s/projects/%d/" % (request.get_host(), corpus.parent_id)
return JsonHttpResponse({
'msg': '''Problem: your corpus is too small (only %d documents).
......@@ -180,16 +189,16 @@ class Graph(APIView):
in order to get a graph.
You can manage your corpus here:
http://%sgargantext.org/projects/%d/
%s
''' % ( data["length"]
, graph_constraints['corpusMin']
, "dev."
, corpus.parent_id
, format_html(link)
),
}, status=400)
elif data["state"] == "mapListError":
# async data case
link = 'http://%s/projects/%d/corpora/%d/terms' % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({
'msg': '''Problem: your map list is too small (currently %d terms).
......@@ -197,18 +206,17 @@ class Graph(APIView):
in order to get a graph.
You can manage your map terms here:
http://%sgargantext.org/projects/%d/corpora/%d/terms
%s
''' % ( data["length"]
, graph_constraints['mapList']
, "dev."
, corpus.parent_id
, corpus.id
, format_html(link)
),
}, status=400)
elif data["state"] == "corpusMax":
# async data case
link = 'http://%s/projects/%d/corpora/%d/myGraphs' % (request.get_host(), corpus.parent_id, corpus.id)
return JsonHttpResponse({
'msg': '''Warning: Async graph generation since your corpus is
big (about %d documents).
......@@ -218,9 +226,9 @@ class Graph(APIView):
Click on the link below and see your current graph
processing on top of the list:
http://%sgargantext.org/projects/%d/corpora/%d/myGraphs
''' % (data["length"], "dev.", corpus.parent_id, corpus.id),
}, status=400)
%s
''' % (data["length"], format_html(link)),
}, status=200)
......
......@@ -357,17 +357,19 @@
</div>
</div>
<div id="errormodal" class="modal fade">
<div id="msgmodal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<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 class="modal-body form-horizontal">
<div id="errormsg"></div>
<div id="msgcontent"></div>
</div>
<div class="modal-footer">
......
......@@ -89,16 +89,24 @@ $.ajax({
});
function showDialog(url, hasError, status, msg) {
console.log('FUN t.main:showErrorDialog')
console.log('FUN t.main:showDialog' + 'hasError:'+hasError)
// hide loader gif etc
$("#semLoader").hide();
$("#closeloader").click();
if (hasError) {
$('#msgtitle').html('Graph generation error')
$('#msgtitle').css('color', 'red')
}
else {
$('#msgtitle').html('Graph generation info')
}
// copy message content
$('#errormsg').html(msg.replace(/\n/g, '<br/>'))
$('#msgcontent').html(msg.replace(/\n/g, '<br/>'))
// show the dialog box
$('#errormodal').modal('show');
$('#msgmodal').modal('show');
}
function MainFunction( RES ) {
......
......@@ -372,17 +372,19 @@
</div>
</div>
<div id="errormodal" class="modal fade">
<div id="msgmodal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<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 class="modal-body form-horizontal">
<div id="errormsg"></div>
<div id="msgcontent"></div>
</div>
<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