From 49b525e5146acb981dca286c8b8a26575ab88d4d Mon Sep 17 00:00:00 2001 From: minottic Date: Tue, 16 Apr 2024 11:20:11 +0200 Subject: [PATCH] Use reset whenever possible for logic standard --- scilog/src/app/core/search-scroll.service.ts | 2 +- .../core/search-window/search-window.component.html | 4 ++-- .../core/search-window/search-window.component.spec.ts | 10 +++++----- .../core/search-window/search-window.component.ts | 8 +++++--- .../app/logbook/core/search/search.component.spec.ts | 6 ------ scilog/src/app/logbook/core/search/search.component.ts | 9 --------- 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/scilog/src/app/core/search-scroll.service.ts b/scilog/src/app/core/search-scroll.service.ts index 933c232b..7a094355 100644 --- a/scilog/src/app/core/search-scroll.service.ts +++ b/scilog/src/app/core/search-scroll.service.ts @@ -17,7 +17,7 @@ export class SearchScrollBaseService extends ScrollBaseService { } -@Injectable() +@Injectable({ providedIn: 'root' }) export class SearchScrollService extends SearchScrollBaseService { constructor( 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 cb1b1c18..9ee94ad5 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 @@ -22,8 +22,8 @@ - -
+ +
Suggestions... 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 a2167873..af5395b0 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 @@ -14,7 +14,6 @@ describe('SearchWindowComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ SearchWindowComponent ], providers: [ { provide: AppConfigService, useValue: { getConfig } }, { provide: MatDialog, useValue: {} }, @@ -51,17 +50,18 @@ describe('SearchWindowComponent', () => { }); it('should submitSearch logbook', () => { - component.searchString = 'some'; - expect(component.submittedSearch).toEqual(undefined); + const resetSpy = spyOn(component['searchScrollService'], 'reset'); + const search = 'some'; + component.searchString = search; component.submitSearch(); - expect(component.submittedSearch).toEqual('some'); + expect(resetSpy).toHaveBeenCalledOnceWith(search); + expect(component.searched).toEqual(search); }); it('should submitSearch overview', () => { component.logbookId = undefined; const search = 'some'; component.searchString = search; - expect(component.submittedSearch).toEqual(undefined); const resetSpy = spyOn(component['logbookIconScrollService'], 'reset'); const emitSpy = spyOn(component.overviewSearch, 'emit'); const closeSearchSpy = spyOn(component, 'closeSearch'); 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 0fdc375d..0a91be9c 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 @@ -6,6 +6,7 @@ import { LogbookInfoService } from '@shared/logbook-info.service'; import { TagService } from '@shared/tag.service'; import { Hotkeys } from '@shared/hotkeys.service'; import { LogbookIconScrollService } from 'src/app/overview/logbook-icon-scroll-service.service'; +import { SearchScrollService } from 'src/app/core/search-scroll.service'; interface SearchResult { location: string[], @@ -41,7 +42,6 @@ export class SearchWindowComponent implements OnInit { tags: string[] = []; _sample_user: string = ""; subscriptions: Subscription[] = []; - submittedSearch: string; logbookId?: string; constructor( @@ -50,6 +50,7 @@ export class SearchWindowComponent implements OnInit { private tagService: TagService, private hotkeys: Hotkeys, private logbookIconScrollService: LogbookIconScrollService, + private searchScrollService: SearchScrollService, ) { } async ngOnInit(): Promise { @@ -74,8 +75,9 @@ export class SearchWindowComponent implements OnInit { } submitSearch() { + this.searched = this.searchString; if (this.logbookId) { - this.submittedSearch = this.searchString; + this.searchScrollService.reset(this.searchString); return } this.logbookIconScrollService.reset(this.searchString); @@ -123,7 +125,7 @@ export class SearchWindowComponent implements OnInit { set searchString(searchString: string) { this._searchString = searchString; - if (this.logbookId && !searchString) this.submittedSearch = searchString; + if (!searchString) this.searched = searchString; } get searchString() { diff --git a/scilog/src/app/logbook/core/search/search.component.spec.ts b/scilog/src/app/logbook/core/search/search.component.spec.ts index ec2f5366..7560a002 100644 --- a/scilog/src/app/logbook/core/search/search.component.spec.ts +++ b/scilog/src/app/logbook/core/search/search.component.spec.ts @@ -32,12 +32,6 @@ describe('SearchComponent', () => { expect(component).toBeTruthy(); }); - it('should submitSearch', () => { - const resetSpy = spyOn(component.searchScrollService, 'reset'); - component.submitSearch(); - expect(resetSpy).toHaveBeenCalled(); - }); - it('should selectedSnippet', () => { const emitSpy = spyOn(component.close, 'emit'); component.selectedSnippet(''); diff --git a/scilog/src/app/logbook/core/search/search.component.ts b/scilog/src/app/logbook/core/search/search.component.ts index 399e5fc1..18f1b844 100644 --- a/scilog/src/app/logbook/core/search/search.component.ts +++ b/scilog/src/app/logbook/core/search/search.component.ts @@ -8,7 +8,6 @@ import { animate, style, transition, trigger } from '@angular/animations'; selector: 'search', templateUrl: './search.component.html', styleUrls: ['./search.component.css'], - providers: [SearchScrollService], animations: [ trigger('spinner', [ transition(':enter', [ @@ -23,9 +22,6 @@ export class SearchComponent implements OnInit { @Input() config: WidgetItemConfig; - @Input() - searchString: string; - @Output() close = new EventEmitter(); constructor( @@ -35,11 +31,6 @@ export class SearchComponent implements OnInit { async ngOnInit(): Promise { this.searchScrollService.initialize(this.config); - if (this.searchString) this.submitSearch(); - } - - submitSearch() { - this.searchScrollService.reset(this.searchString); } selectedSnippet($event) {