bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
61 lines • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageService = void 0;
var core_1 = require("@angular/core");
var rxjs_1 = require("rxjs");
var i0 = require("@angular/core");
/**
*
* TODO: better modal implementation that doesn't use window.confirm
*/
var MessageService = /** @class */ (function () {
function MessageService() {
// Observable string sources
this.observableMessagesSource = new rxjs_1.Subject(); //mensajes generales que se mostrarán como un dialog en el centro de la pantalla
this.observableNotificationsSource = new rxjs_1.Subject(); //notifiaciones que se mostrarán como un growl
this.observableErrorsSource = new rxjs_1.Subject(); //errores del servidor que se mostrarán como un dialog igual con la traza del error
this.observableNotificacionsErrorsSource = new rxjs_1.Subject(); //errores controlados enviados del servidor que se mostrarán como una ventanita similar al growl
this.observableMessages = this.observableMessagesSource.asObservable();
this.observableErrors = this.observableErrorsSource.asObservable();
this.observableNotificationsErrors = this.observableNotificacionsErrorsSource.asObservable();
this.observableNotifications = this.observableNotificationsSource.asObservable();
}
/**
* Ask user to confirm an action. `message` explains the action and choices.
* Returns promise resolving to `true`=confirm or `false`=cancel
*/
MessageService.prototype.confirm = function (message) {
return new Promise(function (resolve) {
return resolve(window.confirm(message || " OK?"));
});
};
/** Enviamos un mensaje. Como mínimo el componente DialogComponent lo recibirá y lo mostrará al usuario */
MessageService.prototype.sendMessage = function (message) {
this.observableMessagesSource.next(message);
};
/**
* Enviamos un error. Si el objeto es de tipo notificación se mostrará como una ventana arriba a la derecha con un close para
* cerrarlo. Si no es de tipo notificación el componente DialogComponent lo recibirá y lo mostrará al usuario en el centro del usuario
**/
MessageService.prototype.sendError = function (error) {
//console.log('sendError', error);
if (error.notificacion) {
this.observableNotificacionsErrorsSource.next(error);
}
else {
this.observableErrorsSource.next(error);
}
};
/** Enviamos una notificación. El componente NotificationComponent lo recibirá y la mostrará en pantalla */
MessageService.prototype.sendNotification = function (message) {
this.observableNotificationsSource.next(message);
};
MessageService.ɵfac = function MessageService_Factory(t) { return new (t || MessageService)(); };
MessageService.ɵprov = i0.ɵɵdefineInjectable({ token: MessageService, factory: MessageService.ɵfac });
return MessageService;
}());
exports.MessageService = MessageService;
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MessageService, [{
type: core_1.Injectable
}], function () { return []; }, null); })();
//# sourceMappingURL=message.service.js.map