Moving some states around based on new smart inventory flow

This commit is contained in:
Michael Abashian
2017-04-12 14:24:58 -04:00
committed by Jared Tabor
parent a7dbd00192
commit c1ad7d69fd
8 changed files with 227 additions and 82 deletions

View File

@@ -162,10 +162,16 @@ table, tbody {
// float: right; // float: right;
} }
.List-actionHolder--leftAlign {
width: 50%;
margin-left: 50%;
justify-content: flex-start;
}
.List-actions { .List-actions {
display: flex; display: flex;
margin-bottom: -32px;
margin-top: 18px; margin-top: 18px;
margin-bottom: -34px;
} }
.List-auxAction { .List-auxAction {

View File

@@ -19,6 +19,7 @@ export default ['i18n', function(i18n) {
trackBy: 'host.id', trackBy: 'host.id',
basePath: 'hosts', basePath: 'hosts',
title: false, title: false,
actionHolderClass: 'List-actionHolder List-actionHolder--leftAlign',
fields: { fields: {
toggleHost: { toggleHost: {
@@ -108,7 +109,7 @@ export default ['i18n', function(i18n) {
buttonContent: 'SMART INVENTORY', buttonContent: 'SMART INVENTORY',
ngShow: 'canAdd', ngShow: 'canAdd',
dataPlacement: "top", dataPlacement: "top",
ngDisabled: '!activeHostSearch' ngDisabled: '!enableSmartInventoryButton'
} }
} }
}; };

View File

@@ -15,7 +15,7 @@ function HostsList($scope, HostsList, $rootScope, GetBasePath,
function init(){ function init(){
$scope.canAdd = false; $scope.canAdd = false;
$scope.activeHostSearch = false; $scope.enableSmartInventoryButton = false;
rbacUiControlService.canAdd('hosts') rbacUiControlService.canAdd('hosts')
.then(function(canAdd) { .then(function(canAdd) {
@@ -39,17 +39,22 @@ function HostsList($scope, HostsList, $rootScope, GetBasePath,
}); });
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams) { $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams) {
if(toParams && toParams.host_search) { if(toState.name === 'hosts.addSmartInventory') {
let hasMoreThanDefaultKeys = false; $scope.enableSmartInventoryButton = false;
angular.forEach(toParams.host_search, function(value, key) {
if(key !== 'order_by' && key !== 'page_size') {
hasMoreThanDefaultKeys = true;
}
});
$scope.activeHostSearch = hasMoreThanDefaultKeys ? true : false;
} }
else { else {
$scope.activeHostSearch = false; if(toParams && toParams.host_search) {
let hasMoreThanDefaultKeys = false;
angular.forEach(toParams.host_search, function(value, key) {
if(key !== 'order_by' && key !== 'page_size') {
hasMoreThanDefaultKeys = true;
}
});
$scope.enableSmartInventoryButton = hasMoreThanDefaultKeys ? true : false;
}
else {
$scope.enableSmartInventoryButton = false;
}
} }
}); });
@@ -110,7 +115,7 @@ function HostsList($scope, HostsList, $rootScope, GetBasePath,
}; };
$scope.smartInventory = function() { $scope.smartInventory = function() {
$state.go('hosts.addSmartInventory'); $state.go('inventories.addSmartInventory');
}; };
} }

View File

@@ -78,6 +78,117 @@ export default ['i18n', function(i18n) {
ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)' ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
} }
}, },
related: {} related: {
permissions: {
name: 'permissions',
awToolTip: i18n._('Please save before assigning permissions'),
dataPlacement: 'top',
basePath: 'api/v1/inventories/{{$stateParams.inventory_id}}/access_list/',
type: 'collection',
title: i18n._('Permissions'),
iterator: 'permission',
index: false,
open: false,
search: {
order_by: 'username'
},
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
username: {
key: true,
label: i18n._('User'),
linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
},
role: {
label: i18n._('Role'),
type: 'role',
nosort: true,
class: 'col-lg-4 col-md-4 col-sm-4 col-xs-4',
},
team_roles: {
label: i18n._('Team Roles'),
type: 'team_roles',
nosort: true,
class: 'col-lg-5 col-md-5 col-sm-5 col-xs-4',
}
}
},
hosts: {
name: 'hosts',
// awToolTip: i18n._('Please save before assigning permissions'),
// dataPlacement: 'top',
basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/hosts/',
type: 'collection',
title: i18n._('Hosts'),
iterator: 'host',
index: false,
open: false,
// search: {
// order_by: 'username'
// },
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
// ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
name: {
label: i18n._('Name'),
// linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
}
}
},
//this is a placeholder for when we're ready for completed jobs
completed_jobs: {
name: 'completed_jobs',
// awToolTip: i18n._('Please save before assigning permissions'),
// dataPlacement: 'top',
basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/completed_jobs/',
type: 'collection',
title: i18n._('Completed Jobs'),
iterator: 'completed_job',
index: false,
open: false,
// search: {
// order_by: 'username'
// },
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
// ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
name: {
label: i18n._('Name'),
// linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
}
}
}
}
};}]; };}];

