Skip to content

Commit

Permalink
phase1 admin save
Browse files Browse the repository at this point in the history
  • Loading branch information
moogoo78 committed Oct 27, 2024
1 parent 3428abf commit 8238656
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
7 changes: 4 additions & 3 deletions app/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,14 @@ def get_all_options(collection):
'options': [x.to_dict() for x in ac.named_area]
}


# phase 1
site = get_current_site(request)
if phase := site.data.get('phase'):
if phase == 1:
data['_phase1'] = site.data['admin']
data['_phase1']['fields'] = site.data.get('fields', [])
data['_phase1'] = {
'form': site.data['admin']['form'][str(collection.id)],
'fields': site.data.get('fields', []),
}

return data

Expand Down
15 changes: 14 additions & 1 deletion app/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ def save_record(record, payload, collection, uid):
if len(changes):
relate_changes['units'] = changes


if phase1_raw := payload.get('_phase1'):
#record.source_data.update(phase1_raw)
raw = {}
for k, v in phase1_raw.items():
if k in record.source_data:
if record.source_data[k] != v:
raw[k] = v
elif v != '':
raw[k] = v
#record.source_data.update(raw)
modify['source_data'] = raw
#changes['_phase1']
if len(modify):
record.update(modify)
#print(modify, flush=True)
Expand All @@ -379,7 +392,7 @@ def save_record(record, payload, collection, uid):
print('modify:', modify, flush=True)
print('record:', changes, flush=True)

if len(changes) or \
if (len(modify) and len(changes)) or \
relate_changes.get('assertions') or \
relate_changes.get('identifications') or \
relate_changes.get('named_areas') or \
Expand Down
2 changes: 1 addition & 1 deletion app/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Collection(Base, TimestampMixin):
people = relationship('Person', secondary=collection_person_map, back_populates='collections')
area_classes = relationship('AreaClass')
organization = relationship('Organization', back_populates='collections')
site = relationship('Site')
site = relationship('Site', back_populates='collections')

def get_options(self, key):
if key == 'assertion_types':
Expand Down
40 changes: 30 additions & 10 deletions app/templates/admin/inc_record-form2.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ $( document ).ready(function() {
};

const preparePayload = (options) => {

if (options._phase1) {
const rawElem = document.querySelectorAll('.ndb-phase1-raw');
let payload = {_phase1: {}};
rawElem.forEach( x => {
payload._phase1[x.id.replace('raw-', '').replace('-id', '')] = x.value || '';
});
return payload;
}

let payload = {
assertions: {},
identifications: [],
Expand Down Expand Up @@ -890,18 +900,28 @@ $( document ).ready(function() {
const label = document.createElement('label');
label.classList.add('uk-form-label');
label.setAttribute('for', `raw-${z}-id`);
const fieldInfo = findItem(z, allOptions._phase1.fields, true);
label.textContent = fieldInfo[1];
//const fieldInfo = findItem(z, allOptions._phase1.fields, true);
label.textContent = (allOptions._phase1.fields[z]) ? allOptions._phase1.fields[z][0] : '';
const control = document.createElement('div');
control.classList.add('uk-form-controls');
// TODO determine type
const input = document.createElement('input');
input.classList.add('uk-input', 'uk-form-small');
input.id = `raw-${z}-id`;
input.value = values.raw_data[z] || '';
input.setAttribute('name', `raw_${z}`);
control.appendChild(input);
// --

if (allOptions._phase1.fields[z] && allOptions._phase1.fields[z].length === 1 ) {
const input = document.createElement('input');
input.classList.add('uk-input', 'uk-form-small', 'ndb-phase1-raw');
input.id = `raw-${z}-id`;
let val = values.raw_data[z] || '';
input.value = val;
input.setAttribute('name', `raw_${z}`);
input.oninput = (e) => {
if ( val === e.target.value) {
e.target.classList.remove('uk-form-success');
} else {
e.target.classList.add('uk-form-success');
}
};
control.appendChild(input);
} else {
}
margin.appendChild(label);
margin.appendChild(control);
widget.appendChild(margin);
Expand Down
1 change: 0 additions & 1 deletion app/templates/sites/taibol/specimen-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ <h2>{% if entity.collection.name == "sample_material" %}遺傳物質{% elif enti
<img src="https://brmas-taibol.s3.ap-northeast-1.amazonaws.com/dpi600/{{entity.source_data.voucher_id}}.jpg" width="600">
{% endif %}
<hr>

<dl class="row">
{% if entity.collection.name == "sample_material" %}
<dt class="col-sm-3">遺傳物質標本號</dt>
Expand Down

0 comments on commit 8238656

Please sign in to comment.