diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.controller.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.controller.js new file mode 100644 index 0000000000..9cd09d55e5 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.controller.js @@ -0,0 +1,19 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + + export default + ['$scope', '$state', '$stateParams', 'DashboardHostsForm', 'GenerateForm', 'host', + function($scope, $state, $stateParams, DashboardHostsForm, GenerateForm, host){ + var generator = GenerateForm, + form = DashboardHostsForm; + + var init = function(){ + $scope.host = host; + GenerateForm.inject(form, {mode: 'edit', related: false, scope: $scope}); + }; + + init(); + }]; \ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.partial.html b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.partial.html new file mode 100644 index 0000000000..5db1583d13 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-edit.partial.html @@ -0,0 +1,4 @@ +
+
+
+
diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.controller.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.controller.js new file mode 100644 index 0000000000..7e891cd1f2 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.controller.js @@ -0,0 +1,48 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +export default + ['$scope', '$state', '$stateParams', 'Rest', 'GetBasePath', 'DashboardHostsList', + 'generateList', 'PaginateInit', 'SetStatus', 'DashboardHostsService', 'hosts', + function($scope, $state, $stateParams, Rest, GetBasePath, DashboardHostsList, GenerateList, PaginateInit, SetStatus, DashboardHostsService, hosts){ + var generator = GenerateList, + list = DashboardHostsList, + defaultUrl = GetBasePath('hosts'); + $scope.editHost = function(id){ + $state.go('dashboardHosts.edit', {id: id}); + }; + $scope.toggleHostEnabled = function(host){ + DashboardHostsService.setHostStatus(host, !host.enabled) + .then(function(res){ + var index = _.findIndex($scope.hosts, function(o) {return o.id === res.data.id;}); + $scope.hosts[index].enabled = res.data.enabled; + }); + }; + var setJobStatus = function(){ + _.forEach($scope.hosts, function(value, key){ + SetStatus({ + scope: $scope, + host: value + }); + }); + }; + var init = function(){ + $scope.list = list; + $scope.host_active_search = false; + $scope.host_total_rows = hosts.length; + $scope.hosts = hosts; + setJobStatus(); + generator.inject(list, {mode: 'edit', scope: $scope}); + PaginateInit({ + scope: $scope, + list: list, + url: defaultUrl + }); + console.log($scope) + $scope.hostLoading = false; + }; + init(); + }]; \ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.partial.html b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.partial.html new file mode 100644 index 0000000000..53511acd75 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts-list.partial.html @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.form.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.form.js new file mode 100644 index 0000000000..78a895953d --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.form.js @@ -0,0 +1,66 @@ +/************************************************* +* Copyright (c) 2016 Ansible, Inc. +* +* All Rights Reserved +*************************************************/ + +export default function(){ + return { + editTitle: '{{host.name}}', + name: 'host', + well: true, + formLabelSize: 'col-lg-3', + formFieldSize: 'col-lg-9', + headerFields:{ + enabled: { + label: 'Enabled?', + type: 'checkbox', + editRequired: false, + 'default': true, + awPopOver: "

Indicates if a host is available and should be included in running jobs.

For hosts that " + + "are part of an external inventory, this flag cannot be changed. It will be set by the inventory sync process.

", + dataTitle: 'Host Enabled' + } + }, + fields: { + enabled: { + label: 'Status', + columnClass: 'List-staticColumn--toggle', + type: 'toggle', + ngClick: 'toggleHostEnabled(host)', + searchable: false, + nosort: true + }, + name: { + label: 'Host Name', + type: 'text', + editRequired: true, + awPopOver: "

Provide a host name, ip address, or ip address:port. Examples include:

" + + "
myserver.domain.com
" + + "127.0.0.1
" + + "10.1.0.140:25
" + + "server.example.com:25" + + "
", + }, + description: { + label: 'Description', + type: 'text', + editRequired: false + }, + variables: { + label: 'Variables', + type: 'textarea', + editRequired: false, + rows: 6, + default: '---', + awPopOver: "

Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

" + + "JSON:
\n" + + "
{
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
\n" + + "YAML:
\n" + + "
---
somevar: somevalue
password: magic
\n" + + '

View JSON examples at www.json.org

' + + '

View YAML examples at docs.ansible.com

', + } + } + } +}; \ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.list.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.list.js new file mode 100644 index 0000000000..aac8f8b330 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.list.js @@ -0,0 +1,91 @@ +/************************************************* +* Copyright (c) 2015 Ansible, Inc. +* +* All Rights Reserved +*************************************************/ + + +export default function(){ + return { + name: 'hosts', + iterator: 'host', + selectTitle: 'Add Existing Hosts', + editTitle: 'Hosts', + listTitle: 'Hosts', + index: false, + hover: true, + well: true, + + fields: { + status: { + basePath: 'unified_jobs', + label: '', + iconOnly: true, + searchable: true, + searchType: 'select', + nosort: true, + searchOptions: [], + searchLabel: 'Job Status', + icon: 'icon-job-{{ host.active_failures }}', + awToolTip: '{{ host.badgeToolTip }}', + awTipPlacement: 'right', + dataPlacement: 'right', + awPopOver: '{{ host.job_status_html }}', + ngClick:'viewHost(host.id)', + columnClass: 'col-lg-1 col-md-1 col-sm-2 col-xs-2 List-staticColumn--smallStatus' + }, + name: { + key: true, + label: 'Name', + columnClass: 'col-lg-5 col-md-5 col-sm-5 col-xs-8 ellipsis List-staticColumnAdjacent', + 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_id }}", + searchable: false + }, + enabled: { + label: 'Status', + columnClass: 'List-staticColumn--toggle', + type: 'toggle', + ngClick: 'toggleHostEnabled(host)', + searchable: false, + nosort: 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 + } + }, + + fieldActions: { + + columnClass: 'col-lg-2 col-md-3 col-sm-3 col-xs-4', + edit: { + label: 'Edit', + ngClick: 'editHost(host.id)', + icon: 'icon-edit', + awToolTip: 'Edit host', + dataPlacement: 'top' + } + }, + + actions: { + + } + } +}; diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js new file mode 100644 index 0000000000..ced2ebfc63 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js @@ -0,0 +1,62 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +import {templateUrl} from '../../shared/template-url/template-url.factory'; +import listController from './dashboard-hosts-list.controller'; +import editController from './dashboard-hosts-edit.controller'; + +var dashboardHostsList = { + name: 'dashboardHosts', + url: '/home/hosts', + controller: listController, + templateUrl: templateUrl('dashboard/hosts/dashboard-hosts-list'), + data: { + activityStream: true, + activityStreamTarget: 'host' + }, + ncyBreadcrumb: { + parent: 'dashboard', + label: "HOSTS" + }, + resolve: { + features: ['FeaturesService', function(FeaturesService) { + return FeaturesService.get(); + }], + hosts: ['Rest', 'GetBasePath', function(Rest, GetBasePath){ + var defaultUrl = GetBasePath('hosts') + '?page_size=10'; + Rest.setUrl(defaultUrl); + return Rest.get().then(function(res){ + return _.map(res.data.results, function(value, key){ + value.inventory_name = value.summary_fields.inventory.name; + value.inventory_id = value.summary_fields.inventory.id; + return value; + }); + }); + }] + } +}; + +var dashboardHostsEdit = { + name: 'dashboardHosts.edit', + url: '/:id', + controller: editController, + templateUrl: templateUrl('dashboard/hosts/dashboard-hosts-edit'), + ncyBreadcrumb: { + parent: 'dashboardHosts', + label: "{{host.name}}" + }, + resolve: { + host: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ + var defaultUrl = GetBasePath('hosts') + '?id=' + $stateParams.id; + Rest.setUrl(defaultUrl); + return Rest.get().then(function(res){ + return res.data.results[0]; + }); + }] + } +}; + +export {dashboardHostsList, dashboardHostsEdit}; \ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.service.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.service.js new file mode 100644 index 0000000000..f85050e060 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.service.js @@ -0,0 +1,18 @@ +export default + ['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', function($rootScope, Rest, GetBasePath, ProcessErrors){ + return { + + setHostStatus: function(host, enabled){ + var url = GetBasePath('hosts') + host.id; + Rest.setUrl(url); + return Rest.put({enabled: enabled, name: host.name}) + .success(function(data){ + return data; + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + } + }; + }]; \ No newline at end of file diff --git a/awx/ui/client/src/dashboard/hosts/main.js b/awx/ui/client/src/dashboard/hosts/main.js new file mode 100644 index 0000000000..65f0da2373 --- /dev/null +++ b/awx/ui/client/src/dashboard/hosts/main.js @@ -0,0 +1,20 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +import {dashboardHostsList, dashboardHostsEdit} from './dashboard-hosts.route'; +import list from './dashboard-hosts.list'; +import form from './dashboard-hosts.form'; +import service from './dashboard-hosts.service'; + +export default + angular.module('dashboardHosts', []) + .service('DashboardHostsService', service) + .factory('DashboardHostsList', list) + .factory('DashboardHostsForm', form) + .run(['$stateExtender', function($stateExtender){ + $stateExtender.addState(dashboardHostsList); + $stateExtender.addState(dashboardHostsEdit); + }]);