datasync-dynamic-form 1.3.9 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/DsDynamicForm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React, { Component, useImperativeHandle, forwardRef } from "react";
|
|
3
3
|
import Multiselect from 'multiselect-react-dropdown';
|
|
4
|
-
import { CTimeStamp, Randomize, SaveDataTierToDatasync, WScrollTo } from "datasync-core";
|
|
4
|
+
import { CTimeStamp, Randomize, SaveDataTierToDatasync, WScrollTo, CGUID } from "datasync-core";
|
|
5
5
|
import { DsBlob } from "datasync-blob";
|
|
6
6
|
import { DsPdf } from "datasync-pdf";
|
|
7
7
|
// reactstrap components
|
|
@@ -89,6 +89,93 @@ export class DsDynamicForm extends Component {
|
|
|
89
89
|
if (this.props.onFormChange)
|
|
90
90
|
this.props.onFormChange(this.local_data_blob.data_tier);
|
|
91
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* PROTOTYPE : uploadToDatasyncCloud
|
|
94
|
+
* Purpose : Upload binary data to My Custom Cloud server using Datasync SncPushCloud endpoint and return the accessible URL for the uploaded file.
|
|
95
|
+
* @param base64Data
|
|
96
|
+
* @param fileName
|
|
97
|
+
*/
|
|
98
|
+
this.uploadToDatasyncCloud = async (fileName, base64Data) => {
|
|
99
|
+
try {
|
|
100
|
+
const formData = new FormData();
|
|
101
|
+
formData.append('action', "syncPushCloud");
|
|
102
|
+
formData.append('filename', fileName);
|
|
103
|
+
formData.append('binary', base64Data);
|
|
104
|
+
const response = await fetch('http://localhost:8888/datasync-service/Sync.php', {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
body: formData,
|
|
107
|
+
});
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
110
|
+
}
|
|
111
|
+
const result = await response.json();
|
|
112
|
+
if (this.debugging) {
|
|
113
|
+
console.log('FTP upload response:', result);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (this.debugging) {
|
|
118
|
+
console.error('FTP upload error details:', error);
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
this.setBlobData = async (fieldName, value, cloudStorage) => {
|
|
124
|
+
//let httpBaseUrl = "localhost:8888/datasync-service/cloud"; // Base URL for accessing files in cloud storage
|
|
125
|
+
let httpBaseUrl = "http://localhost:8888/datasync-service/image_cloud.php?filename"; // Base URL for accessing files in cloud storage
|
|
126
|
+
try {
|
|
127
|
+
if (this.debugging)
|
|
128
|
+
console.log("setBlobData:fieldName ->", fieldName, " value ->", value, " cloudStorage ->", cloudStorage);
|
|
129
|
+
let finalValue = value;
|
|
130
|
+
if (cloudStorage && value) {
|
|
131
|
+
// Extract file extension from base64 data or determine from content
|
|
132
|
+
const mimeToExt = {
|
|
133
|
+
'data:image/jpeg': '.jpg',
|
|
134
|
+
'data:image/jpg': '.jpg',
|
|
135
|
+
'data:image/png': '.png',
|
|
136
|
+
'data:image/gif': '.gif',
|
|
137
|
+
'data:application/pdf': '.pdf',
|
|
138
|
+
'data:text/plain': '.txt'
|
|
139
|
+
};
|
|
140
|
+
let extension = '.bin'; // default extension
|
|
141
|
+
for (const [mimeType, ext] of Object.entries(mimeToExt)) {
|
|
142
|
+
if (value.startsWith(mimeType)) {
|
|
143
|
+
extension = ext;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Generate unique filename: file + guid + extension
|
|
148
|
+
const uniqueFileName = `file_${CGUID()}${extension}`;
|
|
149
|
+
// Upload base64ToBinary content to FTP server
|
|
150
|
+
try {
|
|
151
|
+
await this.uploadToDatasyncCloud(uniqueFileName, value);
|
|
152
|
+
if (this.debugging) {
|
|
153
|
+
console.log("Cloud Upload completed:", uniqueFileName);
|
|
154
|
+
}
|
|
155
|
+
// Store HTTP URL + filename as the final value
|
|
156
|
+
//finalValue = `${httpBaseUrl.endsWith('/') ? httpBaseUrl : httpBaseUrl + '/'}${uniqueFileName}`;
|
|
157
|
+
finalValue = `${httpBaseUrl}=${uniqueFileName}`;
|
|
158
|
+
if (this.debugging) {
|
|
159
|
+
console.log("Cloud storage URL:", finalValue);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (uploadError) {
|
|
163
|
+
console.error("FTP Upload failed:", uploadError);
|
|
164
|
+
throw new Error(`Failed to upload file to FTP server: ${uploadError}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let duplicate_data_tier = JSON.parse(JSON.stringify(this.local_data_blob.data_tier));
|
|
168
|
+
duplicate_data_tier[fieldName] = finalValue;
|
|
169
|
+
this.local_data_blob.data_tier = duplicate_data_tier;
|
|
170
|
+
//this.local_data_blob.data_tier[fieldName] = finalValue
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
alert(error);
|
|
174
|
+
}
|
|
175
|
+
//onFormChange handler return current form value to caller - PMAB on 2025-02-03
|
|
176
|
+
if (this.props.onFormChange)
|
|
177
|
+
this.props.onFormChange(this.local_data_blob.data_tier);
|
|
178
|
+
};
|
|
92
179
|
this.setFieldError = (pFieldObject, value) => {
|
|
93
180
|
try {
|
|
94
181
|
let nextFieldError = this.state.fieldError || {};
|
|
@@ -467,7 +554,16 @@ export class DsDynamicForm extends Component {
|
|
|
467
554
|
/* Checkbox is override with combobox */
|
|
468
555
|
return (_jsxs("div", { className: "field-rendering checkbox", children: [this.getFieldLabelTitle(field), _jsx(Multiselect, { showArrow: true, options: ["Oui", "Non"], isObject: false, displayValue: "key", selectedValues: this.getFieldData(field.name) ? this.getFieldData(field.name).split(";") : [], placeholder: field.placeholder, emptyRecordMsg: "", onSelect: (selectedList, selectedItem) => { this.setFieldData(field.name, selectedList.join(";")); }, onRemove: (selectedList, selectedItem) => { this.setFieldData(field.name, selectedList.join(";")); }, disable: this.props.read_only, singleSelect: true }), this._error_label(field)] }));
|
|
469
556
|
case "blob":
|
|
470
|
-
return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10 blob-fied", children: [_jsx(DsBlob, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name),
|
|
557
|
+
return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10 blob-fied", children: [_jsx(DsBlob, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), cloud_storage: field.cloud_storage || false, uploadPicture: async (UploadFile) => {
|
|
558
|
+
try {
|
|
559
|
+
await this.setBlobData(field.name, UploadFile.data, field.cloud_storage || false);
|
|
560
|
+
this.checkValidation(field);
|
|
561
|
+
}
|
|
562
|
+
catch (error) {
|
|
563
|
+
console.error("Upload failed:", error);
|
|
564
|
+
this.setFieldError(field, "Upload failed");
|
|
565
|
+
}
|
|
566
|
+
}, pictureStyle: "pic", buttonStyle: "btn btn-secondary", width: field.width ? field.width : undefined, height: field.height ? field.height : undefined, maxWidth: field.max_width ? field.max_width : undefined, maxHeight: field.max_height ? field.max_height : undefined, maxKBytes: field.max_kbytes ? field.max_kbytes : undefined, reduceImage: field.reduceImage ? field.reduceImage : undefined, onErrorHandler: (errorObject) => { this.onBlobErrorLocalHandler(errorObject); }, debugging: this.debugging }), this._error_label(field)] })] }));
|
|
471
567
|
case "pdf":
|
|
472
568
|
return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10", children: [_jsx(DsPdf, { item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), uploadPdf: (UploadFile) => { this.setFieldData(field.name, UploadFile.data); this.checkValidation(field); }, pictureStyle: "pic", buttonStyle: "btn btn-secondary" }), this._error_label(field)] })] }));
|
|
473
569
|
case "email":
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { Component, ChangeEvent } from "react";
|
|
2
2
|
import "./flex-grid.css";
|
|
3
3
|
interface Field {
|
|
4
|
+
cloud_storage?: boolean;
|
|
4
5
|
name: string;
|
|
5
6
|
input_type: string;
|
|
6
7
|
placeholder?: string;
|
|
@@ -142,6 +143,14 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
|
|
|
142
143
|
clearForm: () => void;
|
|
143
144
|
getFieldData: (fieldName: string) => string;
|
|
144
145
|
setFieldData: (fieldName: string, value: string) => void;
|
|
146
|
+
/**
|
|
147
|
+
* PROTOTYPE : uploadToDatasyncCloud
|
|
148
|
+
* Purpose : Upload binary data to My Custom Cloud server using Datasync SncPushCloud endpoint and return the accessible URL for the uploaded file.
|
|
149
|
+
* @param base64Data
|
|
150
|
+
* @param fileName
|
|
151
|
+
*/
|
|
152
|
+
private uploadToDatasyncCloud;
|
|
153
|
+
setBlobData: (fieldName: string, value: string, cloudStorage: boolean) => Promise<void>;
|
|
145
154
|
setFieldError: (pFieldObject: Field, value: string) => void;
|
|
146
155
|
getFieldError: (pFieldObject: Field) => string;
|
|
147
156
|
_error_label: (field: Field) => JSX.Element;
|
package/package.json
CHANGED