Skip to content

Commit

Permalink
fix: record.get_named_area_list
Browse files Browse the repository at this point in the history
  • Loading branch information
moogoo78 committed Mar 30, 2024
1 parent 591a892 commit 1c75eeb
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 216 deletions.
10 changes: 6 additions & 4 deletions app/blueprints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def get_search():
elapsed_mapping = None

rows = result.all()
#print(rows, flush=True)
for r in rows:
unit = r[0]
if record := r[1]:
Expand Down Expand Up @@ -552,9 +553,10 @@ def get_record_parts(record_id, part):
if record := session.get(Record, record_id):
ret = {}
if part == 'named-areas':
all_list = record.get_named_area_list()
for name, lst in all_list.items():
ret[name] = [x.to_dict() for x in lst]
named_areas = record.get_named_area_list('default')
ret['default'] = [x.to_dict() for x in named_areas]
#for name, lst in all_list.items():
# ret[name] = [x.to_dict() for x in lst]
return jsonify(ret)

return jsonify({})
Expand Down Expand Up @@ -659,7 +661,7 @@ def get_occurrence():

na_list = []
if record := r[11]:
if named_areas := record.get_named_area_list('legacy'):
if named_areas := record.get_named_area_list('default'):
na_list = [x.display_name for x in named_areas]
if x:= record.locality_text:
na_list.append(x)
Expand Down
190 changes: 0 additions & 190 deletions app/blueprints/static_admin/record.dev.js

This file was deleted.

20 changes: 16 additions & 4 deletions app/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ class Collection(Base, TimestampMixin):

#record_named_area_map = Table(
class RecordNamedAreaMap(Base):
'''
via:
- A: convert from legacy system (area_class_id from 1 to 4)
'''
__tablename__ = 'record_named_area_map'
record_id = Column(Integer, ForeignKey('record.id'), primary_key=True)
named_area_id = Column(Integer, ForeignKey('named_area.id'), primary_key=True)
via = Column(String(10))
record = relationship('Record', back_populates='named_area_maps')
named_area = relationship('NamedArea', back_populates='record_maps')


class Record(Base, TimestampMixin):
__tablename__ = 'record'

Expand Down Expand Up @@ -200,13 +203,13 @@ def __repr__(self):
return '<Record id="{}">'.format(self.id)

def get_named_area_list(self, list_name=''):

# TODO: list_name from setting
list_name_map = {
'default': [7, 8, 9, 10, 5, 6],
'default': [7, 8, 9, 5, 6],
'legacy': [1, 2, 3, 4, 5, 6],
'hast-label': [7, 8, 9, 5, 6],
}

if list_name == '':
ret = {}
for x in list_name_map:
Expand All @@ -217,6 +220,15 @@ def get_named_area_list(self, list_name=''):
ret[x] = sorted(ret[x], key=lambda x: x.area_class.sort)
return ret
else:
if list_name == 'default':
# TODO taiwan use new, other country use old
if country := RecordNamedAreaMap.query.filter(
RecordNamedAreaMap.record_id==self.id,
RecordNamedAreaMap.named_area_id==1311).first():
pass
else:
list_name = 'legacy'

if area_class_ids := list_name_map.get(list_name):
na_list = []
for m in self.named_area_maps:
Expand Down
9 changes: 9 additions & 0 deletions app/models/gazetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ def to_dict(self, with_meta=False):
# dem = Column(String(500))
# timezone = Column(String(500))
# modification_date = Column(String(500))


class AlternativeName(Base, TimestampMixin):
__tablename__ = 'alternative_name'

