Skip to content

Commit

Permalink
having current entry as reacitve object instead of ref
Browse files Browse the repository at this point in the history
  • Loading branch information
arnold-pichler committed Sep 6, 2024
1 parent 6e3208e commit 7346da0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
82 changes: 41 additions & 41 deletions src/components/TheEntryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -615,46 +615,46 @@ function firstUppercase(input) {
}
function addFertilization(cindex) {
entry.value.cultures[cindex].duengung.push({ ...emptyFertilization });
entry.cultures[cindex].duengung.push({ ...emptyFertilization });
}
function deleteFertilization(cindex, findex) {
entry.value.cultures[cindex].duengung.splice(findex, 1);
entry.cultures[cindex].duengung.splice(findex, 1);
}
function fertilizationChanged(what, cindex, findex) {
entry.value.cultures[cindex].duengung[findex].menge = 0;
entry.value.cultures[cindex].duengung[findex].n = 0;
entry.value.cultures[cindex].duengung[findex].p = 0;
entry.value.cultures[cindex].duengung[findex].k = 0;
entry.cultures[cindex].duengung[findex].menge = 0;
entry.cultures[cindex].duengung[findex].n = 0;
entry.cultures[cindex].duengung[findex].p = 0;
entry.cultures[cindex].duengung[findex].k = 0;
if (what == 'typ') {
entry.value.cultures[cindex].duengung[findex].id = '';
entry.cultures[cindex].duengung[findex].id = '';
}
if (what == 'id' && entry.value.cultures[cindex].duengung[findex].typ == 'handelsdünger') {
const hDuenger = lookup[entry.value.cultures[cindex].duengung[findex].typ].find(
(d) => d.ID == entry.value.cultures[cindex].duengung[findex].id,
if (what == 'id' && entry.cultures[cindex].duengung[findex].typ == 'handelsdünger') {
const hDuenger = lookup[entry.cultures[cindex].duengung[findex].typ].find(
(d) => d.ID == entry.cultures[cindex].duengung[findex].id,
);
if (hDuenger) {
entry.value.cultures[cindex].duengung[findex].n = parseFloat(hDuenger['N [%]'])
entry.cultures[cindex].duengung[findex].n = parseFloat(hDuenger['N [%]'])
? parseFloat(hDuenger['N [%]'])
: 0;
entry.value.cultures[cindex].duengung[findex].p = parseFloat(hDuenger['P2O5 [%]'])
entry.cultures[cindex].duengung[findex].p = parseFloat(hDuenger['P2O5 [%]'])
? parseFloat(hDuenger['P2O5 [%]'])
: 0;
entry.value.cultures[cindex].duengung[findex].k = parseFloat(hDuenger['K2O [%]'])
entry.cultures[cindex].duengung[findex].k = parseFloat(hDuenger['K2O [%]'])
? parseFloat(hDuenger['K2O [%]'])
: 0;
}
}
}
function cultureChanged(index) {
entry.value.cultures[index].ertragslage = '';
entry.cultures[index].ertragslage = '';
}
function allCulturesReset() {
for (let c = 0; c < entry.value.cultures.length; c++) {
entry.value.cultures[c].ertragslage = '';
for (let c = 0; c < entry.cultures.length; c++) {
entry.cultures[c].ertragslage = '';
}
}
Expand Down Expand Up @@ -689,7 +689,7 @@ function ertragsLagen(kultur) {
if (dataRow) {
for (const el of lookup.ertragsLagen) {
if (dataRow[`EL ${el} Bereich`] != '') {
if (entry.value.flaechennutzungsart == 'A' && entry.value.ackerzahl < 30) {
if (entry.flaechennutzungsart == 'A' && entry.ackerzahl < 30) {
// Sonderfall Ackerzahl < 30, Ackerkultur
if (lookup.limitAckerzahl.includes(el)) {
itemReturn.push({ title: `${el} (${dataRow[`EL ${el} Bereich`]})`, value: el });
Expand All @@ -704,11 +704,11 @@ function ertragsLagen(kultur) {
}
function deleteCulture(nr) {
entry.value.cultures.splice(nr, 1);
entry.cultures.splice(nr, 1);
}
function addCulture() {
entry.value.cultures.push({ ...emptyCulture });
entry.cultures.push({ ...emptyCulture });
}
function dataSort(a, b) {
Expand All @@ -717,13 +717,13 @@ function dataSort(a, b) {
function saveData() {
if (currentSaved.value !== null) {
savedData.value[currentSaved.value] = { ...entry.value };
savedData[currentSaved.value] = { ...entry };
} else {
savedData.value.push(entry.value);
savedData.value.sort(dataSort);
savedData.push(entry);
savedData.sort(dataSort);
}
localStorage.setItem('fasttool', JSON.stringify(savedData.value));
localStorage.setItem('fasttool', JSON.stringify(savedData));
dataWindow.value = 0;
panelInit.value = ['basisdaten', 'kulturen'];
schlagInfo.value = null;
Expand All @@ -738,22 +738,22 @@ function cancelData() {
watch(schlagInfo, (value) => {
if (value) {
if (entry.value.flaeche_schwereboeden) {
if (value.sl_flaeche_brutto_ha / 2 < entry.value.flaeche_schwereboeden) {
entry.value.bodenart = 'sL - sandiger Lehm';
if (entry.flaeche_schwereboeden) {
if (value.sl_flaeche_brutto_ha / 2 < entry.flaeche_schwereboeden) {
entry.bodenart = 'sL - sandiger Lehm';
}
}
entry.value.flaechennutzungsart = value.fnar_code;
entry.value.flaeche = value.sl_flaeche_brutto_ha;
entry.value.extent = value.extent;
entry.value.parts = value.parts;
entry.value.flaeche = value.sl_flaeche_brutto_ha;
entry.flaechennutzungsart = value.fnar_code;
entry.flaeche = value.sl_flaeche_brutto_ha;
entry.extent = value.extent;
entry.parts = value.parts;
entry.flaeche = value.sl_flaeche_brutto_ha;
// Remove after Test Phase!
entry.value.schlaginfo.basic = JSON.parse(JSON.stringify(schlagInfo.value));
entry.schlaginfo.basic = JSON.parse(JSON.stringify(schlagInfo.value));
entry.value.jahr = new Date().getFullYear();
entry.jahr = new Date().getFullYear();
dataWindow.value = 2;
}
Expand All @@ -762,24 +762,24 @@ watch(schlagInfo, (value) => {
// Area of relevant topics inside the current schlag
watch(topicHectars, (value) => {
if (value) {
if (entry.value.flaeche) {
if (entry.value.flaeche / 2 < value.schwere_boeden) {
entry.value.bodenart = 'sL - sandiger Lehm';
if (entry.flaeche) {
if (entry.flaeche / 2 < value.schwere_boeden) {
entry.bodenart = 'sL - sandiger Lehm';
}
}
entry.value.flaeche_nitratrisikogebiet = value.nitrataktionsprogramm;
entry.value.flaeche_grundwasserschutz = value.bdfl_l16_grundwasserschutz_acker;
entry.flaeche_nitratrisikogebiet = value.nitrataktionsprogramm;
entry.flaeche_grundwasserschutz = value.bdfl_l16_grundwasserschutz_acker;
// Remove after Test Phase!
entry.value.schlaginfo.programs = JSON.parse(JSON.stringify(value));
entry.schlaginfo.programs = JSON.parse(JSON.stringify(value));
entry.value.duengeklasse_grundwasserschutz = '-';
entry.duengeklasse_grundwasserschutz = '-';
let currentDuengeklasse = 0;
for (let l = 1; l < lookup.wrrl.length; l++) {
if (value[lookup.wrrl[l].code] > currentDuengeklasse) {
currentDuengeklasse = value[lookup.wrrl[l].code];
entry.value.duengeklasse_grundwasserschutz = lookup.wrrl[l].value;
entry.duengeklasse_grundwasserschutz = lookup.wrrl[l].value;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/TheEntryList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ watch(entry, (value) => {
showSchlagParts(value.parts);
});
function zoomTo(nr) {
entry.value = JSON.parse(JSON.stringify(savedData.value[nr]));
entry.value = JSON.parse(JSON.stringify(savedData[nr]));
}
function editEntry(nr) {
currentSaved.value = nr;
if (nr !== null) {
entry.value = JSON.parse(JSON.stringify(savedData.value[nr]));
entry.value = JSON.parse(JSON.stringify(savedData[nr]));
} else {
entry.value = JSON.parse(JSON.stringify(emptyEntry));
}
dataWindow.value = nr === null ? 1 : 2;
}
function deleteEntry(nr) {
savedData.value.splice(nr, 1);
localStorage.setItem('fasttool', JSON.stringify(savedData.value));
savedData.splice(nr, 1);
localStorage.setItem('fasttool', JSON.stringify(savedData));
}
</script>
Expand Down
17 changes: 9 additions & 8 deletions src/composables/useDataEntries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref } from 'vue';
import { ref, reactive } from 'vue';

/**
* @typedef fertilization
Expand Down Expand Up @@ -82,27 +82,28 @@ export const emptyEntry = {
cultures: [{ ...emptyCulture }, { ...emptyCulture }],
};

export const entry = ref({ ...emptyEntry });
/** @type Object */
export let entry = reactive({ ...emptyEntry });

/** @type {import('vue').Ref<Array>} */
export const savedData = ref([]);
/** @type Array savedData */
export let savedData = reactive([]);

/** @type {import('vue').Ref<Number>} */
/** @type {import('vue').ShallowRef<Number>} */
export const currentSaved = ref(null);

/** @type {import('vue').Ref<Number>} */
/** @type {import('vue').ShallowRef<Number>} */
export const dataWindow = ref(0);

// load from local storage, if existing
{
const saved = localStorage.getItem('fasttool');
if (saved) {
savedData.value = JSON.parse(saved);
savedData = JSON.parse(saved);
}
}

/**
* @returns {{ currentSaved: import('vue').Ref<Number>, dataWindow:import('vue').Ref<Number>, savedData: import('vue').Ref<Array> , emptyFertilization: fertilization, emptyCulture: culture, emptyEntry: DataEntry, entry: import('vue').Ref<Object> }}
* @returns {{ currentSaved: import('vue').ShallowRef<Number>, dataWindow:import('vue').ShallowRef<Number>, savedData: Array , emptyFertilization: fertilization, emptyCulture: culture, emptyEntry: DataEntry, entry: Object }}
*/
export function useDataEntries() {
return {
Expand Down
6 changes: 6 additions & 0 deletions src/composables/useLookUps.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ for (let k in kulturenItems) {
kulturenItems[k].splice(0, 0, { title: 'Keine', value: '' });
}

/**
* @type Object lookup
*/
export const lookup = reactive({
yearItems: yearItems,
ackerzahlItems: ackerzahlItems,
Expand All @@ -138,6 +141,9 @@ export const lookup = reactive({
entzugstabelleBraugerste,
});

/**
* @returns {{ lookup: Object }}
*/
export function useLookup() {
return { lookup };
}

0 comments on commit 7346da0

Please sign in to comment.