|
| 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 | +} |
0 commit comments