From 80db90b34ced5645e86dba040b27720a95a995b3 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Mon, 12 Mar 2018 14:35:03 -0400 Subject: [PATCH] reduce delete prompting cruft for app ui --- .../list-applications.controller.js | 99 +++++++------------ .../applications/list-applications.view.html | 8 +- 2 files changed, 42 insertions(+), 65 deletions(-) diff --git a/awx/ui/client/features/applications/list-applications.controller.js b/awx/ui/client/features/applications/list-applications.controller.js index e77ede25c0..fd67589a08 100644 --- a/awx/ui/client/features/applications/list-applications.controller.js +++ b/awx/ui/client/features/applications/list-applications.controller.js @@ -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 = `
${strings.get('deleteResource.CONFIRM', 'application')}
`; - 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 => `${count}`; - const buildLabel = label => ` - ${$filter('sanitize')(label)}`; - const buildCountLabel = ({ count, label }) => `
- ${buildLabel(label)}${buildCount(count)}
`; - - 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', diff --git a/awx/ui/client/features/applications/list-applications.view.html b/awx/ui/client/features/applications/list-applications.view.html index 839178607f..1803e5ab66 100644 --- a/awx/ui/client/features/applications/list-applications.view.html +++ b/awx/ui/client/features/applications/list-applications.view.html @@ -48,9 +48,13 @@
- + + +