Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

2.9 KB
Raw Blame
@if (minimal) {
  <ng-container *ngTemplateOutlet="select"></ng-container>
} @else {
  <div class="mb-3 paperless-input-select" [class.disabled]="disabled">
    <div class="row">
      <div class="d-flex align-items-center position-relative hidden-button-container" [class.col-md-3]="horizontal">
        @if (title) {
          <label class="form-label" [class.mb-md-0]="horizontal" [for]="inputId">{{title}}</label>
        }
        @if (removable) {
          <button type="button" class="btn btn-sm btn-danger position-absolute left-0" (click)="removed.emit(this)">
            <pngx-bs-icon name="x" class="me-1"></pngx-bs-icon><ng-container i18n>Remove</ng-container>
          </button>
        }
      </div>
      <div [class.col-md-9]="horizontal">
        <ng-container *ngTemplateOutlet="select"></ng-container>
        @if (hint) {
          <small class="form-text text-muted">{{hint}}</small>
        }
      </div>
    </div>
  </div>
}

<ng-template #select>
  <ng-select name="inputId" [(ngModel)]="selectedDocuments" [ngModelOptions]="{standalone: true}"
    [disabled]="disabled"
    [items]="foundDocuments$ | async"
    [placeholder]="placeholder"
    [notFoundText]="notFoundText"
    [multiple]="true"
    [compareWith]="compareDocuments"
    [trackByFn]="trackByFn"
    [minTermLength]="2"
    [appendTo]="appendTo"
    [loading]="loading()"
    [typeahead]="documentsInput$"
    (mousedown)="$event.stopImmediatePropagation()"
    (change)="onChange(selectedDocumentIDs)">
    <ng-template ng-label-tmp let-document="item">
      <div class="d-flex align-items-center">
        @if (!disabled) {
          <button class="btn p-0 lh-1" (click)="unselect(document)" (mousedown)="$event.stopImmediatePropagation()" type="button" title="Remove link" i18n-title><pngx-bs-icon name="x"></pngx-bs-icon></button>
        }
        @if (document.title) {
          <a routerLink="/documents/{{document.id}}" class="badge bg-light text-primary" (mousedown)="$event.stopImmediatePropagation();" title="Open link" i18n-title>
            <pngx-bs-icon width="0.9em" height="0.9em" name="file-text" class="me-1"></pngx-bs-icon><span>{{document.title}}</span>
          </a>
        } @else {
          <span class="badge bg-light text-muted">
            <pngx-bs-icon width="0.9em" height="0.9em" name="exclamation-triangle-fill" class="me-1"></pngx-bs-icon><span i18n>Unavailable</span>
          </span>
        }
      </div>
    </ng-template>
    <ng-template ng-loadingspinner-tmp>
      <div class="spinner-border spinner-border-sm fw-normal ms-2 me-auto" role="status"></div>
      <div class="visually-hidden" i18n>Loading...</div>
    </ng-template>
    <ng-template ng-option-tmp let-document="item" let-index="index" let-search="searchTerm">
      <div>{{document.title}} <small class="text-muted">({{document.created | customDate:'shortDate'}})</small></div>
    </ng-template>
  </ng-select>
</ng-template>