Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 77 additions & 39 deletions modules/farm_fd2/src/entrypoints/harvest/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
id="harvest-date"
data-cy="harvest-date"
v-bind:required="true"
v-bind:showValidityStyling="true"
v-bind:showValidityStyling="validity.show"
v-model:date="date"
v-on:valid="validity.date = $event"
/>

<CropSelector
id="harvest-crop"
data-cy="harvest-crop"
v-bind:required="true"
v-bind:showValidityStyling="true"
v-bind:showValidityStyling="validity.show"
v-model:selected="crop"
v-on:valid="validity.crop = $event"
v-on:error="(msg) => showErrorToast('Network Error', msg)"
/>

Expand Down Expand Up @@ -66,15 +68,18 @@
data-cy="harvest-quantity"
label="Quantity"
v-bind:required="true"
v-bind:showValidityStyling="validity.show"
v-bind:incDecValues="[1, 5]"
v-bind:minValue="1"
v-model:value="quantity"
v-on:valid="validity.quantity = $event"
/>

<select
id="harvest-units"
data-cy="harvest-units"
v-model="unit"
v-if="this.unitList.length > 1"
v-if="unitList.length > 1"
>
<option
v-for="unit in unitList"
Expand All @@ -84,19 +89,24 @@
{{ unit.attributes.name }}
</option>
</select>

<span
data-cy="single-harvest-unit"
v-if="this.unitList.length === 1"
>{{ unit.attributes.name }}</span
v-if="unitList.length === 1"
>
{{ unit.attributes.name }}
</span>

<hr />

<CommentBox
id="harvest-comment"
data-cy="harvest-comment"
v-model:comment="comment"
v-on:valid="validity.comment = $event"
/>
</div>

<div
id="harvest-no-plants-message"
data-cy="harvest-no-plants-message"
Expand All @@ -108,8 +118,8 @@
<SubmitResetButtons
id="harvest-submit-reset"
data-cy="harvest-submit-reset"
v-bind:enableSubmit="formValid"
v-bind:enableReset="true"
v-bind:enableSubmit="submitEnabled"
v-bind:enableReset="resetEnabled"
v-on:submit="submitForm"
v-on:reset="resetForm"
/>
Expand All @@ -126,6 +136,7 @@ import CommentBox from '@comps/CommentBox/CommentBox.vue';
import SubmitResetButtons from '@comps/SubmitResetButtons/SubmitResetButtons.vue';

import * as farmosUtil from '@libs/farmosUtil/farmosUtil';

