diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/view.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/view.js index 799d8cef35b4b39270d1d6cce36c79fe0f50606a..dbea143e575af3d136dfed6a2e2146741e628bd4 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/view.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Project/view.js @@ -12,7 +12,7 @@ import AppLoader from '../../layout/components/AppLoader'; import PageHeader from '../../layout/components/PageHeader'; import ProjectService from '../../services/project.service'; import UnitConverter from '../../utils/unit.converter'; - +import SchedulingUnitList from './../Scheduling/SchedulingUnitList'; /** * Component to view the details of a project */ @@ -54,9 +54,10 @@ export class ProjectView extends Component { async getProjectDetails() { let project = await ProjectService.getProjectDetails(this.state.projectId); let projectQuota = []; - let resources = []; + let resources = []; if (project) { + // If resources are allocated for the project quota fetch the resources master from the API if (project.quota) { resources = await ProjectService.getResources(); @@ -184,6 +185,17 @@ export class ProjectView extends Component { <div className="p-field p-grid resource-input-grid"> <ResourceDisplayList projectQuota={this.state.projectQuota} unitMap={this.resourceUnitMap} /> </div> + {/* Show Schedule Unit blongest to Project */} + <div className="p-fluid"> + <div className="p-field p-grid"> + <div className="col-lg-3 col-md-3 col-sm-12"> + <h5 data-testid="resource_alloc">Scheduling Unit - List</h5> + </div> + <div className="col-lg-12 col-md-12 "> + <SchedulingUnitList project={this.state.project.name}/> + </div> + </div> + </div> </div> </React.Fragment> } diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/SchedulingUnitList.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/SchedulingUnitList.js index 0a6258a315d9c1b44aeed07cf9dbefdcd497b5fc..fbf29d646003764f7db67b62a8015b00a868b8c7 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/SchedulingUnitList.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/SchedulingUnitList.js @@ -5,7 +5,6 @@ import AppLoader from "./../../layout/components/AppLoader"; import ViewTable from './../../components/ViewTable'; import ScheduleService from '../../services/schedule.service'; - class SchedulingUnitList extends Component{ @@ -39,32 +38,41 @@ class SchedulingUnitList extends Component{ defaultSortColumn: [{id: "Name", desc: false}], } } - - async getSchedulingUnitList () { - const bluePrint = await ScheduleService.getSchedulingUnitBlueprint(); - ScheduleService.getSchedulingUnitDraft().then(scheduleunit =>{ - const output = []; - var scheduleunits = scheduleunit.data.results; - for( const scheduleunit of scheduleunits){ - const blueprintdata = bluePrint.data.results.filter(i => i.draft_id === scheduleunit.id); - blueprintdata.map(blueP => { - blueP.duration = moment.utc(blueP.duration*1000).format('HH:mm:ss'); - blueP.type="Blueprint"; - blueP['actionpath'] = '/schedulingunit/view/blueprint/'+blueP.id; - return blueP; + //Get SU Draft/Blueprints for the Project ID. This request is coming from view Project page. Otherwise it will show all SU + let project = this.props.project; + if(project){ + let scheduleunits = await ScheduleService.getSchedulingListByProject(project); + if(scheduleunits){ + this.setState({ + scheduleunit: scheduleunits, isLoading: false }); - output.push(...blueprintdata); - scheduleunit['actionpath']='/schedulingunit/view/draft/'+scheduleunit.id; - scheduleunit['type'] = 'Draft'; - scheduleunit['duration'] = moment.utc(scheduleunit.duration*1000).format('HH:mm:ss'); - output.push(scheduleunit); } - this.setState({ - scheduleunit: output, isLoading: false - }); - }) + }else{ + const bluePrint = await ScheduleService.getSchedulingUnitBlueprint(); + ScheduleService.getSchedulingUnitDraft().then(scheduleunit =>{ + const output = []; + var scheduleunits = scheduleunit.data.results; + for( const scheduleunit of scheduleunits){ + const blueprintdata = bluePrint.data.results.filter(i => i.draft_id === scheduleunit.id); + blueprintdata.map(blueP => { + blueP.duration = moment.utc(blueP.duration*1000).format('HH:mm:ss'); + blueP.type="Blueprint"; + blueP['actionpath'] = '/schedulingunit/view/blueprint/'+blueP.id; + return blueP; + }); + output.push(...blueprintdata); + scheduleunit['actionpath']='/schedulingunit/view/draft/'+scheduleunit.id; + scheduleunit['type'] = 'Draft'; + scheduleunit['duration'] = moment.utc(scheduleunit.duration*1000).format('HH:mm:ss'); + output.push(scheduleunit); + } + this.setState({ + scheduleunit: output, isLoading: false + }); + }) + } } componentDidMount(){ @@ -88,7 +96,8 @@ class SchedulingUnitList extends Component{ paths - specify the path for navigation - Table will set "id" value for each row in action button */} - {this.state.scheduleunit && + + { (this.state.scheduleunit && this.state.scheduleunit.length>0)? <ViewTable data={this.state.scheduleunit} defaultcolumns={this.state.defaultcolumns} @@ -100,6 +109,7 @@ class SchedulingUnitList extends Component{ paths={this.state.paths} unittest={this.state.unittest} /> + :<div>No scheduling unit found </div> } </> ) 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 a7e65ace0ccd24316cb5902bf1741a14cc94fddb..6bb71382bbb5489bfa57ad3e14f77059b7219b55 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js @@ -227,7 +227,52 @@ const ScheduleService = { console.error(error); return null; } - } + }, + getSchedulingListByProject: async function(project){ + /* + SU - Schedulign Unit + Get Scheduling Unit Draft and It's Blueprints using Project ID. there is no direct API to get SU form project (API request -TMSS-349) + Use Fetch all Scheduling Set and filter Scheduling Set with Project ID => Get SU Draft list and SU Blueprints + */ + try { + let schedulingunitlist = []; + //Fetch all Scheduling Set as there is no API to fetch Scheduling Set for a Project + await this.getSchedulingSets().then(async schedulingsetlist =>{ + let schedulingsets = schedulingsetlist.filter(scheduingset => scheduingset.project_id === project) + for(const scheduleset of schedulingsets){ + //Fecth SU Drafts for the Scheduling Set + await this.getSchedulingBySet(scheduleset.id).then(async suDraftList =>{ + for(const suDraft of suDraftList){ + suDraft['actionpath']='/schedulingunit/view/draft/'+suDraft.id; + suDraft['type'] = 'Draft'; + suDraft['duration'] = moment.utc(suDraft.duration*1000).format('HH:mm:ss'); + schedulingunitlist = schedulingunitlist.concat(suDraft); + //Fetch SU Blue prints for the SU Draft + await this.getBlueprintsByschedulingUnitId(suDraft.id).then(suBlueprintList =>{ + for(const suBlueprint of suBlueprintList.data.results){ + suBlueprint.duration = moment.utc(suBlueprint.duration*1000).format('HH:mm:ss'); + suBlueprint.type="Blueprint"; + suBlueprint['actionpath'] = '/schedulingunit/view/blueprint/'+suBlueprint.id; + schedulingunitlist = schedulingunitlist.concat(suBlueprint); + } + }) + } + }) + } + }) + return schedulingunitlist; + } catch (error) { + console.error('[project.services.getSchedulingListByProject]',error); + } + }, + getSchedulingBySet: async function(id){ + try{ + const response = await axios.get(`/api/scheduling_set/${id}/scheduling_unit_draft/?ordering=id`); + return response.data.results; + } catch (error) { + console.error('[project.services.getSchedulingUnitBySet]',error); + } + } } export default ScheduleService; \ No newline at end of file