| /* |
| ****************************************************************************** |
| * Copyright © 2018 PTA GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| ****************************************************************************** |
| */ |
| import { Injectable, EventEmitter } from '@angular/core'; |
| import { BannerMessageStatusEn, ErrorType, ToasterButtonEventEn, MessageScopeEn } from '../common/enums'; |
| import { SessionContext } from './../common/session-context'; |
| import { BannerMessage } from '../common/banner-message'; |
| |
| export class MessageDefines { |
| static MSG_LOG_IN_SUCCEEDED = 'LOG_IN_SUCCEEDED'; |
| static MSG_LOG_OFF = 'LOG_OFF'; |
| } |
| |
| @Injectable() |
| export class MessageServiceCustom { |
| |
| private messageServiceActive: boolean; |
| |
| public loginLogoff$: EventEmitter<string> = new EventEmitter<string>(); |
| // public bannerButtonEvent$: EventEmitter<ToasterButtonEventEn> = new EventEmitter<ToasterButtonEventEn>(); |
| public errorOccured$: EventEmitter<BannerMessage> = new EventEmitter<BannerMessage>(); |
| // public clearBannerLocalEvent$: EventEmitter<boolean> = new EventEmitter<boolean>(); |
| public clearDecisionBannerLocalEvent$: EventEmitter<boolean> = new EventEmitter<boolean>(); |
| |
| constructor(private sessionContext: SessionContext) { } |
| |
| // public emitError(location: string, errorType?: ErrorType, msgScope?: MessageScopeEn, error?: any) { |
| // if (error === ErrorType.authentication) { |
| // return; |
| // } |
| |
| // let message = ''; |
| |
| // switch (errorType) { |
| // case ErrorType.create: |
| // message = 'Fehler beim Erstellen des Objekts ' + location + '.'; |
| // break; |
| // case ErrorType.update: |
| // message = 'Fehler beim Aktualiseren des Objekts ' + location + '.'; |
| // break; |
| // case ErrorType.delete: |
| // message = 'Fehler beim Löschen des Objekts ' + location + '.'; |
| // break; |
| // case ErrorType.retrieve: |
| // message = 'Fehler beim Zugriff auf ' + location + '.'; |
| // break; |
| // case ErrorType.upload: |
| // message = 'Fehler beim Hochladen der Datei in ' + location + '.'; |
| // break; |
| // case ErrorType.locked: |
| // message = 'Eintrag ist gesperrt von ' + this.sessionContext.getUserMap().findAndRenderUser(location) + '.'; |
| // break; |
| // case ErrorType.datedependency: |
| // message = 'Beginn der ersten geplanten Schrittsequenz muss vor dem Enddatum der geplanten Netzmaßnahme liegen.'; |
| // break; |
| // case ErrorType.stornoLocked: |
| // message = 'Eintrag ist gesperrt. Bitte versuchen Sie es später noch einmal.'; |
| // break; |
| // default: |
| // message = 'Es ist ein unbekannter Fehler aufgetreten.'; |
| // break; |
| // } |
| |
| // this.emitMessage(message, BannerMessageStatusEn.error, msgScope, errorType); |
| // } |
| |
| // public emitInfo(message: string, msgScope: MessageScopeEn) { |
| // this.emitMessage(message, BannerMessageStatusEn.info, msgScope); |
| // } |
| |
| // public emitWarning(message: string, msgScope: MessageScopeEn) { |
| // this.emitMessage(message, BannerMessageStatusEn.warning, msgScope); |
| // } |
| |
| // public deactivateMessage() { |
| // const bannerMessage: BannerMessage = new BannerMessage(); |
| // bannerMessage.isActive = false; |
| // this.errorOccured$.emit(bannerMessage); |
| // } |
| |
| // public emitDecisionMessage(message: string, msgScope: MessageScopeEn) { |
| // const bannerMessage: BannerMessage = new BannerMessage(); |
| // bannerMessage.showDecisionButtons = true; |
| // // bannerMessage.showButton = true; |
| // bannerMessage.isSetTimeout = false; |
| // this.emitAdjustedMessage(bannerMessage, message, BannerMessageStatusEn.info, msgScope); |
| // } |
| |
| // TODO Unlock muss hierüber emittiert werden |
| /* public emitUnlockMessage(message: string, msgScope: MessageScopeEn) { |
| const bannerMessage: BannerMessage = new BannerMessage(); |
| bannerMessage.showButton = true; |
| this.emitAdjustedMessage(bannerMessage); |
| } */ |
| |
| // private emitAdjustedMessage(bannerMessage: BannerMessage, message: string, status: BannerMessageStatusEn, msgScope: MessageScopeEn) { |
| // bannerMessage.text = message; |
| // bannerMessage.isActive = true; |
| // bannerMessage.scope = msgScope; |
| // bannerMessage.status = status; |
| // if (!this.sessionContext.isUserAuthenticated()) { return; } |
| // this.errorOccured$.emit(bannerMessage); |
| // } |
| |
| // private emitMessage(message: string, status: BannerMessageStatusEn, msgScope: MessageScopeEn, errorType?: ErrorType) { |
| // if (!this.sessionContext.isUserAuthenticated()) { return; } |
| // const bannerMessage: BannerMessage = new BannerMessage(); |
| // bannerMessage.isActive = true; |
| // bannerMessage.status = status; |
| // bannerMessage.text = message; |
| // bannerMessage.errorType = errorType; |
| // bannerMessage.scope = msgScope; |
| // this.errorOccured$.emit(bannerMessage); |
| // console.log(message); |
| // } |
| } |