id = Column(Integer, primary_key=True)
name = Column(String(500))
lang = Column(String(8))
named_area_id = Column(Integer, ForeignKey('named_area.id'), primary_key=True)
2 changes: 1 addition & 1 deletion app/templates/admin/print-label.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1 class="page-title">page 1</h1>
</div>
</div>
{% endfor %}
{% set named_areas = item.record.get_named_area_list('hast-label') %}
{% set named_areas = item.record.get_named_area_list('default') %}
<div class="label-title">
<!-- LAYOUT1 span class="institution-name">中央研究院植物標本館</span><span class="institution-code">(HAST)</span-->
<span class="collection-name">{% if item.record.get_named_area('country') %}{% if item.record.get_named_area('country').id == 2 %}BOTANICAL INVENTORY OF TAIWAN{% else %}PLANTS OF {{ item.record.get_named_area('country').name_en.upper() }}{% endif %}{# item.record.get_named_area('country').source_data.countryE #}{% endif %}</span>{# TODO #}
Expand Down
5 changes: 3 additions & 2 deletions frontend/admin/src/components/GazetterSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ export default function GazetterSelector({recordId}) {

const renderSelectors = (areaClasses) => {
return areaClasses.map( (areaClass, index) => {
//console.log((state.values && state.values[areaClass[index]] && state.values.areaClass[index]) ? state.values.areaClass[index]: null});
return (
<div className="uk-margin" key={index}>
<label className="uk-form-label">{areaClass.label}</label>
<div className="uk-form-controls">
<select className="uk-select" id={`named_areas__${areaClass.name}`} onChange={(e) => handleAreaClassChange(e, index) } name={`named_areas__${areaClass.id}`}>
<select className="uk-select" id={`named_areas__${areaClass.name}`} onChange={(e) => handleAreaClassChange(e, index) } name={`named_areas__${areaClass.id}`} value={(state.values && state.values[areaClass[index]] && state.values.areaClass[index]) ? state.values.areaClass[index]: null}>
{(areaClass.items.length > 0) ? <option value="">-- choose --</option> : null}
{areaClass.items.map( x => {
return (<option value={x.id} key={x.id}>{x.display_name}</option>);
Expand All @@ -190,7 +191,7 @@ export default function GazetterSelector({recordId}) {
<>
<button className="uk-button" onClick={(e) => {
e.preventDefault();
dispatch({type: 'SET_DATA', defaultNamedAreas: {}});
dispatch({type: 'SET_DATA', defaultNamedAreas: state.defaultNamedAreas.default});
}}>更改</button>
<div className="uk-text">{display}</div>
</>
Expand Down
22 changes: 11 additions & 11 deletions frontend/admin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ module.exports = (env) => {
module: moduleRules,
devtool: 'eval-source-map'
},
{
entry: {
'search': './src/data-search.js',
},
output: {
path: path.join(__dirname, '../app/static/js'),
filename: `[name]${envExt}`,
},
module: moduleRules,
devtool: 'eval-source-map'
},
// {
// entry: {
// 'search': './src/data-search.js',
// },
// output: {
// path: path.join(__dirname, '../app/static/js'),
// filename: `[name]${envExt}`,
// },
// module: moduleRules,
// devtool: 'eval-source-map'
// },
];


Expand Down
14 changes: 10 additions & 4 deletions frontend/data-search/src/UnitTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<!-- <th class="uk-table-shrink">模式標本</th> -->
<th class="uk-width-medium">物種</th>
<th class="uk-width-small">採集號</th>
<th class="uk-width-small">年份</th>
<th class="uk-table-shrink uk-text-nowrap">地點</th>
<th class=""></th>
<th class="uk-table-shrink">年份</th>
<th class="uk-text-nowrap">地點</th>
<th class="uk-table-shrink">展開</th>
</tr>
</thead>
<tbody id="data-search-results-tbody">
Expand All @@ -37,7 +37,7 @@
<td>{row.taxon_text}</td>
<td>{row.collector.display_name} <strong>{row.field_number}</strong> </td>
<td>{row.collect_date.split('-')[0]}</td>
<td>---</td>
<td>{#each row.named_areas as na, index}{na.name}{#if index <= row.named_areas.length -1}/{/if}{/each}</td>
<td><span uk-icon="{(expands[index] === true) ? 'minus-circle' : 'plus-circle'}" on:click={ () => handleExpand(index)}></span></td>
</tr>
<tr class="{(expands[index] === true)? '' : 'uk-hidden'}">
Expand Down Expand Up @@ -67,6 +67,12 @@
<td>採集日期</td>
<td>{row.collect_date || ''}</td>
</tr>
{#each row.named_areas as na}
<tr>
<td>{na.area_class.label}</td>
<td>{na.name}</td>
</tr>
{/each}
</tbody>
</table>
</div>
Expand Down

0 comments on commit 1c75eeb

Please sign in to comment.