mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 17:28:51 -03:30
reduce delete prompting cruft for app ui
This commit is contained in:
@@ -7,7 +7,6 @@ function ListApplicationsController (
|
|||||||
$filter,
|
$filter,
|
||||||
$scope,
|
$scope,
|
||||||
$state,
|
$state,
|
||||||
Alert,
|
|
||||||
Dataset,
|
Dataset,
|
||||||
ProcessErrors,
|
ProcessErrors,
|
||||||
Prompt,
|
Prompt,
|
||||||
@@ -57,82 +56,56 @@ function ListApplicationsController (
|
|||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.deleteApplication = app => {
|
vm.deleteApplication = (app) => {
|
||||||
if (!app) {
|
const action = () => {
|
||||||
Alert(strings.get('error.DELETE'), strings.get('alert.MISSING_PARAMETER'));
|
$('#prompt-modal').modal('hide');
|
||||||
return;
|
Wait('start');
|
||||||
}
|
application.request('delete', app.id)
|
||||||
|
.then(() => {
|
||||||
|
let reloadListStateParams = null;
|
||||||
|
|
||||||
application.getDependentResourceCounts(application.id)
|
if ($scope.applications.length === 1 && $state.params.application_search &&
|
||||||
.then(counts => displayApplicationDeletePrompt(app, counts));
|
!_.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) {
|
if (parseInt($state.params.application_id, 10) === app.id) {
|
||||||
return ({ data, status }) => {
|
$state.go('^', reloadListStateParams, { reload: true });
|
||||||
const hdr = strings.get('error.HEADER');
|
} else {
|
||||||
const msg = strings.get('error.CALL', { path, action, status });
|
$state.go('.', reloadListStateParams, { reload: true });
|
||||||
ProcessErrors($scope, data, status, null, { hdr, msg });
|
}
|
||||||
|
})
|
||||||
|
.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 deleteModalBody = `<div class="Prompt-bodyQuery">${strings.get('deleteResource.CONFIRM', 'application')}</div>`;
|
||||||
const { page } = _.get($state.params, 'application_search');
|
|
||||||
let reloadListStateParams = null;
|
|
||||||
|
|
||||||
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({
|
Prompt({
|
||||||
action () {
|
hdr: strings.get('deleteResource.HEADER'),
|
||||||
$('#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'),
|
|
||||||
resourceName: $filter('sanitize')(app.name),
|
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 = [
|
ListApplicationsController.$inject = [
|
||||||
'$filter',
|
'$filter',
|
||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$state',
|
||||||
'Alert',
|
|
||||||
'Dataset',
|
'Dataset',
|
||||||
'ProcessErrors',
|
'ProcessErrors',
|
||||||
'Prompt',
|
'Prompt',
|
||||||
|
|||||||
@@ -48,9 +48,13 @@
|
|||||||
</at-row-item>
|
</at-row-item>
|
||||||
</div>
|
</div>
|
||||||
<div class="at-Row-actions">
|
<div class="at-Row-actions">
|
||||||
<at-row-action icon="fa-trash" ng-click="vm.deleteApplication(application)"
|
<!-- TODO: delete application should be based on user capabilities but that's not
|
||||||
ng-show="application.summary_fields.user_capabilities.delete">
|
implemented in the api yet -->
|
||||||
|
<at-row-action icon="fa-trash" ng-click="vm.deleteApplication(application)">
|
||||||
</at-row-action>
|
</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>
|
</div>
|
||||||
</at-row>
|
</at-row>
|
||||||
</at-list>
|
</at-list>
|
||||||
|
|||||||
Reference in New Issue
Block a user