15.0.0 • Published 1 year ago
egov-file-upload v15.0.0
FileUpload Component
Installation
ng add sf-file-upload
Configuration
Setup the hosting component
*.component.html
===================================================================================================
<file-upload
[showFileList]="true"
[showUpload]="true"
[canDelete]="false"
[componentTitle]="'File Upload'"
[fileTypeHint]="'JPG'"
[maxFileCount]="1000"
[showFileTypeHint]="true"
[allowedFileTypes]="['pdf', 'jpg', 'png']"
[showTitle]="true"
[downloadAllowed]="true"
(addFile)="onAddFile($event)"
(downloadFile)=onDownloadFile($event)
(removeFile)="onRemoveFile($event)">
</file-upload>
Accessing the upload component from a other component:
If you have one component then you can use @ViewChild
but if you user more than one component your should user @ViewChildren
Usage...
@ViewChild(FileUploadContainerComponent) upload!: FileUploadContainerComponent;
upload.updateFileList(files);
@ViewChildren(FileUploadContainerComponent) uploads!: QueryList<FileUploadContainerComponent>;
uploads.first.updateFileList(files);
uploads.last.updateFileList(files)
*.component.ts
===================================================================================================
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements {
files!: DocumentResponse[];
@ViewChild(FileUploadContainerComponent) upload!: FileUploadContainerComponent;
@ViewChildren(FileUploadContainerComponent) uppies!: QueryList<FileUploadContainerComponent>;
constructor() { }
onAddFile(fileDescription: DocumentResponse) {
console.log('AppComponent#onAddFile fileDescription=%O', fileDescription);
this.upload.updateFileList(fileDescription);
}
onRemoveFile(id: number) {
console.log('AppComponent#onRemoveFile id=%O', id);
this.files = this.files.filter(file => file.id !== id);
this.upload.setFileList(this.files);
}
}
Styling
.component {
--component-title: gray;
--component-title-size: 2em;
--component-title-margin: 30px 0 0 2px;
--description-text-color: gray;
--description-text-size: 1em;
--description-text-margin: 5px 0 2px 20px;
--file-count-tracker-text-color: gray;
--file-count-tracker-text-size: 1.2em;
--file-count-tracker-text-margin: 0 10px 2px 0;
--max-file-reached-text-color: yellow;
--max-file-reached-text-size: 1.2em;
--max-file-reached-text-margin: 10px 0 2px 10px;
--file-type-hint-text-color: gray;
--file-type-hint-text-size: 1.2em;
--file-type-hint-text-margin: 10px 10px 0 0;
--file-size-exceeded-alert-text-color: red;
--file-size-exceeded-alert-text-size: 1.4em;
--file-size-exceeded-alert-text-margin: 10px 0 0 2px;
--upload-margin: 0 10px 0 10px;
--upload-padding: 3px 3px;
--dropzone-padding: 40px 0 0 0;
--dropzone-height: 350px;
--dropzone-button-color: white;
--drop-icon-text-row-display: inline; // you can set it to flex to make the icon and be displayed in a row
--drop-icon-text-row-direction: row;
--drop-icon-text-row-justify: center;
--dropzone-icon-color: black;
--dropzone-button-text: black;
--dropzone-button-margin: 0 0 0 0;
--dropzone-text-color: black;
--dropzone-text-size: 1.2em;
--dropzone-text-margin: 0 0 10px 0;
--dropzone-text-font-weight: lighter;
--dropzone-background: #f5f5f7;
--dropzone-error-text-color: red;
--dropzone-error-text-size: 1.5em;
--dropzone-error-text-margin: 0 0 0 0;
--dropzone-error-font-weight: normal;
}
```
### Configure the needed icons
With the installation of the package there are also delivered the needed icons. To setup the usage of the icons add following lines to your angular.json.
```
"architect": {
build": {
"options": {
"assets": [
{
"glob": "**/*",
"input": "./node_modules/sf-file-upload/assets/file-upload-images",
"output": "/assets/images"
}
]
}
}
}
Parameters
You can customize your file upload with the following parameters
Parameter | Type | Default | Description |
---|---|---|---|
files | Observable<DocumentResponse[]> | of([]) | List of files |
displayFileList | boolean | true | toggle if the list with files is displayed |
displayUpload | boolean | true | toggle if the upload area is displayed |
downloadAllowed | boolean | true | display File name as link |
canDelete | boolean | true | display Delete Button |
title | string | '' | The Maintitle over the component |
displayTitle | boolean | true | toggle if the main title of the component is displayed |
fileTypeHint | string | '' | Information text about the allowed file types |
description | boolean | '' | description of the file-upload |
displayDescription | boolean | false | Should the description be displayed |
displayFileTypeHint | boolean | true | Set if file type hints are displayed |
allowedFileTypes | string[] | [] | toggle if the upload area is displayed |
maxFileCount | number | 1000 | Max allowed files who can be uploaded |
maxFileReachedText | string | Max file count exceeded | Text displayed when the allowed file count is exceeded |
displayFileCountTrackingText | boolean | true | display the tracking value of files they have been already uploaded |
fileCountTrackingText | string | '%COUNT%/' + this.maxFileCount + ' uploaded' | %COUNT% will be replaced with the value of the current file count. If you don't pass a %COUNT% placeholder the message will be passd as given. |
maxFileReachedText | string | 'You have uploaded the maximum number of documents (%MAX%) allowed.' | %COUNT% will be replaced with the value of the current file count. If you don't pass a %COUNT% placeholder the message will be passd as given. |
maxMbAllowed | number | 100 | Sets the max MB allowed to upload over all files |
trackMaxMbAmount | boolean | false | Sets the max MB allowed to upload over all files |
maxMbTrackingText | string | The max allowed MB amount of %SIZE% over all files is exceeded | Text Displayed when the max file sizes over all files is exceeded. %SIZE% will be replaced with the actual size amount. If you don't pass a %SIZE% placeholder the message will be passd as given. |
displayMaxMbTrackingText | boolean | true | Sets if the overall MB text will be displayed |
maxMbExceedText | string | 'This file could not be added, it is to big you can upload max. %SIZE% Mb. The file %FILENAME% has a size of %FILESIZE%.' | Text displayed in the drop area |
dropAreaText | string | Drop documentes here | Text displayed in the drop area |
hideDropAreaWhenMaxCountReached | boolean | false | Should the upload area be hidden when the maxFile value is reached |
displayWrongFileTypeErrorInDragArea | boolean | true | Decide if the wrong file format error message should be displayed inside the drag area or above the drag area. |
browseButtonText | string | Explore harddisk | Button text for the harddisk explorer |
displayDropAreaButton | boolean | true | Set if the drop area button will be displayed |
displayDropAreaIcon | boolean | true | Set if the drop area Icon will be displayed |
displayDropAreaText | boolean | true | Set if the drop area Text will bes displayed |
wrongFileFormatMessage | string | This type of file is not allowed | Text displayed when the user try to upload a file who isn't allowed |
displayFileSize | boolean | true | Set if the files should be displayed in the file list |
fileListNameRowLabel | string | Name | Sets the filename row label |
fileListCreateDateRowLabel | string | Uploaded | Sets the uploaded row label |
fileListSizeRowLabel | string | Size | Sets the size row label |
a11yExplainFileDownloadIcon | string | Accessibility text for download Icon | |
a11yExplainFileName | string | Accessibility text for file name, this. is only allowed if download isn't allowed | |
a11yExplainFileDownload | string | Accessibility text for file download this is only announcent if download is allowed. The Annoucnement is a combimnation of a11yExplainFileName and a11yExplainFileDownload | |
a11yExplainFilesize | string | Accessibility text for file size | |
a11yExplainFileCreateDate | string | Accessibility text for create date | |
a11yExplainFileDeleteButton | string | Accessibility text for delete Button | |
a11yExplainUploadTitle | string | Accessibility text for upload title | |
a11yExplainBrowseButton | string | Accessibility text for browse harddisk button | |
a11yFileDownloadAnnouncement | string | Live announcement when the user downloads a file | |
a11yFileCountTrackingAnnouncement | string | Live announcement when the file count changes |
Models
export interface DocumentResponse {
id: number;
createDate: Date;
filename: string;
fileSize: number;
mimeType: string;
}
Functions
To react to user actions like upload and delete of files you can implement this functions in your component.
Parameter | Type | Description |
---|---|---|
addFile | EventEmitter | User implementation to react to a file upload |
removeFile | EventEmitter | User implementation to react to user deleting a file |
downloadFile | EventEmitter | User implementation to react to user downloading a file |
Paginator translation
The Paginator is in english and can't be translated without ngx-translate.
The Host applction should have the ngx-translation up an running:
{
"general.paginator.from.to.label": "von",
"general.paginator.items.per.page": "Anzahl Einträge",
"general.paginator.next.page": "Nächste Seite",
"general.paginator.previous.page": "Vorherige Seite",
"general.paginator.last.page": "Letzte Seite",
"general.paginator.first.page": "Erste Seite"
}
app.module.ts
imports: [
FileUploadModule,
TranslateModule.forRoot({
defaultLanguage: 'de',
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}), providers: [
{ provide: MatPaginatorIntl, useClass: TranslatedPaginatorService },
],
]
Development
When testing the library by installing it from file sistem npm instal ../local/directory/dist/lib
or by linking npm directory npm link ...
you must use preserveSymlink in the host application.
angular.json
"architect": {
"build": {
"options": {
"preserveSymlinks": true,
.
.
.
15.0.0
1 year ago