@nova-ui/dashboards
Version:
Nova Dashboards is a framework designed to provide feature developers with a common solution for presenting data coming from various sources within a single view, as well as a set of predefined widget visualizations that are 100% configuration-driven and
105 lines • 4.85 kB
JavaScript
"use strict";
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.VirtualScrollFeatureAddonService = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular/core");
// eslint-disable-next-line import/no-deprecated
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const bits_1 = require("@nova-ui/bits");
const types_1 = require("../../../services/types");
let VirtualScrollFeatureAddonService = class VirtualScrollFeatureAddonService {
constructor() {
this.visibleItems = [];
}
initWidget(widget) {
this.widget = widget;
}
initVirtualScroll(widget) {
if (!this.widget) {
this.initWidget(widget);
}
if (this.widget.hasVirtualScroll) {
this.registerVirtualScroll();
}
else {
this.deregisterVirtualScroll();
}
}
registerVirtualScroll() {
if (this.widget.dataSource) {
this.widget.dataSource.registerComponent({
[(0, bits_1.nameof)("virtualScroll")]: {
componentInstance: this.widget.viewportManager,
},
});
}
}
deregisterVirtualScroll() {
if (this.widget.dataSource) {
this.widget.dataSource.deregisterComponent?.((0, bits_1.nameof)("virtualScroll"));
}
}
/**
* Subscribe to virtual scroll rendered items and fetches next items
*/
subscribeToVirtualScroll() {
if (!this.widget.vscrollViewport) {
return;
}
// Note: Using this additional stream to pass the visible range to
// the table and trigger change detection on range change and table data update.
// eslint-disable-next-line import/no-deprecated
(0, rxjs_1.merge)(this.widget.vscrollViewport.renderedRangeStream, this.widget.tableUpdate$.pipe((0, operators_1.map)(() => this.widget.vscrollViewport?.getRenderedRange())))
.pipe((0, operators_1.tap)((range) => {
this.visibleItems = this.widget.tableData.slice(range?.start, range?.end);
// Since we're using onPush strategy we should trigger CD manually to ensure that visible items are updated properly
this.widget.changeDetector.detectChanges();
}), (0, operators_1.takeUntil)(this.widget.onDestroy$))
.subscribe();
this.widget.viewportManager
.setViewport(this.widget.vscrollViewport)
.observeNextPage$({
pageSize: this.widget.range,
emitFirstPage: true,
})
.pipe(
// Note: A special check to keep our server-client-side sorting in place
(0, operators_1.filter)((range) => range.end >=
(this.widget.vscrollViewport?.getDataLength() ?? 0)), (0, operators_1.tap)((range) => this.widget.zone.run(() => {
// TODO: Remove "page" in V10. Compute page on datasource level. - NUI-5830
// @ts-ignore: Provide a proper interface to DS
this.widget.dataSource.page =
range.end / (range.end - range.start);
this.widget.eventBus
.getStream(types_1.SCROLL_NEXT_PAGE)
.next({});
this.widget.changeDetector.detectChanges();
})), (0, operators_1.takeUntil)(this.widget.onDestroy$))
.subscribe();
}
};
exports.VirtualScrollFeatureAddonService = VirtualScrollFeatureAddonService;
exports.VirtualScrollFeatureAddonService = VirtualScrollFeatureAddonService = tslib_1.__decorate([
(0, core_1.Injectable)()
], VirtualScrollFeatureAddonService);
//# sourceMappingURL=virtual-scroll-feature-addon.service.js.map