@andersonalmeidax0/webcomponents 0.1.13 → 0.1.15
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/RestAPIAdapter.js
CHANGED
|
@@ -151,14 +151,70 @@ X-Colocar o MetalMarlek em outro server AWS ... com docker... com outra conta de
|
|
|
151
151
|
r=await this.getJSONResponse(response);
|
|
152
152
|
|
|
153
153
|
//tag de dados pode ser nada,result, data
|
|
154
|
-
if(this.tagData==null)
|
|
154
|
+
if(this.tagData==null){
|
|
155
|
+
if(vo.fileData)
|
|
156
|
+
await uploadFile(vo.fileData);
|
|
157
|
+
return r;
|
|
158
|
+
|
|
159
|
+
}
|
|
155
160
|
|
|
156
161
|
var respBlock=this.tagData;
|
|
157
162
|
if(r[respBlock])
|
|
158
163
|
r[respBlock].insertedId=r.insertedId;
|
|
159
|
-
if(r[respBlock])
|
|
164
|
+
if(r[respBlock]) {
|
|
165
|
+
if(vo.fileData)
|
|
166
|
+
await uploadFile(vo.fileData);
|
|
167
|
+
return r[respBlock];
|
|
168
|
+
}
|
|
160
169
|
throw new PlatAPIError('Invalid payload response');
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
161
173
|
};
|
|
174
|
+
|
|
175
|
+
/** ***********************
|
|
176
|
+
*
|
|
177
|
+
*********************** */
|
|
178
|
+
async uploadFile(fileData) {
|
|
179
|
+
alert('UPLOAD start');
|
|
180
|
+
let formData = new FormData();
|
|
181
|
+
formData.append('file', fileData);
|
|
182
|
+
const response = await fetch(urlAPI+'/api/upload', {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
body: formData,
|
|
185
|
+
})
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
if(response.status===404)
|
|
188
|
+
throw new PlatAPIDBNotFound( `An error has occured: ${response.status}`);
|
|
189
|
+
if(response.status===403)
|
|
190
|
+
throw new PlatAPIForbidden( `An error has occured: ${response.status}`);
|
|
191
|
+
if(response.status===401)
|
|
192
|
+
throw new PlatAPIAuthError( `An error has occured: ${response.status}`);
|
|
193
|
+
throw new PlatAPIReturnCodeError();
|
|
194
|
+
}
|
|
195
|
+
r=await response.json();
|
|
196
|
+
alert("upload response:"+JSON.stringify(r));
|
|
197
|
+
return r;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
async downloadFile(f) {
|
|
202
|
+
var response=await fetch(urlAPI+'/api/download/'+f, {
|
|
203
|
+
method: 'GET'
|
|
204
|
+
})
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
if(response.status===404)
|
|
207
|
+
throw new PlatAPIDBNotFound( `An error has occured: ${response.status}`);
|
|
208
|
+
if(response.status===403)
|
|
209
|
+
throw new PlatAPIForbidden( `An error has occured: ${response.status}`);
|
|
210
|
+
if(response.status===401)
|
|
211
|
+
throw new PlatAPIAuthError( `An error has occured: ${response.status}`);
|
|
212
|
+
throw new PlatAPIReturnCodeError();
|
|
213
|
+
}
|
|
214
|
+
var blob = await response.blob();
|
|
215
|
+
return blob;
|
|
216
|
+
}
|
|
217
|
+
|
|
162
218
|
/** ***********************
|
|
163
219
|
*
|
|
164
220
|
*********************** */
|
|
@@ -88,11 +88,11 @@ class XFormEdit extends React.Component {
|
|
|
88
88
|
</React.Fragment>)
|
|
89
89
|
}
|
|
90
90
|
else
|
|
91
|
-
if (v.type === '
|
|
91
|
+
if (v.type === 'file') /* file */ {
|
|
92
92
|
return (
|
|
93
93
|
<React.Fragment key={i}>
|
|
94
94
|
<div className=""><div>{v.label}</div>
|
|
95
|
-
<p>{this.props.formData[v.attr]}</p>
|
|
95
|
+
<p>{this.props.formData[v.attr]?this.props.formData[v.attr]:"No file selected"}</p>
|
|
96
96
|
<XButton id={this.props.id + '_F' + i} attachFile={true} disabled={v.readOnly} onClick={(e)=>{this.props.formData[v.attr]=e.target.files[0].name;this.props.formData.filedata=e.target.files[0]}} textlabel='Select File'></XButton>
|
|
97
97
|
</div>
|
|
98
98
|
</React.Fragment>)
|
|
@@ -117,7 +117,7 @@ function nfmtM(n) {
|
|
|
117
117
|
</thead>
|
|
118
118
|
<tbody>
|
|
119
119
|
{this.props.list.map((item,index,arr)=> {
|
|
120
|
-
return <XTableCell key={index} item={item} index={index} lastIndex={arr.length} {...this.props} notifyChangeFn={this.cellChanged} /> })}
|
|
120
|
+
return <XTableCell key={index} item={item} index={index} lastIndex={arr.length} {...this.props} notifyChangeFn={this.cellChanged} api={this.props.api} /> })}
|
|
121
121
|
</tbody>
|
|
122
122
|
</table>
|
|
123
123
|
</div>
|
|
@@ -134,7 +134,7 @@ function nfmtM(n) {
|
|
|
134
134
|
//var XTableCell_ID=0;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* recebe "api"> só quando chamado de JZlist vem preenchido. Usa para download.
|
|
138
138
|
*/
|
|
139
139
|
class XTableCell extends React.Component {
|
|
140
140
|
constructor(props) {
|
|
@@ -186,6 +186,24 @@ class XTableCell extends React.Component {
|
|
|
186
186
|
this.props.notifyChangeFn();
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
evtDownload = async(f) => {
|
|
190
|
+
alert(f)
|
|
191
|
+
if(this.props.api) {
|
|
192
|
+
var blob=await this.props.api.download(urlAPI+'/api/download/'+f)
|
|
193
|
+
// 2. Create blob link to download
|
|
194
|
+
const url = window.URL.createObjectURL(new Blob([blob]));
|
|
195
|
+
const link = document.createElement('a');
|
|
196
|
+
link.href = url;
|
|
197
|
+
link.setAttribute('download', `${f}`);
|
|
198
|
+
// 3. Append to html page
|
|
199
|
+
document.body.appendChild(link);
|
|
200
|
+
// 4. Force download
|
|
201
|
+
link.click();
|
|
202
|
+
// 5. Clean up and remove the link
|
|
203
|
+
link.parentNode.removeChild(link);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
189
207
|
renderListItem(item,p1,lastIndex) {
|
|
190
208
|
//var kk='ASD'+(p1+1234);
|
|
191
209
|
//XTableCell_ID=XTableCell_ID+1;
|
|
@@ -252,7 +270,9 @@ class XTableCell extends React.Component {
|
|
|
252
270
|
if(v.type=='c'){
|
|
253
271
|
return <td key={i} align={v.align} className={v.className}><XCheckbox disabled={v.readOnly} id={this.props.id+'_R'+p1+'_C'+i} defaultValue={item[v.attr]} onChange={(ev)=>{this.inputChange(ev,item,v)}} xonChange={this.inputChangeNew} />{DEBUG_ID2&&this.props.id+'_R'+p1+'_C'+i}</td>
|
|
254
272
|
}
|
|
255
|
-
|
|
273
|
+
if(v.type=='file'){
|
|
274
|
+
return <td key={i} align={v.align} className={v.className} id={this.props.id+'_R'+p1+'_C'+i}><a onClick={()=>{this.evtDownload(cellFmt)}}>{cellFmt}</a> {DEBUG_ID2&&'['+this.props.id+'_R'+p1+'_C'+i+']'}</td>
|
|
275
|
+
}
|
|
256
276
|
return <td key={i} align={v.align} className={v.className} id={this.props.id+'_R'+p1+'_C'+i}>{cellFmt} {DEBUG_ID2&&'['+this.props.id+'_R'+p1+'_C'+i+']'}</td>
|
|
257
277
|
}
|
|
258
278
|
})}
|
package/package.json
CHANGED
package/releasenotes.txt
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
0.1.10: add css
|
|
11
11
|
0.0.11: no alert on update / XButton upload com text=true
|
|
12
12
|
0.1.12: remove getStorage from APIAdapter
|
|
13
|
-
0.1.13: new form type: "f"=file upload
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
0.1.13: new form type: "f"=file upload (Part 1: UI CREATE)
|
|
14
|
+
0.1.14: RestAPIAdapter => (Part 2: CREATE: file upload REST API / Part3: show fileField on list with download link
|
|
15
|
+
0.1.15: fix bug
|
|
16
16
|
npm login
|
|
17
17
|
npm publish --access public
|
|
18
18
|
|