Merge pull request #518 from gconsidine/ui/fix/credential-kind-list-display

Use credential_type to fetch associated types in list view
This commit is contained in:
Greg Considine 2017-10-10 11:42:34 -04:00 committed by Matthew Jones
commit d23fd0515d
3 changed files with 37 additions and 14 deletions

View File

@ -41,10 +41,7 @@ function LegacyCredentialsService (pathService) {
return qs.search(path, $stateParams[`${list.iterator}_search`]);
}
],
credentialType: ['CredentialTypeModel', CredentialType => {
return new CredentialType('get');
}]
]
}
};

View File

@ -43,21 +43,28 @@ function requestWithCache (method, resource) {
* supported by the API.
*
* @arg {Object} params - An object of keys and values to to format and
* to the URL as a query string. Refer to the API documentation for the
* to the URL as a query string. Refer to the API documentation for the
* resource in use for specifics.
* @arg {Object} config - Configuration specific to the UI to accommodate
* common use cases.
*
* @yields {boolean} - Indicating a match has been found. If so, the results
* @yields {boolean} - Indicating a match has been found. If so, the results
* are set on the model.
*/
function search (params, config) {
function search (params = {}, config = {}) {
let req = {
method: 'GET',
url: this.path,
params
url: this.path
};
if (typeof params === 'string') {
req.url = `?params`;
} else if (Array.isArray(params)) {
req.url += `?${params.join('&')}`;
} else {
req.params = params;
}
return $http(req)
.then(({ data }) => {
if (!data.count) {

View File

@ -5,10 +5,13 @@
*************************************************/
export default ['$scope', 'Rest', 'CredentialList', 'Prompt', 'ProcessErrors', 'GetBasePath',
'Wait', '$state', '$filter', 'rbacUiControlService', 'Dataset', 'credentialType', 'i18n',
'Wait', '$state', '$filter', 'rbacUiControlService', 'Dataset', 'CredentialTypeModel',
'i18n',
function($scope, Rest, CredentialList, Prompt,
ProcessErrors, GetBasePath, Wait, $state, $filter, rbacUiControlService, Dataset,
credentialType, i18n) {
CredentialType, i18n) {
const credentialType = new CredentialType();
var list = CredentialList,
defaultUrl = GetBasePath('credentials');
@ -45,9 +48,25 @@ export default ['$scope', 'Rest', 'CredentialList', 'Prompt', 'ProcessErrors', '
return;
}
$scope[list.name].forEach(credential => {
credential.kind = credentialType.match('id', credential.credential_type).name;
});
const params = $scope[list.name]
.reduce((accumulator, credential) => {
accumulator.push(credential.credential_type);
return accumulator;
}, [])
.filter((id, i, array) => array.indexOf(id) === i)
.map(id => `or__id=${id}`);
credentialType.search(params)
.then(found => {
if (!found) {
return;
}
$scope[list.name].forEach(credential => {
credential.kind = credentialType.match('id', credential.credential_type).name;
});
});
}
// iterate over the list and add fields like type label, after the