Commit a00b5547 authored by Romain Courteaud's avatar Romain Courteaud Committed by Jérome Perrin

Migrate run knowledge extraction button.

parent 4309aa4a
......@@ -152,7 +152,7 @@ def getConfigurationDict():
@app.route("/runKnowledgeExtraction", methods=["POST", "OPTIONS"])
def runKnowledgeExtraction():
parameter_dict = request.json['json']
parameter_dict = request.json
try:
timeout = int(parameter_dict['general']['processTimeout'])
except (KeyError, ValueError, TypeError):
......
......@@ -27,9 +27,6 @@
<a id="layout_graph"><i class="fa fa-sitemap"></i> Layout Graph</a>
<a id="zoom_in"><i class="fa fa-plus"></i> Zoom +</a>
<a id="zoom_out"><i class="fa fa-minus"></i> Zoom -</a>
<a id="run_knowledge_extraction">
<i class="fa fa-spinner fa-spin" id="ke_loading_spinner" style="display:none"></i>
Run Knowledge Extraction</a>
</div>
</div>
......
......@@ -322,24 +322,6 @@
that.setGeneralProperties(properties);
}
/** Runs the knowledge extraction, and call the callback with results once the
* KE is finished.
*/
that.runKnowledgeExtraction = function (callback) {
that.readGeneralPropertiesDialog()
$.ajax(
'../runKnowledgeExtraction', {
data: JSON.stringify({
json: that.getData()
}),
contentType: 'application/json',
type: 'POST',
success: function (data, textStatus, jqXHR) {
callback(data);
}
});
};
that.displayResult = function (idx, result) {
// the list of available widgets, in the same order that in html
var available_widget_list = [
......
......@@ -159,25 +159,6 @@
});
});
// Enable "Run Knowledge Extraction" button
$("#run_knowledge_extraction").button().click(
function (e) {
$("#ke_loading_spinner").show();
$("#run_knowledge_extraction").button('disable');
$('#error').empty();
dream_instance.runKnowledgeExtraction(
function(data) {
$("#ke_loading_spinner").hide();
$("#run_knowledge_extraction").button('enable');
if (data['success']) {
loadData(data.data);
} else {
$("#error").text(data["error"]).show().effect('shake', 50);
console.error(data['error'])
}
});
});
// // Enable "Run Simulation" button
// $("#run_simulation").button().click(
// function (e) {
......
......@@ -6,12 +6,17 @@
<title>Manage document</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>" type="text/javascript"></script>
<script src="document_page_mixin.js" type="text/javascript"></script>
<script src="manage_document.js" type="text/javascript"></script>
</head>
<body>
<a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a>
<form class="knowledge_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-refresh ui-btn-icon-right">Run Knowledge Extraction</button>
</form>
<form class="delete_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-delete ui-btn-icon-right">Delete</button>
</form>
......
/*global console, rJS, RSVP, initDocumentPageMixin */
(function (window, rJS, RSVP, initDocumentPageMixin) {
/*global console, rJS, RSVP, initDocumentPageMixin, jQuery */
(function (window, rJS, RSVP, initDocumentPageMixin, $) {
"use strict";
function datatouri(data, mime_type) {
......@@ -35,6 +35,96 @@
return new RSVP.Promise(resolver, canceller);
}
function disableAllButtons(gadget) {
// Prevent double click
var i,
button_list = gadget.props.element.getElementsByClassName("ui-btn");
for (i = 0; i < button_list.length; i += 1) {
button_list[i].disabled = true;
}
}
function waitForKnowledgeExtraction(gadget) {
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("knowledge_form")[0],
'submit',
false
);
})
.push(function () {
disableAllButtons(gadget);
return gadget.aq_getAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json"
});
})
.push(function (body_json) {
$.mobile.loading('show');
// XXX Hardcoded relative URL
return gadget.aq_ajax({
url: "../../runKnowledgeExtraction",
type: "POST",
data: body_json,
headers: {
"Content-Type": 'application/json'
}
});
})
.push(undefined, function (error) {
// Always drop the loader
$.mobile.loading('hide');
throw error;
})
.push(function (evt) {
$.mobile.loading('hide');
var json_data = JSON.parse(evt.target.responseText);
if (json_data.success !== true) {
throw new Error(json_data.error);
}
return gadget.aq_putAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json",
"_data": JSON.stringify(json_data.data, null, 2),
"_mimetype": "application/json"
});
})
.push(function () {
return gadget.whoWantToDisplayThisDocument(gadget.props.jio_key);
})
.push(function (url) {
return gadget.pleaseRedirectMyHash(url);
});
}
function waitForDeletion(gadget) {
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("delete_form")[0],
'submit',
false
);
})
.push(function () {
disableAllButtons(gadget);
// Delete jIO document
return gadget.aq_remove({
"_id": gadget.props.jio_key
});
})
.push(function (result) {
return gadget.whoWantToDisplayHome();
})
.push(function (url) {
return gadget.pleaseRedirectMyHash(url);
});
}
var gadget_klass = rJS(window);
initDocumentPageMixin(gadget_klass);
gadget_klass
......@@ -59,8 +149,12 @@
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_remove", "jio_remove")
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("aq_get", "jio_get")
.declareAcquiredMethod("aq_ajax", "jio_ajax")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantToDisplayThisDocument",
"whoWantToDisplayThisDocument")
.declareAcquiredMethod("whoWantToDisplayHome",
"whoWantToDisplayHome")
......@@ -92,30 +186,9 @@
})
.declareMethod("startService", function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("delete_form")[0],
'submit',
false
);
})
.push(function () {
// Prevent double click
gadget.props.element
.getElementsByClassName("ui-btn")[0].disabled = true;
// Delete jIO document
return gadget.aq_remove({
"_id": gadget.props.jio_key
});
})
.push(function (result) {
return gadget.whoWantToDisplayHome();
})
.push(function (url) {
return gadget.pleaseRedirectMyHash(url);
});
return RSVP.all([
waitForDeletion(this),
waitForKnowledgeExtraction(this)
]);
});
}(window, rJS, RSVP, initDocumentPageMixin));
}(window, rJS, RSVP, initDocumentPageMixin, jQuery));
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