diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js index 0fe820c3d263e9adfe5582f3952ae71eb55a15b5..754be5119c8b4abe6af04cfbca511db1e577f179 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js @@ -2,6 +2,7 @@ import axios from 'axios' //import moment from 'moment'; import TaskService from './task.service'; import moment from 'moment'; +import _ from 'lodash'; import DataProductService from './data.product.service'; const SU_EXPAND_FIELDS = [ "draft", "draft.observation_strategy_template", "draft.scheduling_constraints_doc", @@ -661,29 +662,31 @@ const ScheduleService = { suObsResponse.data['output_pinned'] = schedulingUnit.output_pinned; schedulingUnit = suObsResponse.data; if (schedulingUnit && schedulingUnit.id) { - // Update the newly created SU draft requirement_doc with captured parameter values + // Update the newly created SU draft constraints and task drafts with captured parameter values schedulingUnit.scheduling_constraints_doc = constraint.scheduling_constraints_doc; schedulingUnit.scheduling_constraints_template_id = constraint.id; schedulingUnit.scheduling_constraints_template = constraint.constraint.url; - delete schedulingUnit['duration']; - schedulingUnit = await this.updateSchedulingUnitDraft(schedulingUnit); - if (!schedulingUnit || !schedulingUnit.id) { - return { - error: true, - messsage: 'Unable to Create Scheduling Unit' - }; + let suTaskDrafts = (await axios.get(`/api/scheduling_unit_draft/${schedulingUnit.id}/?expand=task_drafts&fields=task_drafts`)).data.task_drafts; + // Update only the tasks for which parameters are captured + let tasksToUpdate = {}; + for (const param of observStrategy.template.parameters) { + const refs = param.refs[0].split('/'); + if (refs[1] === 'tasks') { + tasksToUpdate[refs[2]] = refs[2]; + } } + await this.updateSUDraftFromObservStrategy(observStrategy, schedulingUnit, suTaskDrafts, tasksToUpdate, station_groups); if (schedulingUnit.task_drafts.length > 0) { schedulingUnit['isSUUpdated'] = true; schedulingUnit['taskName'] = '(Tasks)'; return schedulingUnit; } + } else { + return { + error: true, + messsage: 'Unable to Create Scheduling Unit' + }; } - return { - taskName: '(Tasks)', - error: true, - message: 'Unable to Create Task Drafts' - }; } catch (error) { console.error(error); return {