diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.css b/scilog/src/app/logbook/core/search-window/search-window.component.css
index 96af2218..9aa96066 100644
--- a/scilog/src/app/logbook/core/search-window/search-window.component.css
+++ b/scilog/src/app/logbook/core/search-window/search-window.component.css
@@ -57,3 +57,9 @@
width: 50vw !important;
}
+.searchConfig {
+ width: 50px;
+ color: var(--toolbar-text-color);
+ filter: brightness(0.5);
+ margin-inline-end: 5px;
+}
diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.html b/scilog/src/app/logbook/core/search-window/search-window.component.html
index b95e98a4..ae6a9851 100644
--- a/scilog/src/app/logbook/core/search-window/search-window.component.html
+++ b/scilog/src/app/logbook/core/search-window/search-window.component.html
@@ -5,11 +5,10 @@
Search search
+
-
diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts b/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts
index 5254070f..cfa6af46 100644
--- a/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts
+++ b/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts
@@ -96,10 +96,30 @@ describe('SearchWindowComponent', () => {
[
undefined,
- {
- general: { type: 'logbook', title: 'Logbook view' },
- filter: { targetId: 'id' }
- } as WidgetItemConfig,
+ {config:
+ {
+ general: { type: 'logbook', title: 'Logbook view' },
+ filter: { targetId: 'id' }
+ } as WidgetItemConfig,
+ searchStringFromConfig: '',
+ configOut:
+ {
+ general: { type: 'logbook', title: 'Logbook view' },
+ filter: { targetId: 'id' }
+ } as WidgetItemConfig,
+ },
+ {config:
+ {
+ general: { type: 'logbook', title: 'Logbook view' },
+ filter: { targetId: 'id', tags: ['a', 'b'], excludeTags: ['c', 'd'] }
+ } as WidgetItemConfig,
+ searchStringFromConfig: '-#c -#d #a #b',
+ configOut:
+ {
+ general: { type: 'logbook', title: 'Logbook view' },
+ filter: { targetId: 'id' }
+ } as WidgetItemConfig,
+ }
].forEach((t, i) => {
it(`should _prepareConfig ${i}`, () => {
const defaultConfig = {
@@ -117,8 +137,41 @@ describe('SearchWindowComponent', () => {
}
};
if (t)
- component.configsArray = [{ cols: 0, rows: 1, y: 2, x: 3, config: t }];
- expect(component["_prepareConfig"]()).toEqual(t ?? defaultConfig);
+ component.configsArray = [{ cols: 0, rows: 1, y: 2, x: 3, config: t.config }];
+ expect(component["_prepareConfig"]()).toEqual(t? t.configOut: defaultConfig);
+ if (t)
+ expect(component.searchStringFromConfig).toEqual(t.searchStringFromConfig);
+ });
+ });
+
+ [
+ {filter: {tags: ['a', 'b'], excludeTags: ['c', 'd'] }, prefix: '#', key: 'tags', output: '#a #b'},
+ {filter: {tags: ['a', 'b'], excludeTags: ['c', 'd'] }, prefix: '-#', key: 'excludeTags', output: '-#c -#d'},
+ ].forEach((t, i) => {
+ it(`should tagsToString ${i}`, () => {
+ expect(component['tagsToString'](t.filter, t.key, t.prefix)).toEqual(t.output);
+ });
+ });
+
+ it('should composeSearchString', () => {
+ const tagFilter = {tags: ['a', 'b'], excludeTags: ['c', 'd'] };
+ expect(component['composeSearchString'](tagFilter)).toEqual('-#c -#d #a #b');
+ });
+
+ [
+ {searchString: '', searchStringFromConfig: '', output: ''},
+ {searchString: ' ', searchStringFromConfig: ' ', output: ''},
+ {searchString: ' ', searchStringFromConfig: 'def', output: 'def'},
+ {searchString: 'abc', searchStringFromConfig: '', output: 'abc'},
+ {searchString: 'abc', searchStringFromConfig: ' ', output: 'abc'},
+ {searchString: 'abc', searchStringFromConfig: 'def', output: 'abc def'},
+ {searchString: 'abc', searchStringFromConfig: 'def ', output: 'abc def'},
+ {searchString: ' abc', searchStringFromConfig: 'def ', output: 'abc def'},
+ ].forEach((t, i) => {
+ it(`should concatSearchStrings ${i}`, () => {
+ component.searchString = t.searchString;
+ component.searchStringFromConfig = t.searchStringFromConfig;
+ expect(component['concatSearchStrings']()).toEqual(t.output);
});
});
diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.ts b/scilog/src/app/logbook/core/search-window/search-window.component.ts
index 7a7f243c..5eb75eec 100644
--- a/scilog/src/app/logbook/core/search-window/search-window.component.ts
+++ b/scilog/src/app/logbook/core/search-window/search-window.component.ts
@@ -34,6 +34,7 @@ export class SearchWindowComponent implements OnInit {
_sample_user: string = "";
subscriptions: Subscription[] = [];
logbookId?: string;
+ searchStringFromConfig = '';
constructor(
public userPreferences: UserPreferencesService,
@@ -68,7 +69,7 @@ export class SearchWindowComponent implements OnInit {
submitSearch() {
this.searched = this.searchString;
if (this.logbookId) {
- this.searchScrollService.reset(this.searchString);
+ this.searchScrollService.reset(this.concatSearchStrings());
return
}
this.logbookIconScrollService.reset(this.searchString);
@@ -76,6 +77,10 @@ export class SearchWindowComponent implements OnInit {
this.closeSearch();
}
+ private concatSearchStrings(): string {
+ return `${this.searchString} ${this.searchStringFromConfig}`.trim();
+ }
+
private async _initialize_help() {
this._sample_user = this.userPreferences.userInfo.username;
@@ -141,7 +146,10 @@ export class SearchWindowComponent implements OnInit {
}
private _prepareConfig() {
- return this._extractConfig() ?? this.defaultConfig;
+ const config = JSON.parse(JSON.stringify(this._extractConfig() ?? this.defaultConfig));
+ if (config.filter?.tags || config.filter?.excludeTags)
+ this.searchStringFromConfig = this.composeSearchString(config.filter);
+ return config;
}
private _extractConfig() {
@@ -152,6 +160,16 @@ export class SearchWindowComponent implements OnInit {
)?.[0]?.config;
}
+ private tagsToString(configFilter: WidgetItemConfig['filter'], tagKey: string, prefix: string) {
+ const tagsString = `${configFilter?.[tagKey]?.length > 0? `${prefix}` + configFilter?.[tagKey].join(` ${prefix}`): ''}`
+ delete configFilter[tagKey]
+ return tagsString
+ }
+
+ private composeSearchString(configFilter: WidgetItemConfig['filter']) {
+ return `${this.tagsToString(configFilter, 'excludeTags', '-#')} ${this.tagsToString(configFilter, 'tags', '#')}`.trim();
+ }
+
ngOnDestroy(): void {
//Called once, before the instance is destroyed.
//Add 'implements OnDestroy' to the class.