Michael Davis | 43366db | 2017-05-15 18:12:35 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Controller for firmware |
| 3 | * |
| 4 | * @module app/configuration |
| 5 | * @exports firmwareController |
| 6 | * @name firmwareController |
| 7 | * @version 0.1.0 |
| 8 | */ |
| 9 | |
| 10 | window.angular && (function (angular) { |
| 11 | 'use strict'; |
| 12 | |
| 13 | angular |
| 14 | .module('app.configuration') |
| 15 | .controller('firmwareController', [ |
| 16 | '$scope', |
| 17 | '$window', |
| 18 | 'APIUtils', |
| 19 | 'dataService', |
| 20 | '$location', |
| 21 | '$anchorScroll', |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 22 | 'Constants', |
| 23 | function ($scope, $window, APIUtils, dataService, $location, $anchorScroll, Constants) { |
Michael Davis | 43366db | 2017-05-15 18:12:35 -0500 | [diff] [blame] | 24 | $scope.dataService = dataService; |
| 25 | |
Michael Davis | 43366db | 2017-05-15 18:12:35 -0500 | [diff] [blame] | 26 | //Scroll to target anchor |
| 27 | $scope.gotoAnchor = function () { |
| 28 | $location.hash('upload'); |
| 29 | $anchorScroll(); |
| 30 | }; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 31 | |
| 32 | $scope.firmwares = []; |
| 33 | $scope.bmcActiveVersion = ""; |
| 34 | $scope.hostActiveVersion = ""; |
| 35 | $scope.display_error = false; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 36 | $scope.reboot_confirm = false; |
| 37 | $scope.preserve_settings_confirm = false; |
| 38 | $scope.delete_image_id = ""; |
Gunnar Mills | 607a120 | 2018-03-01 16:26:50 -0600 | [diff] [blame] | 39 | $scope.delete_image_version = ""; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 40 | $scope.activate_image_id = ""; |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 41 | $scope.priority_image_id = ""; |
Gunnar Mills | 6473a41 | 2018-03-01 16:19:37 -0600 | [diff] [blame] | 42 | $scope.priority_image_version = ""; |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 43 | $scope.priority_from = -1; |
| 44 | $scope.priority_to = -1; |
| 45 | $scope.confirm_priority = false; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 46 | $scope.file_empty = true; |
| 47 | $scope.uploading = false; |
| 48 | |
| 49 | $scope.error = { |
| 50 | modal_title: "", |
| 51 | title: "", |
| 52 | desc: "", |
| 53 | type: "warning" |
| 54 | }; |
| 55 | |
| 56 | $scope.activateImage = function(imageId){ |
| 57 | $scope.activate_image_id = imageId; |
| 58 | $scope.preserve_settings_confirm = true; |
| 59 | } |
| 60 | |
| 61 | $scope.displayError = function(data){ |
| 62 | $scope.error = data; |
| 63 | $scope.display_error = true; |
| 64 | } |
| 65 | |
| 66 | $scope.preserveSettingsConfirmed = function(){ |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 67 | $scope.uploading = true; |
| 68 | APIUtils.activateImage($scope.activate_image_id).then(function(response){ |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 69 | $scope.uploading = false; |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 70 | if(response.status == 'error'){ |
| 71 | $scope.displayError({ |
| 72 | modal_title: response.data.description, |
| 73 | title: response.data.description, |
| 74 | desc: response.data.exception, |
| 75 | type: 'Error' |
| 76 | }); |
| 77 | }else{ |
| 78 | $scope.loadFirmwares(); |
| 79 | } |
| 80 | }); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 81 | $scope.preserve_settings_confirm = false; |
| 82 | } |
| 83 | |
| 84 | $scope.confirmWarmReboot = function(){ |
| 85 | $scope.reboot_confirm = false; |
| 86 | } |
| 87 | |
| 88 | $scope.upload = function(){ |
Gunnar Mills | dddb149 | 2018-02-19 16:27:27 -0600 | [diff] [blame] | 89 | if($scope.file) { |
| 90 | $scope.uploading = true; |
| 91 | APIUtils.uploadImage($scope.file).then(function(response){ |
| 92 | $scope.uploading = false; |
| 93 | if(response.status == 'error'){ |
| 94 | $scope.displayError({ |
| 95 | modal_title: response.data.description, |
| 96 | title: response.data.description, |
| 97 | desc: response.data.exception, |
| 98 | type: 'Error' |
| 99 | }); |
| 100 | }else{ |
| 101 | $scope.loadFirmwares(); |
| 102 | } |
| 103 | }); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 104 | } |
| 105 | } |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 106 | |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 107 | $scope.download = function(){ |
| 108 | $scope.downloading = true; |
| 109 | APIUtils.downloadImage($scope.download_host, $scope.download_filename).then(function(response){ |
| 110 | var data = response.data; |
| 111 | $scope.downloading = false; |
| 112 | var headers = response.headers(); |
| 113 | |
| 114 | var filename = headers['x-filename']; |
| 115 | var contentType = headers['content-type']; |
| 116 | |
| 117 | if(!headers['x-filename']){ |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 118 | filename = $scope.download_filename; |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | var linkElement = document.createElement('a'); |
| 122 | try { |
| 123 | var blob = new Blob([data], { type: contentType }); |
| 124 | var url = window.URL.createObjectURL(blob); |
| 125 | |
| 126 | linkElement.setAttribute('href', url); |
| 127 | linkElement.setAttribute("download", filename); |
| 128 | |
| 129 | var clickEvent = new MouseEvent("click", { |
| 130 | "view": window, |
| 131 | "bubbles": true, |
| 132 | "cancelable": false |
| 133 | }); |
| 134 | linkElement.dispatchEvent(clickEvent); |
| 135 | } catch (ex) { |
| 136 | console.log(ex); |
| 137 | } |
| 138 | }); |
| 139 | } |
| 140 | |
Gunnar Mills | 6473a41 | 2018-03-01 16:19:37 -0600 | [diff] [blame] | 141 | $scope.changePriority = function(imageId, imageVersion, from, to){ |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 142 | $scope.priority_image_id = imageId; |
Gunnar Mills | 6473a41 | 2018-03-01 16:19:37 -0600 | [diff] [blame] | 143 | $scope.priority_image_version = imageVersion; |
Iftekharul Islam | 1acb412 | 2017-11-02 13:20:32 -0500 | [diff] [blame] | 144 | $scope.priority_from = from; |
| 145 | $scope.priority_to = to; |
| 146 | |
| 147 | if((from + to) == 1){ |
| 148 | $scope.confirm_priority = true; |
| 149 | }else{ |
| 150 | $scope.confirmChangePriority(); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | $scope.confirmChangePriority = function(){ |
| 155 | $scope.loading = true; |
| 156 | APIUtils.changePriority($scope.priority_image_id, $scope.priority_to).then(function(response){ |
| 157 | $scope.loading = false; |
| 158 | if(response.status == 'error'){ |
| 159 | $scope.displayError({ |
| 160 | modal_title: response.data.description, |
| 161 | title: response.data.description, |
| 162 | desc: response.data.exception, |
| 163 | type: 'Error' |
| 164 | }); |
| 165 | }else{ |
| 166 | $scope.loadFirmwares(); |
| 167 | } |
| 168 | }); |
| 169 | $scope.confirm_priority = false; |
| 170 | } |
Gunnar Mills | 607a120 | 2018-03-01 16:26:50 -0600 | [diff] [blame] | 171 | $scope.deleteImage = function(imageId, imageVersion){ |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 172 | $scope.delete_image_id = imageId; |
Gunnar Mills | 607a120 | 2018-03-01 16:26:50 -0600 | [diff] [blame] | 173 | $scope.delete_image_version = imageVersion; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 174 | $scope.confirm_delete = true; |
| 175 | } |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 176 | $scope.confirmDeleteImage = function(){ |
| 177 | $scope.loading = true; |
| 178 | APIUtils.deleteImage($scope.delete_image_id).then(function(response){ |
| 179 | $scope.loading = false; |
| 180 | if(response.status == 'error'){ |
| 181 | $scope.displayError({ |
| 182 | modal_title: response.data.description, |
| 183 | title: response.data.description, |
| 184 | desc: response.data.exception, |
| 185 | type: 'Error' |
| 186 | }); |
| 187 | }else{ |
| 188 | $scope.loadFirmwares(); |
| 189 | } |
| 190 | }); |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 191 | $scope.confirm_delete = false; |
| 192 | } |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 193 | $scope.fileNameChanged = function(){ |
| 194 | $scope.file_empty = false; |
| 195 | } |
| 196 | |
| 197 | $scope.uploading = false; |
| 198 | $scope.filters = { |
| 199 | bmc: { |
| 200 | imageType: 'BMC' |
| 201 | }, |
| 202 | host: { |
| 203 | imageType: 'Host' |
| 204 | } |
| 205 | }; |
| 206 | |
| 207 | $scope.loadFirmwares = function(){ |
Michael Davis | df3bd12 | 2017-08-10 11:03:42 -0500 | [diff] [blame] | 208 | APIUtils.getFirmwares().then(function(result){ |
| 209 | $scope.firmwares = result.data; |
| 210 | $scope.bmcActiveVersion = result.bmcActiveVersion; |
| 211 | $scope.hostActiveVersion = result.hostActiveVersion; |
Iftekharul Islam | c016139 | 2017-06-14 15:46:15 -0500 | [diff] [blame] | 212 | }); |
| 213 | } |
| 214 | |
| 215 | $scope.loadFirmwares(); |
Michael Davis | 43366db | 2017-05-15 18:12:35 -0500 | [diff] [blame] | 216 | } |
| 217 | ] |
| 218 | ); |
| 219 | |
| 220 | })(angular); |