datasync-dynamic-form 1.4.8 → 1.5.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.
@@ -1,9 +1,10 @@
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, CGUID } from "datasync-core";
4
+ import { CTimeStamp, Randomize, SaveDataTierToDatasync, WScrollTo } from "datasync-core";
5
5
  import { DsBlob } from "datasync-blob";
6
6
  import { DsPdf } from "datasync-pdf";
7
+ import { CGUID } from "datasync-core";
7
8
  // reactstrap components
8
9
  import { Button, Label, FormGroup, Input, InputGroupText, InputGroup, Row as ReactstrapRow, Col as ReactstrapCol, } from "reactstrap";
9
10
  import "./flex-grid.css";
@@ -89,93 +90,6 @@ export class DsDynamicForm extends Component {
89
90
  if (this.props.onFormChange)
90
91
  this.props.onFormChange(this.local_data_blob.data_tier);
91
92
  };
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
- };
179
93
  this.setFieldError = (pFieldObject, value) => {
180
94
  try {
181
95
  let nextFieldError = this.state.fieldError || {};
@@ -554,16 +468,11 @@ export class DsDynamicForm extends Component {
554
468
  /* Checkbox is override with combobox */
555
469
  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)] }));
556
470
  case "blob":
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
+ return (_jsxs(_Fragment, { children: [this.getFieldLabelTitle(field), _jsxs("div", { className: "col-md-10 blob-fied", children: [_jsx(DsBlob
472
+ /*--- Cloud management ---*/
473
+ , {
474
+ /*--- Cloud management ---*/
475
+ cloud_storage: field.cloud ? field.cloud : false, cloud_url_prefix: `${this.props.datasync_url}/cloud/_${CGUID()}.jpg`, item_id: field.name, readOnly: this.props.read_only ? this.props.read_only : false, Caption: `${this.getFieldPrompt(field)} ...`, data: this.getFieldData(field.name), uploadPicture: (UploadFile) => { this.setFieldData(field.name, UploadFile.data); this.checkValidation(field); }, 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)] })] }));
567
476
  case "pdf":
568
477
  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)] })] }));
569
478
  case "email":
@@ -1,7 +1,6 @@
1
1
  import React, { Component, ChangeEvent } from "react";
2
2
  import "./flex-grid.css";
3
3
  interface Field {
4
- cloud_storage?: boolean;
5
4
  name: string;
6
5
  input_type: string;
7
6
  placeholder?: string;
@@ -23,6 +22,7 @@ interface Field {
23
22
  name_year?: string;
24
23
  name_hour?: string;
25
24
  name_min?: string;
25
+ cloud?: boolean;
26
26
  }
27
27
  interface Col {
28
28
  Id: string;
@@ -143,14 +143,6 @@ export declare class DsDynamicForm extends Component<DsDynamicFormProps, DsDynam
143
143
  clearForm: () => void;
144
144
  getFieldData: (fieldName: string) => string;
145
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>;
154
146
  setFieldError: (pFieldObject: Field, value: string) => void;
155
147
  getFieldError: (pFieldObject: Field) => string;
156
148
  _error_label: (field: Field) => JSX.Element;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "datasync-dynamic-form",
3
3
  "description": "Datasync Dynamic Form component",
4
- "version": "1.4.8",
4
+ "version": "1.5.0",
5
5
  "main": "dist/DsDynamicForm.js",
6
6
  "module": "dist/DsDynamicForm.js",
7
7
  "types": "dist/types/DsDynamicForm.d.ts",
@@ -19,7 +19,7 @@
19
19
  "devDependencies": {
20
20
  "@types/react": "^18.2.75",
21
21
  "@types/react-dom": "^18.2.25",
22
- "datasync-core": "^1.0.44",
22
+ "datasync-core": "^1.0.46",
23
23
  "multiselect-react-dropdown": "^2.0.25",
24
24
  "react": ">=18.2.0",
25
25
  "reactstrap": ">=8.4.1",
@@ -37,7 +37,7 @@
37
37
  "license": "ISC",
38
38
  "dependencies": {
39
39
  "axios": "^1.7.2",
40
- "datasync-blob": "^1.1.22",
40
+ "datasync-blob": "^1.1.12",
41
41
  "datasync-pdf": "^0.0.1",
42
42
  "runscripts": "^0.0.1"
43
43
  }