blob: d46b6e498d235fb645ac1940fa1e84547633c497 [file] [log] [blame]
Michael Davis43366db2017-05-15 18:12:35 -05001/**
2 * Controller for firmware
3 *
4 * @module app/configuration
5 * @exports firmwareController
6 * @name firmwareController
7 * @version 0.1.0
8 */
9
10window.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 Islam1acb4122017-11-02 13:20:32 -050022 'Constants',
23 function ($scope, $window, APIUtils, dataService, $location, $anchorScroll, Constants) {
Michael Davis43366db2017-05-15 18:12:35 -050024 $scope.dataService = dataService;
25
Michael Davis43366db2017-05-15 18:12:35 -050026 //Scroll to target anchor
27 $scope.gotoAnchor = function () {
28 $location.hash('upload');
29 $anchorScroll();
30 };
Iftekharul Islamc0161392017-06-14 15:46:15 -050031
32 $scope.firmwares = [];
33 $scope.bmcActiveVersion = "";
34 $scope.hostActiveVersion = "";
35 $scope.display_error = false;
Iftekharul Islamc0161392017-06-14 15:46:15 -050036 $scope.reboot_confirm = false;
37 $scope.preserve_settings_confirm = false;
38 $scope.delete_image_id = "";
Gunnar Mills607a1202018-03-01 16:26:50 -060039 $scope.delete_image_version = "";
Iftekharul Islamc0161392017-06-14 15:46:15 -050040 $scope.activate_image_id = "";
Iftekharul Islam1acb4122017-11-02 13:20:32 -050041 $scope.priority_image_id = "";
Gunnar Mills6473a412018-03-01 16:19:37 -060042 $scope.priority_image_version = "";
Iftekharul Islam1acb4122017-11-02 13:20:32 -050043 $scope.priority_from = -1;
44 $scope.priority_to = -1;
45 $scope.confirm_priority = false;
Iftekharul Islamc0161392017-06-14 15:46:15 -050046 $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 Islam2a489552017-11-02 13:23:08 -050067 $scope.uploading = true;
68 APIUtils.activateImage($scope.activate_image_id).then(function(response){
Gunnar Millseedefd32018-02-28 17:02:34 -060069 $scope.uploading = false;
Iftekharul Islam2a489552017-11-02 13:23:08 -050070 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 Islamc0161392017-06-14 15:46:15 -050081 $scope.preserve_settings_confirm = false;
82 }
83
84 $scope.confirmWarmReboot = function(){
85 $scope.reboot_confirm = false;
86 }
87
88 $scope.upload = function(){
Gunnar Millsdddb1492018-02-19 16:27:27 -060089 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 Islamc0161392017-06-14 15:46:15 -0500104 }
105 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500106
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500107 $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 Islam2a489552017-11-02 13:23:08 -0500118 filename = $scope.download_filename;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500119 }
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 Mills6473a412018-03-01 16:19:37 -0600141 $scope.changePriority = function(imageId, imageVersion, from, to){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500142 $scope.priority_image_id = imageId;
Gunnar Mills6473a412018-03-01 16:19:37 -0600143 $scope.priority_image_version = imageVersion;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500144 $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 Mills607a1202018-03-01 16:26:50 -0600171 $scope.deleteImage = function(imageId, imageVersion){
Iftekharul Islamc0161392017-06-14 15:46:15 -0500172 $scope.delete_image_id = imageId;
Gunnar Mills607a1202018-03-01 16:26:50 -0600173 $scope.delete_image_version = imageVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500174 $scope.confirm_delete = true;
175 }
Iftekharul Islam2a489552017-11-02 13:23:08 -0500176 $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 Islamc0161392017-06-14 15:46:15 -0500191 $scope.confirm_delete = false;
192 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500193 $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 Davisdf3bd122017-08-10 11:03:42 -0500208 APIUtils.getFirmwares().then(function(result){
209 $scope.firmwares = result.data;
210 $scope.bmcActiveVersion = result.bmcActiveVersion;
211 $scope.hostActiveVersion = result.hostActiveVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500212 });
213 }
214
215 $scope.loadFirmwares();
Michael Davis43366db2017-05-15 18:12:35 -0500216 }
217 ]
218 );
219
220})(angular);