Skip to content

Commit ef418f2

Browse files
authored
Merge pull request #4 from aplmicrons/mgmt-downsample
added downsample status and buttons
2 parents 540941e + ef4cf0a commit ef418f2

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

django/mgmt/static/js/downsample.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
function set_status_str(val){
3+
// Set the status label and color
4+
var ds_label = $("#downsample_status");
5+
remove_label_styles(ds_label);
6+
if (val == "NOT_DOWNSAMPLED") {
7+
status = "Not Downsampled";
8+
ds_label.addClass('label-default');
9+
} else if (val == "IN_PROGRESS") {
10+
status = "In Progress";
11+
ds_label.addClass('label-info');
12+
} else if (val == "DOWNSAMPLED") {
13+
status = "Downsampled";
14+
ds_label.addClass('label-success');
15+
} else if (val == "FAILED") {
16+
status = "Failed";
17+
ds_label.addClass('label-danger');
18+
}
19+
20+
ds_label.text(status);
21+
}
22+
23+
function remove_label_styles(object) {
24+
object.removeClass('label-default');
25+
object.removeClass('label-primary');
26+
object.removeClass('label-success');
27+
object.removeClass('label-info');
28+
object.removeClass('label-warning');
29+
object.removeClass('label-danger');
30+
}
31+
32+
function set_button_modes(val) {
33+
// Method to update the button disabled states
34+
if (val == "NOT_DOWNSAMPLED") {
35+
$("#downsample-btn").removeClass('disabled');
36+
$("#cancel-btn").addClass('disabled');
37+
} else if (val == "IN_PROGRESS") {
38+
// Uploading
39+
$("#downsample-btn").addClass('disabled');
40+
$("#cancel-btn").removeClass('disabled');
41+
} else if (val == "DOWNSAMPLED") {
42+
// Complete
43+
$("#downsample-btn").addClass('disabled');
44+
$("#cancel-btn").addClass('disabled');
45+
} else {
46+
// Failed
47+
$("#downsample-btn").removeClass('disabled');
48+
$("#cancel-btn").addClass('disabled');
49+
}
50+
}
51+
52+
function get_downsample_status() {
53+
// Use generic methods for Bootstrap tables, since no params needed, set to empty dict
54+
var params = {};
55+
var resources = get_resource_names();
56+
get_api_call(API_ROOT + "downsample/" + resources[0] + "/" + resources[1]+ "/" + resources[2], params, get_downsample_callback);
57+
}
58+
59+
function get_downsample_callback(params, response){
60+
// Update Status
61+
set_status_str(response['status']);
62+
63+
// Update Button State
64+
set_button_modes(response['status'])
65+
}
66+
67+
function downsample_ajax(collection, experiment, channel, type){
68+
$.ajax({
69+
url: API_ROOT + "downsample/" + collection + "/" + experiment + "/" + channel,
70+
type: type,
71+
headers: {
72+
"Accept" : "application/json; charset=utf-8",
73+
"Content-Type": "application/json; charset=utf-8",
74+
"X-CSRFToken": get_csrf_token()
75+
},
76+
cache: false,
77+
statusCode: {
78+
201: function (response) {
79+
// Good to go. refresh dumping any prior form posts
80+
swal({text: 'Please wait...',
81+
type: "info",
82+
showConfirmButton: false,
83+
timer: 5000,
84+
onClose:function() {
85+
window.location = window.location.protocol +'//'+ window.location.host + window.location.pathname
86+
}
87+
})
88+
},
89+
204: function (response) {
90+
// Good to go. refresh dumping any prior form posts
91+
swal({text: 'Please wait...',
92+
type: "info",
93+
showConfirmButton: false,
94+
timer: 5000,
95+
onClose:function() {
96+
window.location = window.location.protocol +'//'+ window.location.host + window.location.pathname
97+
}
98+
})
99+
},
100+
404: function (response) {
101+
raise_ajax_error(response);
102+
$("#downsample-btn").removeClass('disabled');
103+
},
104+
400: function (response) {
105+
raise_ajax_error(response);
106+
$("#downsample-btn").removeClass('disabled');
107+
},
108+
403: function (response) {
109+
raise_ajax_error(response);
110+
$("#downsample-btn").removeClass('disabled');
111+
},
112+
500: function (response) {
113+
raise_ajax_error(response);
114+
$("#downsample-btn").removeClass('disabled');
115+
}
116+
}
117+
});
118+
}
119+
120+
121+
function start_downsample(collection, experiment, channel){
122+
$("#downsample-btn").addClass('disabled');
123+
downsample_ajax(collection, experiment, channel, "POST")
124+
125+
}
126+
127+
function cancel_downsample(collection, experiment, channel){
128+
$("#cancel-btn").addClass('disabled');
129+
130+
swal({
131+
title: 'Are you sure?',
132+
text: "You won't be able to revert this!",
133+
type: 'warning',
134+
showCancelButton: true,
135+
confirmButtonColor: '#18BC9C',
136+
cancelButtonColor: '#E74C3C',
137+
confirmButtonText: 'Yes, cancel it!'
138+
}).then(function () {
139+
downsample_ajax(collection, experiment, channel, "DELETE")
140+
});
141+
$("#cancel-btn").removeClass('disabled');
142+
}

django/mgmt/templates/channel.html

+23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ <h3 class="panel-title">Channel Properties</h3>
2525
<div class="panel-body">
2626
<div class="row">
2727
<div class="col-xs-10 col-xs-offset-1">
28+
<div class="row">
29+
<div class="col-xs-10 col-xs-offset-2">
30+
<div class="panel panel-default">
31+
<div class="row">
32+
<div class="col-xs-5">
33+
<div class="panel-body">
34+
<strong>Downsample Status: </strong> <span id="downsample_status" class="label label-default"> </span>
35+
</div>
36+
</div>
37+
<div class="col-xs-7">
38+
<div class="panel-body">
39+
<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>
40+
<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>
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
</div>
2847
{% mgmt_url current_url action="update" as update_url %}
2948
{% update_form chan_form chan_error "Update Channel" update_url Creator=channel.creator %}
3049
</div>
@@ -118,6 +137,7 @@ <h3 class="panel-title">Channel Metadata</h3>
118137

119138
{% block js_includes %}
120139
<script type="text/javascript" src="{% static "js/channel.js" %}"></script>
140+
<script type="text/javascript" src="{% static "js/downsample.js" %}"></script>
121141
<script type="text/javascript">
122142
$(function () {
123143
$('[data-toggle="popover"]').popover();
@@ -128,6 +148,9 @@ <h3 class="panel-title">Channel Metadata</h3>
128148
$('#permission_table').bootstrapTable({
129149
data: perm_data
130150
});
151+
152+
// Get the channel's downsample status and update the UI
153+
get_downsample_status()
131154
});
132155
</script>
133156
{% endblock %}`

0 commit comments

Comments
 (0)