@WidgetComponent

nm-google-translate

File

src/app/shared/widgets/apps/google-translate/google-translate.component.ts

Description

Used in App google-translate. Surrounded by widgetframe Provides form for google-translate configuration app

Metadata

selector nm-google-translate
styleUrls google-translate.component.scss
templateUrl ./google-translate.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(_progressbarService: ProgressbarService, _widgetframeService: WidgetframeService, _notificationService: CustomNotificationService, _halService: HalService, translateService: TranslateService, http: HttpClient)
Parameters :
Name Type Optional
_progressbarService ProgressbarService no
_widgetframeService WidgetframeService no
_notificationService CustomNotificationService no
_halService HalService no
translateService TranslateService no
http HttpClient no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig<GoogleTranslateConfiguration> no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public testKey
testKey(key: )
Parameters :
Name Optional
key no
Returns : void

Properties

Public _id
_id: string
Type : string
Decorators : WidgetId
Public action
action: any
Type : any
Public appData
appData: any
Type : any
Public appSetup
appSetup: any[]
Type : any[]
Public component
component: string
Type : string
Public configuration
configuration: WidgetConfig<GoogleTranslateConfiguration>
Type : WidgetConfig<GoogleTranslateConfiguration>
Decorators : WidgetConfiguration
Public header
header: string
Type : string
Public href
href: Subject<string>
Type : Subject<string>
Default value : new ReplaySubject<string>(1)
Public keyTestUrl
keyTestUrl: string
Type : string
Public title
title: string
Type : string
import { map, filter } from "rxjs/operators";
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Subject, ReplaySubject } from "rxjs";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import {
  WidgetConfiguration,
  WidgetId,
  WidgetConfigure,
  WidgetComponent,
} from "../../widget.metadata";
import { WidgetConfig } from "../../widget.configuration";
import { ProgressbarService } from "../../../components/progressbar/progressbar.service";
import { CustomNotificationService } from "../../../components/notification/customnotification.service";
import { HalService } from "../../../components/hal/hal.service";
import { TranslateService } from "@ngx-translate/core";

declare var contextPath: string;

export interface GoogleTranslateConfiguration {
  /**
   * Sets the title shown in the Google Translate configuration header
   */
  title: string;

  /**
   * Sets CSS class name for the embedded header component
   */
  header: string;

  /**
   * Sets place holder text for Google Translate API key input field
   */
  keyKey: string;

  /**
   * Sets the url used for testing the validity of the provided Google Translate API key @default('')
   * (currently the component only checks if the url is not empty and uses a hard-coded value)
   */
  keyTestUrl?: string;

  /**
   * Sets the name for Google Translate API key
   */
  keyname: string;
}

/**
 * Used in App google-translate.
 * Surrounded by widgetframe
 * Provides form for google-translate configuration app
 */
@WidgetComponent("nm-google-translate")
@Component({
  selector: "nm-google-translate",
  templateUrl: "./google-translate.component.html",
  styleUrls: ["./google-translate.component.scss"],
})
export class GoogleTranslateComponent {
  public title: string;
  public header: string;
  public component: string;
  public keyTestUrl: string;

  public appSetup: any[];
  public appData: any;

  public action: any;

  @WidgetConfiguration()
  public configuration: WidgetConfig<GoogleTranslateConfiguration>;

  @WidgetId()
  public _id: string;

  public href: Subject<string> = new ReplaySubject<string>(1);

