3.0.0 • Published 3 months ago

@eqproject/eqp-attachments v3.0.0

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

Table of contents

Required

  • Angular Material installed and imported
  • Sweetalert2 (v9)

Getting started

This package allows the upload/download of one or multiple attachments (one at a time). The attachments can be files or links (except video files, this feature will be added later). Has the possibility to render a preview for image files inside the eqp-table (an inline preview). Can open a dialog containing a preview of the uploaded IAttachmentDTO (whatever it is - a document, an image or a link).

Notes

The directive does not comunicate with the backend of any application to save the attachments, all uploaded files are locally managed.

Step 1: Install eqp-attachments:

NPM

npm install --save @eqproject/eqp-attachments

Step 2:

Import the EqpAttachmentsModule:

import { EqpAttachmentsModule } from '@eqproject/eqp-attachments';

@NgModule({
  declarations: [AppComponent],
  imports: [EqpAttachmentsModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

Include the following stylesheet from fontawesome in your global scss file:

@import "~@fortawesome/fontawesome-free/css/all.min.css";

API

Inputs

InputTypeDefaultRequiredDescription
disableActionbooleanfalsenoHas effect only if [multipleAttachment]="true". If TRUE then the eqp-table containing the list of attachments does not show the action column.
showHeaderbooleantruenoHas effect only if [multipleAttachment]="true". If TRUE then shows the header of the mat-card.
headerTitlestring"Elenco allegati"noHas effect only if [multipleAttachment]="true" and [showHeader]="true". It defines the title of the mat-card .
attachmentsListArray<IAttachmentDTO>nullnoDefines the initial array of attachments. If not passed it is instantiated as an empty array. Even in case multipleAttachment is set to FALSE you need to pass the eventual attachment as an Array.
showMatCardbooleantruenoIf TRUE applies the box-shadow style of the mat-card
multipleAttachmentbooleantruenoDefines how many attachments the directive needs to handle. If TRUE shows an eqp-table containing the values of attachmentsList with the possibility to download/open or delete any row. With any other value it shows only a button to upload one IAttachmentDTO (link or file).
loadMultipleFilesbooleanfalsenoIf it assumes the value TRUE then it will be possible to load multiple files at the same time. This feature is active ONLY if you manage multiple attachments, so if the multipleAttachment input takes on the value TRUE, otherwise it is always disabled.
attachmentsColumnsArray<ConfigColumn>nullnoHas effect only if [multipleAttachment]="true". Columns configuration for the eqp-table showing the list of IAttachmentDTO.
emptyTableMessagestring"Nessun dato trovato"noHas effect only if [multipleAttachment]="true". Sets the message to show if the eqp-table contains no elements.
allowOnlyImagesbooleanfalsenoIf TRUE allows the user to upload only image files of the following types: ["image/bmp", "image/gif", "image/jpeg", "image/tiff", "image/png"]. If FALSE the user can upload a file of any type.
acceptedFileTypesstring*noSets the accept input attribute describing which file type to allow.
isDisabledbooleanfalsenoIf TRUE it disables the buttons to add a new IAttachmentDTO.
showInlinePreviewbooleantruenoHas effect only if [multipleAttachment]="true" and attachmentsColumns are not defined. Adds a column to the eqp-table to show a small preview of the IAttachmentDTO (if it is an image, otherwise an icon based on the content type of the file). With a click on it opens a dialog to view the selected attachment.
getAttachmentEndpointstringnullnoSets the endpoint to call to get the complete IAttachmentDTO to be displayed inside the preview dialog. Used only for images with the FileDataBase64 property missing (in any other case the FilePath property is used to render the preview). The directive makes a POST request without any token and with the selected IAttachmentDTO in the body.
productionBaseUrlstringnullnoHostname of the production environment. Needed to display in the preview dialog any document using the google viewer (example: "https://eqproject.it" - without any "/" at the end). Combined with the FilePath property sets the access path to the selected file. Make sure the forlder is accessible.
compressionOptionsIOptions{ maxSizeMB: 0.5, maxWidthOrHeight: 1920, useWebWorker: true }noSets the compression options for the uploaded images.
downloadTooltipPositionstring"below"noDefines the position of the tooltip used by the eqp-table in the download column. The possible values are the following: "below", "above", "left", "right".
openLinkLabelstring"Apri linknoSets the open a link button label.
addButtonLabelstring"Aggiungi"noSets the add button label.
downloadLabelstring"Download"noSets the download button label.
deleteLabelstring"Elimina"noSets the delete button label.
fileNameLabelstring"Nome file"noSets the file name feld label.
previewLabelstring"Anteprima"noSets the preview label.
uploadFileLabelstring"Carica file"noSets the upload file button label.
confirmLabelstring"Conferma"noSets the confirm button label.
abortLabelstring"Annulla"noSets the abort button label.
saveLabelstring"Salva"noSets the save button label.
exitLabelstring"Esci"noSets the exit button label.
uploadWithDropboxLabelstring"Carica con Dropbox"noSets the dropbox button label.";
cropLabelstring"Scegli le dimensioni dell'immagine"noSets the crop label.";
flipHorinzontalLabelstring"Capovolgi orizzontalmente"noSets the horizontal flip button label.";
flipVerticalLabelstring"Capovolgi verticalmente"noSets the vertical flip button label.";
rotateRightLabelstring"Ruota a destra"noSets the rotation left button label.";
rotateLeftLabelstring"Ruota a sinistra"noSets the rotation right button label.";
eqpTableSearchTextstring"Cerca"noSets the eqp-table search input placeholder.
isTableSearcheablebooleantruenoIt allows you to establish, in the case of multiple attachments management, whether the table is searchable or not (default: true)
deleteDialogTitlestring"Sei sicuro di voler procedere?"noSets the confirm dialog title when deleting an IAttachmentDTO.
deleteDialogMessagestring"Sei sicuro di voler cancellare quest'allegato?"noSets the confirm dialog message when deleting an IAttachmentDTO.
noImageSelectedErrorMessagestring"Non è possibile selezionare un file che non sia un'immagine"noHas effect only if [allowOnlyImages]="true". Sets the error dialog message when the user tries to upload a file which is not an image.
wrongTypeSelectedErrorMessagestring"Non è possibile caricare il file selezionato."noSets the error dialog message when user tries to upload a not allowed file .
videoPreviewErrorMessagestringImpossibile aprire l'anteprima di un file video.noSets the warning dialog merrage when the user tries to open the preview of a video file.
audioPreviewErrorMessagestringImpossibile aprire l'anteprima di un file audio.noSets the warning dialog merrage when the user tries to open the preview of an audio file.
isEqpTableMultiLanguagebooleanfalsenoIt allows you to establish whether the eqp-table containing the list of attachments uses multilanguage or not
tablePaginatorVisiblebooleantruenoIt allows you to establish, in the case of multiple attachments management, whether the table containing the list of attachments must be paged or not (default: true)
tablePaginatorSizenumbernullnoIn case of managing multiple attachments, it allows you to establish the default page size for the table containing the list of attachments (default: null)
showPreviewbooleantruenoIt allows you to establish if there is the possibility to view the preview (default: true)
separatedUploadButtonsbooleanfalsenoIt allows you to establish, if the uploading buttons are separated or included in a menu (default: false)
singleAttachmentDragAndDropbooleanfalsenoIn the case of single attachment management, it allows you to establish if the drag and drop is included for the upload of the file (default: false)
cropOptionsArray<CropOptionEnum>[]noArray of options to include during the crop of a file
allowedTypesArray<AttachmentType>[ AttachmentType.FILE, AttachmentType.LINK ]noArray to establish what type of attachments can be loaded
cropDialogClassstringnoIt allows you to establish the css class of the image cropper (It needs the ::ng-deep pseudo-class)

Outputs

OutputEvent ArgumentsRequiredDescription
(localEditedAttachments)EventEmitter<Array<IAttachmentDTO>>noInvoked when an IAttachmentDTO is created and added to attachmentsList or is deleted. It always return an Array of IAttachmentDTO, even if [multipleAttachment]="true".
(abortAddAttachment)EventEmitter<any>noEvent triggered by pressing the EXIT button of the file upload modal.
(downloadAttachment)EventEmitternoInvoked when the user tries to download an IAttachmentDTO with at least one of the following properties not defined: "FileDataBase64", "FileContentType", "FileName". It returns the user selected object.
(onDeleteAttachment)EventEmitter<IAttachmentDTO>noInvoked when an IAttachmentDTO is deleted from attachmentsList. It returns the deleted element.

Model, Interfaces and Enums used

IAttachmentDTO Interface

PropertyDescriptionTypeExamples
IDID of the recordnumber | string-
FileNameSets the name of the uploaded file or linkstring-
FileContentTypeContains the content type of the uploaded filestring"image/bmp", "image/gif", "image/jpeg", ...
FileExtensionContains the extension of the uploaded filestring"pdf", "jpg", "docx",...
FilePathContains the path where the uploaded file gets physically saved or contains the actual link uploaded by the userstring"C:\Users\EQProject\Desktop\" or "https://eqproject.it/".
AttachmentTypeIt is an enum defining the type of the IAttachmentDTOAttachmentTypePossible values: FILE = 1, LINK = 2 and DROPBOX = 3.
FileDataBase64Contains the base64 string of the uploaded filestring-
IsImageIt is set to TRUE if the uploaded file is an image.boolean-
FileThumbnailBase64Contains the base64 string of a thumbnail of the uploaded image. When uploading an attachment it is always null. Usefull to display the inline preview of a previously uploaded image if the full image base64 is too havy (specially loading a long list of IAttachmentDTO).string-

IOptions Interface

PropertyDescriptionTypeExamples
maxSizeMBMax size of compressed file expressed in MB.number-
maxWidthOrHeightCompressedFile will scale down by ratio to a point that width or height is smaller than maxWidthOrHeight but, automatically reduce the size to smaller than the maximum Canvas size supported by each browser.number-
useWebWorkerUse multi-thread web worker, fallback to run in main-thread.boolean-

Enums description

EnumTypeDescriptionNotes
AttachmentTypeDefine the type of the IAttachmentDTOFILE = 1: the user uploaded a file; LINK = 2: the user uploaded a link; DROPBOX = 3: the user uploaded a file using Dropbox

Use cases

Use Example in class :

Notes

To make this examples work you need to replace the FileDataBase64 property value with a complete base64 string.

Breaking changes from the 2.0.3 version

File upload modal has been removed. So when using ViewChild, use addFile() function instead of openModalAddAttachment().

CASE 1: Single attachment

<eqp-attachments 
    [multipleAttachment]="false" [attachmentsList]="[singleAttachment]"
    [allowOnlyImages]="false"
    [isDisabled]="false" [allowedTypes]="[1,2,3]"
    (downloadAttachment)="viewAttachment($event)"
    (localEditedAttachments)="catchAttachmentList($event)"
    (onDeleteAttachment)="onDeleteAttachment($event)"
    [showPreview]="false" [cropOptions]="[1,2]">
</eqp-attachments>
    singleAttachment: IAttachmentDTO = {
        ID: 0,
        IsImage: true,
        AttachmentType: 1,
        FileContentType: "image/png",
        FileName: "logo_eqp.png",
        FileExtension: "png",
        FileDataBase64: "iVBORw0KGgoAAAANSUhEUgAAAK[...]XSNgP0pGR02YAAAAASUVORK5CYII="
    }
  
    catchAttachmentList(event) {
        // TODO
    }
  
    viewAttachment(event) {
        // TODO
    }

    onDeleteAttachment(event) {
        // TODO
    }

CASE 2: Multiple attachments

<eqp-attachments [multipleAttachment]="true" [attachmentsList]="attachmentsList"
    [allowOnlyImages]="false" [downloadTooltipPosition]="'below'" (downloadAttachment)="viewAttachment($event)"
    (localEditedAttachments)="catchAttachmentList($event)" [isTableSearcheable]="false"
    [tablePaginatorVisible]="false" [allowedTypes]="[1,2,3]" [cropOptions]="[1,2]">
</eqp-attachments>
    attachmentsList: Array<IAttachmentDTO> = [
    {
        ID: 0,
        IsImage: true,
        AttachmentType: 1,
        FileContentType: "image/png",
        FileName: "logo_eqp.png",
        FileExtension: "png",
        FileDataBase64: "iVBORw0KGgoAAAANSUhEUgAAAK[...]XSNgP0pGR02YAAAAASUVORK5CYII="
    },
    {
        ID: 0,
        IsImage: false,
        AttachmentType: 2,
        FileName: "EqProject",
        FilePath: "https://www.eqproject.it/",
    },
    ];
    
    catchAttachmentList(event) {
        // TODO
    }
  
    viewAttachment(event) {
        // TODO
    }

Credits

This library has been developed by EqProject SRL, for more info contact: info@eqproject.it

2.5.1

3 months ago

3.0.0

3 months ago

2.1.4

4 months ago

2.5.0

4 months ago

2.1.5

4 months ago

2.1.2

7 months ago

2.1.1

7 months ago

2.1.3

7 months ago

2.10.0

7 months ago

2.0.7

7 months ago

2.0.6

9 months ago

2.0.9

7 months ago

2.0.8

7 months ago

0.1.17

9 months ago

0.1.18

9 months ago

2.0.5

10 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

2.0.1

1 year ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

2.0.0

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago