Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 26 additions & 45 deletions packages/schema/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ import { Modes } from './types';

const SETTINGS_ID = '@jupytergis/jupytergis-core:jupytergis-settings';

const DEFAULT_SETTINGS: IJupyterGISSettings = {
proxyUrl: 'https://corsproxy.io',
leftPanelDisabled: false,
rightPanelDisabled: false,
layersDisabled: false,
stacBrowserDisabled: false,
filtersDisabled: false,
objectPropertiesDisabled: false,
annotationsDisabled: false,
identifyDisabled: false,
};

export class JupyterGISModel implements IJupyterGISModel {
constructor(options: JupyterGISModel.IOptions) {
const { annotationModel, sharedModel, settingRegistry } = options;
Expand All @@ -61,17 +73,7 @@ export class JupyterGISModel implements IJupyterGISModel {
this._pathChanged = new Signal<JupyterGISModel, string>(this);
this._settingsChanged = new Signal<JupyterGISModel, string>(this);

this._jgisSettings = {
proxyUrl: 'https://corsproxy.io',
leftPanelDisabled: false,
rightPanelDisabled: false,
layersDisabled: false,
stacBrowserDisabled: false,
filtersDisabled: false,
objectPropertiesDisabled: false,
annotationsDisabled: false,
identifyDisabled: false,
};
this._jgisSettings = { ...DEFAULT_SETTINGS };

this.initSettings();
}
Expand All @@ -92,17 +94,9 @@ export class JupyterGISModel implements IJupyterGISModel {
this._updateLocalSettings();
const newSettings = this._jgisSettings;

const keys: (keyof IJupyterGISSettings)[] = [
'proxyUrl',
'leftPanelDisabled',
'rightPanelDisabled',
'layersDisabled',
'stacBrowserDisabled',
'filtersDisabled',
'objectPropertiesDisabled',
'annotationsDisabled',
'identifyDisabled',
];
const keys = Object.keys(
DEFAULT_SETTINGS,
) as (keyof IJupyterGISSettings)[];

keys.forEach(key => {
if (oldSettings[key] !== newSettings[key]) {
Expand All @@ -112,36 +106,23 @@ export class JupyterGISModel implements IJupyterGISModel {
});
} catch (error) {
console.error(`Failed to load settings for ${SETTINGS_ID}:`, error);
this._jgisSettings = {
proxyUrl: 'https://corsproxy.io',
leftPanelDisabled: false,
rightPanelDisabled: false,
layersDisabled: false,
stacBrowserDisabled: false,
filtersDisabled: false,
objectPropertiesDisabled: false,
annotationsDisabled: false,
identifyDisabled: false,
};
this._jgisSettings = { ...DEFAULT_SETTINGS };
}
}
}

private _updateLocalSettings(): void {
const composite = this._settings.composite;

this._jgisSettings = {
proxyUrl: (composite.proxyUrl as string) ?? 'https://corsproxy.io',
leftPanelDisabled: (composite.leftPanelDisabled as boolean) ?? false,
rightPanelDisabled: (composite.rightPanelDisabled as boolean) ?? false,
layersDisabled: (composite.layersDisabled as boolean) ?? false,
stacBrowserDisabled: (composite.stacBrowserDisabled as boolean) ?? false,
filtersDisabled: (composite.filtersDisabled as boolean) ?? false,
objectPropertiesDisabled:
(composite.objectPropertiesDisabled as boolean) ?? false,
annotationsDisabled: (composite.annotationsDisabled as boolean) ?? false,
identifyDisabled: (composite.identifyDisabled as boolean) ?? false,
};
this._jgisSettings = Object.entries(DEFAULT_SETTINGS).reduce(
(acc, [key, defaultValue]) => {
const typedKey = key as keyof IJupyterGISSettings;
const compositeValue = composite[typedKey];
(acc as any)[typedKey] = compositeValue ?? defaultValue;
return acc;
},
{} as typeof DEFAULT_SETTINGS,
);
}

get jgisSettings(): IJupyterGISSettings {
Expand Down
Loading