X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-FE-common%2Fclient%2Fapp%2Fviews%2Fusers%2Fnew-user-dialogs%2Fbulk-user.controller.js;h=ae3907b2100c6a5408f25f06de37d53f0c177031;hb=80ddb55b9f5569c6443104150cb74ba2ae4fcb08;hp=8c9420d44a375497fdc696d2bdc04d27f9729349;hpb=99565bb6bd87cfc46591cea73985c58c3a3697dd;p=portal.git diff --git a/ecomp-portal-FE-common/client/app/views/users/new-user-dialogs/bulk-user.controller.js b/ecomp-portal-FE-common/client/app/views/users/new-user-dialogs/bulk-user.controller.js index 8c9420d4..ae3907b2 100644 --- a/ecomp-portal-FE-common/client/app/views/users/new-user-dialogs/bulk-user.controller.js +++ b/ecomp-portal-FE-common/client/app/views/users/new-user-dialogs/bulk-user.controller.js @@ -1,21 +1,39 @@ /*- - * ================================================================================ - * ECOMP Portal - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ================================================================================ + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * */ /** * bulk user upload controller @@ -23,7 +41,7 @@ 'use strict'; (function () { class BulkUserModalCtrl { - constructor($scope, $log, $filter, $q, usersService, applicationsService, confirmBoxService, functionalMenuService, ngDialog) { + constructor($scope, $log, $filter, $q, usersService, applicationsService, confirmBoxService, functionalMenuService, ngDialog,$modal) { // Set to true for copious console output var debug = false; @@ -47,6 +65,8 @@ // Flag that indicates background work is proceeding $scope.isProcessing = true; + + $scope.isProcessedRecords = false; // Load user's admin applications applicationsService.getAdminApps().promise().then(apps => { @@ -73,9 +93,11 @@ $scope.selectedApplication = $scope.adminApps[0]; } $scope.isProcessing = false; + $scope.isProcessedRecords = false; }).catch(err => { $log.error('BulkUserModalCtrl::init: getAdminApps threw', err); $scope.isProcessing = false; + $scope.isProcessedRecords = false; }); }; // init @@ -112,8 +134,17 @@ // Caches the file name supplied by the event handler. $scope.fileChangeHandler = (event, files) => { - this.fileSelected = true; - this.fileToRead = files[0]; + var fileName = files[0].name; + var validFormats = ['csv', 'txt']; + //Get file extension + var ext = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); + //Check for valid format + if(validFormats.indexOf(ext) == -1){ + this.fileSelected = false; + }else{ + this.fileSelected = true; + this.fileToRead = files[0]; + } if (debug) $log.debug("BulkUserModalCtrl::fileChangeHandler: file is ", this.fileToRead); }; // file change handler @@ -131,6 +162,8 @@ */ $scope.readValidateFile = () => { $scope.isProcessing = true; + $scope.conformMsg = ''; + $scope.isProcessedRecords = true; $scope.progressMsg = 'Reading upload file..'; var reader = new FileReader(); reader.onload = function(event) { @@ -174,22 +207,26 @@ $log.debug('BulkUserModalCtrl::readValidateFile inner-then ends'); $scope.progressMsg = 'Done.'; $scope.isProcessing = false; + $scope.isProcessedRecords = false; }, function(error) { $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving user-app roles'); $scope.isProcessing = false; + $scope.isProcessedRecords = false; } ); // then of app promises }, function(error) { $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving user info'); $scope.isProcessing = false; + $scope.isProcessedRecords = false; } ); // then of user promises }, function(error) { $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving app role info'); $scope.isProcessing = false; + $scope.isProcessedRecords = false; } ); // then of role promise @@ -340,7 +377,7 @@ if (prevRow == null || prevRow.orgUserId.toLowerCase() !== uploadRow.orgUserId.toLowerCase()) { if (debug) $log.debug('BulkUserModalCtrl::buildAppRoleChecks: create request for orgUserId ' + uploadRow.orgUserId); - let appPromise = usersService.getUserAppRoles(appId, uploadRow.orgUserId,true).promise().then( (userAppRolesResult) => { + let appPromise = usersService.getUserAppRoles(appId, uploadRow.orgUserId,true, false).promise().then( (userAppRolesResult) => { // Reply for unknown user has all defined roles with isApplied=false on each. if (typeof userAppRolesResult[0] !== "undefined") { if (debug) @@ -425,6 +462,8 @@ */ $scope.updateDB = () => { $scope.isProcessing = true; + $scope.conformMsg = ''; + $scope.isProcessedRecords = true; $scope.progressMsg = 'Sending requests to application..'; if (debug) $log.debug('BulkUserModalCtrl::updateDB: request length is ' + appUserRolesRequest.length); @@ -458,11 +497,11 @@ // Run all the promises $q.all(promises).then(function(){ + $scope.conformMsg = 'Processed ' + numberUsersSucceeded + ' users.'; $scope.isProcessing = false; - confirmBoxService.showInformation('Processed ' + numberUsersSucceeded + ' users.').then(isConfirmed => { - // Close the upload-confirm dialog - ngDialog.close(); - }); + $scope.isProcessedRecords = true; + $scope.uploadFile = []; + }); }; // updateDb @@ -486,10 +525,13 @@ // Start the process $scope.readValidateFile(); // Dialog shows progress - ngDialog.open({ - templateUrl: 'app/views/users/new-user-dialogs/bulk-user.confirm.html', - scope: $scope - }); + $modal.open({ + templateUrl: 'app/views/users/new-user-dialogs/bulk-user.confirm.html', + controller: '', + sizeClass: 'modal-medium', + resolve:'', + scope: $scope + }) }; // Invoked by the Cancel button on the confirmation dialog. @@ -500,7 +542,7 @@ init(); } // constructor } // class - BulkUserModalCtrl.$inject = ['$scope', '$log', '$filter', '$q', 'usersService', 'applicationsService', 'confirmBoxService', 'functionalMenuService', 'ngDialog']; + BulkUserModalCtrl.$inject = ['$scope', '$log', '$filter', '$q', 'usersService', 'applicationsService', 'confirmBoxService', 'functionalMenuService', 'ngDialog','$modal']; angular.module('ecompApp').controller('BulkUserModalCtrl', BulkUserModalCtrl); angular.module('ecompApp').directive('fileChange', ['$parse', function($parse){