UNPKG

@nepwork/dashboards

Version:

Dashboards for emergencies and monitoring

75 lines 2.4 kB
import { __decorate, __metadata, __param } from "tslib"; /** * @license * Copyright Akveo. All Rights Reserved. * Licensed under the MIT License. See License.txt in the project root for license information. */ import { Injectable, Inject } from '@angular/core'; import { NB_DOCUMENT } from '../theme.options'; /** * Service to control the global page spinner. */ var NbSpinnerService = /** @class */ (function () { function NbSpinnerService(document) { this.document = document; this.loaders = []; this.selector = 'nb-global-spinner'; } /** * Appends new loader to the list of loader to be completed before * spinner will be hidden * @param method Promise<any> */ NbSpinnerService.prototype.registerLoader = function (method) { this.loaders.push(method); }; /** * Clears the list of loader */ NbSpinnerService.prototype.clear = function () { this.loaders = []; }; /** * Start the loader process, show spinnder and execute loaders */ NbSpinnerService.prototype.load = function () { this.showSpinner(); this.executeAll(); }; NbSpinnerService.prototype.executeAll = function (done) { var _this = this; if (done === void 0) { done = function () { }; } Promise.all(this.loaders).then(function (values) { _this.hideSpinner(); done.call(null, values); }) .catch(function (error) { // TODO: Promise.reject console.error(error); }); }; // TODO is there any better way of doing this? NbSpinnerService.prototype.showSpinner = function () { var el = this.getSpinnerElement(); if (el) { el.style['display'] = 'block'; } }; NbSpinnerService.prototype.hideSpinner = function () { var el = this.getSpinnerElement(); if (el) { el.style['display'] = 'none'; } }; NbSpinnerService.prototype.getSpinnerElement = function () { return this.document.getElementById(this.selector); }; NbSpinnerService = __decorate([ Injectable(), __param(0, Inject(NB_DOCUMENT)), __metadata("design:paramtypes", [Object]) ], NbSpinnerService); return NbSpinnerService; }()); export { NbSpinnerService }; //# sourceMappingURL=spinner.service.js.map