Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added restrictionUniqueName #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "filedropper",
"widgetName": "FileDropper",
"version": "1.4.1",
"version": "1.5.0",
"description": "Drop files in your Mendix Application",
"copyright": "Mendix 2020",
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",
"config": {
"widgetPath": "./dist/MxTestProject/widgets",
"projectPath": "./dist/MxTestProject/",
"widgetPath": "../../widgets",
"projectPath": "../../",
"mendixHost": "http://windows:8080",
"developmentPort": "3000"
},
Expand Down
1 change: 1 addition & 0 deletions src/FileDropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class FileDropperContainer extends Component<FileDropperContainerProps, {}> {
autoSave: props.dataAutoSave,
maxNumber: props.restrictionMaxFileCount,
maxSize: maxFileSize,
uniqueName: props.restrictionUniqueName,
validationMessages,
accept,
texts,
Expand Down
4 changes: 4 additions & 0 deletions src/FileDropper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
Note 1: This might not always be accurate. There can be differences between platforms &amp; browsers. To be sure it is better to use the 'onAccept Microflow'
Note 2: When using an Entity that is/inherits 'System.Image', Mime types will always be ignored and set to 'image/*'. You can further restrict this using the 'onAccept Microflow'</description>
</property>
<property key="restrictionUniqueName" type="boolean" required="true" defaultValue="true">
<caption>Restrict Duplicates</caption>
<description>Restrict uploads to have unique names. If true, will ignore a file upload with a repeated name, regardless of file path.</description>
</property>
</propertyGroup>

<!-- VERIFICATION -->
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="FileDropper" version="1.4.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="FileDropper" version="1.5.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="FileDropper.xml"/>
</widgetFiles>
Expand Down
9 changes: 6 additions & 3 deletions src/store/fileDropperStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FileDropperStoreOptions {
accept?: string;
maxNumber?: number;
maxSize?: number;
uniqueName: boolean;
contextObject?: mendix.lib.MxObject;
validationMessages?: ValidationMessage[];
saveBase64?: boolean;
Expand All @@ -34,6 +35,7 @@ export class FileDropperStore implements FileDropperStoreProps {
public accept: string | undefined;
public maxNumber: number;
public maxSize: number | undefined;
public uniqueName: boolean;

public saveMethod: ((file: IFileDropperFile) => Promise<boolean>) | null;
public deleteMethod: ((file: IFileDropperFile) => Promise<boolean>) | null;
Expand Down Expand Up @@ -72,7 +74,7 @@ export class FileDropperStore implements FileDropperStoreProps {
// We need to make sure we first clear all subscriptions, otherwise it will delete twice
this.subscriptionHandler({});
const files = this.files;
const found = files.findIndex(f => f.name === file.name);
const found = files.findIndex(f => f.guid === file.guid);
if (found !== -1) {
if (file.status === "saved" && this.deleteMethod !== null) {
const deleted = yield this.deleteMethod(file);
Expand Down Expand Up @@ -111,6 +113,7 @@ export class FileDropperStore implements FileDropperStoreProps {
maxNumber,
accept,
maxSize,
uniqueName,
texts,
validationMessages,
saveBase64
Expand All @@ -128,6 +131,7 @@ export class FileDropperStore implements FileDropperStoreProps {
this.accept = accept;
this.maxNumber = typeof maxNumber !== "undefined" ? maxNumber : 0;
this.maxSize = maxSize;
this.uniqueName = uniqueName;
this.texts = texts;
}

Expand Down Expand Up @@ -157,8 +161,7 @@ export class FileDropperStore implements FileDropperStoreProps {

@action
public addFile(file: File): void {
const found = this.files.findIndex(f => f.name === file.name);
if (found === -1) {
if (!this.uniqueName || this.files.every(f => f.name !== file.name)) {
const newFile = new FileDropperFile(file, this.saveMethod, this.saveBase64);
this.files.push(newFile);
this.saveFile(newFile);
Expand Down
1 change: 1 addition & 0 deletions typings/FileDropperProps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface FileDropperContainerProps extends CommonProps {
restrictionMaxFileSize: number;
restrictionMaxFileCount: number;
restrictionMimeType: string;
restrictionUniqueName: boolean;

verificationOnAcceptMicroflow: string;
verificationEntity: string;
Expand Down