blob: 6356a7351b1204f6050b78c16161254bb64cc6a1 [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 = "";
41 $scope.priority_from = -1;
42 $scope.priority_to = -1;
43 $scope.confirm_priority = false;
Iftekharul Islamc0161392017-06-14 15:46:15 -050044 $scope.file_empty = true;
45 $scope.uploading = false;
46
47 $scope.error = {
48 modal_title: "",
49 title: "",
50 desc: "",
51 type: "warning"
52 };
53
54 $scope.activateImage = function(imageId){
55 $scope.activate_image_id = imageId;
56 $scope.preserve_settings_confirm = true;
57 }
58
59 $scope.displayError = function(data){
60 $scope.error = data;
61 $scope.display_error = true;
62 }
63
64 $scope.preserveSettingsConfirmed = function(){
Iftekharul Islam2a489552017-11-02 13:23:08 -050065 $scope.uploading = true;
66 APIUtils.activateImage($scope.activate_image_id).then(function(response){
Gunnar Millseedefd32018-02-28 17:02:34 -060067 $scope.uploading = false;
Iftekharul Islam2a489552017-11-02 13:23:08 -050068 if(response.status == 'error'){
69 $scope.displayError({
70 modal_title: response.data.description,
71 title: response.data.description,
72 desc: response.data.exception,
73 type: 'Error'
74 });
75 }else{
76 $scope.loadFirmwares();
77 }
78 });
Iftekharul Islamc0161392017-06-14 15:46:15 -050079 $scope.preserve_settings_confirm = false;
80 }
81
82 $scope.confirmWarmReboot = function(){
83 $scope.reboot_confirm = false;
84 }
85
86 $scope.upload = function(){
Gunnar Millsdddb1492018-02-19 16:27:27 -060087 if($scope.file) {
88 $scope.uploading = true;
89 APIUtils.uploadImage($scope.file).then(function(response){
90 $scope.uploading = false;
91 if(response.status == 'error'){
92 $scope.displayError({
93 modal_title: response.data.description,
94 title: response.data.description,
95 desc: response.data.exception,
96 type: 'Error'
97 });
98 }else{
99 $scope.loadFirmwares();
100 }
101 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500102 }
103 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500104
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500105 $scope.download = function(){
106 $scope.downloading = true;
107 APIUtils.downloadImage($scope.download_host, $scope.download_filename).then(function(response){
108 var data = response.data;
109 $scope.downloading = false;
110 var headers = response.headers();
111
112 var filename = headers['x-filename'];
113 var contentType = headers['content-type'];
114
115 if(!headers['x-filename']){
Iftekharul Islam2a489552017-11-02 13:23:08 -0500116 filename = $scope.download_filename;
Iftekharul Islam1acb4122017-11-02 13:20:32 -0500117 }
118
119 var linkElement = document.createElement('a');
120 try {
121 var blob = new Blob([data], { type: contentType });
122 var url = window.URL.createObjectURL(blob);
123
124 linkElement.setAttribute('href', url);
125 linkElement.setAttribute("download", filename);
126
127 var clickEvent = new MouseEvent("click", {
128 "view": window,
129 "bubbles": true,
130 "cancelable": false
131 });
132 linkElement.dispatchEvent(clickEvent);
133 } catch (ex) {
134 console.log(ex);
135 }
136 });
137 }
138
139 $scope.changePriority = function(imageId, from, to){
140 $scope.priority_image_id = imageId;
141 $scope.priority_from = from;
142 $scope.priority_to = to;
143
144 if((from + to) == 1){
145 $scope.confirm_priority = true;
146 }else{
147 $scope.confirmChangePriority();
148 }
149 }
150
151 $scope.confirmChangePriority = function(){
152 $scope.loading = true;
153 APIUtils.changePriority($scope.priority_image_id, $scope.priority_to).then(function(response){
154 $scope.loading = false;
155 if(response.status == 'error'){
156 $scope.displayError({
157 modal_title: response.data.description,
158 title: response.data.description,
159 desc: response.data.exception,
160 type: 'Error'
161 });
162 }else{
163 $scope.loadFirmwares();
164 }
165 });
166 $scope.confirm_priority = false;
167 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500168 $scope.deleteImage = function(imageId){
169 $scope.delete_image_id = imageId;
170 $scope.confirm_delete = true;
171 }
Iftekharul Islam2a489552017-11-02 13:23:08 -0500172 $scope.confirmDeleteImage = function(){
173 $scope.loading = true;
174 APIUtils.deleteImage($scope.delete_image_id).then(function(response){
175 $scope.loading = false;
176 if(response.status == 'error'){
177 $scope.displayError({
178 modal_title: response.data.description,
179 title: response.data.description,
180 desc: response.data.exception,
181 type: 'Error'
182 });
183 }else{
184 $scope.loadFirmwares();
185 }
186 });
Iftekharul Islamc0161392017-06-14 15:46:15 -0500187 $scope.confirm_delete = false;
188 }
Iftekharul Islamc0161392017-06-14 15:46:15 -0500189 $scope.fileNameChanged = function(){
190 $scope.file_empty = false;
191 }
192
193 $scope.uploading = false;
194 $scope.filters = {
195 bmc: {
196 imageType: 'BMC'
197 },
198 host: {
199 imageType: 'Host'
200 }
201 };
202
203 $scope.loadFirmwares = function(){
Michael Davisdf3bd122017-08-10 11:03:42 -0500204 APIUtils.getFirmwares().then(function(result){
205 $scope.firmwares = result.data;
206 $scope.bmcActiveVersion = result.bmcActiveVersion;
207 $scope.hostActiveVersion = result.hostActiveVersion;
Iftekharul Islamc0161392017-06-14 15:46:15 -0500208 });
209 }
210
211 $scope.loadFirmwares();
Michael Davis43366db2017-05-15 18:12:35 -0500212 }
213 ]
214 );
215
216})(angular);