diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.edit.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.edit.js index e2eb10aac84a4b3b923bf27cbe49cd064e910343..27ca5a4078dee5e595891377c3f84ccf121f7d84 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.edit.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.edit.js @@ -29,11 +29,15 @@ export class ReservationEdit extends Component { errors: {}, // Validation Errors validFields: {}, // For Validation validForm: false, // To enable Save Button - validEditor: false + validEditor: false, + reservationStrategy: { + id: null, + }, }; this.hasProject = false; // disable project column if project already this.projects = []; // All projects to load project dropdown this.reservationTemplates = []; + this.reservationStrategies = []; this.setEditorOutput = this.setEditorOutput.bind(this); this.setEditorFunction = this.setEditorFunction.bind(this); @@ -70,13 +74,15 @@ export class ReservationEdit extends Component { const promises = [ ProjectService.getProjectList(), ReservationService.getReservationTemplates(), - UtilService.getUTC() + UtilService.getUTC(), + ReservationService.getReservationStrategyTemplates() ]; let emptyProjects = [{url: null, name: "Select Project"}]; Promise.all(promises).then(responses => { this.projects = emptyProjects.concat(responses[0]); this.reservationTemplates = responses[1]; let systemTime = moment.utc(responses[2]); + this.reservationStrategies = responses[3]; let schema = { properties: {} }; @@ -102,7 +108,6 @@ export class ReservationEdit extends Component { await ReservationService.getReservation(id) .then(async (reservation) => { if (reservation) { - console.log( this.reservationTemplates) let reservationTemplate = this.reservationTemplates.find(reserTemplate => reserTemplate.id === reservation.specifications_template_id); if (this.state.editorFunction) { this.state.editorFunction(); @@ -117,7 +122,18 @@ export class ReservationEdit extends Component { } let project = this.projects.find(project => project.name === reservation.project_id); reservation['project']= project ? project.name: null; + let strategyName = reservation.specifications_doc.activity.name; + let reservationStrategy = null; + if (strategyName) { + reservationStrategy = this.reservationStrategies.find(strategy => strategy.name === strategyName); + } else { + reservationStrategy= { + id: null, + } + } + this.setState({ + reservationStrategy: reservationStrategy, reservation: reservation, reservationTemplate: reservationTemplate, paramsSchema: schema,}); @@ -443,6 +459,20 @@ export class ReservationEdit extends Component { {(this.state.errors.project && this.state.touched.project) ? this.state.errors.project : this.state.reservation.project? '': "Select Project"} </label> </div> + <div className="col-lg-1 col-md-1 col-sm-12"></div> + <label htmlFor="strategy" className="col-lg-2 col-md-2 col-sm-12">Reservation Strategy</label> + <div className="col-lg-3 col-md-3 col-sm-12" data-testid="strategy" > + {this.state.reservationStrategy.id && + <Dropdown inputId="strategy" optionLabel="name" optionValue="id" + tooltip="Choose Reservation Strategy Template to set default values for create Reservation" tooltipOptions={this.tooltipOptions} + value={this.state.reservationStrategy.id} + options={this.reservationStrategies} + onChange={(e) => {this.changeStrategy(e.value)}} + placeholder="Select Strategy" + disabled= {true} /> + } + </div> + </div> <div className="p-grid"> diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.view.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.view.js index f3d5b51910cf366e723aab7135040326196262f4..8c7400479b7578f1e8fd8bb29fb3d209ecfbdd5c 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.view.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Reservation/reservation.view.js @@ -174,8 +174,8 @@ export class ReservationView extends Component { <div className="p-grid"> <label className="col-lg-2 col-md-2 col-sm-12">Project</label> <span className="col-lg-4 col-md-4 col-sm-12">{(this.state.reservation.project_id)?this.state.reservation.project_id:''}</span> - <label className="col-lg-2 col-md-2 col-sm-12">Template Id</label> - <span className="col-lg-4 col-md-4 col-sm-12">{this.state.reservation.specifications_template_id}</span> + <label className="col-lg-2 col-md-2 col-sm-12">Reservation Strategy</label> + <span className="col-lg-4 col-md-4 col-sm-12">{this.state.reservation.specifications_doc.activity.name}</span> </div> <div className="p-fluid"> diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/reservation.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/reservation.service.js index 14f18ddc2c4f2ca25ee7d171870c5edc47d58040..d50476d3d0e5faeff74d5b39e2c6fe847a9a5b2b 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/reservation.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/reservation.service.js @@ -64,7 +64,16 @@ const ReservationService = { console.error(error); return false; } - } + }, + getReservationStrategyTemplates: async function () { + try { + const url = `/api/reservation_strategy_template/?ordering=id`; + const response = await axios.get(url); + return response.data.results; + } catch (error) { + console.error(error); + } + }, } export default ReservationService;