blob: 9416177dd8b1a26e28cf526710b242a173dc0bed [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 = "";
39 $scope.activate_image_id = "";
Iftekharul Islam1acb4122017-11-02 13:20:32 -050040 $scope.priority_image_id = "";
Gunnar Mills6473a412018-03-01 16:19:37 -060041 $scope.priority_image_version = "";
Iftekharul Islam1acb4122017-11-02 13:20:32 -050042 $scope.priority_from = -1;
43 $scope.priority_to = -1;
44 $scope.confirm_priority = false;
Iftekharul Islamc0161392017-06-14 15:46:15 -050045 $scope.file_empty = true;
46 $scope.uploading = false;
47
48 $scope.error = {
49 modal_title: "",
50 title: "",
51 desc: "",
52 type: "warning"
53 };
54
55 $scope.activateImage = function(imageId){
56 $scope.activate_image_id = imageId;
57 $scope.preserve_settings_confirm = true;
58 }
59
60 $scope.displayError = function(data){
61 $scope.error = data;
62 $scope.display_error = true;
63 }
64
65 $scope.preserveSettingsConfirmed = function(){
Iftekharul Islam2a489552017-11-02 13:23:08 -050066 $scope.uploading = true;
67 APIUtils.activateImage($scope.activate_image_id).then(function(response){
Gunnar Millseedefd32018-02-28 17:02:34 -060068 $scope.uploading = false;
Iftekharul Islam2a489552017-11-02 13:23:08 -050069 if(response.status == 'error'){
70 $scope.displayError({
71 modal_title: response.data.description,
72 title: response.data.description,
73 desc: response.data.exception,
74 type: 'Error'
75 });
76 }else{
77 $scope.loadFirmwares();
78 }
79 });
Iftekharul Islamc0161392017-06-14 15:46:15 -050080 $scope.preserve_settings_confirm = false;
81 }
82
83 $scope.confirmWarmReboot = function(){
84 $scope.reboot_confirm = false;
85 }
86
87 $scope.upload = function(){
Gunnar Millsdddb1492018-02-19 16:27:27 -060088 if($scope.file) {
89 $scope.uploading = true;
90 APIUtils.uploadImage($scope.file).then(function(response){
91 $scope.uploading = false;
92 if(response.status == 'error'){
93 $scope.displayError({
94 modal_title: response.data.description,
95 title: response.data.description,
96 desc: response.data.exception,
97 type: 'Error'
98 });
99 }else{
100 $scope.loadFirmwares();
101 }
102 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500103 }
104 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500105
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500106 $scope.download = function(){
107 $scope.downloading = true;
108 APIUtils.downloadImage($scope.download_host, $scope.download_filename).then(function(response){
109 var data = response.data;
110 $scope.downloading = false;
111 var headers = response.headers();
112
113 var filename = headers['x-filename'];
114 var contentType = headers['content-type'];
115
116 if(!headers['x-filename']){
Iftekharul Islam2a489552017-11-02 13:23:08 -0500117 filename = $scope.download_filename;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500118 }
119
120 var linkElement = document.createElement('a');
121 try {
122 var blob = new Blob([data], { type: contentType });
123 var url = window.URL.createObjectURL(blob);
124
125 linkElement.setAttribute('href', url);
126 linkElement.setAttribute("download", filename);
127
128 var clickEvent = new MouseEvent("click", {
129 "view": window,
130 "bubbles": true,
131 "cancelable": false
132 });
133 linkElement.dispatchEvent(clickEvent);
134 } catch (ex) {
135 console.log(ex);
136 }
137 });
138 }
139
Gunnar Mills6473a412018-03-01 16:19:37 -0600140 $scope.changePriority = function(imageId, imageVersion, from, to){
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500141 $scope.priority_image_id = imageId;
Gunnar Mills6473a412018-03-01 16:19:37 -0600142 $scope.priority_image_version = imageVersion;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500143 $scope.priority_from = from;
144 $scope.priority_to = to;
145
146 if((from + to) == 1){
147 $scope.confirm_priority = true;
148 }else{
149 $scope.confirmChangePriority();
150 }
151 }
152
153 $scope.confirmChangePriority = function(){
154 $scope.loading = true;
155 APIUtils.changePriority($scope.priority_image_id, $scope.priority_to).then(function(response){
156 $scope.loading = false;
157 if(response.status == 'error'){
158 $scope.displayError({
159 modal_title: response.data.description,
160 title: response.data.description,
161 desc: response.data.exception,
162 type: 'Error'
163 });
164 }else{
165 $scope.loadFirmwares();
166 }
167 });
168 $scope.confirm_priority = false;
169 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500170 $scope.deleteImage = function(imageId){
171 $scope.delete_image_id = imageId;
172 $scope.confirm_delete = true;
173 }
Iftekharul Islam2a489552017-11-02 13:23:08 -0500174 $scope.confirmDeleteImage = function(){
175 $scope.loading = true;
176 APIUtils.deleteImage($scope.delete_image_id).then(function(response){
177 $scope.loading = false;
178 if(response.status == 'error'){
179 $scope.displayError({
180 modal_title: response.data.description,
181 title: response.data.description,
182 desc: response.data.exception,
183 type: 'Error'
184 });
185 }else{
186 $scope.loadFirmwares();
187 }
188 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500189 $scope.confirm_delete = false;
190 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500191 $scope.fileNameChanged = function(){
192 $scope.file_empty = false;
193 }
194
195 $scope.uploading = false;
196 $scope.filters = {
197 bmc: {
198 imageType: 'BMC'
199 },
200 host: {
201 imageType: 'Host'
202 }
203 };
204
205 $scope.loadFirmwares = function(){
Michael Davisdf3bd122017-08-10 11:03:42 -0500206 APIUtils.getFirmwares().then(function(result){
207 $scope.firmwares = result.data;
208 $scope.bmcActiveVersion = result.bmcActiveVersion;
209 $scope.hostActiveVersion = result.hostActiveVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500210 });
211 }
212
213 $scope.loadFirmwares();
Michael Davis43366db2017-05-15 18:12:35 -0500214 }
215 ]
216 );
217
218})(angular);