Skip to content

Commit

Permalink
Fix 'sv-file-preview' component is not available when showPreview: fa…
Browse files Browse the repository at this point in the history
…lse (#7066)
  • Loading branch information
dk981234 authored Oct 4, 2023
1 parent 950f06a commit 6409081
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
<ng-template #template>
<div [class]="question.cssClasses.fileList || undefined">
<span *ngFor="let val of question.previewValue; index as index; trackBy: trackFilesFn"
[visible]="val && question.isPreviewVisible(index)" [class]="question.cssClasses.preview">
<div *ngIf="val.name && question.cssClasses.fileSign" [class]="question.cssClasses.fileSign">
<a (click)="question.doDownloadFile($event, val)" [attr.href]="val.content | safeUrl"
[attr.title]="val.name" [attr.download]="val.name" [style.width]="question.imageWidth">{{ val.name
}}</a>
</div>
<div [class]="question.cssClasses.imageWrapper">
<img *ngIf="question.canPreviewImage(val)" [attr.src]="val.content | safeUrl"
[style.height]="question.imageHeight" [style.width]="question.imageWidth" alt="File preview" />
<svg *ngIf="question.defaultImage(val)" [iconName]="question.cssClasses.defaultImageIconId"
[partCss]="question.cssClasses.defaultImage" [size]="'auto'" sv-ng-svg-icon></svg>
<div *ngIf="val.name && !question.isReadOnly" [class]="question.getRemoveButtonCss()"
(click)="question.doRemoveFile(val)">
<span [class]="question.cssClasses.removeFile">{{ question.removeFileCaption }}</span>
<svg *ngIf="question.cssClasses.removeFileSvgIconId" [title]="question.removeFileCaption"
[partCss]="question.cssClasses.removeFileSvg"
[iconName]="question.cssClasses.removeFileSvgIconId" [size]="'auto'" sv-ng-svg-icon></svg>
<ng-container *ngIf="question.showPreviewContainer">
<div [class]="question.cssClasses.fileList || undefined">
<span *ngFor="let val of question.previewValue; index as index; trackBy: trackFilesFn"
[visible]="val && question.isPreviewVisible(index)" [class]="question.cssClasses.preview">
<div *ngIf="val.name && question.cssClasses.fileSign" [class]="question.cssClasses.fileSign">
<a (click)="question.doDownloadFile($event, val)" [attr.href]="val.content | safeUrl"
[attr.title]="val.name" [attr.download]="val.name" [style.width]="question.imageWidth">{{
val.name
}}</a>
</div>
</div>
<div *ngIf="val.name && question.cssClasses.fileSignBottom" [class]="question.cssClasses.fileSignBottom">
<a (click)="question.doDownloadFile($event, val)" [attr.href]="val.content | safeUrl"
[attr.title]="val.name" [attr.download]="val.name" [style.width]="question.imageWidth">{{ val.name
}}</a>
</div>
</span>
</div>
<div [class]="question.cssClasses.imageWrapper">
<img *ngIf="question.canPreviewImage(val)" [attr.src]="val.content | safeUrl"
[style.height]="question.imageHeight" [style.width]="question.imageWidth" alt="File preview" />
<svg *ngIf="question.defaultImage(val)" [iconName]="question.cssClasses.defaultImageIconId"
[partCss]="question.cssClasses.defaultImage" [size]="'auto'" sv-ng-svg-icon></svg>
<div *ngIf="val.name && !question.isReadOnly" [class]="question.getRemoveButtonCss()"
(click)="question.doRemoveFile(val)">
<span [class]="question.cssClasses.removeFile">{{ question.removeFileCaption }}</span>
<svg *ngIf="question.cssClasses.removeFileSvgIconId" [title]="question.removeFileCaption"
[partCss]="question.cssClasses.removeFileSvg"
[iconName]="question.cssClasses.removeFileSvgIconId" [size]="'auto'" sv-ng-svg-icon></svg>
</div>
</div>
<div *ngIf="val.name && question.cssClasses.fileSignBottom"
[class]="question.cssClasses.fileSignBottom">
<a (click)="question.doDownloadFile($event, val)" [attr.href]="val.content | safeUrl"
[attr.title]="val.name" [attr.download]="val.name" [style.width]="question.imageWidth">{{
val.name
}}</a>
</div>
</span>
</div>
</ng-container>
</ng-template>
5 changes: 4 additions & 1 deletion packages/survey-vue3-ui/src/components/file/FilePreview.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div :class="question.cssClasses.fileList || undefined">
<div
v-if="question.showPreviewContainer"
:class="question.cssClasses.fileList || undefined"
>
<span
v-for="(val, index) in question.previewValue"
:key="question.inputId + '_' + index"
Expand Down
5 changes: 3 additions & 2 deletions src/knockout/components/file/file-preview.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<!-- ko if: question.koHasValue && question.showPreviewContainer -->
<div data-bind="css: question.cssClasses.fileList, foreach: question.koData, visible: question.koHasValue">
<span data-bind="visible: question.isPreviewVisible($index()), css: question.cssClasses.preview">
<!-- ko template: { name: 'survey-question-file-sign', data: {question: question, item: $data, fileSignCss: question.cssClasses.fileSign} } --><!-- /ko -->
Expand All @@ -22,4 +22,5 @@
</div>
<!-- ko template: { name: 'survey-question-file-sign', data: {question: question, item: $data, fileSignCss: question.cssClasses.fileSignBottom} } --><!-- /ko -->
</span>
</div>
</div>
<!-- /ko -->
5 changes: 4 additions & 1 deletion src/question_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ export class QuestionFileModel extends Question {
public get allowShowPreview(): boolean {
const isShowLoadingIndicator = this.showLoadingIndicator;
const isPlayingVideo = this.isPlayingVideo;
return this.previewValue && this.previewValue.length > 0 && !isShowLoadingIndicator && !isPlayingVideo;
return !isShowLoadingIndicator && !isPlayingVideo;
}
public get showPreviewContainer(): boolean {
return this.previewValue && this.previewValue.length > 0;
}
//todo: remove in V2
get showRemoveButtonCore(): boolean {
Expand Down
3 changes: 3 additions & 0 deletions src/react/components/file/file-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class SurveyFilePreview extends SurveyElementBase<{ question: QuestionFil
});
return <div className={this.question.cssClasses.fileList || undefined}>{previews}</div>;
}
protected canRender(): boolean {
return this.question.showPreviewContainer;
}
}
ReactElementFactory.Instance.registerElement(
"sv-file-preview",
Expand Down
2 changes: 1 addition & 1 deletion src/vue/components/file/file-preview.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="question.cssClasses.fileList || undefined">
<div v-if="question.showPreviewContainer" :class="question.cssClasses.fileList || undefined">
<span
v-for="(val, index) in question.previewValue"
:key="question.inputId + '_' + index"
Expand Down

0 comments on commit 6409081

Please sign in to comment.