Skip to content
Snippets Groups Projects
Commit 8497f99f authored by Ramesh Kumar's avatar Ramesh Kumar
Browse files

TMSS-226: Updated code to update multiple tasks.

parent e4a23025
No related branches found
No related tags found
1 merge request!214Resolve TMSS-348 - Merged other local branches
...@@ -19,7 +19,9 @@ import ScheduleService from '../../services/schedule.service'; ...@@ -19,7 +19,9 @@ import ScheduleService from '../../services/schedule.service';
import TaskService from '../../services/task.service'; import TaskService from '../../services/task.service';
import UIConstants from '../../utils/ui.constants'; import UIConstants from '../../utils/ui.constants';
/**
* Compoenent to edit scheduling unit draft
*/
export class EditSchedulingUnit extends Component { export class EditSchedulingUnit extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -36,7 +38,7 @@ export class EditSchedulingUnit extends Component { ...@@ -36,7 +38,7 @@ export class EditSchedulingUnit extends Component {
paramsSchema: null, paramsSchema: null,
validEditor: false, validEditor: false,
validFields: {}, validFields: {},
taskDraft: {} observStrategyVisible: false
} }
this.projects = []; this.projects = [];
this.schedulingSets = []; this.schedulingSets = [];
...@@ -68,7 +70,7 @@ export class EditSchedulingUnit extends Component { ...@@ -68,7 +70,7 @@ export class EditSchedulingUnit extends Component {
* @param {number} strategyId * @param {number} strategyId
*/ */
async changeStrategy (strategyId) { async changeStrategy (strategyId) {
let taskDraftName; let tasksToUpdate = {};
const observStrategy = _.find(this.observStrategies, {'id': strategyId}); const observStrategy = _.find(this.observStrategies, {'id': strategyId});
const tasks = observStrategy.template.tasks; const tasks = observStrategy.template.tasks;
let paramsOutput = {}; let paramsOutput = {};
...@@ -90,7 +92,7 @@ export class EditSchedulingUnit extends Component { ...@@ -90,7 +92,7 @@ export class EditSchedulingUnit extends Component {
schema['$schema'] = taskTemplate.schema['$schema']; schema['$schema'] = taskTemplate.schema['$schema'];
observStrategy.template.parameters.forEach(async(param, index) => { observStrategy.template.parameters.forEach(async(param, index) => {
if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) { if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) {
taskDraftName = taskName; tasksToUpdate[taskName] = taskName;
// Resolve the identified template // Resolve the identified template
const $templateRefs = await $RefParser.resolve(taskTemplate); const $templateRefs = await $RefParser.resolve(taskTemplate);
let property = { }; let property = { };
...@@ -117,7 +119,7 @@ export class EditSchedulingUnit extends Component { ...@@ -117,7 +119,7 @@ export class EditSchedulingUnit extends Component {
} }
}); });
} }
this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput, taskDraft: taskDraftName}); this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput, tasksToUpdate: tasksToUpdate});
// Function called to clear the JSON Editor fields and reload with new schema // Function called to clear the JSON Editor fields and reload with new schema
if (this.state.editorFunction) { if (this.state.editorFunction) {
...@@ -138,10 +140,12 @@ export class EditSchedulingUnit extends Component { ...@@ -138,10 +140,12 @@ export class EditSchedulingUnit extends Component {
this.schedulingSets = responses[1]; this.schedulingSets = responses[1];
this.observStrategies = responses[2]; this.observStrategies = responses[2];
this.taskTemplates = responses[3]; this.taskTemplates = responses[3];
this.setState({ taskDrafts: responses[5].data.results });
responses[4].project = this.schedulingSets.find(i => i.id === responses[4].scheduling_set_id).project_id; responses[4].project = this.schedulingSets.find(i => i.id === responses[4].scheduling_set_id).project_id;
this.setState({ schedulingUnit: responses[4] }); this.setState({ schedulingUnit: responses[4], taskDrafts: responses[5].data.results,
this.changeStrategy(responses[4].observation_strategy_template_id); observStrategyVisible: responses[4].observation_strategy_template_id?true:false });
if (responses[4].observation_strategy_template_id) {
this.changeStrategy(responses[4].observation_strategy_template_id);
}
if (this.state.schedulingUnit.project) { if (this.state.schedulingUnit.project) {
const projectSchedSets = _.filter(this.schedulingSets, {'project_id': this.state.schedulingUnit.project}); const projectSchedSets = _.filter(this.schedulingSets, {'project_id': this.state.schedulingUnit.project});
this.setState({isLoading: false, schedulingSets: projectSchedSets}); this.setState({isLoading: false, schedulingSets: projectSchedSets});
...@@ -241,21 +245,24 @@ export class EditSchedulingUnit extends Component { ...@@ -241,21 +245,24 @@ export class EditSchedulingUnit extends Component {
* Function to create Scheduling unit * Function to create Scheduling unit
*/ */
async saveSchedulingUnit() { async saveSchedulingUnit() {
let observStrategy = _.cloneDeep(this.state.observStrategy); if (this.state.schedulingUnit.observation_strategy_template_id) {
const $refs = await $RefParser.resolve(observStrategy.template); let observStrategy = _.cloneDeep(this.state.observStrategy);
observStrategy.template.parameters.forEach(async(param, index) => { const $refs = await $RefParser.resolve(observStrategy.template);
$refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]); observStrategy.template.parameters.forEach(async(param, index) => {
}); $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]);
const task = this.state.taskDrafts.find(draft => draft.name === this.state.taskDraft); });
const schedulingUnit = await ScheduleService.updateSUDraftFromObservStrategy(observStrategy, this.state.schedulingUnit, task, this.state.taskDraft); const schedulingUnit = await ScheduleService.updateSUDraftFromObservStrategy(observStrategy, this.state.schedulingUnit, this.state.taskDrafts, this.state.tasksToUpdate);
if (schedulingUnit) { if (schedulingUnit) {
this.growl.show({severity: 'success', summary: 'Success', detail: 'Scheduling Unit and tasks edited successfully!'}); // this.growl.show({severity: 'success', summary: 'Success', detail: 'Scheduling Unit and tasks edited successfully!'});
this.props.history.push({ this.props.history.push({
pathname: `/schedulingunit/view/draft/${this.props.match.params.id}`, pathname: `/schedulingunit/view/draft/${this.props.match.params.id}`,
}); });
} else { } else {
this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Unable to update Scheduling Unit/Tasks'}); this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Unable to update Scheduling Unit/Tasks'});
} }
} else {
this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Template Missing.'});
}
} }
/** /**
...@@ -337,16 +344,20 @@ export class EditSchedulingUnit extends Component { ...@@ -337,16 +344,20 @@ export class EditSchedulingUnit extends Component {
</div> </div>
</div> </div>
<div className="p-field p-grid"> <div className="p-field p-grid">
<label htmlFor="observStrategy" className="col-lg-2 col-md-2 col-sm-12">Observation Strategy </label> { this.state.observStrategyVisible &&
<div className="col-lg-3 col-md-3 col-sm-12" data-testid="observStrategy" > <>
<Dropdown inputId="observStrategy" optionLabel="name" optionValue="id" <label htmlFor="observStrategy" className="col-lg-2 col-md-2 col-sm-12">Observation Strategy </label>
tooltip="Observation Strategy Template to be used to create the Scheduling Unit and Tasks" tooltipOptions={this.tooltipOptions} <div className="col-lg-3 col-md-3 col-sm-12" data-testid="observStrategy" >
value={this.state.schedulingUnit.observation_strategy_template_id} <Dropdown inputId="observStrategy" optionLabel="name" optionValue="id"
disabled={this.state.schedulingUnit.observation_strategy_template_id} tooltip="Observation Strategy Template to be used to create the Scheduling Unit and Tasks" tooltipOptions={this.tooltipOptions}
options={this.observStrategies} value={this.state.schedulingUnit.observation_strategy_template_id}
onChange={(e) => {this.changeStrategy(e.value)}} disabled={this.state.schedulingUnit.observation_strategy_template_id}
placeholder="Select Strategy" /> options={this.observStrategies}
</div> onChange={(e) => {this.changeStrategy(e.value)}}
placeholder="Select Strategy" />
</div>
</>
}
<div className="col-lg-1 col-md-1 col-sm-12"></div> <div className="col-lg-1 col-md-1 col-sm-12"></div>
</div> </div>
......
...@@ -211,16 +211,19 @@ const ScheduleService = { ...@@ -211,16 +211,19 @@ const ScheduleService = {
}; };
}, },
updateSUDraftFromObservStrategy: async function(observStrategy, schedulingUnit,task,taskName) { updateSUDraftFromObservStrategy: async function(observStrategy, schedulingUnit,tasks,tasksToUpdate) {
try { try {
delete schedulingUnit['duration']; delete schedulingUnit['duration'];
schedulingUnit = await this.updateSchedulingUnitDraft(schedulingUnit); schedulingUnit = await this.updateSchedulingUnitDraft(schedulingUnit);
task.specifications_doc = observStrategy.template.tasks[taskName].specifications_doc; for (const taskToUpdate in tasksToUpdate) {
delete task['duration']; let task = tasks.find(task => { return task.name === taskToUpdate});
delete task['relative_start_time']; task.specifications_doc = observStrategy.template.tasks[taskToUpdate].specifications_doc;
delete task['relative_stop_time']; delete task['duration'];
task = await this.updateTask(task); delete task['relative_start_time'];
return task; delete task['relative_stop_time'];
task = await this.updateTask(task);
}
return schedulingUnit;
} catch(error) { } catch(error) {
console.error(error); console.error(error);
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment