Skip to content

Commit

Permalink
_cif_warning support
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-donarise committed Jan 31, 2025
1 parent 8d8ac3c commit 5d7c220
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 20 deletions.
6 changes: 5 additions & 1 deletion matinfio/cif/cif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ namespace $ {
continue

} else if( fingerprt.startsWith( '_cif_error' ) ) { // custom tag
const error_message = cur_line.substr( 12, cur_line.length - 13 )
const error_message = cur_line.substr( 11, cur_line.length - 11 )
return this.$mol_fail( new $mol_data_error( error_message ) )

} else if( fingerprt.startsWith( '_cif_warning' ) ) { // custom tag
cur_structure.warning = cur_line.substr( 13, cur_line.length - 13 )
continue

} else if( fingerprt.startsWith( '_pauling_file_entry' ) ) { // custom tag
cur_structure.mpds_data = true
continue
Expand Down
4 changes: 4 additions & 0 deletions matinfio/matinfio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace $ {
cartesian: boolean,
mpds_demo: boolean,
mpds_data: boolean,

warning?: string,
}

export type $optimade_cifplayer_matinfio_player_obj = {
Expand All @@ -69,6 +71,8 @@ namespace $ {
info: string,
mpds_demo: boolean,
mpds_data: boolean,

warning?: string,
}

export class $optimade_cifplayer_matinfio extends $mol_object2 {
Expand Down
4 changes: 3 additions & 1 deletion matinfio/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace $ {
ng_name: parseInt( crystal.ng_name ),
info: crystal.info,
mpds_data: crystal.mpds_data,
mpds_demo: crystal.mpds_demo
mpds_demo: crystal.mpds_demo,

warning: crystal.warning,
}

const groups: { fpos: number[] | null, cpos: number[], atoms: $optimade_cifplayer_matinfio_internal_obj_atom[] }[] = []
Expand Down
39 changes: 29 additions & 10 deletions player/player.view.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
namespace $.$$ {

const Message_card = {
position: 'absolute',
zIndex: 1,
top: '6rem',
width: '100%',
align: {
items: 'center'
},
background: {
color: 'transparent',
},
boxShadow: 'none',
} as const

$mol_style_define( $optimade_cifplayer_player, {

background: {
Expand Down Expand Up @@ -136,19 +150,24 @@ namespace $.$$ {
height: '2rem',
},

Message: {
position: 'absolute',
zIndex: 1,
top: '6rem',
left: 0,
right: 0,
Error_card: {
...Message_card,

Content: {
background: {
color: $optimade_cifplayer_theme.error,
},
},
},

Message_card: {
background: {
color: $mol_theme.back,
Warning_card: {
...Message_card,

Content: {
background: {
color: $optimade_cifplayer_theme.warning,
},
},
margin: 'auto',
},

Three: {
Expand Down
10 changes: 5 additions & 5 deletions player/player.web.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ $optimade_cifplayer_player $mol_view
\
\display none
S \elements
^ message_visible / <= Message $mol_view
sub /
<= Message_card $mol_card
theme \$mol_theme_special
title <= message \
^ message_visible /
<= Error_card $mol_card
title <= error \
<= Warning_card $mol_card
title <= warning \
colors_light *
a \#990000
b \#009900
Expand Down
17 changes: 14 additions & 3 deletions player/player.web.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,27 @@ namespace $.$$ {

@ $mol_mem
message_visible() {
return this.message() ? super.message_visible() : []
if( this.error() ) return [ this.Error_card() ]
if( this.warning() ) return [ this.Warning_card() ]
return []
}

@ $mol_mem
message(): string {
warning(): string {
try {
return this.structure_3d_data()?.warning ?? ''
} catch( error ) {
return ''
}
}

@ $mol_mem
error(): string {
try {
this.structure_3d_data()
return ''

} catch ( error: any ) {
} catch( error: any ) {
return error.message || error
}
}
Expand Down
9 changes: 9 additions & 0 deletions theme/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[mol_theme="$mol_theme_light"] {
--optimade_cifplayer_theme_error: hsl(0, 87%, 69%);
--optimade_cifplayer_theme_warning: hsl(290, 61%, 80%);
}

[mol_theme="$mol_theme_dark"] {
--optimade_cifplayer_theme_error: hsl(0, 59%, 26%);
--optimade_cifplayer_theme_warning: hsl(290, 53%, 28%);
}
11 changes: 11 additions & 0 deletions theme/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace $ {

export const $optimade_cifplayer_theme = $mol_style_prop(
'optimade_cifplayer_theme',
[
'error',
'warning',
] as const
)

}

0 comments on commit 5d7c220

Please sign in to comment.