-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to customize file preview component (#7062)
* Allow to customize file preview component * Fix angular build
- Loading branch information
Showing
24 changed files
with
185 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
packages/survey-angular-ui/src/components/file/file-preview.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<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> | ||
</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-template> |
15 changes: 15 additions & 0 deletions
15
packages/survey-angular-ui/src/components/file/file-preview.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Action, QuestionFileModel } from "survey-core"; | ||
import { AngularComponentFactory } from "../../component-factory"; | ||
import { Component, Input } from "@angular/core"; | ||
import { EmbeddedViewContentComponent } from "../../embedded-view-content.component"; | ||
@Component({ | ||
selector: "sv-ng-file-preview", | ||
templateUrl: "./file-preview.component.html" | ||
}) | ||
export class FilePreviewComponent extends EmbeddedViewContentComponent { | ||
@Input() question!: QuestionFileModel; | ||
trackFilesFn: (index: number) => string = (index: number): string => { | ||
return this.question.inputId + "_" + index; | ||
} | ||
} | ||
AngularComponentFactory.Instance.registerComponent("sv-file-preview", FilePreviewComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
<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 --> | ||
<div data-bind="css: question.cssClasses.imageWrapper"> | ||
<!-- ko if: question.canPreviewImage($data) --> | ||
<img data-bind="attr: { src: $data.content }, style : { height: question.imageHeight, width: question.imageWidth }" alt="File preview"> | ||
<!-- /ko --> | ||
<!-- ko if: question.defaultImage($data) --> | ||
<!-- ko component: { name: 'sv-svg-icon', params: { css: question.cssClasses.defaultImage, iconName: question.cssClasses.defaultImageIconId, size: 'auto' } } --><!-- /ko --> | ||
<!-- /ko --> | ||
<!-- ko if: $data.name --> | ||
<!-- ko ifnot: question.isReadOnly --> | ||
<div data-bind="click: question.doremovefile, css: question.getRemoveButtonCss()"> | ||
<span data-bind="css: question.cssClasses.removeFile, text: question.removeFileCaption"></span> | ||
<!-- ko if: question.cssClasses.removeFileSvgIconId --> | ||
<!-- ko component: { name: 'sv-svg-icon', params: { css: question.cssClasses.removeFileSvg, title: question.removeFileCaption, iconName: question.cssClasses.removeFileSvgIconId, size: 'auto' } } --><!-- /ko --> | ||
<!-- /ko --> | ||
</div> | ||
<!-- /ko --> | ||
<!-- /ko --> | ||
</div> | ||
<!-- ko template: { name: 'survey-question-file-sign', data: {question: question, item: $data, fileSignCss: question.cssClasses.fileSignBottom} } --><!-- /ko --> | ||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as ko from "knockout"; | ||
|
||
const template = require("./file-preview.html"); | ||
|
||
export var SurveyFilePreview: any; | ||
|
||
ko.components.register("sv-file-preview", { | ||
viewModel: { | ||
createViewModel: (params: any, componentInfo: any) => { | ||
return params; | ||
}, | ||
}, | ||
template: template, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.