Skip to content
Snippets Groups Projects

Resolve "Pydantic models for UI config."

Merged Lauri Himanen requested to merge 1257-pydantic-models-for-ui-config into develop
All threads resolved!
1 file
+ 148
0
Compare changes
  • Side-by-side
  • Inline
+ 148
0
@@ -34,6 +34,7 @@ over defaults.
import logging
import os
from enum import Enum
import inspect
import os.path
import yaml
@@ -732,6 +733,153 @@ class Archive(NomadSettings):
archive = Archive()
class UIConfiguration(NomadSettings):
'''Common configuration class used for enabling/disabling certain UI
elements and defining the configuration of each element.
'''
include: List[str] = Field(description='''
List of options to include in the UI. Note that you can specify only this
field to modify the default options.
''')
exclude: List[str] = Field(description='''
List of configuration options to exclude. Note that you can specify only this
field only to exclude certain fields from the default options.
''')
options: dict = Field(description='The possible configuration options.')
class CardOption(NomadSettings):
'''Option for a filter menu shown on the left side of the search page.'''
error: str = Field(description='The error message to show if an error is encountered within the card.')
class Cards(UIConfiguration):
options: dict[str, CardOption] = Field(description='All available card options.')
class EntryContext(UIConfiguration):
cards: Cards
class ModeEnum(str, Enum):
Standard = 'standard'
Scientific = 'scientific'
Separators = 'separators'
class Format(NomadSettings):
decimals: int = Field(3, description='Number of decimals to show.')
mode: ModeEnum = Field('standard', description='The display mode for numbers.')
class ColumnOption(NomadSettings):
'''Option for a column show in the search results.'''
label: str = Field(description='Label shown in the header')
align: str = Field(description='rror message to show if an error is encountered within the card.')
unit: str = Field(description='''
Unit to convert to when displaying. If not given will be displayed in
using the default unit in the active unit system.
''')
format: Format
class Columns(UIConfiguration):
enable: List[str] = [
'entry_name',
'results.material.chemical_formula_hill',
'entry_type',
'upload_create_time',
'authors'
]
include: List[str] = [
'entry_name',
'results.material.chemical_formula_hill',
'entry_type',
'results.method.method_name',
'results.method.simulation.program_name',
'results.method.simulation.dft.basis_set_name',
'results.method.simulation.dft.xc_functional_type',
'results.material.structural_type',
'results.material.symmetry.crystal_system',
'results.material.symmetry.space_group_symbol',
'results.material.symmetry.space_group_number',
'results.eln.lab_ids',
'results.eln.sections',
'results.eln.methods',
'results.eln.tags',
'results.eln.instruments',
'mainfile',
'upload_create_time',
'authors',
'comment',
'references',
'datasets',
'published',
]
options: dict[str, CardOption] = Field(
description='All available column options.',
default={
'entry_name': ColumnOption(label='Name', align='left'),
'results.material.chemical_formula_hill': ColumnOption(label='Formula', align='left'),
'entry_type': ColumnOption(label='Entry type', align='left'),
'results.method.method_name': ColumnOption(label='Method name'),
'results.method.simulation.program_name': ColumnOption(label='Program name'),
'results.method.simulation.dft.basis_set_name': ColumnOption(label='Basis set name'),
'results.method.simulation.dft.xc_functional_type': ColumnOption(label='XC functional type'),
'results.material.structural_type': ColumnOption(label='Structural type'),
'results.material.symmetry.crystal_system': ColumnOption(label='Crystal system'),
'results.material.symmetry.space_group_symbol': ColumnOption(label='Space group symbol'),
'results.material.symmetry.space_group_number': ColumnOption(label='Space group number'),
'results.eln.lab_ids': ColumnOption(label='Lab IDs'),
'results.eln.sections': ColumnOption(label='Sections'),
'results.eln.methods': ColumnOption(label='Methods'),
'results.eln.tags': ColumnOption(label='Tags'),
'results.eln.instruments': ColumnOption(label='Instruments'),
'mainfile': ColumnOption(label='Mainfile', align='left'),
'upload_create_time': ColumnOption(label='Upload time', align='left'),
'authors': ColumnOption(label='Authors', align='left'),
'comment': ColumnOption(label='Comment', align='left'),
'references': ColumnOption(label='References', align='left'),
'datasets': ColumnOption(label='Datasets', align='left'),
'published': ColumnOption(label='Access')
}
)
class Actions(NomadSettings):
enable: bool = Field(True, description='Whether to enable row actions.')
class Details(NomadSettings):
enable: bool = Field(True, description='Whether to show row details.')
class Selection(NomadSettings):
enable: bool = Field(True, description='Whether to show the row selection.')
class Rows(NomadSettings):
actions=Actions()
details=Details()
selection=Selection()
class Pagination(NomadSettings):
order_by: str = Field('upload_create_time', description='Field used for sorting.'),
order: str = Field('desc', description='Sorting order.'),
page_size: int = Field(20, description='Number of results on each page.'),
class EntryContext(UIConfiguration):
cards: Cards
class FilterMenuOption(NomadSettings):
'''Option for a filter menu shown on the left side of the search page.'''
label: str = Field(description='Menu label to show in the UI.')
level: int = Field(description='Indentation level of the menu.')
size: str = Field(description='Width of the menu.')
class UIConfig(NomadSettings):
default_unit_system = 'Custom'
north_enabled = Field(True, description='This is a derived value filled with north.enabled.')
Loading