File

C:/GoDev/src/TCSTK-Angular/projects/tibco-tcstk/tc-messaging-lib/src/lib/components/eftl-messaging-settings/eftl-messaging-settings.component.ts

Description

Component to manage configuration of Tibco Cloud Messaging connections

alt-text

Implements

OnInit

Example

<tcmsg-eftl-messaging-settings></tcmsg-eftl-messaging-settings>

Metadata

selector tcmsg-eftl-messaging-settings
styleUrls ./eftl-messaging-settings.component.css
templateUrl ./eftl-messaging-settings.component.html

Index

Properties
Methods

Constructor

constructor(route: ActivatedRoute, messagingConfigService: EFTLConfigService, snackBar: MatSnackBar, dialog: MatDialog)
Parameters :
Name Type Optional
route ActivatedRoute No
messagingConfigService EFTLConfigService No
snackBar MatSnackBar No
dialog MatDialog No

Methods

Protected getLiveAppsConfigService
getLiveAppsConfigService()
Returns : EFTLConfigService
Public ngOnInit
ngOnInit()
Returns : void

Properties

Public claims
Type : Claim
Public clearMessagingConfig
Default value : () => {...}
connectionPanels
Type : QueryList<MatExpansionPanel>
Decorators :
@ViewChildren(MatExpansionPanel)
createConnectionFunction
Default value : () => {...}
Public currentConnection
Type : MessagingConnection
deleteConnectionFunction
Default value : () => {...}
Public generalConfig
Type : GeneralConfig
Public isAdmin
Default value : false
Public messagingConfig
Type : MessagingConfig
Public newPanelId
Type : string
Public runSaveFunction
Default value : () => {...}
Public sandboxId
Type : number
selectedConnection
Default value : () => {...}
import {Component, OnInit, QueryList, ViewChildren} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Claim, GeneralConfig, RoleAttribute, TibcoCloudNewElementComponent} from '@tibco-tcstk/tc-core-lib';
import { MatDialog } from '@angular/material/dialog';
import { MatExpansionPanel } from '@angular/material/expansion';
import { MatSnackBar } from '@angular/material/snack-bar';
import {MessagingConfig} from '../../models/messaging-config';
import {EFTLConfigService} from '../../services/e-ftl-config.service';
import {MessagingConnection} from '../../models/messaging-connection';


/**
 * Component to manage configuration of Tibco Cloud Messaging connections
 *
 * ![alt-text](../messaging-settings.png "")
 *
 *@example <tcmsg-eftl-messaging-settings></tcmsg-eftl-messaging-settings>
 */
@Component({
  selector: 'tcmsg-eftl-messaging-settings',
  templateUrl: './eftl-messaging-settings.component.html',
  styleUrls: ['./eftl-messaging-settings.component.css']
})
export class EftlMessagingSettingsComponent implements OnInit {

  @ViewChildren(MatExpansionPanel) connectionPanels: QueryList<MatExpansionPanel>;

  public sandboxId: number;
  public claims: Claim;
  public generalConfig: GeneralConfig;
  public messagingConfig: MessagingConfig;
  public currentConnection: MessagingConnection;
  public newPanelId: string;
  public isAdmin = false;

  constructor(protected route: ActivatedRoute, protected messagingConfigService: EFTLConfigService, protected snackBar: MatSnackBar, protected dialog: MatDialog) {
  }

  protected getLiveAppsConfigService(): EFTLConfigService {
    return this.messagingConfigService;
  }

  public ngOnInit() {
    this.claims = this.route.snapshot.data.claims;
    const adminGroup = this.claims.primaryProductionSandbox.groups.find(group => {
      return group.type === 'Administrator';
    });
    this.isAdmin = adminGroup ? true : false;
    this.sandboxId = Number(this.claims.primaryProductionSandbox.id);
    this.generalConfig = this.route.snapshot.data.generalConfigHolder;
    this.messagingConfig = this.route.snapshot.data.messagingConfig ? this.route.snapshot.data.messagingConfig : { connections: [] };
  }

  deleteConnectionFunction = (): void => {
    this.messagingConfig.connections = this.messagingConfig.connections.filter(element => element.id !== this.currentConnection.id);
    this.currentConnection = undefined;
  }

  selectedConnection = (connection: MessagingConnection): void => {
    this.currentConnection = connection;
  }

  createConnectionFunction = (): void => {
    const dialogRef = this.dialog.open(TibcoCloudNewElementComponent, {
      panelClass: 'tcs-style-dialog',
      data: { resourceType: 'Messaging Connection', idReadOnly: true, id: this.messagingConfig.connections.length + 1 }
    });

    dialogRef.afterClosed().subscribe(result => {
      if (result) {
        const newConnection = new MessagingConnection().deserialize({id: result.id, name: result.name });
        // forces panel to open on creation
        this.newPanelId = result.id;
        this.messagingConfig.connections.push(newConnection);
      }
    });
  }

