device-credentials-dialog.component.html 3.46 KB
<!--

    Copyright © 2016-2020 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<form [formGroup]="deviceCredentialsFormGroup" (ngSubmit)="save()" style="min-width: 350px;">
  <mat-toolbar color="primary">
    <h2 translate>device.device-credentials</h2>
    <span fxFlex></span>
    <button mat-icon-button
            (click)="cancel()"
            type="button">
      <mat-icon class="material-icons">close</mat-icon>
    </button>
  </mat-toolbar>
  <mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async">
  </mat-progress-bar>
  <div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div>
  <div mat-dialog-content>
    <fieldset [disabled]="(isLoading$ | async) || isReadOnly">
      <mat-form-field class="mat-block">
        <mat-label translate>device.credentials-type</mat-label>
        <mat-select formControlName="credentialsType"
                    (ngModelChange)="credentialsTypeChanged()">
          <mat-option *ngFor="let credentialsType of credentialsTypes" [value]="credentialsType">
            {{ credentialTypeNamesMap.get(deviceCredentialsType[credentialsType]) }}
          </mat-option>
        </mat-select>
      </mat-form-field>
      <mat-form-field *ngIf="deviceCredentialsFormGroup.get('credentialsType').value === deviceCredentialsType.ACCESS_TOKEN"
                      class="mat-block">
        <mat-label translate>device.access-token</mat-label>
        <input matInput formControlName="credentialsId" required>
        <mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsId').hasError('required')">
          {{ 'device.access-token-required' | translate }}
        </mat-error>
        <mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsId').hasError('pattern')">
          {{ 'device.access-token-invalid' | translate }}
        </mat-error>
      </mat-form-field>
      <mat-form-field *ngIf="deviceCredentialsFormGroup.get('credentialsType').value === deviceCredentialsType.X509_CERTIFICATE"
                      class="mat-block">
        <mat-label translate>device.rsa-key</mat-label>
        <textarea matInput formControlName="credentialsValue" cols="15" rows="5" required></textarea>
        <mat-error *ngIf="deviceCredentialsFormGroup.get('credentialsValue').hasError('required')">
          {{ 'device.rsa-key-required' | translate }}
        </mat-error>
      </mat-form-field>
    </fieldset>
  </div>
  <div mat-dialog-actions fxLayoutAlign="end center">
    <button *ngIf="!isReadOnly" mat-raised-button color="primary"
            type="submit"
            [disabled]="(isLoading$ | async) || deviceCredentialsFormGroup.invalid
            || !deviceCredentialsFormGroup.dirty">
      {{ 'action.save' | translate }}
    </button>
    <button mat-button color="primary"
            type="button"
            [disabled]="(isLoading$ | async)"
            (click)="cancel()" cdkFocusInitial>
      {{ (isReadOnly ? 'action.close' : 'action.cancel') | translate }}
    </button>
  </div>
</form>