summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-01-18 17:12:54 +0100
committermr <mr@mrautenberg.de>2011-01-18 17:12:54 +0100
commit8da8b742db45faeff56afc5b70d1ca263e4c0bb0 (patch)
tree7be1bcc6dbe6efcb61a55f03187c8306feeea6c6
parent318fb6deb86e326c3e6676c493fd8d327f38c1e1 (diff)
fix javascript
-rw-r--r--application.rb24
-rwxr-xr-xpublic/javascripts/toxcreate.js14
-rw-r--r--views/model.haml8
-rw-r--r--views/models.haml4
-rw-r--r--views/predict.haml2
5 files changed, 38 insertions, 14 deletions
diff --git a/application.rb b/application.rb
index fbd29a9..31bab62 100644
--- a/application.rb
+++ b/application.rb
@@ -26,6 +26,25 @@ helpers do
redirect url_for('/create')
end
+ private
+ def delete_model(model, subjectid=nil)
+ begin RestClient.put(File.join(model.task_uri, 'Cancelled'),subjectid) if model.task_uri rescue LOGGER.warn "Can not cancel task #{model.task_uri}" end
+ delete_dependent(model.uri, subjectid) if model.uri
+ delete_dependent(model.validation_uri, subjectid) if model.validation_uri
+ delete_dependent(model.validation_report_uri, subjectid) if model.validation_report_uri
+ delete_dependent(model.validation_qmrf_uri, subjectid) if model.validation_qmrf_uri
+ delete_dependent(model.training_dataset, subjectid) if model.training_dataset
+ delete_dependent(model.feature_dataset, subjectid) if model.feature_dataset
+ end
+
+ def delete_dependent(uri, subjectid=nil)
+ begin
+ RestClient.delete(uri, :subjectid => subjectid) if subjectid
+ RestClient.delete(uri) if !subjectid
+ rescue
+ LOGGER.warn "Can not delete uri: #{uri}"
+ end
+ end
end
before do
@@ -234,6 +253,7 @@ post '/models' do # create a new model
end
post '/predict/?' do # post chemical name to model
+ subjectid = session[:subjectid] ? session[:subjectid] : nil
@identifier = params[:identifier]
unless params[:selection] and params[:identifier] != ''
flash[:notice] = "Please enter a compound identifier and select an endpoint from the list."
@@ -376,8 +396,8 @@ end
delete '/model/:id/?' do
model = ToxCreateModel.get(params[:id])
begin
- RestClient.delete(model.uri, :subjectid => session[:subjectid]) if model.uri
- RestClient.delete model.task_uri if model.task_uri
+
+ delete_model(model, session[:subjectid])
model.destroy
unless ToxCreateModel.get(params[:id])
begin
diff --git a/public/javascripts/toxcreate.js b/public/javascripts/toxcreate.js
index 500b685..c74701a 100755
--- a/public/javascripts/toxcreate.js
+++ b/public/javascripts/toxcreate.js
@@ -14,19 +14,19 @@ $(function() {
});
};
- checkStati = function(stati) {
- stati = stati.split(", ")
+ checkStati = function(stati, subjectstr) {
+ stati = stati.split(", ");
$("body")
var newstati = new Array;
$.each(stati, function(){
- if(checkStatus(this) > 0) newstati.push(this);
+ if(checkStatus(this, subjectstr) > 0) newstati.push(this);
});
- if (newstati.length > 0) var statusCheck = setTimeout('checkStati("' + newstati.join(", ") + '")',10000);
+ if (newstati.length > 0) var statusCheck = setTimeout('checkStati("' + newstati.join(", ") + '", "' + subjectstr + '")',10000);
};
- checkStatus = function(id) {
+ checkStatus = function(id, subjectstr) {
if(id == "") return -1;
- var opts = {method: 'get', action: 'model/' + id + '/status', id: id};
+ var opts = {method: 'get', action: 'model/' + id + '/status' + subjectstr, id: id};
var status_changed = $.ajax({
type: opts.method,
url: opts.action,
@@ -36,7 +36,7 @@ $(function() {
'_method': 'get'
},
success: function(data) {
- var erg = data.search(/Running/);
+ var erg = data.search(/Running|Creating|Upload|Validating/);
status_changed = false;
if(erg < 0) status_changed = true;
$("span#model_" + id + "_status").animate({"opacity": "0.1"},1000);
diff --git a/views/model.haml b/views/model.haml
index 1788250..6c2aa56 100644
--- a/views/model.haml
+++ b/views/model.haml
@@ -14,9 +14,13 @@
%dd
%span{:id => "model_#{model.id}_status", :class => model.status}
= haml :model_status, :locals=>{:model=>model}, :layout => false
- - if is_authorized(model.web_uri, "DELETE")
+ - if is_authorized(model.web_uri, "DELETE")
(
- %a{:href => url_for("/model/#{model.id}"), :id => "delete_#{model.id}", :class => 'delete'} delete
+ %a{:href => url_for("/model/#{model.id}"), :id => "delete_#{model.id}", :class => 'delete'}
+ - if model.status == "Completed"
+ delete
+ - else
+ stop
)
%dt Started:
%dd= model.created_at.strftime("%m/%d/%Y - %I:%M:%S%p")
diff --git a/views/models.haml b/views/models.haml
index e4e9fbb..ab113c5 100644
--- a/views/models.haml
+++ b/views/models.haml
@@ -3,10 +3,10 @@
:javascript
$(function() {
if(#{stati != 0}) {
- setTimeout('checkStati("#{stati_to_check}")',5000);
+ setTimeout('checkStati("#{stati_to_check}", "#{subjectstring}")',5000);
}
var reload_validation = true;
- if(reload_validation) setTimeout('checkValidation()',15000);
+ //if(reload_validation) setTimeout('checkValidation()',15000);
});
-# %p Get an overview about ToxCreate models. This page is refreshed every 15 seconds to update the model status.
diff --git a/views/predict.haml b/views/predict.haml
index 7d81402..cd5c0d4 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -26,7 +26,7 @@
- @models.each do |model|
%label{:for => model.id}
= model.name
- %input{:type => 'checkbox', :name => "selection[#{model.id}]", :value => true, :id => model.id, :disabled => !is_authorized(model.uri, "POST")}
+ %input{:type => 'checkbox', :name => "selection[#{model.id}]", :value => true, :id => model.id}
%br
%input{:type => 'hidden', :name => 'subjectid', :id => 'subjectid', :value => session[:subjectid]}