  public runSaveFunction = (): void => {
    if (this.messagingConfig.id) {
      // update existing config
      this.messagingConfigService.updateMessagingConfig(this.sandboxId, this.generalConfig.uiAppId, this.messagingConfig, this.messagingConfig.id).subscribe(
        result => {
          this.snackBar.open('Messaging configuration settings saved', 'OK', {
            duration: 3000
          });
        },
        error => {
          this.snackBar.open('Error saving messaging configuration', 'OK', {
            duration: 3000
          });
        }
      );
    } else {
      // create new config
      this.messagingConfigService.createMessagingConfig(this.sandboxId, this.generalConfig.uiAppId, this.messagingConfig).subscribe(
        next => {
          this.messagingConfig = next;
          this.snackBar.open('Messaging configuration settings saved', 'OK', {
            duration: 3000
          });
        },
        error => {
          this.snackBar.open('Error saving messaging configuration', 'OK', {
            duration: 3000
          });
        }
      );
    }
  }

  public clearMessagingConfig = () => {
    this.messagingConfigService.removeMessagingConfig(Number(this.messagingConfig.id)).subscribe(
      next => {
        this.messagingConfig = new MessagingConfig().deserialize({connections: []});
        this.snackBar.open('Messaging configuration settings cleared', 'OK', {
          duration: 3000
        });
      },
      error => {
        this.snackBar.open('Error clearing messaging configuration', 'OK', {
          duration: 3000
        });
      }
    );
  }

}
<div fxLayout="column" class="tcs-live-apps-settings-pane" fxFill>
  <tc-tibco-cloud-widget-header style="height: 40px;" [icon]="'tcs-capabilities'" [headerText]="'Messaging Configuration'">
  </tc-tibco-cloud-widget-header>
  <div fxFlex style="padding: 20px; overflow: hidden" fxLayout="column">
    <div style="overflow: auto;">
      <div fxLayout="column" fxFlex>
        <p class="tcs-settings-text">Configure Tibco Cloud Messaging connections for this application:</p>
        <br>
        <!-- Role specific -->
        <mat-accordion>
          <!-- expanded forces panel to open when added by user -->
          <mat-expansion-panel *ngFor="let connection of messagingConfig.connections" [expanded]="connection.id === newPanelId" (opened)="selectedConnection(connection)">
            <mat-expansion-panel-header>
              <mat-panel-title>{{connection.name}}</mat-panel-title>
            </mat-expansion-panel-header>
            <div fxLayout="column">
              <div fxLayoutGap="10px" fxLayout="row wrap">
                <mat-form-field fxFlex>
                  <input matInput placeholder="Id" [(ngModel)]="connection.id" readonly>
                </mat-form-field>
                <mat-form-field fxFlex>
                  <input matInput placeholder="Name" [(ngModel)]="connection.name" required>
                </mat-form-field>
                <mat-form-field fxFlex>
                  <input matInput placeholder="Event" [(ngModel)]="connection.event" required>
                </mat-form-field>
                <mat-form-field fxFlex>
                  <input matInput placeholder="Matcher" [(ngModel)]="connection.matcher" required>
                </mat-form-field>
                <mat-form-field fxFlex>
                  <input matInput placeholder="Durable" [(ngModel)]="connection.durable" required>
                </mat-form-field>
              </div>
              <div fxLayoutGap="10px" fxLayout="row wrap">
                <mat-form-field fxFlex style="min-width: 1000px;">
                  <input matInput placeholder="WSS URL" [(ngModel)]="connection.wssUrl" required>
                </mat-form-field>
                <mat-form-field fxFlex style="min-width: 1000px;">
                  <input matInput placeholder="API Key" type="password" [(ngModel)]="connection.apiKey" required>
                </mat-form-field>
              </div>
            </div>
          </mat-expansion-panel>
        </mat-accordion>
      </div>

    </div>
    <div fxFlex class="tcs-filler-panel"></div>
    <div fxLayout="row" fxLayoutAlign="start end" fxLayoutGap="10px" style="min-height: 50px" *ngIf="(messagingConfig.id || isAdmin); else cannotCreate">
      <div fxLayoutAlign="start end">
        <button mat-raised-button color="seconday" *ngIf="messagingConfig?.id" (click)="clearMessagingConfig()">Clear All Saved Messsage Config</button>
      </div>
      <div fxLayoutAlign="end end" fxFlex fxLayoutGap="10px">
        <button mat-raised-button color="secondary" [disabled]="!currentConnection"
                (click)="deleteConnectionFunction()">Delete Connection</button>
        <button mat-raised-button color="secondary" (click)="createConnectionFunction()">Create Connection</button>
        <button mat-raised-button color="primary" (click)="runSaveFunction()">Save</button>
      </div>
    </div>
    <ng-template  #cannotCreate>
        <span class="tcs-warning-text">Warning: You must be a member of the administrators group to save messaging configuration</span>
    </ng-template>
  </div>
</div>

./eftl-messaging-settings.component.css

.tcs-card-config-widget-pane {
  overflow: hidden;
}

.tcs-settings-text {
  font-family: Source Sans Pro;
  font-size: 14px;
  font-weight: normal;
  font-style: normal;
  font-stretch: normal;
  line-height: 1.5;
  letter-spacing: 0.3px;
}

.tcs-checkbox-label {
  font-family: Source Sans Pro;
  font-size: 14px;
  font-weight: normal;
  font-style: normal;
  font-stretch: normal;
  line-height: 1.5;
  letter-spacing: 0.3px;
}

.tcs-warning-text {
  font-family: Source Sans Pro;
  font-size: 14px;
  font-weight: normal;
  font-style: normal;
  font-stretch: normal;
  line-height: 1.5;
  letter-spacing: 0.3px;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""