src/app/features/conflict-resolution/conflict-resolution-list/conflict-resolution-list.component.ts

Description

List all document conflicts and allow the user to expand for details and manual resolution.

Implements

AfterViewInit

Example

Metadata

Relationships

Used by

No results matching.

Depends on

Index

Properties

Constructor

constructor()

Properties

columnsToDisplay
Type : []
Default value : ["id", "data"]

visible table columns in the template

dataSource
Type : QueryDataSource<Entity>

data for the table in the template

paginator
Type : MatPaginator
Decorators :
@ViewChild(MatPaginator)

reference to mat-table paginator from template, required to set up pagination

import {
  AfterViewInit,
  Component,
  ViewChild,
  inject,
  ChangeDetectionStrategy,
} from "@angular/core";
import { MatPaginator, MatPaginatorModule } from "@angular/material/paginator";
import { QueryDataSource } from "../../../core/database/query-data-source";
import { Entity } from "../../../core/entity/model/entity";
import { Database } from "../../../core/database/database";
import { AsyncPipe } from "@angular/common";
import { MatProgressBarModule } from "@angular/material/progress-bar";
import { MatTableModule } from "@angular/material/table";
import { MatSortModule } from "@angular/material/sort";
import { CompareRevComponent } from "../compare-rev/compare-rev.component";
import { RouteTarget } from "../../../route-target";
import { DatabaseResolverService } from "../../../core/database/database-resolver.service";
import { ViewTitleComponent } from "../../../core/common-components/view-title/view-title.component";

/**
 * List all document conflicts and allow the user to expand for details and manual resolution.
 */
@RouteTarget("ConflictResolution")
@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-conflict-resolution-list",
  templateUrl: "./conflict-resolution-list.component.html",
  imports: [
    ViewTitleComponent,
    MatProgressBarModule,
    AsyncPipe,
    MatTableModule,
    MatSortModule,
    CompareRevComponent,
    MatPaginatorModule,
  ],
})
export class ConflictResolutionListComponent implements AfterViewInit {
  /** visible table columns in the template */
  columnsToDisplay = ["id", "data"];

  /** data for the table in the template */
  dataSource: QueryDataSource<Entity>;

  /** reference to mat-table paginator from template, required to set up pagination */
  @ViewChild(MatPaginator) paginator: MatPaginator;

  private readonly db: Database;

  constructor() {
    const dbResolver = inject(DatabaseResolverService);

    this.db = dbResolver.getDatabase();
  }

  async ngAfterViewInit() {
    await this.createDatabaseIndexForConflicts();
    this.dataSource = new QueryDataSource(this.db, "conflicts/all");
    this.dataSource.paginator = this.paginator;
  }

  /**
   * Create the database index to query document conflicts, if the index doesn't exist already.
   */
  private createDatabaseIndexForConflicts() {
    const designDoc = {
      _id: "_design/conflicts",
      views: {
        all: {
          map:
            "(doc) => { " +
            "if (doc._conflicts) { emit(doc._conflicts, doc._id); } " +
            "}",
        },
      },
    };

    return this.db.saveDatabaseIndex(designDoc);
  }
}
<app-view-title i18n>Database Conflicts</app-view-title>

<p i18n>conflicts to resolve:</p>

<div class="mat-elevation-z1">
  @if (dataSource?.loading$ | async) {
    <div>
      <mat-progress-bar mode="indeterminate"></mat-progress-bar>
    </div>
  }

  <table
    mat-table
    [dataSource]="dataSource"
    matSort
    class="full-width"
    i18n-aria-label
    aria-label="Table showing the conflicts"
  >
    <ng-container matColumnDef="id">
      <!-- eslint-disable-next-line @angular-eslint/template/i18n -- raw database field name -->
      <th mat-header-cell *matHeaderCellDef mat-sort-header>_id</th>
      <td mat-cell *matCellDef="let row">{{ row.id }}</td>
    </ng-container>

    <ng-container matColumnDef="data" class="full-width">
      <th mat-header-cell *matHeaderCellDef mat-sort-header i18n>Data</th>
      <td mat-cell *matCellDef="let row">
        @for (rev of row.key; track rev) {
          <app-compare-rev [rev]="rev" [doc]="row.doc"></app-compare-rev>
        }
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr>
    <tr
      mat-row
      *matRowDef="let entity; columns: columnsToDisplay"
      class="table-list-item"
    ></tr>
  </table>

  <mat-paginator
    [pageSizeOptions]="[5, 10, 20]"
    [pageSize]="10"
    showFirstLastButtons
  ></mat-paginator>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""