diff --git a/awx/ui/client/features/credentials/add-credentials.controller.js b/awx/ui/client/features/credentials/add-credentials.controller.js
index 41fbcb5c6a..22fbc0f025 100644
--- a/awx/ui/client/features/credentials/add-credentials.controller.js
+++ b/awx/ui/client/features/credentials/add-credentials.controller.js
@@ -1,50 +1,32 @@
-function AddCredentialsController (credentialType) {
+function AddCredentialsController (models) {
let vm = this || {};
- vm.name = {
- state: {
- required: true
- },
- label: {
- text: 'Name',
- popover: {
- text: 'a, b, c'
- }
- }
- };
-
- vm.description = {
- label: {
- text: 'Description'
- }
- };
-
+ let credential = models.credential;
+ let credentialType = models.credentialType;
+
vm.heading = {
text: 'Create Credentials'
};
+ vm.name = {
+ options: credential.getPostOptions('name')
+ };
+
+ vm.description = {
+ options: credential.getPostOptions('description')
+ };
+
+ vm.dynamic = {
+ update: type => {
+ this.inputs = type ? type.inputs.fields : null;
+ }
+ };
+
vm.kind = {
- state: {
- required: true,
- },
- label: {
- text: 'Type',
- popover: {
- text: 'x, y, z'
- }
- },
- placeholder: 'Select a Type',
- text: 'kind',
- value: 'id',
- data: credentialType.categorizeByKind()
- };
-
- vm.save = {
- type: 'save'
- };
-
- vm.cancel = {
- type: 'cancel'
+ options: credential.getPostOptions('credential_type'),
+ data: credentialType.categorizeByKind(),
+ notify: vm.dynamic.update,
+ placeholder: 'Select a Type'
};
}
diff --git a/awx/ui/client/features/credentials/add-credentials.view.html b/awx/ui/client/features/credentials/add-credentials.view.html
index d9ac817beb..65e4bf62ea 100644
--- a/awx/ui/client/features/credentials/add-credentials.view.html
+++ b/awx/ui/client/features/credentials/add-credentials.view.html
@@ -12,9 +12,11 @@
+
+
-
-
+
+
diff --git a/awx/ui/client/features/credentials/index.js b/awx/ui/client/features/credentials/index.js
index 761bd1e6dc..0ccee11daf 100644
--- a/awx/ui/client/features/credentials/index.js
+++ b/awx/ui/client/features/credentials/index.js
@@ -40,6 +40,21 @@ function config ($stateExtenderProvider, pathServiceProvider) {
}
});
+ function credentialTypeResolve ($q, credentialModel, credentialTypeModel) {
+ let promises = [
+ credentialModel.options(),
+ credentialTypeModel.get()
+ ];
+
+ return $q.all(promises)
+ .then(() => ({
+ credential: credentialModel,
+ credentialType: credentialTypeModel
+ }));
+ }
+
+ credentialTypeResolve.$inject = ['$q', 'CredentialModel', 'CredentialTypeModel'];
+
stateExtender.addState({
name: 'credentials.add',
route: '/add',
@@ -54,9 +69,7 @@ function config ($stateExtenderProvider, pathServiceProvider) {
}
},
resolve: {
- credentialType: ['CredentialType', credentialType => {
- return credentialType.get().then(() => credentialType);
- }]
+ credentialType: credentialTypeResolve
}
});
diff --git a/awx/ui/client/lib/components/action/action.directive.js b/awx/ui/client/lib/components/action/action.directive.js
index 817076b047..5dcf6b41ce 100644
--- a/awx/ui/client/lib/components/action/action.directive.js
+++ b/awx/ui/client/lib/components/action/action.directive.js
@@ -17,12 +17,14 @@ function atActionController ($state) {
form = _form_;
scope = _scope_;
+ scope.config = scope.config || {};
scope.config.state = scope.config.state || {};
+
state = scope.config.state;
scope.form = form.use('action', state);
- switch(scope.config.type) {
+ switch(scope.type) {
case 'cancel':
vm.setCancelDefaults();
break;
@@ -61,7 +63,7 @@ function atAction (pathService) {
controllerAs: 'vm',
link,
scope: {
- config: '='
+ type: '@'
}
};
}
diff --git a/awx/ui/client/lib/components/action/action.partial.html b/awx/ui/client/lib/components/action/action.partial.html
index cb46276e8b..b6f5e9dc90 100644
--- a/awx/ui/client/lib/components/action/action.partial.html
+++ b/awx/ui/client/lib/components/action/action.partial.html
@@ -1,5 +1,5 @@
diff --git a/awx/ui/client/lib/components/input/dynamic-group.directive.js b/awx/ui/client/lib/components/input/dynamic-group.directive.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/awx/ui/client/lib/components/input/dynamic-group.partial.html b/awx/ui/client/lib/components/input/dynamic-group.partial.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/awx/ui/client/lib/components/input/label.partial.html b/awx/ui/client/lib/components/input/label.partial.html
index f1a53a6203..8227c88ff9 100644
--- a/awx/ui/client/lib/components/input/label.partial.html
+++ b/awx/ui/client/lib/components/input/label.partial.html
@@ -1,5 +1,5 @@
diff --git a/awx/ui/client/lib/components/input/select.directive.js b/awx/ui/client/lib/components/input/select.directive.js
index 6662b8cb5d..3b8863a33c 100644
--- a/awx/ui/client/lib/components/input/select.directive.js
+++ b/awx/ui/client/lib/components/input/select.directive.js
@@ -24,6 +24,7 @@ function AtInputSelectController (eventService) {
scope.config.state = scope.config.state || {};
state = scope.config.state;
+ state.required = scope.config.options.required;
if (scope.tab === 1) {
select.focus();
@@ -76,6 +77,10 @@ function AtInputSelectController (eventService) {
state.isValid = isValid;
form.check();
}
+
+ if (scope.config.notify) {
+ scope.config.notify(state.value);
+ }
};
}
diff --git a/awx/ui/client/lib/components/input/select.partial.html b/awx/ui/client/lib/components/input/select.partial.html
index 99e3492a62..3445daf4a5 100644
--- a/awx/ui/client/lib/components/input/select.partial.html
+++ b/awx/ui/client/lib/components/input/select.partial.html
@@ -3,7 +3,6 @@
diff --git a/awx/ui/client/lib/components/input/text.directive.js b/awx/ui/client/lib/components/input/text.directive.js
index 20dd10f52d..d61a79e676 100644
--- a/awx/ui/client/lib/components/input/text.directive.js
+++ b/awx/ui/client/lib/components/input/text.directive.js
@@ -21,6 +21,7 @@ function AtInputTextController () {
scope.config.state = scope.config.state || {};
state = scope.config.state;
+ state.required = scope.config.options.required;
if (scope.tab === '1') {
input.focus();
diff --git a/awx/ui/client/lib/components/input/text.partial.html b/awx/ui/client/lib/components/input/text.partial.html
index f04b8dc93d..c57aadff75 100644
--- a/awx/ui/client/lib/components/input/text.partial.html
+++ b/awx/ui/client/lib/components/input/text.partial.html
@@ -2,7 +2,8 @@
diff --git a/awx/ui/client/lib/components/popover/popover.partial.html b/awx/ui/client/lib/components/popover/popover.partial.html
index 18fbfdac3b..74769372b1 100644
--- a/awx/ui/client/lib/components/popover/popover.partial.html
+++ b/awx/ui/client/lib/components/popover/popover.partial.html
@@ -1,4 +1,4 @@
-
+
@@ -6,6 +6,6 @@
-
{{::config.text}}
+
{{::config.options.help_text}}
diff --git a/awx/ui/client/lib/models/Base.js b/awx/ui/client/lib/models/Base.js
index 4573c44b5a..fe0c067da8 100644
--- a/awx/ui/client/lib/models/Base.js
+++ b/awx/ui/client/lib/models/Base.js
@@ -1,21 +1,29 @@
let $resource;
function options () {
- return this.model.query().$promise
+ let actions = {
+ options: {
+ method: 'OPTIONS'
+ }
+ };
+
+ return $resource(this.path, null, actions).options().$promise
.then(response => {
- this.response = response;
- this.data = this.response.results;
+ this.model.options = response;
});
}
function get () {
return $resource(this.path).get().$promise
.then(response => {
- this.response = response;
- this.data = this.response.results;
+ this.model.data = response;
});
}
+function getPostOptions (name) {
+ return this.model.options.actions.POST[name];
+}
+
function normalizePath (resource) {
let version = '/api/v2/';
@@ -25,9 +33,13 @@ function normalizePath (resource) {
function Base (_$resource_) {
$resource = _$resource_;
- this.options = options;
- this.get = get;
- this.normalizePath = normalizePath;
+ return () => ({
+ model: {},
+ get,
+ options,
+ getPostOptions,
+ normalizePath
+ });
}
Base.$inject = ['$resource'];
diff --git a/awx/ui/client/lib/models/Credential.js b/awx/ui/client/lib/models/Credential.js
index 3914c0ce33..75f5066d0c 100644
--- a/awx/ui/client/lib/models/Credential.js
+++ b/awx/ui/client/lib/models/Credential.js
@@ -1,5 +1,7 @@
function Credential (BaseModel) {
- return Object.assign({}, BaseModel);
+ Object.assign(this, BaseModel());
+
+ this.path = this.normalizePath('credentials');
}
Credential.$inject = ['BaseModel'];
diff --git a/awx/ui/client/lib/models/CredentialType.js b/awx/ui/client/lib/models/CredentialType.js
index 511f9c9b86..9a2c742294 100644
--- a/awx/ui/client/lib/models/CredentialType.js
+++ b/awx/ui/client/lib/models/CredentialType.js
@@ -1,7 +1,7 @@
function categorizeByKind () {
let group = {};
- this.data.forEach(result => {
+ this.model.data.results.forEach(result => {
group[result.kind] = group[result.kind] || [];
group[result.kind].push(result);
});
@@ -12,12 +12,19 @@ function categorizeByKind () {
}));
}
+function getTypeFromName (name) {
+ let type = this.model.data.results.filter(result => result.name === name);
+
+ return type.length ? type[0] : null;
+}
+
function CredentialType (BaseModel) {
- Object.assign(this, BaseModel);
+ Object.assign(this, BaseModel());
this.path = this.normalizePath('credential_types');
this.categorizeByKind = categorizeByKind;
+ this.getTypeFromName = getTypeFromName;
}
CredentialType.$inject = ['BaseModel'];
diff --git a/awx/ui/client/lib/models/index.js b/awx/ui/client/lib/models/index.js
index 75f7aacaf2..287aadb836 100644
--- a/awx/ui/client/lib/models/index.js
+++ b/awx/ui/client/lib/models/index.js
@@ -1,4 +1,5 @@
import Base from './Base';
+import Credential from './Credential';
import CredentialType from './CredentialType';
function config ($resourceProvider) {
@@ -11,5 +12,6 @@ angular
.module('at.lib.models', [])
.config(config)
.service('BaseModel', Base)
- .service('CredentialType', CredentialType);
+ .service('CredentialModel', Credential)
+ .service('CredentialTypeModel', CredentialType);