Skip to content
Snippets Groups Projects
Commit e08a074a authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: config

parent d7ebb30e
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,8 @@ function init() { ...@@ -42,7 +42,8 @@ function init() {
controls: { controls: {
...DefaultPluginSpec.layout && DefaultPluginSpec.layout.controls ...DefaultPluginSpec.layout && DefaultPluginSpec.layout.controls
} }
} },
config: DefaultPluginSpec.config
}; };
const plugin = createPlugin(document.getElementById('app')!, spec); const plugin = createPlugin(document.getElementById('app')!, spec);
trySetSnapshot(plugin); trySetSnapshot(plugin);
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
> li { > li {
position: relative; position: relative;
overflow: hidden;
> button:first-child { > button:first-child {
border-left: $control-spacing solid color-increase-contrast($default-background, 12%) !important; border-left: $control-spacing solid color-increase-contrast($default-background, 12%) !important;
......
...@@ -15,6 +15,7 @@ import { PluginState } from '../../mol-plugin/state'; ...@@ -15,6 +15,7 @@ import { PluginState } from '../../mol-plugin/state';
import { urlCombine } from '../../mol-util/url'; import { urlCombine } from '../../mol-util/url';
import { IconButton, Icon, SectionHeader } from '../controls/common'; import { IconButton, Icon, SectionHeader } from '../controls/common';
import { formatTimespan } from '../../mol-util/now'; import { formatTimespan } from '../../mol-util/now';
import { PluginConfig } from '../../mol-plugin/config';
export class StateSnapshots extends PluginUIComponent<{ }> { export class StateSnapshots extends PluginUIComponent<{ }> {
downloadToFile = () => { downloadToFile = () => {
...@@ -161,22 +162,22 @@ class LocalStateSnapshotList extends PluginUIComponent<{ }, { }> { ...@@ -161,22 +162,22 @@ class LocalStateSnapshotList extends PluginUIComponent<{ }, { }> {
export type RemoteEntry = { url: string, removeUrl: string, timestamp: number, id: string, name: string, description: string, isSticky?: boolean } export type RemoteEntry = { url: string, removeUrl: string, timestamp: number, id: string, name: string, description: string, isSticky?: boolean }
export class RemoteStateSnapshots extends PluginUIComponent< export class RemoteStateSnapshots extends PluginUIComponent<
{ listOnly?: boolean }, { listOnly?: boolean },
{ params: PD.Values<typeof RemoteStateSnapshots.Params>, entries: OrderedMap<string, RemoteEntry>, isBusy: boolean }> { { params: PD.Values<RemoteStateSnapshots['Params']>, entries: OrderedMap<string, RemoteEntry>, isBusy: boolean }> {
state = { params: PD.getDefaultValues(RemoteStateSnapshots.Params), entries: OrderedMap<string, RemoteEntry>(), isBusy: false }; Params = {
static Params = {
name: PD.Text(), name: PD.Text(),
options: PD.Group({ options: PD.Group({
description: PD.Text(), description: PD.Text(),
playOnLoad: PD.Boolean(false), playOnLoad: PD.Boolean(false),
serverUrl: PD.Text('https://webchem.ncbr.muni.cz/molstar-state') serverUrl: PD.Text(this.plugin.config.get(PluginConfig.PluginState.Server))
}) })
}; };
static ListOnlyParams = { state = { params: PD.getDefaultValues(this.Params), entries: OrderedMap<string, RemoteEntry>(), isBusy: false };
ListOnlyParams = {
options: PD.Group({ options: PD.Group({
serverUrl: PD.Text('https://webchem.ncbr.muni.cz/molstar-state') serverUrl: PD.Text(this.plugin.config.get(PluginConfig.PluginState.Server))
}, { isFlat: true }) }, { isFlat: true })
}; };
...@@ -268,7 +269,7 @@ export class RemoteStateSnapshots extends PluginUIComponent< ...@@ -268,7 +269,7 @@ export class RemoteStateSnapshots extends PluginUIComponent<
<SectionHeader title='Remote States' /> <SectionHeader title='Remote States' />
{!this.props.listOnly && <> {!this.props.listOnly && <>
<ParameterControls params={RemoteStateSnapshots.Params} values={this.state.params} onEnter={this.upload} onChange={p => { <ParameterControls params={this.Params} values={this.state.params} onEnter={this.upload} onChange={p => {
this.setState({ params: { ...this.state.params, [p.name]: p.value } } as any); this.setState({ params: { ...this.state.params, [p.name]: p.value } } as any);
}} isDisabled={this.state.isBusy}/> }} isDisabled={this.state.isBusy}/>
<div className='msp-btn-row-group'> <div className='msp-btn-row-group'>
...@@ -281,7 +282,7 @@ export class RemoteStateSnapshots extends PluginUIComponent< ...@@ -281,7 +282,7 @@ export class RemoteStateSnapshots extends PluginUIComponent<
fetch={this.fetch} remove={this.props.listOnly ? void 0 : this.remove} /> fetch={this.fetch} remove={this.props.listOnly ? void 0 : this.remove} />
{this.props.listOnly && <> {this.props.listOnly && <>
<ParameterControls params={RemoteStateSnapshots.ListOnlyParams} values={this.state.params} onEnter={this.upload} onChange={p => { <ParameterControls params={this.ListOnlyParams} values={this.state.params} onEnter={this.upload} onChange={p => {
this.setState({ params: { ...this.state.params, [p.name]: p.value } } as any); this.setState({ params: { ...this.state.params, [p.name]: p.value } } as any);
}} isDisabled={this.state.isBusy}/> }} isDisabled={this.state.isBusy}/>
<div className='msp-btn-row-group'> <div className='msp-btn-row-group'>
......
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
export class PluginConfigItem<T = any> {
toString() { return this.key; }
valueOf() { return this.key; }
constructor(public key: string, public defaultValue?: T) { }
}
function item<T>(key: string, defaultValue?: T) { return new PluginConfigItem(key, defaultValue); }
export const PluginConfig = {
item,
PluginState: { Server: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state') }
}
export class PluginConfigManager {
private _config = new Map<PluginConfigItem<any>, unknown>();
get<T>(key: PluginConfigItem<T>) {
if (!this._config.has(key)) return key.defaultValue;
return this._config.get(key) as T;
}
set<T>(key: PluginConfigItem<T>, value: T) {
this._config.set(key, value);
}
delete<T>(key: PluginConfigItem<T>) {
this._config.delete(key);
}
constructor(initial?: Map<PluginConfigItem, unknown>) {
if (!initial) return;
initial.forEach((v, k) => this._config.set(k, v));
}
}
\ No newline at end of file
...@@ -44,6 +44,7 @@ import { StructureMeasurementManager } from './util/structure-measurement'; ...@@ -44,6 +44,7 @@ import { StructureMeasurementManager } from './util/structure-measurement';
import { ViewportScreenshotHelper } from './util/viewport-screenshot'; import { ViewportScreenshotHelper } from './util/viewport-screenshot';
import { StructureRepresentationManager } from './state/representation/structure'; import { StructureRepresentationManager } from './state/representation/structure';
import { CustomProperty } from '../mol-model-props/common/custom-property'; import { CustomProperty } from '../mol-model-props/common/custom-property';
import { PluginConfigManager } from './config';
interface Log { interface Log {
entries: List<LogEntry> entries: List<LogEntry>
...@@ -89,6 +90,8 @@ export class PluginContext { ...@@ -89,6 +90,8 @@ export class PluginContext {
} }
} as const } as const
readonly config = new PluginConfigManager(this.spec.config);
readonly behaviors = { readonly behaviors = {
state: { state: {
isAnimating: this.ev.behavior<boolean>(false), isAnimating: this.ev.behavior<boolean>(false),
...@@ -113,6 +116,7 @@ export class PluginContext { ...@@ -113,6 +116,7 @@ export class PluginContext {
readonly lociLabels: LociLabelManager; readonly lociLabels: LociLabelManager;
readonly structureRepresentation = { readonly structureRepresentation = {
registry: new StructureRepresentationRegistry(), registry: new StructureRepresentationRegistry(),
themeCtx: { colorThemeRegistry: ColorTheme.createRegistry(), sizeThemeRegistry: SizeTheme.createRegistry() } as ThemeRegistryContext, themeCtx: { colorThemeRegistry: ColorTheme.createRegistry(), sizeThemeRegistry: SizeTheme.createRegistry() } as ThemeRegistryContext,
......
...@@ -18,6 +18,7 @@ import { InitVolumeStreaming, BoxifyVolumeStreaming, CreateVolumeStreamingBehavi ...@@ -18,6 +18,7 @@ import { InitVolumeStreaming, BoxifyVolumeStreaming, CreateVolumeStreamingBehavi
import { StructureRepresentationInteraction } from './behavior/dynamic/selection/structure-representation-interaction'; import { StructureRepresentationInteraction } from './behavior/dynamic/selection/structure-representation-interaction';
import { TransformStructureConformation } from './state/actions/structure'; import { TransformStructureConformation } from './state/actions/structure';
import { VolumeStreamingCustomControls } from '../mol-plugin-ui/custom/volume'; import { VolumeStreamingCustomControls } from '../mol-plugin-ui/custom/volume';
import { PluginConfig } from './config';
export const DefaultPluginSpec: PluginSpec = { export const DefaultPluginSpec: PluginSpec = {
actions: [ actions: [
...@@ -86,7 +87,10 @@ export const DefaultPluginSpec: PluginSpec = { ...@@ -86,7 +87,10 @@ export const DefaultPluginSpec: PluginSpec = {
AnimateAssemblyUnwind, AnimateAssemblyUnwind,
AnimateUnitsExplode, AnimateUnitsExplode,
AnimateStateInterpolation AnimateStateInterpolation
] ],
config: new Map([
[PluginConfig.PluginState.Server, 'https://webchem.ncbr.muni.cz/molstar-state']
])
} }
export function createPlugin(target: HTMLElement, spec?: PluginSpec): PluginContext { export function createPlugin(target: HTMLElement, spec?: PluginSpec): PluginContext {
......
...@@ -10,6 +10,7 @@ import { StateTransformParameters } from '../mol-plugin-ui/state/common'; ...@@ -10,6 +10,7 @@ import { StateTransformParameters } from '../mol-plugin-ui/state/common';
import { PluginLayoutStateProps } from './layout'; import { PluginLayoutStateProps } from './layout';
import { PluginStateAnimation } from './state/animation/model'; import { PluginStateAnimation } from './state/animation/model';
import { ParamDefinition as PD } from '../mol-util/param-definition'; import { ParamDefinition as PD } from '../mol-util/param-definition';
import { PluginConfigItem } from './config';
export { PluginSpec } export { PluginSpec }
...@@ -25,7 +26,8 @@ interface PluginSpec { ...@@ -25,7 +26,8 @@ interface PluginSpec {
}, },
components?: { components?: {
remoteState?: 'none' | 'default' // TODO: props for server etc remoteState?: 'none' | 'default' // TODO: props for server etc
} },
config?: Map<PluginConfigItem, unknown>
} }
namespace PluginSpec { namespace PluginSpec {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment