From 434097101f9efd5f410841c22564a07867e301e1 Mon Sep 17 00:00:00 2001 From: Leigh Johnson Date: Fri, 22 Apr 2016 14:27:58 -0400 Subject: [PATCH] cloneDeep list config and add additional ignored field params --- awx/ui/client/src/app.js | 22 +--- awx/ui/client/src/controllers/Home.js | 112 +----------------- awx/ui/client/src/controllers/Projects.js | 1 - awx/ui/client/src/dashboard/main.js | 3 +- awx/ui/client/src/lists.js | 2 - awx/ui/client/src/lists/HomeHosts.js | 103 ---------------- .../src/search/getSearchHtml.service.js | 7 +- .../client/src/search/tagSearch.controller.js | 3 +- awx/ui/client/src/search/tagSearch.service.js | 5 +- 9 files changed, 14 insertions(+), 244 deletions(-) delete mode 100644 awx/ui/client/src/lists/HomeHosts.js diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index efd17c9661..6880c37411 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -20,7 +20,7 @@ import './lists'; import './widgets'; import './help'; import './filters'; -import {Home, HomeGroups, HomeHosts} from './controllers/Home'; +import {Home, HomeGroups} from './controllers/Home'; import {SocketsController} from './controllers/Sockets'; import {CredentialsAdd, CredentialsEdit, CredentialsList} from './controllers/Credentials'; import {JobsListController} from './controllers/Jobs'; @@ -175,7 +175,6 @@ var tower = angular.module('Tower', [ 'CredentialsHelper', 'StreamListDefinition', 'HomeGroupListDefinition', - 'HomeHostListDefinition', 'ActivityDetailDefinition', 'VariablesHelper', 'SchedulesListDefinition', @@ -269,25 +268,6 @@ var tower = angular.module('Tower', [ } }). - state('dashboardHosts', { - url: '/home/hosts?has_active_failures&name&id', - templateUrl: urlPrefix + 'partials/subhome.html', - controller: HomeHosts, - data: { - activityStream: true, - activityStreamTarget: 'host' - }, - ncyBreadcrumb: { - parent: 'dashboard', - label: "HOSTS" - }, - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] - } - }). - state('jobs', { url: '/jobs', templateUrl: urlPrefix + 'partials/jobs.html', diff --git a/awx/ui/client/src/controllers/Home.js b/awx/ui/client/src/controllers/Home.js index 3d8adebad2..b2fe9dbda8 100644 --- a/awx/ui/client/src/controllers/Home.js +++ b/awx/ui/client/src/controllers/Home.js @@ -1,5 +1,5 @@ /************************************************* - * Copyright (c) 2015 Ansible, Inc. + * Copyright (c) 2016 Ansible, Inc. * * All Rights Reserved *************************************************/ @@ -155,7 +155,6 @@ export function HomeGroups($rootScope, $log, $scope, $filter, $compile, $locatio ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. - var generator = GenerateList, list = HomeGroupList, defaultUrl = GetBasePath('groups'), @@ -517,112 +516,3 @@ HomeGroups.$inject = ['$rootScope', '$log', '$scope', '$filter', '$compile', '$l * @description This loads the page for 'home/hosts' * */ - -export function HomeHosts($scope, $location, $stateParams, HomeHostList, GenerateList, ProcessErrors, ReturnToCaller, ClearScope, - GetBasePath, SearchInit, PaginateInit, FormatDate, SetStatus, ToggleHostEnabled, HostsEdit, Find, ShowJobSummary) { - - ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior - //scope. - - var generator = GenerateList, - list = HomeHostList, - defaultUrl = GetBasePath('hosts'); - - if ($scope.removePostRefresh) { - $scope.removePostRefresh(); - } - $scope.removePostRefresh = $scope.$on('PostRefresh', function () { - for (var i = 0; i < $scope.hosts.length; i++) { - $scope.hosts[i].inventory_name = $scope.hosts[i].summary_fields.inventory.name; - //SetHostStatus($scope['hosts'][i]); - SetStatus({ - $scope: $scope, - host: $scope.hosts[i] - }); - } - - generator.inject(list, { mode: 'edit', scope: $scope }); - - }); - - SearchInit({ - scope: $scope, - set: 'hosts', - list: list, - url: defaultUrl - }); - - PaginateInit({ - scope: $scope, - list: list, - url: defaultUrl - }); - - // Process search params - if ($stateParams.name) { - $scope[HomeHostList.iterator + 'InputDisable'] = false; - $scope[HomeHostList.iterator + 'SearchValue'] = $stateParams.name; - $scope[HomeHostList.iterator + 'SearchField'] = 'name'; - $scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.name.label; - } - - if ($stateParams.id) { - $scope[HomeHostList.iterator + 'InputDisable'] = false; - $scope[HomeHostList.iterator + 'SearchValue'] = $stateParams.id; - $scope[HomeHostList.iterator + 'SearchField'] = 'id'; - $scope[HomeHostList.iterator + 'SearchFieldLabel'] = list.fields.id.label; - $scope[HomeHostList.iterator + 'SearchSelectValue'] = null; - } - - if ($stateParams.has_active_failures) { - $scope[HomeHostList.iterator + 'InputDisable'] = true; - $scope[HomeHostList.iterator + 'SearchValue'] = $stateParams.has_active_failures; - $scope[HomeHostList.iterator + 'SearchField'] = 'has_active_failures'; - $scope[HomeHostList.iterator + 'SearchFieldLabel'] = HomeHostList.fields.has_active_failures.label; - $scope[HomeHostList.iterator + 'SearchSelectValue'] = ($stateParams.has_active_failures === 'true') ? { value: 1 } : { value: 0 }; - } - - $scope.search(list.iterator); - - $scope.refreshHosts = function() { - $scope.search(list.iterator); - }; - - $scope.toggleHostEnabled = function (id, sources) { - ToggleHostEnabled({ - host_id: id, - external_source: sources, - host_scope: $scope - }); - }; - - $scope.editHost = function (host_id) { - var host = Find({ - list: $scope.hosts, - key: 'id', - val: host_id - }); - if (host) { - HostsEdit({ - host_scope: $scope, - host_id: host_id, - inventory_id: host.inventory, - group_id: null, - hostsReload: false, - mode: 'edit' - }); - } - }; - - $scope.showJobSummary = function (job_id) { - ShowJobSummary({ - job_id: job_id - }); - }; - -} - -HomeHosts.$inject = ['$scope', '$location', '$stateParams', 'HomeHostList', 'generateList', 'ProcessErrors', 'ReturnToCaller', - 'ClearScope', 'GetBasePath', 'SearchInit', 'PaginateInit', 'FormatDate', 'SetStatus', 'ToggleHostEnabled', 'HostsEdit', - 'Find', 'ShowJobSummary' -]; diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index a603f69bf2..c7ca0d1ab4 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -28,7 +28,6 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams, mode = (base === 'projects') ? 'edit' : 'select', url = (base === 'teams') ? GetBasePath('teams') + $stateParams.team_id + '/projects/' : defaultUrl, choiceCount = 0; - view.inject(list, { mode: mode, scope: $scope }); $rootScope.flashMessage = null; diff --git a/awx/ui/client/src/dashboard/main.js b/awx/ui/client/src/dashboard/main.js index 80f27a1ff1..bd0fd75743 100644 --- a/awx/ui/client/src/dashboard/main.js +++ b/awx/ui/client/src/dashboard/main.js @@ -2,7 +2,8 @@ import dashboardCounts from './counts/main'; import dashboardGraphs from './graphs/main'; import dashboardLists from './lists/main'; import dashboardDirective from './dashboard.directive'; +import dashboardHosts from './hosts/main'; export default - angular.module('dashboard', [dashboardCounts.name, dashboardGraphs.name, dashboardLists.name]) + angular.module('dashboard', [dashboardHosts.name, dashboardCounts.name, dashboardGraphs.name, dashboardLists.name]) .directive('dashboard', dashboardDirective); diff --git a/awx/ui/client/src/lists.js b/awx/ui/client/src/lists.js index da4aa67f7b..925f57bd65 100644 --- a/awx/ui/client/src/lists.js +++ b/awx/ui/client/src/lists.js @@ -11,7 +11,6 @@ import AllJobs from "./lists/AllJobs"; import Credentials from "./lists/Credentials"; import Groups from "./lists/Groups"; import HomeGroups from "./lists/HomeGroups"; -import HomeHosts from "./lists/HomeHosts"; import Hosts from "./lists/Hosts"; import Inventories from "./lists/Inventories"; import InventoryGroups from "./lists/InventoryGroups"; @@ -39,7 +38,6 @@ export Credentials, Groups, HomeGroups, - HomeHosts, Hosts, Inventories, InventoryGroups, diff --git a/awx/ui/client/src/lists/HomeHosts.js b/awx/ui/client/src/lists/HomeHosts.js deleted file mode 100644 index ffa5fc2d52..0000000000 --- a/awx/ui/client/src/lists/HomeHosts.js +++ /dev/null @@ -1,103 +0,0 @@ -/************************************************* - * Copyright (c) 2015 Ansible, Inc. - * - * All Rights Reserved - *************************************************/ - - -export default - angular.module('HomeHostListDefinition', []) - .value('HomeHostList', { - - name: 'hosts', - iterator: 'host', - selectTitle: 'Add Existing Hosts', - editTitle: 'Hosts', - listTitle: 'Hosts', - index: false, - hover: true, - well: true, - - fields: { - status: { - label: "", - iconOnly: true, - icon: "{{ 'icon-job-' + host.active_failures }}", - awToolTip: "{{ host.badgeToolTip }}", - awTipPlacement: "right", - dataPlacement: "right", - awPopOver: "{{ host.job_status_html }}", - ngClick:"bob", - columnClass: "List-staticColumn--smallStatus", - searchable: false, - nosort: true - }, - name: { - key: true, - label: 'Name', - columnClass: 'col-lg-5 col-md-5 col-sm-5 col-xs-8 ellipsis List-staticColumnAdjacent', - ngClass: "{ 'host-disabled-label': !host.enabled }", - ngClick: "editHost(host.id)" - }, - inventory_name: { - label: 'Inventory', - sourceModel: 'inventory', - sourceField: 'name', - columnClass: 'col-lg-5 col-md-4 col-sm-4 hidden-xs elllipsis', - linkTo: "{{ '/#/inventories/' + host.inventory }}" - }, - enabled: { - label: 'Disabled?', - searchSingleValue: true, - searchType: 'boolean', - searchValue: 'false', - searchOnly: true - }, - has_active_failures: { - label: 'Has failed jobs?', - searchSingleValue: true, - searchType: 'boolean', - searchValue: 'true', - searchOnly: true - }, - has_inventory_sources: { - label: 'Has external source?', - searchSingleValue: true, - searchType: 'boolean', - searchValue: 'true', - searchOnly: true - }, - id: { - label: 'ID', - searchOnly: true - } - }, - - fieldActions: { - - columnClass: 'col-lg-2 col-md-3 col-sm-3 col-xs-4', - - /*active_failures: { - //label: 'Job Status', - //ngHref: "\{\{'/#/hosts/' + host.id + '/job_host_summaries/?inventory=' + inventory_id \}\}", - awPopOver: "{{ host.job_status_html }}", - dataTitle: "{{ host.job_status_title }}", - awToolTip: "{{ host.badgeToolTip }}", - awTipPlacement: 'top', - dataPlacement: 'left', - iconClass: "{{ 'fa icon-failures-' + host.has_active_failures }}" - }*/ - edit: { - label: 'Edit', - ngClick: "editHost(host.id)", - icon: 'icon-edit', - awToolTip: 'Edit host', - dataPlacement: 'top' - } - }, - - actions: { - - } - - }); diff --git a/awx/ui/client/src/search/getSearchHtml.service.js b/awx/ui/client/src/search/getSearchHtml.service.js index 12b9f47da9..b7da64f702 100644 --- a/awx/ui/client/src/search/getSearchHtml.service.js +++ b/awx/ui/client/src/search/getSearchHtml.service.js @@ -1,16 +1,21 @@ export default ['GetBasePath', function(GetBasePath) { // given the list, return the fields that need searching this.getList = function(list) { - var f = _.clone(list.fields); + var f = _.cloneDeep(list.fields); return JSON.stringify(Object .keys(f) .filter(function(i) { return (f[i] .searchable !== false); }).map(function(i) { + // delete any fields which might include AngularJS interpolation tags {{ }} delete f[i].awToolTip; + delete f[i].awPopover; + delete f[i].linkTo; + delete f[i].dataTitle; delete f[i].ngClass; delete f[i].ngClick; + delete f[i].icon; return {[i]: f[i]}; }).reduce(function (acc, i) { var key = Object.keys(i); diff --git a/awx/ui/client/src/search/tagSearch.controller.js b/awx/ui/client/src/search/tagSearch.controller.js index 21121a648a..a07362bfba 100644 --- a/awx/ui/client/src/search/tagSearch.controller.js +++ b/awx/ui/client/src/search/tagSearch.controller.js @@ -1,7 +1,8 @@ export default ['$scope', 'Refresh', 'tagSearchService', function($scope, Refresh, tagSearchService) { // JSONify passed field elements that can be searched - $scope.list = JSON.parse($scope.list); + console.log($scope.list) + $scope.list = angular.fromJson($scope.list); // Access config lines from list spec $scope.listConfig = $scope.$parent.list; // Grab options for the left-dropdown of the searchbar diff --git a/awx/ui/client/src/search/tagSearch.service.js b/awx/ui/client/src/search/tagSearch.service.js index 7b53d28c8c..eb004a2e39 100644 --- a/awx/ui/client/src/search/tagSearch.service.js +++ b/awx/ui/client/src/search/tagSearch.service.js @@ -35,8 +35,7 @@ export default ['Rest', '$q', 'GetBasePath', 'Wait', 'ProcessErrors', '$log', fu obj.value = value; obj.label = label; obj.type = type; - - + obj.basePath = field['basePath'] || null; // return the built option if (type === 'select') { @@ -79,7 +78,7 @@ export default ['Rest', '$q', 'GetBasePath', 'Wait', 'ProcessErrors', '$log', fu if (needsRequest.length) { // make the options request to reutrn the typeOptions - Rest.setUrl(needsRequest[0].basePath ? needsRequest[0].basePath : basePath); + Rest.setUrl(needsRequest[0].basePath ? GetBasePath(needsRequest[0].basePath) : basePath); Rest.options() .success(function (data) { try {