Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

5.1 KB
Raw Blame
<form
  class="d-flex flex-column h-100"
  [formGroup]="accessForm"
  (keyup.enter)="accessForm.valid && !isSubmitting() && onSubmit()"
  (ngSubmit)="onSubmit()"
>
  <h1 mat-dialog-title>
    @if (mode === 'create') {
      <span i18n>Grant access</span>
    } @else {
      <span i18n>Edit access</span>
    }
  </h1>
  <div class="flex-grow-1 py-3" mat-dialog-content>
    <div>
      <mat-form-field appearance="outline" class="w-100">
        <mat-label i18n>Alias</mat-label>
        <input
          formControlName="alias"
          matInput
          type="text"
          (keydown.enter)="$event.stopPropagation()"
        />
      </mat-form-field>
    </div>
    <div class="mb-3">
      <mat-form-field
        appearance="outline"
        class="w-100"
        [class.without-hint]="!isPublicAccess"
      >
        <mat-label i18n>Type</mat-label>
        <mat-select formControlName="type">
          <mat-option i18n value="PRIVATE">Private</mat-option>
          <mat-option i18n value="PUBLIC">Public</mat-option>
          @if (canGrantMcpAccess) {
            <mat-option value="MCP">Model Context Protocol (MCP)</mat-option>
          }
        </mat-select>
        @if (isPublicAccess) {
          <mat-hint i18n
            >Any person who has the link can view the data.</mat-hint
          >
        }
      </mat-form-field>
    </div>

    <div class="mb-3">
      <mat-form-field
        appearance="outline"
        class="w-100"
        [class.without-hint]="!showExpiresAtErrorMessage"
      >
        <mat-label i18n>Expiration Date</mat-label>
        <input
          formControlName="expiresAt"
          matInput
          [matDatepicker]="expiresAt"
          [min]="minExpiresAt"
        />
        <mat-datepicker-toggle class="me-2" matSuffix [for]="expiresAt">
          <ion-icon
            class="text-body-secondary"
            matDatepickerToggleIcon
            name="calendar-clear-outline"
          />
        </mat-datepicker-toggle>
        <mat-datepicker #expiresAt />
        @if (showExpiresAtErrorMessage) {
          <mat-error i18n>Date must be in the future.</mat-error>
        }
      </mat-form-field>
    </div>

    <div>
      <mat-form-field appearance="outline" class="w-100">
        <mat-label i18n>Permission</mat-label>
        <mat-select formControlName="accessLevel">
          <mat-select-trigger>
            <gf-access-level-icon [accessLevel]="accessLevel" />
          </mat-select-trigger>
          <mat-option value="READ_RESTRICTED">
            <gf-access-level-icon accessLevel="READ_RESTRICTED" />
          </mat-option>
          @if (canGrantRestrictedWriteAccess) {
            <mat-option
              value="CREATE_READ_RESTRICTED_UPDATE_DELETE"
              [disabled]="!canGrantWriteAccess"
            >
              <gf-access-level-icon
                accessLevel="CREATE_READ_RESTRICTED_UPDATE_DELETE"
              />
            </mat-option>
          }
          @if (canGrantUnrestrictedReadAccess) {
            <mat-option value="READ">
              <gf-access-level-icon accessLevel="READ" />
            </mat-option>
            <mat-option
              value="CREATE_READ_UPDATE_DELETE"
              [disabled]="!canGrantWriteAccess"
            >
              <gf-access-level-icon accessLevel="CREATE_READ_UPDATE_DELETE" />
            </mat-option>
          }
        </mat-select>
      </mat-form-field>
    </div>
    @if (accessForm.get('type')?.value === 'PRIVATE') {
      <div>
        <mat-form-field appearance="outline" class="w-100">
          <mat-label>
            Ghostfolio <ng-container i18n>User ID</ng-container>
          </mat-label>
          <input
            formControlName="granteeUserId"
            matInput
            type="text"
            (keydown.enter)="$event.stopPropagation()"
          />
        </mat-form-field>
      </div>
    }
    @if (canApplyFilters) {
      <h2 class="h6" i18n>Portfolio Filters</h2>
      <gf-portfolio-filter-form
        appearance="outline"
        class="w-100"
        formControlName="filters"
        [accounts]="accounts"
        [assetClasses]="assetClasses"
        [holdings]="holdings"
        [tags]="tags"
      />
    }
    @if (showMcpDetails || showPublicDetails) {
      <h2 class="h6" i18n>Details</h2>
      @if (showMcpDetails) {
        <pre class="m-0"><code>{{ mcpConfiguration | json }}</code></pre>
      } @else if (showPublicDetails) {
        <div>
          <code class="text-break"
            >GET {{ baseUrl }}/api/v1/public/{{ accessId }}/portfolio</code
          >
        </div>
      }
    }
  </div>
  <div class="justify-content-end" mat-dialog-actions>
    <button mat-button type="button" (click)="onCancel()">
      @if (accessForm.dirty) {
        <ng-container i18n>Cancel</ng-container>
      } @else {
        <ng-container i18n>Close</ng-container>
      }
    </button>
    <button
      color="primary"
      mat-flat-button
      type="submit"
      [disabled]="
        (mode === 'create'
          ? !(accessForm.dirty && accessForm.valid)
          : !accessForm.valid) || isSubmitting()
      "
    >
      <ng-container i18n>Save</ng-container>
    </button>
  </div>
</form>