@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
121 lines • 4.99 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.PaginatorFeatureAddonService = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular/core");
const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const types_1 = require("../../../services/types");
let PaginatorFeatureAddonService = class PaginatorFeatureAddonService {
constructor() {
this.defaultPaginatorState = {
page: 1,
pageSize: 10,
pageSizeSet: [10, 20, 50],
total: 0,
};
this.paginatorState = this.defaultPaginatorState;
this.reinit$ = new rxjs_1.Subject();
}
initPaginator(widget) {
this.reinit$.next();
this.widget = widget;
this.setPaginatorState();
this.listenPaginatorChanges();
}
applyFilters() {
this.widget.dataSource.applyFilters();
}
registerPaginator() {
if (this.widget.dataSource) {
this.widget.dataSource.registerComponent({
paginator: {
componentInstance: this.widget.paginator,
},
});
}
}
deregisterPaginator() {
if (this.widget.dataSource) {
this.widget.dataSource.deregisterComponent?.("paginator");
}
}
setPaginatorState() {
const paginatorConfiguration = this.widget.configuration?.paginatorConfiguration;
if (this.widget.hasPaginator && this.widget.paginator) {
this.registerPaginator();
// pageSize, pageSizeSet comes from static config
const modifiedConfiguration = {
pageSize: paginatorConfiguration?.pageSize ??
this.defaultPaginatorState.pageSize,
pageSizeSet: paginatorConfiguration?.pageSizeSet ??
this.defaultPaginatorState.pageSizeSet,
};
// update only if needed to avoid additional calls to ds
if (!(0, isEqual_1.default)(modifiedConfiguration, {
pageSize: this.paginatorState.pageSize,
pageSizeSet: this.paginatorState.pageSizeSet,
})) {
this.updatePaginatorState(modifiedConfiguration);
this.widget.eventBus.getStream(types_1.SET_NEXT_PAGE).next({});
this.widget.changeDetector.detectChanges();
}
// page and total are dynamically set
this.widget.dataSource.outputsSubject
.pipe((0, operators_1.takeUntil)((0, rxjs_1.merge)(this.reinit$, this.widget.onDestroy$)))
.subscribe((data) => {
this.updatePaginatorState({
total: data.paginator?.total ?? 0,
});
});
}
else {
this.deregisterPaginator();
}
}
updatePaginatorState(param) {
this.paginatorState = {
...this.paginatorState,
...param,
};
}
listenPaginatorChanges() {
this.widget.eventBus
.getStream(types_1.SET_NEXT_PAGE)
.pipe((0, operators_1.takeUntil)((0, rxjs_1.merge)(this.reinit$, this.widget.onDestroy$)))
.subscribe(({ payload }) => {
if (!payload) {
return;
}
this.updatePaginatorState({
page: payload.page ?? 1,
});
this.applyFilters();
});
}
};
exports.PaginatorFeatureAddonService = PaginatorFeatureAddonService;
exports.PaginatorFeatureAddonService = PaginatorFeatureAddonService = tslib_1.__decorate([
(0, core_1.Injectable)()
], PaginatorFeatureAddonService);
//# sourceMappingURL=paginator-feature-addon.service.js.map