From d1cce109fb1c5b75d07c0c2f841f217d8cd4046c Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Thu, 8 Nov 2018 09:41:06 -0500 Subject: [PATCH 1/4] update schedule base route to include resource being scheduled --- .../src/scheduler/scheduled-jobs.list.js | 2 +- .../src/scheduler/schedulerList.controller.js | 47 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/awx/ui/client/src/scheduler/scheduled-jobs.list.js b/awx/ui/client/src/scheduler/scheduled-jobs.list.js index 8a15b3cb92..2d49b04806 100644 --- a/awx/ui/client/src/scheduler/scheduled-jobs.list.js +++ b/awx/ui/client/src/scheduler/scheduled-jobs.list.js @@ -33,7 +33,7 @@ export default ['i18n', function(i18n) { sourceModel: 'unified_job_template', sourceField: 'name', // ngBind: 'schedule.summary_fields.unified_job_template.name', - ngClick: "editSchedule(schedule)", + uiSref: "{{schedule.linkToDetails}}", awToolTip: "{{ schedule.nameTip | sanitize}}", dataTipWatch: 'schedule.nameTip', dataPlacement: "top", diff --git a/awx/ui/client/src/scheduler/schedulerList.controller.js b/awx/ui/client/src/scheduler/schedulerList.controller.js index 5a6ea5e0e1..185732b194 100644 --- a/awx/ui/client/src/scheduler/schedulerList.controller.js +++ b/awx/ui/client/src/scheduler/schedulerList.controller.js @@ -101,18 +101,30 @@ export default [ } buildTooltips(itm); - if (!$state.is('schedules')){ - if($state.current.name.endsWith('.add')) { - itm.linkToDetails = `^.edit({schedule_id:schedule.id})`; - } - else if($state.current.name.endsWith('.edit')) { - itm.linkToDetails = `.({schedule_id:schedule.id})`; - } - else { - itm.linkToDetails = `.edit({schedule_id:schedule.id})`; + let stateParams = { schedule_id: item.id }; + let route = ''; + if (item.summary_fields.unified_job_template) { + if (item.summary_fields.unified_job_template.unified_job_type === 'job') { + route = 'templates.editJobTemplate.schedules.edit'; + stateParams.job_template_id = item.summary_fields.unified_job_template.id; + } else if (item.summary_fields.unified_job_template.unified_job_type === 'project_update') { + route = 'projects.edit.schedules.edit'; + stateParams.project_id = item.summary_fields.unified_job_template.id; + } else if (item.summary_fields.unified_job_template.unified_job_type === 'workflow_job') { + route = 'templates.editWorkflowJobTemplate.schedules.edit'; + stateParams.workflow_job_template_id = item.summary_fields.unified_job_template.id; + } else if (item.summary_fields.unified_job_template.unified_job_type === 'inventory_update') { + route = 'inventories.edit.inventory_sources.edit.schedules.edit'; + stateParams.inventory_id = parseInt(item.related.inventory.split("/").slice(-2, -1)[0]); + stateParams.inventory_source_id = item.summary_fields.unified_job_template.id; + } else if (item.summary_fields.unified_job_template.unified_job_type === 'system_job') { + route = 'managementJobsList.schedule'; + stateParams.id = item.summary_fields.unified_job_template.id; } } - + itm.route = route; + itm.stateParams = stateParams; + itm.linkToDetails = `${route}(${JSON.stringify(stateParams)})`; }); } @@ -157,20 +169,7 @@ export default [ }; $scope.editSchedule = function(schedule) { - if ($state.is('schedules')){ - $state.go('schedules.edit', {schedule_id: schedule.id}); - } - else { - if($state.current.name.endsWith('.add')) { - $state.go('^.edit', { schedule_id: schedule.id }); - } - else if($state.current.name.endsWith('.edit')) { - $state.go('.', { schedule_id: schedule.id }); - } - else { - $state.go('.edit', { schedule_id: schedule.id }); - } - } + $state.go(schedule.route, schedule.stateParams); }; $scope.toggleSchedule = function(event, id) { From f37391397e5cd704796a62205086c86d6eb95c6b Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 8 Nov 2018 11:47:31 -0500 Subject: [PATCH 2/4] add inventory to schedule summary fields * Use the same logic that related inventory uses. If there is an inventory that overrides the inventory on the unified job template then summarize that field. Else, use the inventory on the unified job template being scheduled. --- awx/api/serializers.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index aaf28acb46..8db2994cb6 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4614,6 +4614,22 @@ class ScheduleSerializer(LaunchConfigurationBaseSerializer, SchedulePreviewSeria res['inventory'] = obj.unified_job_template.inventory.get_absolute_url(self.context.get('request')) return res + def get_summary_fields(self, obj): + summary_fields = super(ScheduleSerializer, self).get_summary_fields(obj) + inventory = None + if obj.inventory: + inventory = obj.inventory + elif obj.unified_job_template and getattr(obj.unified_job_template, 'inventory', None): + inventory = obj.unified_job_template.inventory + else: + return summary_fields + + summary_fields['inventory'] = dict() + for field in SUMMARIZABLE_FK_FIELDS['inventory']: + summary_fields['inventory'][field] = getattr(inventory, field, None) + + return summary_fields + def validate_unified_job_template(self, value): if type(value) == InventorySource and value.source not in SCHEDULEABLE_PROVIDERS: raise serializers.ValidationError(_('Inventory Source must be a cloud resource.')) From e3614c3012229d0b93cfd118c03de0d3f0e5e68f Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Thu, 8 Nov 2018 12:22:02 -0500 Subject: [PATCH 3/4] update to using new inventory id from summary fields of UJT if applicable --- awx/ui/client/src/scheduler/schedulerList.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui/client/src/scheduler/schedulerList.controller.js b/awx/ui/client/src/scheduler/schedulerList.controller.js index 185732b194..f53df2f2b3 100644 --- a/awx/ui/client/src/scheduler/schedulerList.controller.js +++ b/awx/ui/client/src/scheduler/schedulerList.controller.js @@ -115,7 +115,7 @@ export default [ stateParams.workflow_job_template_id = item.summary_fields.unified_job_template.id; } else if (item.summary_fields.unified_job_template.unified_job_type === 'inventory_update') { route = 'inventories.edit.inventory_sources.edit.schedules.edit'; - stateParams.inventory_id = parseInt(item.related.inventory.split("/").slice(-2, -1)[0]); + stateParams.inventory_id = item.summary_fields.inventory.id; stateParams.inventory_source_id = item.summary_fields.unified_job_template.id; } else if (item.summary_fields.unified_job_template.unified_job_type === 'system_job') { route = 'managementJobsList.schedule'; From 23e1feba96e9b8970b3b82d159959e7e0eb5e16c Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 8 Nov 2018 12:37:27 -0500 Subject: [PATCH 4/4] fill in summary inv for sched only when needed * If scheduler inv exists then the inv summary will be filled in with our generic summary filler inner. Else, if the related unified job has an inventory, fill in the inv summary with that, explicitly. --- awx/api/serializers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 8db2994cb6..cc7cf1fea3 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4616,10 +4616,11 @@ class ScheduleSerializer(LaunchConfigurationBaseSerializer, SchedulePreviewSeria def get_summary_fields(self, obj): summary_fields = super(ScheduleSerializer, self).get_summary_fields(obj) + if 'inventory' in summary_fields: + return summary_fields + inventory = None - if obj.inventory: - inventory = obj.inventory - elif obj.unified_job_template and getattr(obj.unified_job_template, 'inventory', None): + if obj.unified_job_template and getattr(obj.unified_job_template, 'inventory', None): inventory = obj.unified_job_template.inventory else: return summary_fields