@datagrok/bio 2.4.17 → 2.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,31 @@ export const LIB_STORAGE_NAME = 'Libraries';
15
15
  export const LIB_PATH = 'System:AppData/Bio/libraries/';
16
16
  export const LIB_DEFAULT: { [fileName: string]: string } = {'HELMCoreLibrary.json': 'HELMCoreLibrary.json'};
17
17
 
18
+ /** Type for user settings of monomer library set to use. */
19
+ export type LibSettings = {
20
+ exclude: string[],
21
+ }
22
+
23
+ export async function getLibFileNameList(): Promise<string[]> {
24
+ const res: string[] = (await grok.dapi.files.list(`${LIB_PATH}`, false, ''))
25
+ .map((it) => it.fileName);
26
+ return res;
27
+ }
28
+
29
+ export async function getUserLibSettings(): Promise<LibSettings> {
30
+ const resStr: string = await grok.dapi.userDataStorage.getValue(LIB_STORAGE_NAME, 'Settings', true);
31
+ const res: LibSettings = resStr ? JSON.parse(resStr) : {exclude: []};
32
+
33
+ // Fix empty object returned in case there is no settings stored for user
34
+ res.exclude = res.exclude instanceof Array ? res.exclude : [];
35
+
36
+ return res;
37
+ }
38
+
39
+ export async function setUserLibSetting(value: LibSettings): Promise<void> {
40
+ await grok.dapi.userDataStorage.postValue(LIB_STORAGE_NAME, 'Settings', JSON.stringify(value), true);
41
+ }
42
+
18
43
  export class MonomerLib implements IMonomerLib {
19
44
  private _monomers: { [type: string]: { [name: string]: Monomer } } = {};
20
45
  private _onChanged = new Subject<any>();
@@ -104,11 +129,16 @@ export class MonomerLibHelper implements IMonomerLibHelper {
104
129
  */
105
130
  async loadLibraries(reload: boolean = false): Promise<void> {
106
131
  return this.loadLibrariesPromise = this.loadLibrariesPromise.then(async () => {
107
- const userLibrariesSettings: string[] = Object.keys(await grok.dapi.userDataStorage.get(LIB_STORAGE_NAME, true));
108
- const libs: IMonomerLib[] = await Promise.all(userLibrariesSettings.map((libFileName) => {
109
- //TODO handle whether files are in place
110
- return this.readLibrary(LIB_PATH, libFileName);
111
- }));
132
+ const [libFileNameList, settings]: [string[], LibSettings] = await Promise.all([
133
+ getLibFileNameList(),
134
+ getUserLibSettings()
135
+ ]);
136
+ const libs: IMonomerLib[] = await Promise.all(libFileNameList
137
+ .filter((libFileName) => !settings.exclude.includes(libFileName))
138
+ .map((libFileName) => {
139
+ //TODO handle whether files are in place
140
+ return this.readLibrary(LIB_PATH, libFileName);
141
+ }));
112
142
  this._monomerLib.updateLibs(libs, reload);
113
143
  });
114
144
  }