Implement firmware upload function

Change-Id: Ie89793ec9add1fc9e5241b422cfff64784f7b078
Signed-off-by: Iftekharul Islam <iislam@us.ibm.com>
diff --git a/app/configuration/controllers/firmware-controller.js b/app/configuration/controllers/firmware-controller.js
index 0eef4ea..2bdfced 100644
--- a/app/configuration/controllers/firmware-controller.js
+++ b/app/configuration/controllers/firmware-controller.js
@@ -27,6 +27,99 @@
                         $location.hash('upload');
                         $anchorScroll();
                     };
+
+                    $scope.firmwares = [];
+                    $scope.bmcActiveVersion = "";
+                    $scope.hostActiveVersion = "";
+                    $scope.display_error = false;
+                    $scope.confirm_upload_image = false;
+                    $scope.reboot_confirm = false;
+                    $scope.preserve_settings_confirm = false;
+                    $scope.delete_image_id = "";
+                    $scope.activate_image_id = "";
+                    $scope.file_empty = true;
+                    $scope.uploading = false;
+
+                    $scope.error = {
+                        modal_title: "",
+                        title: "",
+                        desc: "",
+                        type: "warning"
+                    };
+
+                    $scope.activateImage = function(imageId){
+                        $scope.activate_image_id = imageId;
+                        $scope.preserve_settings_confirm = true;
+                    }
+
+                    $scope.displayError = function(data){
+                        $scope.error = data;
+                        $scope.display_error = true;
+                    }
+
+                    $scope.preserveSettingsConfirmed = function(){
+                        //show progress..callapi..hide..iferror..show error
+                        $scope.preserve_settings_confirm = false;
+                    }
+
+                    $scope.confirmWarmReboot = function(){
+                        $scope.reboot_confirm = false;
+                    }
+
+                    $scope.upload = function(){
+                        if(!$scope.file_empty){
+                            $scope.confirm_upload_image = true;
+                        }
+                    }
+                    $scope.confirmUpload = function(){
+                        $scope.uploading = true;
+                        APIUtils.uploadImage($scope.file, function(response){
+                            $scope.uploading = false; 
+                            if(response.status == 'error'){
+                                $scope.displayError({
+                                    modal_title: response.data.description,
+                                    title: response.data.description,
+                                    desc: response.data.exception,
+                                    type: 'Error'
+                                });
+                            }else{
+                                $scope.loadFirmwares();
+                            }
+                        });
+                        $scope.confirm_upload_image = false;
+                    }
+
+                    $scope.deleteImage = function(imageId){
+                        $scope.delete_image_id = imageId;
+                        $scope.confirm_delete = true;
+                    }
+                    $scope.confirmDeleteImage = function(imageId){
+                        $scope.confirm_delete = false;
+                    }
+
+                    $scope.fileNameChanged = function(){
+                        $scope.file_empty = false;
+                    }
+
+                    $scope.uploading = false;
+                    $scope.filters = {
+                        bmc: {
+                            imageType: 'BMC'
+                        },
+                        host: {
+                            imageType: 'Host'
+                        }
+                    };
+
+                    $scope.loadFirmwares = function(){
+                        APIUtils.getFirmwares(function(data, bmcActiveVersion, hostActiveVersion){
+                           $scope.firmwares = data;
+                           $scope.bmcActiveVersion = bmcActiveVersion;
+                           $scope.hostActiveVersion = hostActiveVersion;
+                        });
+                    }
+
+                    $scope.loadFirmwares();
                 }
             ]
         );