Skip to content

Commit

Permalink
fix ppi admin identification bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
moogoo78 committed Jul 10, 2024
1 parent 657719b commit 4e242a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions app/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def save_record(record, payload, collection, uid):
relate_changes['assertions'] = changes

if value := payload.get('identifications'):
print('-------------', flush=True)
changes = {}
pv = {}
update_ids = [x['id'] for x in value if x.get('id')]
Expand All @@ -148,7 +149,7 @@ def save_record(record, payload, collection, uid):
session.commit()

i2 = dict(i)
#print(i2, flush=True)
print(i2, flush=True)
if x := i2.get('identifier_id'):
i2['identifier_id'] = x
iden.update({'identifier_id': x})
Expand All @@ -157,7 +158,7 @@ def save_record(record, payload, collection, uid):
iden.update({'taxon_id': x})

iden_modify = make_editable_values(iden, i)
#print(iden_modify, flush=True)
print(iden_modify, flush=True)
if len(iden_modify):
iden.update(iden_modify)
iden_changes = inspect_model(iden)
Expand Down
36 changes: 23 additions & 13 deletions app/templates/sites/ppi/admin/record-form-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
identifications: [],
};

//console.log(identificationCounter);
console.log(identificationCounter);
for (let i=0;i<=identificationCounter;i++) {
// TODO custom sequence
let idObj = {
Expand All @@ -407,14 +407,22 @@
if (identifier && identifier.dataset.value) {
idObj.identifier_id = identifier.dataset.value
}
['date', 'date_text', 'verbatim_date', 'note', 'verbatim_identification', 'verbatim_identifier'].forEach( x => {
//console.log(x);
if (i === 0) {
let elem = document.getElementById(`${x}-id`);
idObj[x] = elem.value;
} else {
let elem = document.getElementById(`identifications-${i}-${x}-id`);
idObj[x] = elem.value;
}
});
data.identifications.push(idObj);
}

let formData = new FormData(formElem);
for (const pair of formData.entries()) {
//data[pair[0]] = pair[1];
//console.log(pair);

/*
if (pair[0].indexOf('identifications-')>=0){
let stacks = pair[0].split('-');
Expand Down Expand Up @@ -484,7 +492,7 @@
.then(response => response.json())
.then(result => {
//console.log(result);
document.location.replace(`/admin/records`);
document.location.replace(`/admin/records?msg=foo`);
//} else {
// UIkit.notification('已儲存', {timeout: 5000});
// }
Expand Down Expand Up @@ -585,28 +593,30 @@
}
});

//console.log(result);
//console.log(result.identifications);
if (result.identifications.length > 1) {
for (let i=1; i<result.identifications.length;i++) {
identificationCounter++;

const clone = identificationTemplate.content.cloneNode(true);
let seqAuto = clone.getElementById('tpl-sequence-auto');
seqAuto.textContent = identificationCounter;
seqAuto.textContent = i;
let box = clone.getElementById(`tpl-box`);
box.id = `identifications-${identificationCounter}-box`;
box.id = `identifications-${i}-box`;
let removeButton = clone.getElementById('tpl-remove');
removeButton.dataset.index = identificationCounter;
removeButton.dataset.index = i;
removeButton.onclick = handleRemoveIdentification;
// input
['sequence', 'verbatim_identification', 'verbatim_identifier', 'date', 'date_text', 'verbatim_date', 'note'].forEach(x => {
let elem = clone.getElementById(`tpl-${x}-id`);
elem.id = `identifications-${identificationCounter}-${x}-id`;
elem.name =`identifications-${identificationCounter}-${x}`;
elem.value = result.identifications[identificationCounter][x];
elem.id = `identifications-${i}-${x}-id`;
elem.name =`identifications-${i}-${x}`;
elem.value = result.identifications[i][x];
//console.log(x, elem, result.identifications[i][x]);
});
identificationMore.appendChild(clone);
}
}
identificationCounter = result.identifications.length-1;
}

loading.style.display = 'none';
Expand Down Expand Up @@ -813,7 +823,7 @@ <h3 class="uk-heading-bullet">標本</h3>
{{ widget('tpl-verbatim_identification', '[逐字]學名', '', '1-2@s', 'input') }}

{{ widget('tpl-identifier', '鑑定者', '', '1-4@s', 'combobox') }}
{{ widget('verbatim_identifier', '[逐字]鑑定者', '', '1-4@s') }}
{{ widget('tpl-verbatim_identifier', '[逐字]鑑定者', '', '1-4@s') }}
{{ widget('tpl-note', '備註', '', '1-2@s', 'textarea') }}

{{ widget('tpl-date', '鑑定日期', '', '1-4@s', 'input', placeholder='2024-07-09') }}
Expand Down

0 comments on commit 4e242a6

Please sign in to comment.