Skip to content

Commit

Permalink
Merge pull request #4 from aplmicrons/mgmt-downsample
Browse files Browse the repository at this point in the history
added downsample status and buttons
  • Loading branch information
sandyhider authored May 5, 2017
2 parents 540941e + ef4cf0a commit ef418f2
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
142 changes: 142 additions & 0 deletions django/mgmt/static/js/downsample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

function set_status_str(val){
// Set the status label and color
var ds_label = $("#downsample_status");
remove_label_styles(ds_label);
if (val == "NOT_DOWNSAMPLED") {
status = "Not Downsampled";
ds_label.addClass('label-default');
} else if (val == "IN_PROGRESS") {
status = "In Progress";
ds_label.addClass('label-info');
} else if (val == "DOWNSAMPLED") {
status = "Downsampled";
ds_label.addClass('label-success');
} else if (val == "FAILED") {
status = "Failed";
ds_label.addClass('label-danger');
}

ds_label.text(status);
}

function remove_label_styles(object) {
object.removeClass('label-default');
object.removeClass('label-primary');
object.removeClass('label-success');
object.removeClass('label-info');
object.removeClass('label-warning');
object.removeClass('label-danger');
}

function set_button_modes(val) {
// Method to update the button disabled states
if (val == "NOT_DOWNSAMPLED") {
$("#downsample-btn").removeClass('disabled');
$("#cancel-btn").addClass('disabled');
} else if (val == "IN_PROGRESS") {
// Uploading
$("#downsample-btn").addClass('disabled');
$("#cancel-btn").removeClass('disabled');
} else if (val == "DOWNSAMPLED") {
// Complete
$("#downsample-btn").addClass('disabled');
$("#cancel-btn").addClass('disabled');
} else {
// Failed
$("#downsample-btn").removeClass('disabled');
$("#cancel-btn").addClass('disabled');
}
}

function get_downsample_status() {
// Use generic methods for Bootstrap tables, since no params needed, set to empty dict
var params = {};
var resources = get_resource_names();
get_api_call(API_ROOT + "downsample/" + resources[0] + "/" + resources[1]+ "/" + resources[2], params, get_downsample_callback);
}

function get_downsample_callback(params, response){
// Update Status
set_status_str(response['status']);

// Update Button State
set_button_modes(response['status'])
}

function downsample_ajax(collection, experiment, channel, type){
$.ajax({
url: API_ROOT + "downsample/" + collection + "/" + experiment + "/" + channel,
type: type,
headers: {
"Accept" : "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8",
"X-CSRFToken": get_csrf_token()
},
cache: false,
statusCode: {
201: function (response) {
// Good to go. refresh dumping any prior form posts
swal({text: 'Please wait...',
type: "info",
showConfirmButton: false,
timer: 5000,
onClose:function() {
window.location = window.location.protocol +'//'+ window.location.host + window.location.pathname
}
})
},
204: function (response) {
// Good to go. refresh dumping any prior form posts
swal({text: 'Please wait...',
type: "info",
showConfirmButton: false,
timer: 5000,
onClose:function() {
window.location = window.location.protocol +'//'+ window.location.host + window.location.pathname
}
})
},
404: function (response) {
raise_ajax_error(response);
$("#downsample-btn").removeClass('disabled');
},
400: function (response) {
raise_ajax_error(response);
$("#downsample-btn").removeClass('disabled');
},
403: function (response) {
raise_ajax_error(response);
$("#downsample-btn").removeClass('disabled');
},
500: function (response) {
raise_ajax_error(response);
$("#downsample-btn").removeClass('disabled');
}
}
});
}


function start_downsample(collection, experiment, channel){
$("#downsample-btn").addClass('disabled');
downsample_ajax(collection, experiment, channel, "POST")

}

function cancel_downsample(collection, experiment, channel){
$("#cancel-btn").addClass('disabled');

swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#18BC9C',
cancelButtonColor: '#E74C3C',
confirmButtonText: 'Yes, cancel it!'
}).then(function () {
downsample_ajax(collection, experiment, channel, "DELETE")
});
$("#cancel-btn").removeClass('disabled');
}
23 changes: 23 additions & 0 deletions django/mgmt/templates/channel.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ <h3 class="panel-title">Channel Properties</h3>
<div class="panel-body">
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<div class="row">
<div class="col-xs-10 col-xs-offset-2">
<div class="panel panel-default">
<div class="row">
<div class="col-xs-5">
<div class="panel-body">
<strong>Downsample Status: </strong> <span id="downsample_status" class="label label-default"> </span>
</div>
</div>
<div class="col-xs-7">
<div class="panel-body">
<a id="downsample-btn" type='button' class='btn btn-primary btn-sm action-button disabled' href='javascript:void(0);' onclick='start_downsample("{{ collection_name }}", "{{ experiment_name }}", "{{ channel_name }}")'><span class='glyphicon glyphicon-sort-by-attributes-alt' aria-hidden='true'></span> Start Downsample</a>
<a id="cancel-btn" type='button' class='btn btn-danger btn-sm action-button disabled' href='javascript:void(0);' onclick='cancel_downsample("{{collection_name }}", "{{ experiment_name }}", "{{ channel_name }}")'><span class='glyphicon glyphicon-remove' aria-hidden='true'></span> Cancel Downsample</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% mgmt_url current_url action="update" as update_url %}
{% update_form chan_form chan_error "Update Channel" update_url Creator=channel.creator %}
</div>
Expand Down Expand Up @@ -118,6 +137,7 @@ <h3 class="panel-title">Channel Metadata</h3>

{% block js_includes %}
<script type="text/javascript" src="{% static "js/channel.js" %}"></script>
<script type="text/javascript" src="{% static "js/downsample.js" %}"></script>
<script type="text/javascript">
$(function () {
$('[data-toggle="popover"]').popover();
Expand All @@ -128,6 +148,9 @@ <h3 class="panel-title">Channel Metadata</h3>
$('#permission_table').bootstrapTable({
data: perm_data
});

// Get the channel's downsample status and update the UI
get_downsample_status()
});
</script>
{% endblock %}`

0 comments on commit ef418f2

Please sign in to comment.