Improved popup preview with embedded viewer, plaintext, error handling
This commit is contained in:
parent
829836ddf6
commit
0af4638676
@ -107,6 +107,7 @@ import { CustomFieldsDropdownComponent } from './components/common/custom-fields
|
|||||||
import { ProfileEditDialogComponent } from './components/common/profile-edit-dialog/profile-edit-dialog.component'
|
import { ProfileEditDialogComponent } from './components/common/profile-edit-dialog/profile-edit-dialog.component'
|
||||||
import { PdfViewerComponent } from './components/common/pdf-viewer/pdf-viewer.component'
|
import { PdfViewerComponent } from './components/common/pdf-viewer/pdf-viewer.component'
|
||||||
import { DocumentLinkComponent } from './components/common/input/document-link/document-link.component'
|
import { DocumentLinkComponent } from './components/common/input/document-link/document-link.component'
|
||||||
|
import { PreviewPopupComponent } from './components/common/preview-popup/preview-popup.component'
|
||||||
|
|
||||||
import localeAf from '@angular/common/locales/af'
|
import localeAf from '@angular/common/locales/af'
|
||||||
import localeAr from '@angular/common/locales/ar'
|
import localeAr from '@angular/common/locales/ar'
|
||||||
@ -261,6 +262,7 @@ function initializeApp(settings: SettingsService) {
|
|||||||
ProfileEditDialogComponent,
|
ProfileEditDialogComponent,
|
||||||
PdfViewerComponent,
|
PdfViewerComponent,
|
||||||
DocumentLinkComponent,
|
DocumentLinkComponent,
|
||||||
|
PreviewPopupComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
<div class="preview-popup-container">
|
||||||
|
<div *ngIf="error; else noError" class="w-100 h-100 position-relative">
|
||||||
|
<p class="fst-italic position-absolute top-50 start-50 translate-middle" i18n>Error loading preview</p>
|
||||||
|
</div>
|
||||||
|
<ng-template #noError>
|
||||||
|
<ng-container *ngIf="renderAsPlainText; else renderAsObject">
|
||||||
|
<div class="preview-sticky bg-light p-3 overflow-auto" width="100%">{{previewText}}</div>
|
||||||
|
</ng-container>
|
||||||
|
<ng-template #renderAsObject>
|
||||||
|
<object *ngIf="useNativePdfViewer; else pngxViewer" [data]="previewURL | safeUrl" width="100%"></object>
|
||||||
|
<ng-template #pngxViewer>
|
||||||
|
<div *ngIf="requiresPassword" class="w-100 h-100 position-relative">
|
||||||
|
<svg width="2em" height="2em" fill="currentColor" class="position-absolute top-50 start-50 translate-middle">
|
||||||
|
<use xlink:href="assets/bootstrap-icons.svg#file-earmark-lock"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<pngx-pdf-viewer *ngIf="!requiresPassword"
|
||||||
|
[src]="previewURL"
|
||||||
|
[original-size]="false"
|
||||||
|
[show-borders]="true"
|
||||||
|
[show-all]="false"
|
||||||
|
(error)="onError($event)">
|
||||||
|
</pngx-pdf-viewer>
|
||||||
|
</ng-template>
|
||||||
|
</ng-template>
|
||||||
|
</ng-template>
|
||||||
|
</div>
|
@ -0,0 +1,9 @@
|
|||||||
|
.preview-popup-container > * {
|
||||||
|
width: 30rem !important;
|
||||||
|
height: 22rem !important;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .popover.popover-preview {
|
||||||
|
max-width: 32rem;
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||||
|
|
||||||
|
import { PreviewPopupComponent } from './preview-popup.component'
|
||||||
|
import { PdfViewerComponent } from '../pdf-viewer/pdf-viewer.component'
|
||||||
|
import { By } from '@angular/platform-browser'
|
||||||
|
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||||
|
|
||||||
|
describe('PreviewPopupComponent', () => {
|
||||||
|
let component: PreviewPopupComponent
|
||||||
|
let fixture: ComponentFixture<PreviewPopupComponent>
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [PreviewPopupComponent, PdfViewerComponent, SafeUrlPipe],
|
||||||
|
})
|
||||||
|
fixture = TestBed.createComponent(PreviewPopupComponent)
|
||||||
|
component = fixture.componentInstance
|
||||||
|
fixture.detectChanges()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render object if use native PDF viewer', () => {
|
||||||
|
component.useNativePdfViewer = true
|
||||||
|
component.previewURL = 'sample.pdf'
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.query(By.css('object'))).not.toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render pngx viewer if not use native PDF viewer', () => {
|
||||||
|
component.useNativePdfViewer = false
|
||||||
|
component.previewURL = 'sample.pdf'
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.query(By.css('object'))).toBeNull()
|
||||||
|
expect(fixture.debugElement.query(By.css('pngx-pdf-viewer'))).not.toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render plain text if needed', () => {
|
||||||
|
component.renderAsPlainText = true
|
||||||
|
component.previewText = 'Hello world'
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.query(By.css('object'))).toBeNull()
|
||||||
|
expect(fixture.debugElement.query(By.css('pngx-pdf-viewer'))).toBeNull()
|
||||||
|
expect(fixture.debugElement.nativeElement.textContent).toContain(
|
||||||
|
'Hello world'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show lock icon on password error', () => {
|
||||||
|
component.onError({ name: 'PasswordException' })
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.query(By.css('svg'))).not.toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show message on error', () => {
|
||||||
|
component.onError({})
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.nativeElement.textContent).toContain(
|
||||||
|
'Error loading preview'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,31 @@
|
|||||||
|
import { Component, Input } from '@angular/core'
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'pngx-preview-popup',
|
||||||
|
templateUrl: './preview-popup.component.html',
|
||||||
|
styleUrls: ['./preview-popup.component.scss'],
|
||||||
|
})
|
||||||
|
export class PreviewPopupComponent {
|
||||||
|
@Input()
|
||||||
|
renderAsPlainText: boolean = false
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
previewText: string
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
previewURL: string
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
useNativePdfViewer: boolean = false
|
||||||
|
|
||||||
|
error = false
|
||||||
|
requiresPassword: boolean = false
|
||||||
|
|
||||||
|
onError(event) {
|
||||||
|
if (event.name == 'PasswordException') {
|
||||||
|
this.requiresPassword = true
|
||||||
|
} else {
|
||||||
|
this.error = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,12 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<ng-template #previewContent>
|
<ng-template #previewContent>
|
||||||
<object [data]="getPreviewUrl(doc) | safeUrl" class="preview" width="100%"></object>
|
<pngx-preview-popup
|
||||||
|
[previewURL]="getPreviewUrl(doc)"
|
||||||
|
[useNativePdfViewer]="useNativePdfViewer"
|
||||||
|
[previewText]="doc.content"
|
||||||
|
[renderAsPlainText]="!isPdf(doc)">
|
||||||
|
</pngx-preview-popup>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<a [href]="getDownloadUrl(doc)" class="btn px-4 btn-dark border-dark-subtle" title="Download" i18n-title (click)="$event.stopPropagation()">
|
<a [href]="getDownloadUrl(doc)" class="btn px-4 btn-dark border-dark-subtle" title="Download" i18n-title (click)="$event.stopPropagation()">
|
||||||
<svg class="buttonicon-xs" fill="currentColor">
|
<svg class="buttonicon-xs" fill="currentColor">
|
||||||
|
@ -29,6 +29,7 @@ import { SavedViewWidgetComponent } from './saved-view-widget.component'
|
|||||||
import { By } from '@angular/platform-browser'
|
import { By } from '@angular/platform-browser'
|
||||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||||
import { DragDropModule } from '@angular/cdk/drag-drop'
|
import { DragDropModule } from '@angular/cdk/drag-drop'
|
||||||
|
import { PreviewPopupComponent } from 'src/app/components/common/preview-popup/preview-popup.component'
|
||||||
|
|
||||||
const savedView: PaperlessSavedView = {
|
const savedView: PaperlessSavedView = {
|
||||||
id: 1,
|
id: 1,
|
||||||
@ -74,6 +75,7 @@ describe('SavedViewWidgetComponent', () => {
|
|||||||
CustomDatePipe,
|
CustomDatePipe,
|
||||||
DocumentTitlePipe,
|
DocumentTitlePipe,
|
||||||
SafeUrlPipe,
|
SafeUrlPipe,
|
||||||
|
PreviewPopupComponent,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
PermissionsGuard,
|
PermissionsGuard,
|
||||||
|
@ -22,14 +22,13 @@ import { DocumentListViewService } from 'src/app/services/document-list-view.ser
|
|||||||
import { ComponentWithPermissions } from 'src/app/components/with-permissions/with-permissions.component'
|
import { ComponentWithPermissions } from 'src/app/components/with-permissions/with-permissions.component'
|
||||||
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { queryParamsFromFilterRules } from 'src/app/utils/query-params'
|
import { queryParamsFromFilterRules } from 'src/app/utils/query-params'
|
||||||
|
import { SettingsService } from 'src/app/services/settings.service'
|
||||||
|
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'pngx-saved-view-widget',
|
selector: 'pngx-saved-view-widget',
|
||||||
templateUrl: './saved-view-widget.component.html',
|
templateUrl: './saved-view-widget.component.html',
|
||||||
styleUrls: [
|
styleUrls: ['./saved-view-widget.component.scss'],
|
||||||
'./saved-view-widget.component.scss',
|
|
||||||
'../../../document-list/popover-preview/popover-preview.scss',
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class SavedViewWidgetComponent
|
export class SavedViewWidgetComponent
|
||||||
extends ComponentWithPermissions
|
extends ComponentWithPermissions
|
||||||
@ -43,7 +42,8 @@ export class SavedViewWidgetComponent
|
|||||||
private list: DocumentListViewService,
|
private list: DocumentListViewService,
|
||||||
private consumerStatusService: ConsumerStatusService,
|
private consumerStatusService: ConsumerStatusService,
|
||||||
public openDocumentsService: OpenDocumentsService,
|
public openDocumentsService: OpenDocumentsService,
|
||||||
public documentListViewService: DocumentListViewService
|
public documentListViewService: DocumentListViewService,
|
||||||
|
private settingsService: SettingsService
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@ -113,6 +113,10 @@ export class SavedViewWidgetComponent
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get useNativePdfViewer(): boolean {
|
||||||
|
return this.settingsService.get(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER)
|
||||||
|
}
|
||||||
|
|
||||||
getPreviewUrl(document: PaperlessDocument): string {
|
getPreviewUrl(document: PaperlessDocument): string {
|
||||||
return this.documentService.getPreviewUrl(document.id)
|
return this.documentService.getPreviewUrl(document.id)
|
||||||
}
|
}
|
||||||
@ -121,6 +125,13 @@ export class SavedViewWidgetComponent
|
|||||||
return this.documentService.getDownloadUrl(document.id)
|
return this.documentService.getDownloadUrl(document.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isPdf(document: PaperlessDocument) {
|
||||||
|
return (
|
||||||
|
document.original_file_name?.endsWith('.pdf') ||
|
||||||
|
document.archived_file_name?.endsWith('.pdf')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
mouseEnterPreview(doc: PaperlessDocument) {
|
mouseEnterPreview(doc: PaperlessDocument) {
|
||||||
this.popover = this.popovers.get(this.documents.indexOf(doc))
|
this.popover = this.popovers.get(this.documents.indexOf(doc))
|
||||||
this.mouseOnPreview = true
|
this.mouseOnPreview = true
|
||||||
|
@ -56,7 +56,12 @@
|
|||||||
</svg> <span class="d-none d-md-inline" i18n>View</span>
|
</svg> <span class="d-none d-md-inline" i18n>View</span>
|
||||||
</a>
|
</a>
|
||||||
<ng-template #previewContent>
|
<ng-template #previewContent>
|
||||||
<object [data]="previewUrl | safeUrl" class="preview" width="100%"></object>
|
<pngx-preview-popup
|
||||||
|
[previewURL]="previewUrl"
|
||||||
|
[useNativePdfViewer]="useNativePdfViewer"
|
||||||
|
[previewText]="document.content"
|
||||||
|
[renderAsPlainText]="!isPdf">
|
||||||
|
</pngx-preview-popup>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<a class="btn btn-sm btn-outline-secondary" [href]="getDownloadUrl()">
|
<a class="btn btn-sm btn-outline-secondary" [href]="getDownloadUrl()">
|
||||||
<svg class="sidebaricon" fill="currentColor" class="sidebaricon">
|
<svg class="sidebaricon" fill="currentColor" class="sidebaricon">
|
||||||
|
@ -19,6 +19,9 @@ import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
|||||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||||
import { DocumentCardLargeComponent } from './document-card-large.component'
|
import { DocumentCardLargeComponent } from './document-card-large.component'
|
||||||
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
|
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
|
||||||
|
import { SettingsService } from 'src/app/services/settings.service'
|
||||||
|
import { PreviewPopupComponent } from '../../common/preview-popup/preview-popup.component'
|
||||||
|
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||||
|
|
||||||
const doc = {
|
const doc = {
|
||||||
id: 10,
|
id: 10,
|
||||||
@ -40,6 +43,7 @@ const doc = {
|
|||||||
describe('DocumentCardLargeComponent', () => {
|
describe('DocumentCardLargeComponent', () => {
|
||||||
let component: DocumentCardLargeComponent
|
let component: DocumentCardLargeComponent
|
||||||
let fixture: ComponentFixture<DocumentCardLargeComponent>
|
let fixture: ComponentFixture<DocumentCardLargeComponent>
|
||||||
|
let settingsService: SettingsService
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -50,6 +54,7 @@ describe('DocumentCardLargeComponent', () => {
|
|||||||
IfPermissionsDirective,
|
IfPermissionsDirective,
|
||||||
SafeUrlPipe,
|
SafeUrlPipe,
|
||||||
IsNumberPipe,
|
IsNumberPipe,
|
||||||
|
PreviewPopupComponent,
|
||||||
],
|
],
|
||||||
providers: [DatePipe],
|
providers: [DatePipe],
|
||||||
imports: [
|
imports: [
|
||||||
@ -62,6 +67,7 @@ describe('DocumentCardLargeComponent', () => {
|
|||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
|
|
||||||
fixture = TestBed.createComponent(DocumentCardLargeComponent)
|
fixture = TestBed.createComponent(DocumentCardLargeComponent)
|
||||||
|
settingsService = TestBed.inject(SettingsService)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
component.document = doc
|
component.document = doc
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
@ -87,6 +93,23 @@ describe('DocumentCardLargeComponent', () => {
|
|||||||
expect(component.popover.isOpen()).toBeFalsy()
|
expect(component.popover.isOpen()).toBeFalsy()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
it('should guess if file is pdf by file name', () => {
|
||||||
|
component.document.original_file_name = 'sample.pdf'
|
||||||
|
expect(component.isPdf).toBeTruthy()
|
||||||
|
component.document.archived_file_name = 'sample.pdf'
|
||||||
|
expect(component.isPdf).toBeTruthy()
|
||||||
|
component.document.archived_file_name = undefined
|
||||||
|
component.document.original_file_name = 'sample.txt'
|
||||||
|
expect(component.isPdf).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return settings for native PDF viewer', () => {
|
||||||
|
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false)
|
||||||
|
expect(component.useNativePdfViewer).toBeFalsy()
|
||||||
|
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, true)
|
||||||
|
expect(component.useNativePdfViewer).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
it('should trim content', () => {
|
it('should trim content', () => {
|
||||||
expect(component.contentTrimmed).toHaveLength(503) // includes ...
|
expect(component.contentTrimmed).toHaveLength(503) // includes ...
|
||||||
})
|
})
|
||||||
|
@ -15,10 +15,7 @@ import { ComponentWithPermissions } from '../../with-permissions/with-permission
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'pngx-document-card-large',
|
selector: 'pngx-document-card-large',
|
||||||
templateUrl: './document-card-large.component.html',
|
templateUrl: './document-card-large.component.html',
|
||||||
styleUrls: [
|
styleUrls: ['./document-card-large.component.scss'],
|
||||||
'./document-card-large.component.scss',
|
|
||||||
'../popover-preview/popover-preview.scss',
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class DocumentCardLargeComponent extends ComponentWithPermissions {
|
export class DocumentCardLargeComponent extends ComponentWithPermissions {
|
||||||
constructor(
|
constructor(
|
||||||
@ -106,6 +103,17 @@ export class DocumentCardLargeComponent extends ComponentWithPermissions {
|
|||||||
return this.documentService.getPreviewUrl(this.document.id)
|
return this.documentService.getPreviewUrl(this.document.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get useNativePdfViewer(): boolean {
|
||||||
|
return this.settingsService.get(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER)
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPdf(): boolean {
|
||||||
|
return (
|
||||||
|
this.document?.original_file_name?.endsWith('.pdf') ||
|
||||||
|
this.document?.archived_file_name?.endsWith('.pdf')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
mouseEnterPreview() {
|
mouseEnterPreview() {
|
||||||
this.mouseOnPreview = true
|
this.mouseOnPreview = true
|
||||||
if (!this.popover.isOpen()) {
|
if (!this.popover.isOpen()) {
|
||||||
|
@ -94,7 +94,12 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
<ng-template #previewContent>
|
<ng-template #previewContent>
|
||||||
<object [data]="previewUrl | safeUrl" class="preview" width="100%"></object>
|
<pngx-preview-popup
|
||||||
|
[previewURL]="previewUrl"
|
||||||
|
[useNativePdfViewer]="useNativePdfViewer"
|
||||||
|
[previewText]="document.content"
|
||||||
|
[renderAsPlainText]="!isPdf">
|
||||||
|
</pngx-preview-popup>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<a [href]="getDownloadUrl()" class="btn btn-sm btn-outline-secondary" title="Download" i18n-title (click)="$event.stopPropagation()">
|
<a [href]="getDownloadUrl()" class="btn btn-sm btn-outline-secondary" title="Download" i18n-title (click)="$event.stopPropagation()">
|
||||||
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
@ -22,6 +22,9 @@ import { By } from '@angular/platform-browser'
|
|||||||
import { TagComponent } from '../../common/tag/tag.component'
|
import { TagComponent } from '../../common/tag/tag.component'
|
||||||
import { PaperlessTag } from 'src/app/data/paperless-tag'
|
import { PaperlessTag } from 'src/app/data/paperless-tag'
|
||||||
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
|
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
|
||||||
|
import { SettingsService } from 'src/app/services/settings.service'
|
||||||
|
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||||
|
import { PreviewPopupComponent } from '../../common/preview-popup/preview-popup.component'
|
||||||
|
|
||||||
const doc = {
|
const doc = {
|
||||||
id: 10,
|
id: 10,
|
||||||
@ -53,6 +56,7 @@ const doc = {
|
|||||||
describe('DocumentCardSmallComponent', () => {
|
describe('DocumentCardSmallComponent', () => {
|
||||||
let component: DocumentCardSmallComponent
|
let component: DocumentCardSmallComponent
|
||||||
let fixture: ComponentFixture<DocumentCardSmallComponent>
|
let fixture: ComponentFixture<DocumentCardSmallComponent>
|
||||||
|
let settingsService: SettingsService
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -64,6 +68,7 @@ describe('DocumentCardSmallComponent', () => {
|
|||||||
SafeUrlPipe,
|
SafeUrlPipe,
|
||||||
TagComponent,
|
TagComponent,
|
||||||
IsNumberPipe,
|
IsNumberPipe,
|
||||||
|
PreviewPopupComponent,
|
||||||
],
|
],
|
||||||
providers: [DatePipe],
|
providers: [DatePipe],
|
||||||
imports: [
|
imports: [
|
||||||
@ -76,6 +81,7 @@ describe('DocumentCardSmallComponent', () => {
|
|||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
|
|
||||||
fixture = TestBed.createComponent(DocumentCardSmallComponent)
|
fixture = TestBed.createComponent(DocumentCardSmallComponent)
|
||||||
|
settingsService = TestBed.inject(SettingsService)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
component.document = Object.assign({}, doc)
|
component.document = Object.assign({}, doc)
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
@ -105,6 +111,23 @@ describe('DocumentCardSmallComponent', () => {
|
|||||||
).toHaveLength(6)
|
).toHaveLength(6)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should guess if file is pdf by file name', () => {
|
||||||
|
component.document.original_file_name = 'sample.pdf'
|
||||||
|
expect(component.isPdf).toBeTruthy()
|
||||||
|
component.document.archived_file_name = 'sample.pdf'
|
||||||
|
expect(component.isPdf).toBeTruthy()
|
||||||
|
component.document.archived_file_name = undefined
|
||||||
|
component.document.original_file_name = 'sample.txt'
|
||||||
|
expect(component.isPdf).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return settings for native PDF viewer', () => {
|
||||||
|
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false)
|
||||||
|
expect(component.useNativePdfViewer).toBeFalsy()
|
||||||
|
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, true)
|
||||||
|
expect(component.useNativePdfViewer).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
it('should show preview on mouseover after delay to preload content', fakeAsync(() => {
|
it('should show preview on mouseover after delay to preload content', fakeAsync(() => {
|
||||||
component.mouseEnterPreview()
|
component.mouseEnterPreview()
|
||||||
expect(component.popover.isOpen()).toBeTruthy()
|
expect(component.popover.isOpen()).toBeTruthy()
|
||||||
|
@ -16,10 +16,7 @@ import { ComponentWithPermissions } from '../../with-permissions/with-permission
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'pngx-document-card-small',
|
selector: 'pngx-document-card-small',
|
||||||
templateUrl: './document-card-small.component.html',
|
templateUrl: './document-card-small.component.html',
|
||||||
styleUrls: [
|
styleUrls: ['./document-card-small.component.scss'],
|
||||||
'./document-card-small.component.scss',
|
|
||||||
'../popover-preview/popover-preview.scss',
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class DocumentCardSmallComponent extends ComponentWithPermissions {
|
export class DocumentCardSmallComponent extends ComponentWithPermissions {
|
||||||
constructor(
|
constructor(
|
||||||
@ -80,6 +77,17 @@ export class DocumentCardSmallComponent extends ComponentWithPermissions {
|
|||||||
return $localize`Private`
|
return $localize`Private`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get useNativePdfViewer(): boolean {
|
||||||
|
return this.settingsService.get(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER)
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPdf(): boolean {
|
||||||
|
return (
|
||||||
|
this.document?.original_file_name?.endsWith('.pdf') ||
|
||||||
|
this.document?.archived_file_name?.endsWith('.pdf')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
getTagsLimited$() {
|
getTagsLimited$() {
|
||||||
const limit = this.document.notes.length > 0 ? 6 : 7
|
const limit = this.document.notes.length > 0 ? 6 : 7
|
||||||
return this.document.tags$.pipe(
|
return this.document.tags$.pipe(
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
::ng-deep .popover.popover-preview {
|
|
||||||
max-width: 40rem;
|
|
||||||
|
|
||||||
.preview {
|
|
||||||
min-width: 30rem;
|
|
||||||
min-height: 18rem;
|
|
||||||
max-height: 35rem;
|
|
||||||
overflow-y: scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
.spinner-border {
|
|
||||||
position: absolute;
|
|
||||||
top: 4rem;
|
|
||||||
left: calc(50% - 0.5rem);
|
|
||||||
z-index: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
::ng-deep .popover-hidden .popover {
|
|
||||||
opacity: 0;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
@ -555,6 +555,11 @@ table.table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popover-hidden .popover {
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
// Tour
|
// Tour
|
||||||
.tour-active .popover {
|
.tour-active .popover {
|
||||||
min-width: 360px;
|
min-width: 360px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user