  constructor(
    private _progressbarService: ProgressbarService,
    private _widgetframeService: WidgetframeService,
    private _notificationService: CustomNotificationService,
    private _halService: HalService,
    private translateService: TranslateService,
    private http: HttpClient
  ) {
    this._progressbarService.requestFinished();
  }

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig<GoogleTranslateConfiguration>
  ) {
    this.action = {};
    this.component = configuration.component;
    this.title = this.configuration.configuration.title;
    this.header = this.configuration.configuration.header;
    this.keyTestUrl = this.configuration.configuration.keyTestUrl
      ? this.configuration.configuration.keyTestUrl
      : "";
    let href = configuration._links["data"]["href"];
    this._progressbarService.addRequest();
    this._widgetframeService.getData(href).subscribe((data) => {
      this.appData = data;

      if (this.appData.enabled == "true") {
        console.log("if true", this.appData.enabled);
        this.appData.enabled = true;
      } else {
        this.appData.enabled = false;
      }
      this._progressbarService.requestFinished();
      console.log("this.appData.enabled", this.appData.enabled);
    });

    this.action.description = this.component;
    this.action.href = href;
    this.action.title = this.component;
    this.action.type = "request";

    this._halService
      .getActionEvents()
      .pipe(
        filter((event) => event.name === this.component),
        map((event) => (<any>event).response)
      )
      .subscribe((resp) => {
        this._notificationService.fromJson(resp);
      });
  }

  public testKey(key) {
    if (this.keyTestUrl.length > 0) {
      let url =
        "https://www.googleapis.com/language/translate/v2?key=" +
        key +
        "&source=en&target=de&q=Hello%20world";
      this._progressbarService.addRequest();
      this.http.get(url).subscribe(
        (response) => {
          this._notificationService.create(
            this.translateService.instant(
              "message.success.googleapitest.title"
            ),
            this.translateService.instant("message.success.googleapitest.body"),
            "success"
          );
          this._progressbarService.requestFinished();
        },
        (err) => {
          this._progressbarService.requestFinished();
          this._notificationService.create(
            this.translateService.instant("message.error.googleapitest.title"),
            this.translateService.instant("message.error.googleapitest.body"),
            "error"
          );
        }
      );
    } else {
      this._progressbarService.addRequest();

      window.setTimeout(() => {
        this._notificationService.create(
          this.translateService.instant("message.success.googleapitest.title"),
          this.translateService.instant("message.success.googleapitest.body"),
          "success"
        );

        this._progressbarService.requestFinished();
      }, 700);
    }
  }

  ngOnInit(): void {}

  ngOnDestroy(): void {}
}
<form class="app-form" #appForm="ngForm" *ngIf="appData">
  <nm-widgetframe
    [header]="header"
    style="width: 1000px; padding-top: 15px"
    widgetId="{{ _id }}"
  >
    <div slot="title" class="nm-widgetframe__title">
      <span style="float: left; line-height: 55px"
        >{{ title | translate }}
      </span>
    </div>
    <div slot="content" class="nm-widgetframe__content nm-goole-translate-app">
      <div class="app-container">
        <div class="config-container">
          <!--<i class="material-icons nm-app-icon-detail" [class.enabled]="(appData.enabled === 'true'|| appData.enabled)"> compare_arrows</i>-->
          <h4 class="nm-app-hl">{{ "hl.configuration" | translate }}</h4>
        </div>
        <mat-divider
          style="margin: 0 16px; width: calc(100% - 32px)"
        ></mat-divider>
        <br />

        <div class="config-container">
          <mat-form-field class="full-width">
            <input
              matInput
              placeholder="{{
                configuration.configuration['keyKey'] | translate
              }}"
              [disabled]="!appData.enabled"
              required
              name="googleapikey"
              type="text"
              [(ngModel)]="appData[configuration.configuration['keyname']]"
            />
          </mat-form-field>
          <button mat-button type="button" (click)="testKey(appData.key)">
            {{ "button.testKey" | translate }}
          </button>
          <br />
          <br />
          <mat-slide-toggle
            style="margin-right: 15px"
            color="primary"
            name="enabled"
            [checked]="appData.enabled"
            [(ngModel)]="appData.enabled"
          >
            <span *ngIf="appData.enabled">
              {{ "placeholder.enabled" | translate }}
            </span>
            <span *ngIf="!appData.enabled">
              {{ "placeholder.disabled" | translate }}
            </span>
          </mat-slide-toggle>
          <br />
          <br />
        </div>
        <div class="modal-footer">
          <button
            mat-raised-button
            color="primary"
            [nm-action]="action"
            [action-name]="component"
            [disabled]="!appForm.form.valid"
            [action-name]="'app'"
            [action-payload]="appData"
          >
            {{ "button.update" | translate }}
          </button>
        </div>
      </div>
    </div>
  </nm-widgetframe>
</form>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""