export default {
components: {
DateSelector,
Expand All @@ -144,16 +155,31 @@ export default {
comment: '',
plantList: [],
unitList: [],
validity: {
show: false,
date: null,
crop: null,
quantity: null,
comment: null,
},
submitting: false,
};
},
computed: {
formValid() {
submitEnabled() {
return !this.validity.show || (this.validToSubmit && !this.submitting);
},
resetEnabled() {
return !this.submitting;
},
validToSubmit() {
return (
this.date != '' &&
this.crop != null &&
this.validity.date === true &&
this.validity.crop === true &&
this.pickedPlant != null &&
this.quantity > 0 &&
this.unit != null
this.validity.quantity === true &&
this.unit != null &&
this.validity.comment === true
);
},
sortedPlantList() {
Expand All @@ -164,6 +190,12 @@ export default {
},
methods: {
resetForm() {
this.validity.show = false;
this.validity.date = null;
this.validity.crop = null;
this.validity.quantity = null;
this.validity.comment = null;

this.date = '2019-06-15';
this.crop = null;
this.pickedPlant = null;
Expand All @@ -172,30 +204,39 @@ export default {
this.comment = '';
},
async submitForm() {
let measure = '';
if (this.unit.relationships.parent.length > 0) {
const unitMap = await farmosUtil.getUnitIdToTermMap();
const measureObj = unitMap.get(this.unit.relationships.parent[0].id);
measure = measureObj.attributes.name;
}
this.submitting = true;
this.validity.show = true;

const quantity = await farmosUtil.createStandardQuantity(
measure,
this.quantity,
'harvest',
this.unit.attributes.name
);
if (this.validToSubmit) {
let measure = '';
if (this.unit.relationships.parent.length > 0) {
const unitMap = await farmosUtil.getUnitIdToTermMap();
const measureObj = unitMap.get(this.unit.relationships.parent[0].id);
measure = measureObj.attributes.name;
}

const plantAsset = await farmosUtil.getPlantAsset(this.pickedPlant.uuid);
const quantity = await farmosUtil.createStandardQuantity(
measure,
this.quantity,
'harvest',
this.unit.attributes.name
);

await farmosUtil.createHarvestLog(
this.date,
this.pickedPlant.location,
this.pickedPlant.beds,
plantAsset,
quantity,
this.comment
);
const plantAsset = await farmosUtil.getPlantAsset(
this.pickedPlant.uuid
);

await farmosUtil.createHarvestLog(
this.date,
this.pickedPlant.location,
this.pickedPlant.beds,
plantAsset,
quantity,
this.comment
);
}

this.submitting = false;
},
},
watch: {
Expand All @@ -211,22 +252,23 @@ export default {

const units = await farmosUtil.getHarvestUnits(this.crop);
this.unitList = units;
if (this.unitList.length == 1) {

if (this.unitList.length === 1) {
this.unit = this.unitList[0];
} else {
this.unit = null;
}
} else {
this.plantList = [];
this.unitList = [];
this.unit = null;
}
},
},
};
</script>

<style>
/* import some styling that applies to all FD2 entry points */
@import url('@css/fd2-mobile.css');

#harvest-header {
Expand All @@ -238,10 +280,6 @@ export default {
margin-bottom: 10px;
}

.label-margin {
margin-right: 10px;
}

#harvest-table,
#harvest-table-header {
border: 2px solid black;
Expand Down
19 changes: 15 additions & 4 deletions modules/farm_fd2/src/entrypoints/harvest/harvest.e2e.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ describe('Tests for the Harvest form', () => {

cy.login('manager1', 'farmdata2');
cy.visit('fd2_school/OSS1');
cy.get('[data-cy="harvest-submit-reset"]')
.find('[data-cy="submit-button"]')
.should('exist')
.should('be.disabled');
});

afterEach(() => {
Expand All @@ -16,25 +20,28 @@ describe('Tests for the Harvest form', () => {
cy.get('[data-cy="harvest-header"]')
.should('be.visible')
.should('have.text', 'Harvest');

cy.get('[data-cy="harvest-date"]')
.find('[data-cy="date-input"]')
.should('be.visible')
.should('have.value', '2019-06-15');

cy.get('[data-cy="harvest-crop"]')
.find('[data-cy="crop-selector"]')
.find('[data-cy="selector-input"]')
.should('be.visible')
.should('have.value', null);

cy.get('[data-cy="harvest-submit-reset"]').should('be.visible');
cy.get('[data-cy="harvest-submit-reset"]')
.find('[data-cy="submit-button"]')
.should('not.be.enabled');

cy.get('[data-cy="harvest-table"]').should('not.exist');
cy.get('[data-cy="harvest-quantity"]').should(`not.exist`);
cy.get('[data-cy="harvest-units"]').should(`not.exist`);
cy.get('[data-cy="single-harvest-unit"]').should(`not.exist`);
cy.get('[data-cy="harvest-comment"]').should(`not.exist`);
cy.get('[data-cy="harvest-quantity"]').should('not.exist');
cy.get('[data-cy="harvest-units"]').should('not.exist');
cy.get('[data-cy="single-harvest-unit"]').should('not.exist');
cy.get('[data-cy="harvest-comment"]').should('not.exist');
});

it('Selecting crop with harvestable plants', () => {
Expand All @@ -44,14 +51,18 @@ describe('Tests for the Harvest form', () => {
.select('RADISH');

cy.get('[data-cy="harvest-table"]').should('be.visible');

cy.get('[data-cy="harvest-quantity"]')
.find('[data-cy="numeric-input"]')
.should('be.visible')
.should('have.value', '1');

cy.get('[data-cy="harvest-units"]')
.should('be.visible')
.should('have.value', null);

cy.get('[data-cy="single-harvest-unit"]').should('not.exist');

cy.get('[data-cy="harvest-comment"]')
.find('[data-cy="comment-input"]')
.should('be.visible')
Expand Down