Skip to content

Commit

Permalink
saving owner with activities and sub activities
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunaTebel committed Nov 2, 2019
1 parent 8974c47 commit 6f5cb78
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 35 deletions.
39 changes: 36 additions & 3 deletions src/components/ArchestEstimateActivityComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ArchestEstimateActivityComponent extends Component {
featureId: this.props.activity.feature.id,
activityStatus: this.props.activity.status,
activityName: this.props.activity.name,
ownerId: this.props.activity.owner ? this.props.activity.owner.id : '',
activityEstimatedTime: this.props.activity.estimated_time,
subActivityTotalHours: 0,
savingData: false,
Expand All @@ -37,6 +38,7 @@ class ArchestEstimateActivityComponent extends Component {
ArchestHttp.PATCH(BACKEND_ESTIMATOR_API_URL + "/activities/" + this.state.activityId + "/", {
name: this.state.activityName,
feature_id: this.state.featureId,
owner_id: this.state.ownerId,
estimated_time: this.state.activityEstimatedTime,
status: this.state.activityStatus,
}).then(function (response) {
Expand Down Expand Up @@ -107,14 +109,24 @@ class ArchestEstimateActivityComponent extends Component {
render() {
const activityId = this.props.activity.id;

let featureOptions;
let featureOptions = [];
let resourcesOptions = [];

if (this.props.features) {
featureOptions = this.props.features.map(
(feature) => <option value={feature.id} key={feature.id}>{feature.name}</option>
);
}

if (this.props.estimateResources) {
resourcesOptions = this.props.estimateResources.map(
(estimateResource) => <option value={estimateResource.resource.id}
key={estimateResource.resource.id}>{estimateResource.resource.full_name}</option>
);
}

resourcesOptions.unshift(<option value={''} key={''}>{''}</option>);

return (
<Row className="archest-card-container-row">
<Modal show={this.state.showDeleteActivityModal} onHide={this.hideDeleteActivityModal}>
Expand Down Expand Up @@ -183,17 +195,20 @@ class ArchestEstimateActivityComponent extends Component {
</Col>
</Row>
<Row>
<Col lg={11}>
<Col lg={9}>
<Form.Label>Activity</Form.Label>
</Col>
<Col lg={2}>
<Form.Label id="archest-activity-owner-label">Owner</Form.Label>
</Col>
<Col lg={1}>
<Form.Label className="archest-activity-estimated-time-label">
Hrs.
</Form.Label>
</Col>
</Row>
<Row>
<Col lg={11}>
<Col lg={9}>
<Form.Group controlId={'activityForm.ActivityName_' + this.state.activityId}
className="archest-activity-name-form-group">
<Form.Control as="textarea"
Expand All @@ -206,6 +221,23 @@ class ArchestEstimateActivityComponent extends Component {
onBlur={this.saveActivityData}/>
</Form.Group>
</Col>
<Col lg={2}>
<Form.Group as={Row}
controlId={'activityForm.ActivityOwnerId_' + this.state.ownerId}
className="archest-activity-owner-name-form-group">
<Col>
<Form.Control
size="sm"
as="select"
value={this.state.ownerId}
name="ownerId"
onChange={this.handleActivityFormFieldChange}
onBlur={this.saveActivityData}>
{resourcesOptions}
</Form.Control>
</Col>
</Form.Group>
</Col>

<Col lg={1}>
<Row>
Expand Down Expand Up @@ -237,6 +269,7 @@ class ArchestEstimateActivityComponent extends Component {
subActivities={this.props.activity.sub_activities}
subActivityChangeHandler={this.subActivityChangeHandler}
subActivityTotalHours={this.state.subActivityTotalHours}
estimateResources={this.props.estimateResources}
/>
</Form>
</Card.Body>
Expand Down
67 changes: 38 additions & 29 deletions src/components/ArchestEstimateEditComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ArchestEstimateEditComponent extends Component {
redirectTo: false,
estimate: {},
estimateDetails: {},
estimateResources: [],
estimateTableData: [],
breadcrumbs: []
};
Expand All @@ -34,36 +35,43 @@ class ArchestEstimateEditComponent extends Component {

let estimateId = this.props.match.params.estimateId;

ArchestHttp.GET(BACKEND_ESTIMATOR_API_URL + '/estimates/' + estimateId + '/detailed_view/', {})
.then(function (response) {

component.setState({
estimateDetails: response.data.results,
dataLoaded: true
});
})
.catch(function (error) {
console.log(error);
});

ArchestHttp.GET(BACKEND_ESTIMATOR_API_URL + '/estimates/' + estimateId + '/', {})
.then(function (response) {
let estimate = response.data;
component.setState({
estimate: estimate,
breadcrumbs: [
{title: 'Home', url: '/'},
{
title: estimate.phase.name + ' - Estimates',
url: `/phase/${estimate.phase.id}/estimates/`
},
{title: estimate.name, url: '#', active: true},
]
});
})
.catch(function (error) {
console.log(error);
let requestConfigs = [
{
name: 'estimateDetailedView',
url: `${BACKEND_ESTIMATOR_API_URL}/estimates/${estimateId}/detailed_view/`,
params: {}
},
{
name: 'estimate',
url: `${BACKEND_ESTIMATOR_API_URL}/estimates/${estimateId}/`,
params: {}
},
{
name: 'estimateResources',
url: `${BACKEND_ESTIMATOR_API_URL}/estimates/${estimateId}/shared_resources/`,
params: {}
},
];

ArchestHttp.BATCH_GET(requestConfigs, (responses) => {

let estimate = responses.estimate.data;

component.setState({
estimateDetails: responses.estimateDetailedView.data.results,
dataLoaded: true,
estimateResources: responses.estimateResources.data.results,
estimate: estimate,
breadcrumbs: [
{title: 'Home', url: '/'},
{
title: estimate.phase.name + ' - Estimates',
url: `/phase/${estimate.phase.id}/estimates/`
},
{title: estimate.name, url: '#', active: true},
]
});
});

}

Expand Down Expand Up @@ -109,6 +117,7 @@ class ArchestEstimateEditComponent extends Component {
key={activity.id}
activity={activity}
features={this.state.estimate.features}
estimateResources={this.state.estimateResources}
removeActivityItemHandler={this.removeActivityItem}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/ArchestEstimateSubActivitiesComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ArchestEstimateSubActivitiesComponent extends Component {
removeSubActivityItemHandler={this.removeSubActivityItem}
saveSubActivityItemCallback={this.saveSubActivityItemCallback}
subActivityChangeHandler={this.subActivityChangeHandler}
estimateResources={this.props.estimateResources}
/>
);

Expand Down
32 changes: 31 additions & 1 deletion src/components/ArchestEstimateSubActivityItemComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ArchestEstimateSubActivityItemComponent extends Component {
this.state = {
parentActivityId: this.props.subActivity.parent_id,
subActivityId: this.props.subActivity.id,
ownerId: this.props.subActivity.owner ? this.props.subActivity.owner.id : '',
subActivityName: this.props.subActivity.name,
subActivityEstimatedTime: this.props.subActivity.estimated_time,
};
Expand All @@ -25,6 +26,7 @@ class ArchestEstimateSubActivityItemComponent extends Component {
this.props.saveSubActivityItemCallback(this.state.subActivityId, {
name: this.state.subActivityName,
estimated_time: this.state.subActivityEstimatedTime,
owner_id: this.state.ownerId
});

}
Expand Down Expand Up @@ -67,6 +69,17 @@ class ArchestEstimateSubActivityItemComponent extends Component {

render() {

let resourcesOptions = [];

if (this.props.estimateResources) {
resourcesOptions = this.props.estimateResources.map(
(estimateResource) => <option value={estimateResource.resource.id}
key={estimateResource.resource.id}>{estimateResource.resource.full_name}</option>
);
}

resourcesOptions.unshift(<option value={''} key={''}>{''}</option>);

return (
<Row>
<Modal show={this.state.showDeleteActivityModal} onHide={this.hideDeleteActivityModal}>
Expand All @@ -83,7 +96,7 @@ class ArchestEstimateSubActivityItemComponent extends Component {
</Button>
</Modal.Footer>
</Modal>
<Col lg={11}>
<Col lg={9}>
<Form.Group controlId="subActivityForm.ActivityName"
className="archest-sub-activity-item-activity-name-form-group">
<Form.Control size="sm"
Expand All @@ -96,6 +109,23 @@ class ArchestEstimateSubActivityItemComponent extends Component {
onBlur={this.saveSubActivityData}/>
</Form.Group>
</Col>
<Col lg={2}>
<Form.Group as={Row}
controlId={'subActivityForm.OwnerId_' + this.state.ownerId}
className="archest-sub-activity-item-activity-owner-form-group">
<Col>
<Form.Control
size="sm"
as="select"
value={this.state.ownerId}
name="ownerId"
onChange={this.handleSubActivityFormFieldChange}
onBlur={this.saveSubActivityData}>
{resourcesOptions}
</Form.Control>
</Col>
</Form.Group>
</Col>
<Col lg={1} className="archest-sub-activity-item-activity-estimated-time-col">
<Row>
<Form.Group controlId="subActivityForm.ActivityName"
Expand Down
18 changes: 16 additions & 2 deletions src/components/styles/ArchestEstimateEditComponent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
.archest-activity-estimated-time-sync-icon {
margin-top: 0.4rem;
margin-left: 0.3rem;
font-size: 1.3rem;
font-size: 1.1rem;
color: $info;
font-weight: bold;
}
Expand All @@ -71,7 +71,7 @@
color: $danger;
margin-top: 0.45rem;
margin-left: 0.5rem;
font-size: 0.9rem;
font-size: 0.7rem;
}

.archest-sub-activity-item-delete-btn:hover {
Expand Down Expand Up @@ -123,3 +123,17 @@
.archest-activity-sub-activities-save-loading-icon {
margin-top: -10px;
}

.archest-activity-owner-name-form-group {
margin-left: -30%;
width: 124%;
}

.archest-sub-activity-item-activity-owner-form-group {
margin-left: -25%;
width: 130%;
}

#archest-activity-owner-label {
margin-left: -20%;
}

0 comments on commit 6f5cb78

Please sign in to comment.