From 869d4fec23c4381d9073d99528fdc54b4c886476 Mon Sep 17 00:00:00 2001 From: Muthukrishnan <m.krishnan@redkarma.eu> Date: Wed, 11 Nov 2020 09:11:50 +0530 Subject: [PATCH] Update the code for review comments update the code for review comments --- .../routes/Scheduling/create.scheduleset.js | 185 +++++++++--------- 1 file changed, 96 insertions(+), 89 deletions(-) diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.scheduleset.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.scheduleset.js index a4b180724fe..2e330e0fbc7 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.scheduleset.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.scheduleset.js @@ -243,71 +243,13 @@ export class SchedulingSetCreate extends Component { return schema; } + /** * Function to generate AG-Grid column definition. * @param {number} strategyId */ - async createGridColums(scheduleUnit){ - let strategyId = scheduleUnit.observation_strategy_template_id; - let tasksToUpdate = {}; - const observStrategy = _.find(this.observStrategies, {'id': strategyId}); - const tasks = observStrategy.template.tasks; - let paramsOutput = {}; - let schema = { type: 'object', additionalProperties: false, - properties: {}, definitions:{} - }; - - let taskDrafts= []; - await ScheduleService.getTasksDraftBySchedulingUnitId(scheduleUnit.id).then(response =>{ - taskDrafts= response.data.results; - }) - - for (const taskName in tasks) { - const task = tasks[taskName]; - const taskDraft = taskDrafts.find(taskD => taskD.name === taskName); - if (taskDraft) { - task.specifications_doc = taskDraft.specifications_doc; - } - //Resolve task from the strategy template - const $taskRefs = await $RefParser.resolve(task); - - // Identify the task specification template of every task in the strategy template - const taskTemplate = _.find(this.taskTemplates, {'name': task['specifications_template']}); - schema['$id'] = taskTemplate.schema['$id']; - schema['$schema'] = taskTemplate.schema['$schema']; - let index = 0; - for (const param of observStrategy.template.parameters) { - if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) { - tasksToUpdate[taskName] = taskName; - // Resolve the identified template - const $templateRefs = await $RefParser.resolve(taskTemplate); - let property = { }; - let tempProperty = null; - const taskPaths = param.refs[0].split("/"); - // Get the property type from the template and create new property in the schema for the parameters - try { - const parameterRef = param.refs[0]; - tempProperty = $templateRefs.get(parameterRef); - } catch(error) { - tempProperty = _.cloneDeep(taskTemplate.schema.properties[taskPaths[4]]); - if (tempProperty.type === 'array') { - tempProperty = tempProperty.items.properties[taskPaths[6]]; - } - property = tempProperty; - } - property.title = param.name; - property.default = $taskRefs.get(param.refs[0].replace(`#/tasks/${taskName}`, '#')); - paramsOutput[`param_${index}`] = property.default; - schema.properties[`param_${index}`] = property; - // Set property defintions taken from the task template in new schema - for (const definitionName in taskTemplate.schema.definitions) { - schema.definitions[definitionName] = taskTemplate.schema.definitions[definitionName]; - } - } - index++; - } - } - + async createGridColumns(scheduleUnit){ + let schema = await this.getTaskSchema(scheduleUnit); schema = await this.resolveSchema(schema); // AG Grid Cell Specific Properties const cellProps =[]; @@ -356,15 +298,15 @@ export class SchedulingSetCreate extends Component { let childern = []; colProperty = {}; - let childalais = property.title; - childalais = _.lowerCase(childalais).split(' ').map(x => x[0]).join(''); + let childalias = property.title; + childalias = _.lowerCase(childalias).split(' ').map(x => x[0]).join(''); const paramKeys = Object.keys(property.default); paramKeys.forEach(key =>{ - colProperty[key] = childalais+key; + colProperty[key] = childalias+key; let cellAttr = {}; cellAttr['headerName'] = definitions[key].title; - cellAttr['field'] = childalais+key; - colKeyOrder.push(childalais+key); + cellAttr['field'] = childalias+key; + colKeyOrder.push(childalias+key); let cellKeys = Object.keys(cellProps[key]); for(const cellKey of cellKeys){ cellAttr[cellKey] = cellProps[key][cellKey]; @@ -387,6 +329,69 @@ export class SchedulingSetCreate extends Component { } + async getTaskSchema(scheduleUnit){ + let strategyId = scheduleUnit.observation_strategy_template_id; + let tasksToUpdate = {}; + const observStrategy = _.find(this.observStrategies, {'id': strategyId}); + const tasks = observStrategy.template.tasks; + let paramsOutput = {}; + let schema = { type: 'object', additionalProperties: false, + properties: {}, definitions:{} + }; + + let taskDrafts= []; + await ScheduleService.getTasksDraftBySchedulingUnitId(scheduleUnit.id).then(response =>{ + taskDrafts= response.data.results; + }) + + for (const taskName in tasks) { + const task = tasks[taskName]; + const taskDraft = taskDrafts.find(taskD => taskD.name === taskName); + if (taskDraft) { + task.specifications_doc = taskDraft.specifications_doc; + } + //Resolve task from the strategy template + const $taskRefs = await $RefParser.resolve(task); + + // Identify the task specification template of every task in the strategy template + const taskTemplate = _.find(this.taskTemplates, {'name': task['specifications_template']}); + schema['$id'] = taskTemplate.schema['$id']; + schema['$schema'] = taskTemplate.schema['$schema']; + let index = 0; + for (const param of observStrategy.template.parameters) { + if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) { + tasksToUpdate[taskName] = taskName; + // Resolve the identified template + const $templateRefs = await $RefParser.resolve(taskTemplate); + let property = { }; + let tempProperty = null; + const taskPaths = param.refs[0].split("/"); + // Get the property type from the template and create new property in the schema for the parameters + try { + const parameterRef = param.refs[0]; + tempProperty = $templateRefs.get(parameterRef); + } catch(error) { + tempProperty = _.cloneDeep(taskTemplate.schema.properties[taskPaths[4]]); + if (tempProperty.type === 'array') { + tempProperty = tempProperty.items.properties[taskPaths[6]]; + } + property = tempProperty; + } + property.title = param.name; + property.default = $taskRefs.get(param.refs[0].replace(`#/tasks/${taskName}`, '#')); + paramsOutput[`param_${index}`] = property.default; + schema.properties[`param_${index}`] = property; + // Set property defintions taken from the task template in new schema + for (const definitionName in taskTemplate.schema.definitions) { + schema.definitions[definitionName] = taskTemplate.schema.definitions[definitionName]; + } + } + index++; + } + } + return schema; + } + /** * Function to prepare ag-grid row data. @@ -399,7 +404,7 @@ export class SchedulingSetCreate extends Component { let totalSU = this.state.noOfSU; let paramsOutput = {}; //refresh column header - await this.createGridColums(this.state.schedulingUnitList[0]); + await this.createGridColumns(this.state.schedulingUnitList[0]); let observationPropsList = []; for(const scheduleunit of this.state.schedulingUnitList){ let observationProps = { @@ -529,6 +534,7 @@ export class SchedulingSetCreate extends Component { } if(clipboardData){ let suGridRowData= this.state.emptyRow; + clipboardData = _.trim(clipboardData); let suRows = clipboardData.split("\n"); suRows.forEach(line =>{ let colCount = 0; @@ -559,7 +565,7 @@ export class SchedulingSetCreate extends Component { noOfSU: this.tmpRowData.length, totalCount: dataRowCount, }) - + this.state.gridApi.setRowData(this.state.rowData); this.state.gridApi.redrawRows(); @@ -658,7 +664,7 @@ export class SchedulingSetCreate extends Component { const dialog = {header: 'Success', detail: '['+newSUCount+'] Scheduling Units are created & ['+existingSUCount+'] Scheduling Units are updated successfully.'}; this.setState({ dialogVisible: true, dialog: dialog}); }else{ - this.growl.show({severity: 'error', summary: 'Warring', detail: 'No Scheduling Units create/update '}); + this.growl.show({severity: 'error', summary: 'Warning', detail: 'No Scheduling Units create/update '}); } }catch(err){ this.growl.show({severity: 'error', summary: 'Error Occured', detail: 'Unable to create/update Scheduling Units'}); @@ -827,26 +833,27 @@ export class SchedulingSetCreate extends Component { </div> </div> <> - - <div className="ag-theme-alpine" style={ { height: '500px', marginBottom: '10px' } } onKeyDown={this.clipboardEvent}> - <AgGridReact - suppressClipboardPaste={false} - columnDefs={this.state.columnDefs} - columnTypes={this.state.columnTypes} - defaultColDef={this.state.defaultColDef} - rowSelection={this.state.rowSelection} - onGridReady={this.onGridReady} - rowData={this.state.rowData} - frameworkComponents={this.state.frameworkComponents} - context={this.state.context} - components={this.state.components} - modules={this.state.modules} - enableRangeSelection={true} - rowSelection={this.state.rowSelection} - > - - </AgGridReact> - </div> + {this.state.observStrategy.id && + <div className="ag-theme-alpine" style={ { height: '500px', marginBottom: '10px' } } onKeyDown={this.clipboardEvent}> + <AgGridReact + suppressClipboardPaste={false} + columnDefs={this.state.columnDefs} + columnTypes={this.state.columnTypes} + defaultColDef={this.state.defaultColDef} + rowSelection={this.state.rowSelection} + onGridReady={this.onGridReady} + rowData={this.state.rowData} + frameworkComponents={this.state.frameworkComponents} + context={this.state.context} + components={this.state.components} + modules={this.state.modules} + enableRangeSelection={true} + rowSelection={this.state.rowSelection} + > + + </AgGridReact> + </div> + } </> <div className="p-grid p-justify-start"> <div className="p-col-1"> -- GitLab