Commit 90f35b88 authored by Muthu's avatar Muthu

TMSS-240 : Add Edit Cycle feature

Add Edit cycle feature in Cycle
parent 04b6541a
......@@ -36,6 +36,7 @@ class App extends Component {
{label: 'Dashboard', icon: 'pi pi-fw pi-home', to:'/dashboard'},
{label: 'Scheduling Units', icon: 'pi pi-fw pi-calendar', to:'/schedulingunit'},
{label: 'Tasks', icon: 'pi pi-fw pi-check-square', to:'/task'},
{label: 'Cycle', icon: 'pi pi-fw pi-spinner', to:'/cycle'},
{label: 'Project', icon: 'fa fa-fw fa-binoculars', to:'/project'}
];
......
import React, {Component} from 'react';
/**
* Component to get input for Resource allocation while creating and editing Cycle
*/
class ResourceDisplayList extends Component {
constructor(props) {
super(props);
this.state = {
cycleQuota: props.cycleQuota
}
}
render(){
return (
<>
{this.props.cycleQuota.length>0 && this.props.cycleQuota.map((item, index) => (
<React.Fragment key={index+10}>
<label key={'label1-'+ index} className="col-lg-3 col-md-3 col-sm-12">{item.resource.name}</label>
<span key={'div1-'+ index} className="col-lg-3 col-md-3 col-sm-12">
{item.value/(this.props.unitMap[item.resource.quantity_value]?this.props.unitMap[item.resource.quantity_value].conversionFactor:1)}
{` ${this.props.unitMap[item.resource.quantity_value]?this.props.unitMap[item.resource.quantity_value].display:''}`}
</span>
</React.Fragment>
))}
</>
);
}
}
export default ResourceDisplayList;
\ No newline at end of file
import React, {Component} from 'react';
import {InputNumber} from 'primereact/inputnumber';
/**
* Component to get input for Resource allocation while creating and editing Project
*/
export class ResourceInputList extends Component {
constructor(props) {
super(props);
this.state = {
list: props.list,
cycleQuota: props.cycleQuota
}
this.updateEnabled = this.props.list.length===0?true:false;
this.onInputChange = this.onInputChange.bind(this);
}
shouldComponentUpdate() {
return true;
}
onInputChange(field, event) {
if (this.props.callback) {
this.props.callback(field, event);
}
}
removeInput(field) {
if (this.props.removeInputCallback) {
this.props.removeInputCallback(field);
}
}
render(){
return (
<>
{this.props.list.length>0 && this.props.list.map((item, index) => (
<React.Fragment key={index+10}>
<label key={'label1-'+ index} className="col-lg-2 col-md-2 col-sm-12">{item.name}</label>
<div key={'div1-'+ index} className="col-lg-3 col-md-3 col-sm-12">
<InputNumber key={'item1-'+ index} id={'item1-'+ index} name={'item1-'+ index}
suffix={` ${this.props.unitMap[item.quantity_value]?this.props.unitMap[item.quantity_value].display:''}`}
placeholder={` ${this.props.unitMap[item.quantity_value]?this.props.unitMap[item.quantity_value].display:item.name}`} min={0} useGrouping={false}
value={this.state.cycleQuota[item.name]}
onChange={(e) => this.onInputChange(item.name, e)}
onBlur={(e) => this.onInputChange(item.name, e)}
style={{width:"90%", marginRight: "5px"}}
/>
<button className="p-link" data-testid={`${item.name}-btn`} onClick={(e) => this.removeInput(item.name)}>
<i className="fa fa-trash pi-error"></i></button>
</div>
<div className="col-lg-1 col-md-1 col-sm-12"></div>
</React.Fragment>
))}
</>
);
}
}
\ No newline at end of file
This diff is collapsed.
import {CycleEdit} from './edit';
export {CycleEdit} ;
......@@ -9,6 +9,7 @@ import {NotFound} from '../layout/components/NotFound';
import {ProjectList, ProjectCreate, ProjectView, ProjectEdit} from './Project';
import {Dashboard} from './Dashboard';
import {Scheduling} from './Scheduling';
import {CycleEdit} from './Cycle';
import {TaskEdit, TaskView} from './Task';
import ViewSchedulingUnit from './Scheduling/ViewSchedulingUnit'
......@@ -64,7 +65,11 @@ export const routes = [
path: "/project/edit/:id",
component: ProjectEdit,
name: 'Project Edit'
},
},{
path: "/cycle/edit/:id",
component: CycleEdit,
name: 'Cycle Edit'
}
];
export const RoutedContent = () => {
......
......@@ -15,9 +15,8 @@ const CycleService = {
},
getCycle: async function(id) {
try {
const url = `/api/cycle/${id}`;
const response = await axios.get(url);
return response.data.results;
const response = await axios.get((`/api/cycle/${id}`));
return response;
} catch (error) {
console.error(error);
}
......@@ -34,7 +33,82 @@ const CycleService = {
return res;
},
getResources: async function() {
try {
const url = `/api/resource_type`;
const response = await axios.get(url);
return response.data.results;
} catch (error) {
console.error('[cycle.services.getResources]',error);
}
},
getCycleQuota: async function(id) {
try {
const response = await axios.get((`/api/cycle_quota/${id}`));
return response.data;
} catch (error) {
console.error(error);
}
},
saveCycle: async function(cycle, cycleQuota) {
try {
const response = await axios.post(('/api/cycle/'), cycle);
cycle = response.data
for (let quota of cycleQuota) {
quota.cycle = cycle.url;
this.saveCycleQuota(quota);
}
return response.data;
} catch (error) {
console.log(error.response.data);
return error.response.data;
}
},
saveCycleQuota: async function(cycleQuota) {
try {
const response = await axios.post(('/api/cycle_quota/'),cycleQuota);
return response.data;
} catch (error) {
console.error(error);
return null;
}
},
updateCycle: async function(id, cycle) {
try {
const response = await axios.put((`/api/cycle/${id}/`), cycle);
return response.data;
} catch (error) {
console.log(error.response.data);
return error.response.data;
}
},
deleteCycleQuota: async function(cycleQuota) {
try {
const response = await axios.delete(`/api/cycle_quota/${cycleQuota.id}/`);
return response.status===204?{message: 'deleted'}:null;
} catch (error) {
console.error(error);
return null;
}
},
updateCycleQuota: async function(cycleQuota) {
try {
const response = await axios.put(`/api/cycle_quota/${cycleQuota.id}/`, cycleQuota);
return response.data;
} catch (error) {
console.error(error);
return null;
}
},
saveCycleQuota: async function(cycleQuota) {
try {
const response = await axios.post(('/api/cycle_quota/'), cycleQuota);
return response.data;
} catch (error) {
console.error(error);
return null;
}
},
}
export default CycleService;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment