Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import-export options for sidebar filters #1856

Merged
2 changes: 1 addition & 1 deletion application/client/src/app/service/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Service extends Implementation {
return this.provider.export(uuids, filename);
}

public import(filename: string): Promise<void> {
public import(filename: string): Promise<string[]> {
return this.provider.import(filename);
}
}
Expand Down
5 changes: 3 additions & 2 deletions application/client/src/app/service/history/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Provider implements EntryConvertable {
return bridge.entries({ file: filename }).overwrite([this.entry().to()]);
}

public import(filename: string): Promise<void> {
public import(filename: string): Promise<string[]> {
return bridge
.entries({ file: filename })
.get()
Expand All @@ -83,11 +83,12 @@ export class Provider implements EntryConvertable {
});
return col;
});
const uuid: string[] = this.collections.map(collection => collection.uuid);
this.storage.definitions.add(this.definitions);
this.storage.collections.add(this.collections);
this.collections = [];
this.definitions = [];
return undefined;
return uuid;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export class Filters extends ChangesDetector implements OnDestroy, AfterContentI
handler: () => {
this.log().debug(`Not implemented yet`);
},
},
}
];
contextmenu.show({
items: items,
items: this.providers.contextMenuOptions(items),
x: event.pageX,
y: event.pageY,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { Entity } from './definitions/entity';
import { unique } from '@platform/env/sequence';
import { Logger } from '@platform/log';
import { ProvidersEvents } from './definitions/events';
import { history } from '@service/history';
import { bridge } from '@service/bridge';
import { HistorySession } from '@service/history/session';
import { Notification, notifications } from '@ui/service/notifications';

type TSelectedEntities = string[];

Expand Down Expand Up @@ -485,6 +489,7 @@ export class Providers {
});
},
});

this._providers.forEach((provider: Provider<any>) => {
const custom: IMenuItem[] = provider.getContextMenuItems(
event.entity,
Expand All @@ -497,7 +502,90 @@ export class Providers {
event.items = event.items.concat(custom);
}
});

this.injectGeneralMenuItems(event.items);

this.subjects.get().context.emit(event);

}


public injectGeneralMenuItems(items: IMenuItem[]): void {
const historySession = history.get(this.session);
if(historySession === undefined) {
this.logger.error('History session is not defined');
return;
}
items.push({
/* Delimiter */
});
const store = this.session.search.store();
const showExport: boolean = (store.filters().get().length + store.charts().get().length + store.disabled().get().length) !== 0;
showExport && items.push(
{
caption: 'Export All to File',
handler: () => this.filters(historySession).export(),
});
items.push(
{
caption: 'Import from File',
handler: () => this.filters(historySession).import(),
});
}

protected filters(historySession: HistorySession): { import(): void; export(): void } {
const logAndNotifyError = (error: Error): void => {
this.logger.error(error.message);
notifications.notify(
new Notification({
message: error.message,
session: this.session.uuid(),
actions: []
})
);
};

return {
import: (): void => {
bridge.files().select.text()
.then(file => {
if (file.length !== 1) {
this.logger.error('No file selected');
return;
}
history.import(file[0].filename)
.then((uuids: string[]) => {
if (uuids.length === 0) {
this.logger.warn('File does not have a collection');
return;
}
if (uuids.length > 1) {
this.session.switch().toolbar.presets();
return;
} else {
const collection = history.collections.get(uuids[0]);
if (collection === undefined) {
this.logger.error(`Cannot find imported collection with UUID: ${uuids[0]}`);
return;
}
historySession.apply(collection);
}
})
.catch(error => logAndNotifyError(error));
})
.catch(error => logAndNotifyError(error))
},
export: (): void => {
bridge.files().select.save()
.then((filename: string | undefined) => {
if (filename === undefined)
return;
history.export([historySession.collections.uuid], filename)
.catch(error => logAndNotifyError(error))
})
.catch(error => logAndNotifyError(error))
},
};
}

private _onDoubleclickEvent(event: IDoubleclickEvent) {
Expand Down