diff --git a/scilog/src/app/logbook/core/scroll-base.service.spec.ts b/scilog/src/app/logbook/core/scroll-base.service.spec.ts index bebcb6bd..d6ffd705 100644 --- a/scilog/src/app/logbook/core/scroll-base.service.spec.ts +++ b/scilog/src/app/logbook/core/scroll-base.service.spec.ts @@ -1,6 +1,7 @@ import { TestBed } from '@angular/core/testing'; import { ScrollBaseService } from './scroll-base.service'; +import { IDatasource } from 'ngx-ui-scroll'; describe('ScrollBaseService', () => { let service: ScrollBaseService; @@ -15,4 +16,18 @@ describe('ScrollBaseService', () => { it('should be created', () => { expect(service).toBeTruthy(); }); + + it('should decorate with isLoadedDecorator', async () => { + const toDecorate = async (index, count, config) => index + count + config; + const decorated = await service.isLoadedDecorator(toDecorate)(1, 2, 3); + expect(decorated).toEqual(6); + }); + + it('should reset isLoaded flag after reset', async () => { + service.datasource = { adapter: { reset: async () => ({}) } } as IDatasource; + service.isLoaded = true; + service.reset(); + expect(service.isLoaded).toEqual(false); + }); + }); diff --git a/scilog/src/app/logbook/core/scroll-base.service.ts b/scilog/src/app/logbook/core/scroll-base.service.ts index cdef7eb5..b8a8822f 100644 --- a/scilog/src/app/logbook/core/scroll-base.service.ts +++ b/scilog/src/app/logbook/core/scroll-base.service.ts @@ -8,8 +8,11 @@ export class ScrollBaseService { datasource: IDatasource = null; startIndex = 0; config: WidgetItemConfig = null; + isLoaded = false; - constructor() { } + constructor() { + this.getDataBuffer = this.isLoadedDecorator(this.getDataBuffer.bind(this)); + } public async initialize(config: WidgetItemConfig) { // console.log("Config: ", this.config); @@ -64,6 +67,24 @@ export class ScrollBaseService { throw new Error("Abstract method needs to be implemented in derived class.") } + isLoadedDecorator(func: Function) { + const decorated = async (index: number, count: number, config: any) => { + this.isLoaded = false; + let data; + try { + data = await func(index, count, config); + } + catch { + console.log('scroller get data returned an error'); + } + finally { + this.isLoaded = true; + return data; + } + } + return decorated; + } + async updateViewportEstimate() { await this.datasource.adapter.relax(); this.datasource.adapter.check(); @@ -75,6 +96,7 @@ export class ScrollBaseService { reset() { if (this.datasource != null) { + this.isLoaded = false; this.datasource.adapter.reset(); } } 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 7d166bf2..4edbc05d 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 @@ -97,4 +97,12 @@ border: unset; padding: 4px; margin-left: 4px; -} \ No newline at end of file +} + +.spinner { + position: fixed; + z-index: 1031; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} 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 79257645..81b16714 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 @@ -61,6 +61,7 @@