mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
reduce delete prompting cruft for app ui
This commit is contained in:
parent
3cf447c49b
commit
80db90b34c
@ -7,7 +7,6 @@ function ListApplicationsController (
|
||||
$filter,
|
||||
$scope,
|
||||
$state,
|
||||
Alert,
|
||||
Dataset,
|
||||
ProcessErrors,
|
||||
Prompt,
|
||||
@ -57,82 +56,56 @@ function ListApplicationsController (
|
||||
return html;
|
||||
};
|
||||
|
||||
vm.deleteApplication = app => {
|
||||
if (!app) {
|
||||
Alert(strings.get('error.DELETE'), strings.get('alert.MISSING_PARAMETER'));
|
||||
return;
|
||||
}
|
||||
vm.deleteApplication = (app) => {
|
||||
const action = () => {
|
||||
$('#prompt-modal').modal('hide');
|
||||
Wait('start');
|
||||
application.request('delete', app.id)
|
||||
.then(() => {
|
||||
let reloadListStateParams = null;
|
||||
|
||||
application.getDependentResourceCounts(application.id)
|
||||
.then(counts => displayApplicationDeletePrompt(app, counts));
|
||||
};
|
||||
if ($scope.applications.length === 1 && $state.params.application_search &&
|
||||
!_.isEmpty($state.params.application_search.page) &&
|
||||
$state.params.application_search.page !== '1') {
|
||||
const page = `${(parseInt(reloadListStateParams
|
||||
.application_search.page, 10) - 1)}`;
|
||||
reloadListStateParams = _.cloneDeep($state.params);
|
||||
reloadListStateParams.application_search.page = page;
|
||||
}
|
||||
|
||||
function createErrorHandler (path, action) {
|
||||
return ({ data, status }) => {
|
||||
const hdr = strings.get('error.HEADER');
|
||||
const msg = strings.get('error.CALL', { path, action, status });
|
||||
ProcessErrors($scope, data, status, null, { hdr, msg });
|
||||
if (parseInt($state.params.application_id, 10) === app.id) {
|
||||
$state.go('^', reloadListStateParams, { reload: true });
|
||||
} else {
|
||||
$state.go('.', reloadListStateParams, { reload: true });
|
||||
}
|
||||
})
|
||||
.catch(({ data, status }) => {
|
||||
ProcessErrors($scope, data, status, null, {
|
||||
hdr: strings.get('error.HEADER'),
|
||||
msg: strings.get('error.CALL', { path: `${application.path}${app.id}`, status })
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
Wait('stop');
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function handleSuccessfulDelete (app) {
|
||||
const { page } = _.get($state.params, 'application_search');
|
||||
let reloadListStateParams = null;
|
||||
const deleteModalBody = `<div class="Prompt-bodyQuery">${strings.get('deleteResource.CONFIRM', 'application')}</div>`;
|
||||
|
||||
if ($scope.applications.length === 1 && !_.isEmpty(page) && page !== '1') {
|
||||
reloadListStateParams = _.cloneDeep($state.params);
|
||||
const pageNumber = (parseInt(reloadListStateParams.application_search.page, 0) - 1);
|
||||
reloadListStateParams.application_search.page = pageNumber.toString();
|
||||
}
|
||||
|
||||
if (parseInt($state.params.application_id, 0) === app.id) {
|
||||
$state.go('applications', reloadListStateParams, { reload: true });
|
||||
} else {
|
||||
$state.go('.', reloadListStateParams, { reload: true });
|
||||
}
|
||||
}
|
||||
|
||||
function displayApplicationDeletePrompt (app, counts) {
|
||||
Prompt({
|
||||
action () {
|
||||
$('#prompt-modal').modal('hide');
|
||||
Wait('start');
|
||||
application
|
||||
.request('delete', app.id)
|
||||
.then(() => handleSuccessfulDelete(app))
|
||||
.catch(createErrorHandler('delete application', 'DELETE'))
|
||||
.finally(() => Wait('stop'));
|
||||
},
|
||||
hdr: strings.get('DELETE'),
|
||||
hdr: strings.get('deleteResource.HEADER'),
|
||||
resourceName: $filter('sanitize')(app.name),
|
||||
body: buildApplicationDeletePromptHTML(counts),
|
||||
body: deleteModalBody,
|
||||
action,
|
||||
actionText: 'DELETE'
|
||||
});
|
||||
}
|
||||
|
||||
function buildApplicationDeletePromptHTML (counts) {
|
||||
const buildCount = count => `<span class="badge List-titleBadge">${count}</span>`;
|
||||
const buildLabel = label => `<span class="Prompt-warningResourceTitle">
|
||||
${$filter('sanitize')(label)}</span>`;
|
||||
const buildCountLabel = ({ count, label }) => `<div>
|
||||
${buildLabel(label)}${buildCount(count)}</div>`;
|
||||
|
||||
const displayedCounts = counts.filter(({ count }) => count > 0);
|
||||
|
||||
const html = `
|
||||
${displayedCounts.length ? strings.get('deleteResource.USED_BY', 'application') : ''}
|
||||
${strings.get('deleteResource.CONFIRM', 'application')}
|
||||
${displayedCounts.map(buildCountLabel).join('')}
|
||||
`;
|
||||
|
||||
return html;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ListApplicationsController.$inject = [
|
||||
'$filter',
|
||||
'$scope',
|
||||
'$state',
|
||||
'Alert',
|
||||
'Dataset',
|
||||
'ProcessErrors',
|
||||
'Prompt',
|
||||
|
||||
@ -48,9 +48,13 @@
|
||||
</at-row-item>
|
||||
</div>
|
||||
<div class="at-Row-actions">
|
||||
<at-row-action icon="fa-trash" ng-click="vm.deleteApplication(application)"
|
||||
ng-show="application.summary_fields.user_capabilities.delete">
|
||||
<!-- TODO: delete application should be based on user capabilities but that's not
|
||||
implemented in the api yet -->
|
||||
<at-row-action icon="fa-trash" ng-click="vm.deleteApplication(application)">
|
||||
</at-row-action>
|
||||
<!-- <at-row-action icon="fa-trash" ng-click="vm.deleteApplication(application)"
|
||||
ng-show="application.summary_fields.user_capabilities.delete">
|
||||
</at-row-action> -->
|
||||
</div>
|
||||
</at-row>
|
||||
</at-list>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user