Skip to content

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

5.7 KB
Raw Blame
<div class="overflow-x-auto">
  <table
    class="gf-table holdings-table w-100"
    mat-table
    multiTemplateDataRows
    [dataSource]="dataSource"
  >
    <colgroup>
      <col class="w-100" />
      <col />
      <col />
    </colgroup>

    <ng-container matColumnDef="name">
      <th *matHeaderCellDef class="px-2" mat-header-cell>
        <ng-container i18n>Name</ng-container>
      </th>
      <td *matCellDef="let element" class="px-2" mat-cell>
        <div class="text-truncate">{{ prettifyAssetName(element?.name) }}</div>
      </td>
    </ng-container>

    <ng-container matColumnDef="valueInBaseCurrency">
      <th *matHeaderCellDef class="px-2 text-end" mat-header-cell>
        <ng-container i18n>Value</ng-container>
      </th>
      <td *matCellDef="let element" class="px-2" mat-cell>
        <div class="d-flex justify-content-end">
          <gf-value
            [isCurrency]="true"
            [locale]="locale"
            [value]="element?.valueInBaseCurrency"
          />
        </div>
      </td>
    </ng-container>

    <ng-container matColumnDef="allocationInPercentage" stickyEnd>
      <th *matHeaderCellDef class="px-2 text-end" mat-header-cell>
        <span class="d-none d-sm-block" i18n>Allocation</span>
        <span class="d-block d-sm-none" i18n-title title="Allocation">%</span>
      </th>
      <td *matCellDef="let element" class="px-2" mat-cell>
        <div class="d-flex justify-content-end">
          <gf-value
            [isPercent]="true"
            [locale]="locale"
            [value]="element?.allocationInPercentage"
          />
        </div>
      </td>
    </ng-container>

    <ng-container matColumnDef="expandedDetail">
      <td
        *matCellDef="let element"
        class="p-0"
        mat-cell
        [attr.colspan]="displayedColumns.length"
      >
        <div class="detail-expand" [class.expanded]="element.expand">
          <div class="holding-parents-table">
            <table
              class="gf-table w-100"
              mat-table
              [dataSource]="element.parents"
            >
              <colgroup>
                <col class="w-100" />
                <col />
                <col />
              </colgroup>

              <ng-container matColumnDef="name">
                <td
                  *matCellDef="let parentHolding"
                  class="lh-normal px-2"
                  mat-cell
                >
                  <div class="text-truncate">{{ parentHolding?.name }}</div>
                  <div>
                    <small class="text-body-secondary">{{
                      parentHolding?.symbol
                    }}</small>
                  </div>
                </td>
                <td *matFooterCellDef class="px-2" mat-footer-cell>
                  <ng-container i18n>Name</ng-container>
                </td>
              </ng-container>
              <ng-container matColumnDef="valueInBaseCurrency">
                <td *matCellDef="let parentHolding" mat-cell>
                  <div class="d-flex justify-content-end">
                    <gf-value
                      [isCurrency]="true"
                      [locale]="locale"
                      [value]="parentHolding?.valueInBaseCurrency"
                    />
                  </div>
                </td>
                <td *matFooterCellDef class="px-2" mat-footer-cell>
                  <ng-container i18n>Value</ng-container>
                </td>
              </ng-container>
              <ng-container matColumnDef="allocationInPercentage" stickyEnd>
                <td *matCellDef="let parentHolding" mat-cell>
                  <div class="d-flex justify-content-end">
                    <gf-value
                      [isPercent]="true"
                      [locale]="locale"
                      [value]="parentHolding?.allocationInPercentage"
                    />
                  </div>
                </td>
                <td *matFooterCellDef class="px-2" mat-footer-cell>
                  <span class="d-none d-sm-block" i18n>Allocation</span>
                  <span class="d-block d-sm-none">%</span>
                </td>
              </ng-container>
              <tr
                *matRowDef="let row; columns: displayedColumns"
                mat-row
                [class.cursor-pointer]="canShowDetails(row)"
                (click)="onClickHolding(row)"
              ></tr>
              <tr
                *matFooterRowDef="displayedColumns"
                class="invisible"
                mat-footer-row
              ></tr>
            </table>
          </div>
        </div>
      </td>
    </ng-container>

    <tr *matHeaderRowDef="displayedColumns" mat-header-row></tr>
    <tr
      *matRowDef="let element; columns: displayedColumns"
      mat-row
      [class]="{
        'cursor-pointer': element.parents?.length > 0,
        expanded: element.expand ?? false
      }"
      (click)="
        element.expand ? (element.expand = false) : (element.expand = true)
      "
    ></tr>
    <tr
      *matRowDef="let row; columns: ['expandedDetail']"
      class="holding-detail"
      mat-row
      [class.d-none]="!row.parents?.length"
    ></tr>
  </table>
</div>

<mat-paginator class="d-none" [hidePageSize]="true" [pageSize]="pageSize" />

@if (isLoading) {
  <ngx-skeleton-loader
    animation="pulse"
    class="px-4 py-3"
    [theme]="{
      height: '1.5rem',
      width: '100%'
    }"
  />
}

@if (dataSource.data.length > pageSize && !isLoading) {
  <div class="my-3 text-center">
    <button mat-stroked-button (click)="onShowAllHoldings()">
      <ng-container i18n>Show more</ng-container>
    </button>
  </div>
}

@if (dataSource.data.length === 0 && !isLoading) {
  <div class="p-3 text-body-secondary text-center">
    <small i18n>No data available</small>
  </div>
}