blob: b686de8c795503194f73efbec348172cc34c1ae2 [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;
Gunnar Millsf4d9bc42018-03-06 15:42:40 -0600146 $scope.confirm_priority = true;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500147 }
148
149 $scope.confirmChangePriority = function(){
150 $scope.loading = true;
151 APIUtils.changePriority($scope.priority_image_id, $scope.priority_to).then(function(response){
152 $scope.loading = false;
153 if(response.status == 'error'){
154 $scope.displayError({
155 modal_title: response.data.description,
156 title: response.data.description,
157 desc: response.data.exception,
158 type: 'Error'
159 });
160 }else{
161 $scope.loadFirmwares();
162 }
163 });
164 $scope.confirm_priority = false;
165 }
Gunnar Mills607a1202018-03-01 16:26:50 -0600166 $scope.deleteImage = function(imageId, imageVersion){
Iftekharul Islamc0161392017-06-14 15:46:15 -0500167 $scope.delete_image_id = imageId;
Gunnar Mills607a1202018-03-01 16:26:50 -0600168 $scope.delete_image_version = imageVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500169 $scope.confirm_delete = true;
170 }
Iftekharul Islam2a489552017-11-02 13:23:08 -0500171 $scope.confirmDeleteImage = function(){
172 $scope.loading = true;
173 APIUtils.deleteImage($scope.delete_image_id).then(function(response){
174 $scope.loading = false;
175 if(response.status == 'error'){
176 $scope.displayError({
177 modal_title: response.data.description,
178 title: response.data.description,
179 desc: response.data.exception,
180 type: 'Error'
181 });
182 }else{
183 $scope.loadFirmwares();
184 }
185 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500186 $scope.confirm_delete = false;
187 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500188 $scope.fileNameChanged = function(){
189 $scope.file_empty = false;
190 }
191
192 $scope.uploading = false;
193 $scope.filters = {
194 bmc: {
195 imageType: 'BMC'
196 },
197 host: {
198 imageType: 'Host'
199 }
200 };
201
202 $scope.loadFirmwares = function(){
Michael Davisdf3bd122017-08-10 11:03:42 -0500203 APIUtils.getFirmwares().then(function(result){
204 $scope.firmwares = result.data;
205 $scope.bmcActiveVersion = result.bmcActiveVersion;
206 $scope.hostActiveVersion = result.hostActiveVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500207 });
208 }
209
210 $scope.loadFirmwares();
Michael Davis43366db2017-05-15 18:12:35 -0500211 }
212 ]
213 );
214
215})(angular);