2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
22 class SearchUsersCtrl {
23 constructor($log, usersService, $scope) {
24 $scope.UserSearchsIsNull=false;
25 this.scrollApi = {};//scrollTop directive
26 $scope.txtResults = 'result';
28 * Handle all active HTTP requests
29 * activeRequests @type {Array[requests with cancel option]}
31 let activeRequests = [];
32 let clearReq = (req) => {
33 activeRequests.splice(activeRequests.indexOf(req), 1);
37 * this function retrieves users info
39 this.searchUsers = () => {
40 this.isLoading = true;
41 if(this.searchUsersInProgress){
44 this.selectedUser = null;
45 this.searchUsersInProgress = true;
46 this.searchUsersResults = null;
48 let searchUsersReq = usersService.searchUsers(this.searchUserString);
49 activeRequests.push(searchUsersReq);
50 searchUsersReq.promise().then(usersList => {
51 $log.debug('searchUsers found the following users: ', JSON.stringify(usersList));
52 this.searchUsersResults = usersList;
53 $log.debug('searchUsersResults length: ', usersList.length);
54 if (usersList.length != 1) {
55 $scope.txtResults = 'results'
57 $scope.txtResults = 'result'
59 $scope.UserSearchsIsNull=false;
61 $log.error('SearchUsersCtrl.searchUsers: ' + err);
62 $scope.UserSearchsIsNull=true;
64 this.scrollApi.scrollTop();
65 this.searchUsersInProgress = false;
66 clearReq(searchUsersReq);
67 this.isLoading = false;
72 this.isLoading = false;
73 this.searchUsersInProgress = false;
76 this.setSelectedUser = user => {
77 this.selectedUser = user;
82 $scope.$on('$destroy', () => {
83 //cancel all active requests when closing the modal
84 activeRequests.forEach(req => {
90 SearchUsersCtrl.$inject = ['$log', 'usersService', '$scope'];
91 angular.module('ecompApp').controller('SearchUsersCtrl', SearchUsersCtrl);