View File

@@ -63,11 +63,31 @@ export default ['i18n', function(i18n) {
actions: { actions: {
add: { add: {
mode: 'all', // One of: edit, select, all mode: 'all', // One of: edit, select, all
ngClick: 'addInventory()', type: 'buttonDropdown',
basePaths: ['inventories'],
awToolTip: i18n._('Create a new inventory'), awToolTip: i18n._('Create a new inventory'),
actionClass: 'btn List-buttonSubmit', actionClass: 'btn List-dropdownSuccess',
buttonContent: '+ ' + i18n._('ADD'), buttonContent: '+ ' + i18n._('ADD'),
ngShow: 'canAdd' options: [
{
optionContent: i18n._('Inventory'),
optionSref: 'inventories.add',
ngShow: 'canAddInventory'
},
{
optionContent: i18n._('Smart Inventory'),
optionSref: 'inventories.addSmartInventory',
//TODO: this should have its own permission
ngShow: 'canAddInventory'
},
{
optionContent: i18n._('SCM Inventory'),
optionSref: 'inventories.addSCMInventory',
//TODO: this should have its own permission
ngShow: 'canAddInventory'
}
],
ngShow: 'canAddInventory || canAddSmartInventory || canAddSCMInventory'
} }
}, },

View File

@@ -23,8 +23,8 @@ function InventoriesList($scope, $rootScope, $location,
$scope.canAdd = false; $scope.canAdd = false;
rbacUiControlService.canAdd('inventory') rbacUiControlService.canAdd('inventory')
.then(function(params) { .then(function(canAdd) {
$scope.canAdd = params.canAdd; $scope.canAddInventory = canAdd;
}); });
$scope.$watchCollection(list.name, function(){ $scope.$watchCollection(list.name, function(){

View File

@@ -32,17 +32,17 @@ angular.module('inventory', [
let stateDefinitions = stateDefinitionsProvider.$get(), let stateDefinitions = stateDefinitionsProvider.$get(),
stateExtender = $stateExtenderProvider.$get(); stateExtender = $stateExtenderProvider.$get();
function generateHostStates() { function generateInventoryStates() {
let smartInventoryAdd = { let smartInventoryAdd = {
name: 'hosts.addSmartInventory', name: 'inventories.addSmartInventory',
url: '/smartinventory', url: '/smartinventory',
form: 'SmartInventoryForm', form: 'SmartInventoryForm',
ncyBreadcrumb: { ncyBreadcrumb: {
label: "CREATE SMART INVENTORY" label: "CREATE SMART INVENTORY"
}, },
views: { views: {
'form@hosts': { 'form@inventories': {
templateProvider: function(SmartInventoryForm, GenerateForm) { templateProvider: function(SmartInventoryForm, GenerateForm) {
return GenerateForm.buildHTML(SmartInventoryForm, { return GenerateForm.buildHTML(SmartInventoryForm, {
mode: 'add', mode: 'add',
@@ -56,7 +56,7 @@ angular.module('inventory', [
let smartInventoryAddOrgLookup = { let smartInventoryAddOrgLookup = {
searchPrefix: 'organization', searchPrefix: 'organization',
name: 'hosts.addSmartInventory.organization', name: 'inventories.addSmartInventory.organization',
url: '/organization', url: '/organization',
data: { data: {
formChildState: true formChildState: true
@@ -108,7 +108,61 @@ angular.module('inventory', [
}, },
}; };
let hosts = stateDefinitions.generateTree({ let inventories = stateDefinitions.generateTree({
parent: 'inventories', // top-most node in the generated tree (will replace this state definition)
modes: ['add', 'edit'],
list: 'InventoryList',
form: 'InventoryForm',
controllers: {
list: 'InventoryListController',
add: 'InventoryAddController',
edit: 'InventoryEditController',
related: {
groups: 'GroupsListController'
}
},
urls: {
list: '/inventories'
},
ncyBreadcrumb: {
label: N_('INVENTORIES')
},
views: {
'@': {
templateUrl: templateUrl('inventories/inventories')
},
'list@inventories': {
templateProvider: function(InventoryList, generateList) {
let html = generateList.build({
list: InventoryList,
mode: 'edit'
});
return html;
},
controller: 'InventoryListController'
}
}
});
return Promise.all([
inventories
]).then((generated) => {
return {
states: _.reduce(generated, (result, definition) => {
return result.concat(definition.states);
}, [
stateExtender.buildDefinition(smartInventoryAdd),
stateExtender.buildDefinition(smartInventoryAddOrgLookup)
])
};
});
}
$stateProvider.state({
name: 'hosts',
url: '/hosts',
lazyLoad: () => stateDefinitions.generateTree({
parent: 'hosts', // top-most node in the generated tree (will replace this state definition) parent: 'hosts', // top-most node in the generated tree (will replace this state definition)
modes: ['edit'], modes: ['edit'],
list: 'HostsList', list: 'HostsList',
@@ -149,67 +203,13 @@ angular.module('inventory', [
controller: 'HostListController' controller: 'HostListController'
} }
} }
});
return Promise.all([
hosts
]).then((generated) => {
return {
states: _.reduce(generated, (result, definition) => {
return result.concat(definition.states);
}, [
stateExtender.buildDefinition(smartInventoryAdd),
stateExtender.buildDefinition(smartInventoryAddOrgLookup)
])
};
});
}
$stateProvider.state({
name: 'inventories',
url: '/inventories',
lazyLoad: () => stateDefinitions.generateTree({
parent: 'inventories', // top-most node in the generated tree (will replace this state definition)
modes: ['add', 'edit'],
list: 'InventoryList',
form: 'InventoryForm',
controllers: {
list: 'InventoryListController',
add: 'InventoryAddController',
edit: 'InventoryEditController',
related: {
groups: 'GroupsListController'
}
},
urls: {
list: '/inventories'
},
ncyBreadcrumb: {
label: N_('INVENTORIES')
},
views: {
'@': {
templateUrl: templateUrl('inventories/inventories')
},
'list@inventories': {
templateProvider: function(InventoryList, generateList) {
let html = generateList.build({
list: InventoryList,
mode: 'edit'
});
return html;
},
controller: 'InventoryListController'
}
}
}) })
}); });
$stateProvider.state({ $stateProvider.state({
name: 'hosts', name: 'inventories',
url: '/hosts', url: '/inventories',
lazyLoad: () => generateHostStates() lazyLoad: () => generateInventoryStates()
}); });
} }
]); ]);

View File

@@ -174,7 +174,9 @@ export default ['$compile', 'Attr', 'Icon',
html += (!list.wellOverride) ? "List-well" : ""; html += (!list.wellOverride) ? "List-well" : "";
html += `">`; html += `">`;
// List actions // List actions
html += "<div class=\"List-actionHolder\">"; html += "<div class=\"";
html += (list.actionHolderClass) ? list.actionHolderClass : "List-actionHolder";
html += "\">";
html += "<div class=\"List-actions\">"; html += "<div class=\"List-actions\">";
html += `<div ng-include="'${templateUrl('shared/list-generator/list-actions')}'">`; html += `<div ng-include="'${templateUrl('shared/list-generator/list-actions')}'">`;