From deca2bb5c1eef583dee16cce285996b05d42b32b Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 12 Dec 2016 14:02:59 -0500 Subject: [PATCH 1/2] Various fixes to the templates list based on audit feedback --- awx/ui/client/src/lists/Templates.js | 6 +++-- .../list-generator/list-actions.partial.html | 4 +-- .../list-generator/list-generator.factory.js | 25 +++++++++++++++++-- .../templates/labels/labelsList.directive.js | 6 ++--- .../templates/labels/labelsList.partial.html | 6 ++--- .../list/templates-list.controller.js | 2 +- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/awx/ui/client/src/lists/Templates.js b/awx/ui/client/src/lists/Templates.js index 7db934ffd3..67728dada0 100644 --- a/awx/ui/client/src/lists/Templates.js +++ b/awx/ui/client/src/lists/Templates.js @@ -47,6 +47,7 @@ export default label: i18n._('Labels'), type: 'labels', nosort: true, + showDelete: true, columnClass: 'List-tableCell col-lg-2 col-md-4 hidden-sm hidden-xs' } }, @@ -58,7 +59,7 @@ export default basePaths: ['templates'], awToolTip: i18n._('Create a new template'), actionClass: 'btn List-dropdownSuccess', - buttonContent: i18n._('ADD'), + buttonContent: '+ ' + i18n._('ADD'), options: [ { optionContent: i18n._('Job Template'), @@ -109,7 +110,8 @@ export default awToolTip: i18n._('Edit template'), "class": 'btn-default btn-xs', dataPlacement: 'top', - ngShow: 'template.summary_fields.user_capabilities.edit' + ngShow: 'template.summary_fields.user_capabilities.edit', + editStateParams: ['job_template_id', 'workflow_job_template_id'] }, view: { label: i18n._('View'), diff --git a/awx/ui/client/src/shared/list-generator/list-actions.partial.html b/awx/ui/client/src/shared/list-generator/list-actions.partial.html index 796b370924..026852ef3a 100644 --- a/awx/ui/client/src/shared/list-generator/list-actions.partial.html +++ b/awx/ui/client/src/shared/list-generator/list-actions.partial.html @@ -29,9 +29,9 @@ -
+
diff --git a/awx/ui/client/src/shared/list-generator/list-generator.factory.js b/awx/ui/client/src/shared/list-generator/list-generator.factory.js index 9f66266bc0..d9b5702f60 100644 --- a/awx/ui/client/src/shared/list-generator/list-generator.factory.js +++ b/awx/ui/client/src/shared/list-generator/list-generator.factory.js @@ -355,6 +355,16 @@ export default ['$location', '$compile', '$rootScope', 'Attr', 'Icon', innerTable += "
"; + let handleEditStateParams = function(stateParams){console.log(stateParams); + let matchingConditions = []; + + angular.forEach(stateParams, function(stateParam) { + matchingConditions.push(`$stateParams['` + stateParam + `'] == ${list.iterator}.id`); + }); + + return matchingConditions; + }; + for (field_action in list.fieldActions) { if (field_action !== 'columnClass') { if (list.fieldActions[field_action].type && list.fieldActions[field_action].type === 'DropDown') { @@ -376,8 +386,19 @@ export default ['$location', '$compile', '$rootScope', 'Attr', 'Icon', innerTable += "class=\"List-actionButton "; innerTable += (field_action === 'delete' || field_action === 'cancel') ? "List-actionButton--delete" : ""; innerTable += "\" "; - // rowBeingEdited === '{{ " + list.iterator + ".id }}' && listBeingEdited === '" + list.name + "' ? 'List-tableRow--selected' : ''"; - innerTable += (field_action === 'edit') ? `ng-class="{'List-editButton--selected' : $stateParams['${list.iterator}_id'] == ${list.iterator}.id}"`: ''; + if(field_action === 'edit') { + // editStateParams allows us to handle cases where a list might have different types of resources in it. As a result the edit + // icon might now always point to the same state and differing states may have differing stateParams. Specifically this occurs + // on the Templates list where editing a workflow job template takes you to a state where the param is workflow_job_template_id. + // You can also edit a Job Template from this list so the stateParam there would be job_template_id. + if(list.fieldActions[field_action].editStateParams) { + let matchingConditions = handleEditStateParams(list.fieldActions[field_action].editStateParams); + innerTable += `ng-class="{'List-editButton--selected' : ${matchingConditions.join(' || ')}}"`; + } + else { + innerTable += `ng-class="{'List-editButton--selected' : $stateParams['${list.iterator}_id'] == ${list.iterator}.id}"`; + } + } innerTable += (fAction.awPopOver) ? "aw-pop-over=\"" + fAction.awPopOver + "\" " : ""; innerTable += (fAction.dataPlacement) ? Attr(fAction, 'dataPlacement') : ""; innerTable += (fAction.dataTitle) ? Attr(fAction, 'dataTitle') : ""; diff --git a/awx/ui/client/src/templates/labels/labelsList.directive.js b/awx/ui/client/src/templates/labels/labelsList.directive.js index 54c49ef47c..c7b83618db 100644 --- a/awx/ui/client/src/templates/labels/labelsList.directive.js +++ b/awx/ui/client/src/templates/labels/labelsList.directive.js @@ -8,7 +8,8 @@ export default 'Prompt', '$q', '$filter', - function(templateUrl, Wait, Rest, GetBasePath, ProcessErrors, Prompt, $q, $filter) { + '$state', + function(templateUrl, Wait, Rest, GetBasePath, ProcessErrors, Prompt, $q, $filter, $state) { return { restrict: 'E', scope: false, @@ -63,9 +64,8 @@ export default Rest.setUrl(url); Rest.post({"disassociate": true, "id": labelId}) .success(function () { - // @issue: OLD SEARCH - // scope.search("job_template", scope.$parent.job_template_page); Wait('stop'); + $state.go('.', null, {reload: true}); }) .error(function (data, status) { Wait('stop'); diff --git a/awx/ui/client/src/templates/labels/labelsList.partial.html b/awx/ui/client/src/templates/labels/labelsList.partial.html index b14ec6deb9..0837cdfc00 100644 --- a/awx/ui/client/src/templates/labels/labelsList.partial.html +++ b/awx/ui/client/src/templates/labels/labelsList.partial.html @@ -1,10 +1,10 @@
+ ng-click="deleteLabel(template.id, template.name, label.id, label.name)" + ng-show="showDelete && template.summary_fields.user_capabilities.edit">
-
+
{{ label.name }}
diff --git a/awx/ui/client/src/templates/list/templates-list.controller.js b/awx/ui/client/src/templates/list/templates-list.controller.js index f984dd57e3..93f32807ea 100644 --- a/awx/ui/client/src/templates/list/templates-list.controller.js +++ b/awx/ui/client/src/templates/list/templates-list.controller.js @@ -107,7 +107,7 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', 'Al if(template) { Prompt({ hdr: 'Delete', - body: '
Are you sure you want to delete the ' + (template.type === "Workflow Job Template" ? 'workflow ' : '') + 'job template below?
' + $filter('sanitize')(template.name) + '
', + body: '
Are you sure you want to delete the template below?
' + $filter('sanitize')(template.name) + '
', action: function() { function handleSuccessfulDelete() { From 7e54783fca75071ce6023933661d2cc1256e4320 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Tue, 13 Dec 2016 09:26:32 -0500 Subject: [PATCH 2/2] Fixed bug where UI was not hitting different endpoints when deleting wfjt labels v. normal jt labels --- .../list-generator/list-generator.factory.js | 2 +- .../templates/labels/labelsList.directive.js | 39 ++++++++++++------- .../templates/labels/labelsList.partial.html | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/awx/ui/client/src/shared/list-generator/list-generator.factory.js b/awx/ui/client/src/shared/list-generator/list-generator.factory.js index d9b5702f60..c41e059c81 100644 --- a/awx/ui/client/src/shared/list-generator/list-generator.factory.js +++ b/awx/ui/client/src/shared/list-generator/list-generator.factory.js @@ -355,7 +355,7 @@ export default ['$location', '$compile', '$rootScope', 'Attr', 'Icon', innerTable += "
"; - let handleEditStateParams = function(stateParams){console.log(stateParams); + let handleEditStateParams = function(stateParams){ let matchingConditions = []; angular.forEach(stateParams, function(stateParam) { diff --git a/awx/ui/client/src/templates/labels/labelsList.directive.js b/awx/ui/client/src/templates/labels/labelsList.directive.js index c7b83618db..69a2295549 100644 --- a/awx/ui/client/src/templates/labels/labelsList.directive.js +++ b/awx/ui/client/src/templates/labels/labelsList.directive.js @@ -55,28 +55,37 @@ export default scope.seeMoreInactive = true; }; - scope.deleteLabel = function(templateId, templateName, labelId, labelName) { + scope.deleteLabel = function(template, label) { var action = function () { $('#prompt-modal').modal('hide'); scope.seeMoreInactive = true; Wait('start'); - var url = GetBasePath("job_templates") + templateId + "/labels/"; - Rest.setUrl(url); - Rest.post({"disassociate": true, "id": labelId}) - .success(function () { - Wait('stop'); - $state.go('.', null, {reload: true}); - }) - .error(function (data, status) { - Wait('stop'); - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Could not disassociate label from JT. Call to ' + url + ' failed. DELETE returned status: ' + status }); - }); + let url; + if(template.type === 'job_template') { + url = GetBasePath("job_templates") + template.id + "/labels/"; + } + else if(template.type === 'workflow_job_template') { + url = GetBasePath("workflow_job_templates") + template.id + "/labels/"; + } + + if(url) { + Rest.setUrl(url); + Rest.post({"disassociate": true, "id": label.id}) + .success(function () { + Wait('stop'); + $state.go('.', null, {reload: true}); + }) + .error(function (data, status) { + Wait('stop'); + ProcessErrors(scope, data, status, null, { hdr: 'Error!', + msg: 'Could not disassociate label from JT. Call to ' + url + ' failed. DELETE returned status: ' + status }); + }); + } }; Prompt({ - hdr: 'Remove Label from ' + templateName , - body: '
Confirm the removal of the ' + $filter('sanitize')(labelName) + ' label.
', + hdr: 'Remove Label from ' + template.name , + body: '
Confirm the removal of the ' + $filter('sanitize')(label.name) + ' label.
', action: action, actionText: 'REMOVE' }); diff --git a/awx/ui/client/src/templates/labels/labelsList.partial.html b/awx/ui/client/src/templates/labels/labelsList.partial.html index 0837cdfc00..e614692a6e 100644 --- a/awx/ui/client/src/templates/labels/labelsList.partial.html +++ b/awx/ui/client/src/templates/labels/labelsList.partial.html @@ -1,6 +1,6 @@