Skip to content

Commit

Permalink
Backend and Frontend Fixes for Transplanting Report (#615)
Browse files Browse the repository at this point in the history
__Pull Request Description__

Closes #562. This issue makes some changes to the `updateRow` function
located in the Transplanting Report HTML file
[[here](https://github.com/FarmData-2-Dev-Team-2022/FarmData2/blob/fixTransplantingBackend/farmdata2/farmdata2_modules/fd2_barn_kit/transplantingReport/transplantingReport.html)].
These changes are not accompanied by any Cypress e2e testing as that is
a separate issue to be addressed in issue #578. As a result, these
changes have been tested by sight using Hoppscotch.

Additionally, this PR makes a quick fix of the filters for both the
Seeding Report and Transplanting Report where editing once would
permanently disable the filters until the page was refreshed because the
name of the edit cancellation event was changed and the pages were not
updated accordingly to reflect this change.

This PR also brings up the topic of #585 (and #466) of what should be
edit-able. I disabled the ability to edit `bed feet` in the
Transplanting Report because transplanting logs don't have quantity data
for `bed feet` but also enabled the ability to edit `row/bed` because
that does exist in the logs' quantity data. However, should users be
allowed to edit that data? This is beyond the scope of this PR but
wanted to quickly mention this quick thought that occurred to me whilst
making this fix.

---
__Licensing Certification__

FarmData2 is a [Free Cultural
Work](https://freedomdefined.org/Definition) and all accepted
contributions are licensed as described in the LICENSE.md file. This
requires that the contributor holds the rights to do so. By submitting
this pull request __I certify that I satisfy the terms of the [Developer
Certificate of Origin](https://developercertificate.org/)__ for its
contents.
  • Loading branch information
FutzMonitor authored Jan 18, 2023
1 parent f2085ad commit 363ec3e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1 class="text-center">Seeding Report</h1>
</div>
</fieldset>

<custom-table data-cy="report-table" :columns="tableColumns" :rows='tableRows' csv-name="seedingReport_" @row-deleted="deleteRowLog" @row-edited='updateRow' @edit-clicked='disableFilters' @row-canceled='enableFilters' :can-edit='!isMobile' :can-delete='!isMobile'></custom-table>
<custom-table data-cy="report-table" :columns="tableColumns" :rows='tableRows' csv-name="seedingReport_" @row-deleted="deleteRowLog" @row-edited='updateRow' @edit-clicked='disableFilters' @edit-canceled='enableFilters' :can-edit='!isMobile' :can-delete='!isMobile'></custom-table>

<br>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="text-center">Transplanting Report</h1>
</div>
</fieldset>

<custom-table data-cy="report-table" :columns="tableColumns" :rows='tableRows' csv-name="transplantingReport_" @row-deleted="deleteRowLog" @row-edited='updateRow' @edit-clicked='disableFilters' @row-canceled='enableFilters' can-edit can-delete></custom-table>
<custom-table data-cy="report-table" :columns="tableColumns" :rows='tableRows' csv-name="transplantingReport_" @row-deleted="deleteRowLog" @row-edited='updateRow' @edit-clicked='disableFilters' @edit-canceled='enableFilters' can-edit can-delete></custom-table>

<br>
</div>
Expand Down Expand Up @@ -142,25 +142,36 @@ <h1 class="text-center">Transplanting Report</h1>
*/
let keys = Object.keys(updateObject)
if(keys.includes('Hours') || keys.includes('Workers') || keys.includes('Bed Feet') || keys.includes('Row Feet') ||
keys.includes('Rows/Bed') || keys.includes('Trays')){
keys.includes('Rows/Bed') || keys.includes('Trays')){
updateTransplantingObject['quantity'] = this.quantityTransplantSeeding
}

for(i=0; i < keys.length; i++){
if(keys[i] == 'date'){
updateTransplantingObject['timestamp'] = dayjs(updateObject['date'], 'YYYY-MM-DD').unix()
if(keys[i] == 'Date'){
updateTransplantingObject['timestamp'] = dayjs(updateObject['Date'], 'YYYY-MM-DD').unix()

this.updateLog[0].timestamp = dayjs(updateObject['Date'], 'YYYY-MM-DD').unix()
}
else if(keys[i] == 'crop'){
updateTransplantingObject['data'] = {"crop_tid": this.cropToIDMap.get(updateObject['crop'])}
else if(keys[i] == 'Crop'){
updateTransplantingObject['data'] = {"crop_tid": this.cropToIDMap.get(updateObject['Crop'])}
updatePlantObject['crop'] = [{
"id": this.cropToIDMap.get(updateObject['crop']),
"resource": "taxonomy_term"
}]

this.updateLog[0].data = {"crop_tid": this.cropToIDMap.get(updateObject['Crop'])}
}
else if (keys[i] == 'area'){
else if (keys[i] == 'Area'){
updateTransplantingObject['movement'] = { 'area': [{
"id": this.areaToIDMap.get(updateObject['area']),
"resource": "taxonomy_term",}]
"id": this.areaToIDMap.get(updateObject['Area']),
"resource": "taxonomy_term"}],
}

this.updateLog[0].movement = { 'area': [{
"uri": "http://localhost/taxonomy_term/" + this.areaToIDMap.get(updateObject['Area']),
"id": this.areaToIDMap.get(updateObject['Area']),
"resource": "taxonomy_term",
"name": updateObject['Area']}]
}
}
else if(keys[i] == 'Hours'){
Expand All @@ -176,6 +187,9 @@ <h1 class="text-center">Transplanting Report</h1>
else if(keys[i] == 'Comments'){
updateTransplantingObject['notes'] = {'value': updateObject['Comments'],
'format': 'farm_format'}

this.updateLog[0].notes = {'value': updateObject['Comments'],
'format': 'farm_format'}
}
else if(keys[i] == 'User'){
updateTransplantingObject['uid'] = {
Expand All @@ -186,28 +200,32 @@ <h1 class="text-center">Transplanting Report</h1>
'id': this.userToIDMap.get(updateObject['User']),
'resource': 'user'
}
}
else if(keys[i] == 'Row/Bed'){
updateTransplantingObject.quantity[quantityLocation(updateTransplantingObject.quantity, 'Rows/Bed')].value = updateObject['Rows/Bed']

this.updateLog[0].quantity[quantityLocation(this.updateLog[0].quantity, 'Rows/Bed')].value = updateObject['Rows/Bed']
this.updateLog[0].uid = {
'id': this.userToIDMap.get(updateObject['User']),
'resource': 'user'
}
}
else if(keys[i] == 'Row Feet'){
updateTransplantingObject.quantity[quantityLocation(updateTransplantingObject.quantity, 'Amount planted')].value = updateObject['Row Feet']

this.updateLog[0].quantity[quantityLocation(this.updateLog[0].quantity, 'Amount planted')].value = updateObject['Row Feet']
}
else if(keys[i] == '# of Trays'){
else if(keys[i] == 'Rows/Bed'){
updateTransplantingObject.quantity[quantityLocation(updateTransplantingObject.quantity, 'Rows/Bed')].value = updateObject['Rows/Bed']

this.updateLog[0].quantity[quantityLocation(this.updateLog[0].quantity, 'Rows/Bed')].value = updateObject['Rows/Bed']
}
else if(keys[i] == 'Trays'){
updateTransplantingObject.quantity[quantityLocation(updateTransplantingObject.quantity, 'Flats')].value = updateObject['Trays']

this.updateLog[0].quantity[quantityLocation(this.updateLog[0].quantity, 'Flats')].value = updateObject['Trays']
}
}
//replace old update log with current update log
if(keys.includes('Hours') || keys.includes('Num Workers') ||
keys.includes('Row/Bed') || keys.includes('Row Feet') ||
keys.includes('Tray Seeds') || keys.includes('# of Trays') ||
keys.includes('Cells Per Tray')){
if(keys.includes('Hours') || keys.includes('Workers') ||
keys.includes('Rows/Bed') || keys.includes('Row Feet') ||
keys.includes('Trays')){
for(var i=0; i < this.transplantingLogs.length; i++){
if(this.transplantingLogs[i].id === id){
this.transplantingLogs.splice(i, this.updateLog)
Expand All @@ -217,13 +235,26 @@ <h1 class="text-center">Transplanting Report</h1>

let transplantUrl = '/log/' + id
let plantingUrl = '/farm_asset/' + this.updateLog[0].asset[0].id
//call updateRecord function to update planting log
//call updateRecord function to update planting log
if(!(Object.entries(updatePlantObject).length === 0)){
updateRecord(plantingUrl, updatePlantObject, this.sessionToken)
}
//call updateRecord function to update transplanting log
//call updateRecord function to update seeding log
if(!(Object.entries(updateTransplantingObject).length === 0)){
updateRecord(transplantUrl, updateTransplantingObject,this.sessionToken)
//updates quantities and area separately because backend doesn't allow for one updateRecord call with both changes
if(keys.includes("Area") && (keys.includes("Row Feet") || keys.includes("Bed Feet")
|| keys.includes("Trays") || keys.includes("Workers") || keys.includes("Hours"))){
delete updateTransplantingObject.movement
let updateArea = {"movement":{"area":[{"id":this.areaToIDMap.get(updateObject['Area']),"resource":"taxonomy_term"}]}}

updateRecord(transplantUrl, updateArea, this.sessionToken)
.then(() =>{
updateRecord(transplantUrl, updateTransplantingObject, this.sessionToken)
})
}
else{
updateRecord(transplantUrl, updateTransplantingObject, this.sessionToken)
}
}
this.rowBeingEdited = false
},
Expand Down Expand Up @@ -269,28 +300,23 @@ <h1 class="text-center">Transplanting Report</h1>
}
let $vm = this
let rows = filterRows.map(function(h) {
let rowBed = 0
let rowFeet = 0
let bedFeet = 0
let numOfTrays = 0
let hours = 0
let numWorkers = 0

rowFeet = h.quantity[0].value
rowBed = h.quantity[1].value
bedFeet = rowFeet/rowBed
hours = h.quantity[3].value
numWorkers = h.quantity[4].value
let rowFeet = h.quantity[0].value
let rowPerBed = h.quantity[1].value
let bedFeet = rowFeet/rowPerBed // calculation for bed feet
let numOfTrays = h.quantity[2].value
let hours = h.quantity[3].value
let numWorkers = h.quantity[4].value

return{
id: h.id,
data: [
dayjs.unix(h.timestamp).format('YYYY-MM-DD'),
$vm.idToCropMap.get(h.data.crop_tid),
h.movement.area[0].name,
bedFeet,
rowFeet,
rowBed,
numOfTrays = h.quantity[2].value,
bedFeet,
rowPerBed,
numOfTrays,
(Math.round(numWorkers*100))/100,
((Math.round(hours*100))/100).toFixed(2),
h.notes.value,
Expand Down Expand Up @@ -500,10 +526,10 @@ <h1 class="text-center">Transplanting Report</h1>
{"header": 'Date', "visible": true, "inputType" : {'type': 'date'}},
{"header": 'Crop', "visible": true, "inputType" : {'type': 'dropdown', value: this.cropNameArray}},
{"header": 'Area', "visible": true, "inputType" : {'type': 'dropdown', value: this.areaNameArray}},
{"header": 'Row Feet', "visible": false, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Bed Feet', "visible": false, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Rows/Bed', "visible": false, "inputType" : {'type': 'no input'}},
{"header": 'Trays', "visible": false, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Row Feet', "visible": true, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Bed Feet', "visible": true, "inputType" : {'type': 'no input'}},
{"header": 'Rows/Bed', "visible": true, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Trays', "visible": true, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Workers', "visible": true, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*$'}},
{"header": 'Hours', "visible": true, "inputType" : {'type': 'regex', 'regex': '^[1-9]+[0-9]*([.][0-9]{1,2}){0,1}$|^[0]{0,1}[.][1-9][0-9]{0,1}$|^[0]{0,1}[1-9]$|^[1-9]+[0-9]*\.$'}},
{"header": 'Comments', "visible": true, "inputType" : {'type': 'text'}},
Expand Down

0 comments on commit 363ec3e

Please sign in to comment.