ywana-core8 0.0.33 → 0.0.37
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/index.cjs +0 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +0 -4
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +0 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/ContentEditor.css +0 -3
- package/src/domain/CreateContentDialog.js +4 -4
- package/src/domain/EditContentDialog.js +6 -1
- package/src/domain/TablePage.js +8 -17
- package/src/upload/UploadArea.js +18 -0
- package/src/upload/uploader.css +1 -0
- package/src/upload/uploader.js +68 -51
package/package.json
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
}
|
4
4
|
|
5
5
|
.content-editor>section {
|
6
|
-
|
7
6
|
margin-bottom: 1rem;
|
8
7
|
}
|
9
8
|
|
@@ -90,14 +89,12 @@
|
|
90
89
|
background-color: var(--paper-color) !important;
|
91
90
|
}
|
92
91
|
|
93
|
-
|
94
92
|
.collection-adder td.actions {
|
95
93
|
border: solid 0px red;
|
96
94
|
display: flex;
|
97
95
|
align-items: center;
|
98
96
|
}
|
99
97
|
|
100
|
-
|
101
98
|
.field-editor {
|
102
99
|
padding: 0;
|
103
100
|
}
|
@@ -31,9 +31,9 @@ export const CreateContentDialog = ({ label, type, value = {}, filter, validator
|
|
31
31
|
site.closeDialog();
|
32
32
|
}
|
33
33
|
|
34
|
-
function
|
35
|
-
|
36
|
-
|
34
|
+
function filterForm(field, content) {
|
35
|
+
const visible = field.required === true || field.optional === true
|
36
|
+
return filter ? visible && filter(field, content) : visible
|
37
37
|
}
|
38
38
|
|
39
39
|
const actions = (
|
@@ -48,7 +48,7 @@ export const CreateContentDialog = ({ label, type, value = {}, filter, validator
|
|
48
48
|
const content = new Content(type, form)
|
49
49
|
return (
|
50
50
|
<Dialog title={title} open={true} onAction={onAction} actions={actions}>
|
51
|
-
<ContentEditor content={content} onChange={change} filter={
|
51
|
+
<ContentEditor content={content} onChange={change} filter={filterForm} />
|
52
52
|
{errors.map(error => <Text use="overline" tag="div" className="error">{error}</Text>)}
|
53
53
|
</Dialog>
|
54
54
|
)
|
@@ -31,6 +31,11 @@ export const EditContentDialog = ({ label, type, value = {}, filter, validator,
|
|
31
31
|
site.closeDialog();
|
32
32
|
}
|
33
33
|
|
34
|
+
function filterForm(field, content) {
|
35
|
+
const visible = field.required === true || field.optional === true
|
36
|
+
return filter ? visible && filter(field, content) : visible
|
37
|
+
}
|
38
|
+
|
34
39
|
const actions = (
|
35
40
|
<Fragment>
|
36
41
|
<Button label="CLOSE" action={() => onAction("CLOSE")} />
|
@@ -43,7 +48,7 @@ export const EditContentDialog = ({ label, type, value = {}, filter, validator,
|
|
43
48
|
const content = new Content(type, form)
|
44
49
|
return (
|
45
50
|
<Dialog title={title} open={true} onAction={onAction} actions={actions}>
|
46
|
-
<ContentEditor content={content} onChange={change} filter={
|
51
|
+
<ContentEditor content={content} onChange={change} filter={filterForm} />
|
47
52
|
{errors.map(error => <Text use="overline" tag="div" className="error">{error}</Text>)}
|
48
53
|
</Dialog>
|
49
54
|
)
|
package/src/domain/TablePage.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import equal from 'deep-equal'
|
2
2
|
import React, { Fragment, useContext, useEffect, useMemo, useRef, useState } from 'react'
|
3
|
-
import { EditContentDialog } from './EditContentDialog'
|
4
|
-
import { Content } from './ContentType'
|
5
|
-
import { ContentEditor } from './ContentEditor'
|
6
|
-
import { HTTPClient, Session } from '../http'
|
7
|
-
import { SiteContext, PageContext } from '../site'
|
8
3
|
import { Button, DataTable, DropDown, Header, Icon, MenuIcon, MenuItem, Text } from '../html'
|
4
|
+
import { HTTPClient, Session } from '../http'
|
5
|
+
import { PageContext, SiteContext } from '../site'
|
6
|
+
import { ContentEditor } from './ContentEditor'
|
7
|
+
import { Content } from './ContentType'
|
8
|
+
import { CreateContentDialog } from './CreateContentDialog'
|
9
9
|
import "./TablePage.css"
|
10
10
|
|
11
11
|
const http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
|
@@ -16,7 +16,7 @@ const http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
|
|
16
16
|
export const TablePage = (props) => {
|
17
17
|
|
18
18
|
const site = useContext(SiteContext)
|
19
|
-
const { id = "table", icon, title, name = "table 1", schema, url, field, delay = 1000, actions, editable, canAdd = true, dev = false, autosave = true, groupBy, validator, scenario } = props
|
19
|
+
const { id = "table", icon, title, name = "table 1", schema, url, field, delay = 1000, actions, editable, canAdd = true, dev = false, autosave = true, groupBy, validator, scenario, formFilter } = props
|
20
20
|
const [pageContext, setPageContext] = useContext(PageContext)
|
21
21
|
const { selected } = pageContext
|
22
22
|
const timer = useRef(null)
|
@@ -46,7 +46,8 @@ export const TablePage = (props) => {
|
|
46
46
|
await pageContext.create(form);
|
47
47
|
setPageContext(Object.assign({}, pageContext))
|
48
48
|
}
|
49
|
-
site.openDialog(<EditContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} />);
|
49
|
+
//site.openDialog(<EditContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} />);
|
50
|
+
site.openDialog(<CreateContentDialog label={`Crear ${name}`} type={schema} onOK={onOK} validator={validator} filter={formFilter}/>);
|
50
51
|
}
|
51
52
|
|
52
53
|
function change(next) {
|
@@ -369,21 +370,13 @@ const TableAPI = (url) => {
|
|
369
370
|
all(filters) {
|
370
371
|
let queryParams = "?"
|
371
372
|
if (filters) {
|
372
|
-
|
373
|
-
console.log('filters', filters)
|
374
|
-
|
375
373
|
const filterQuery = Object.keys(filters).reduce((query, key) => {
|
376
|
-
|
377
374
|
const value = filters[key]
|
378
|
-
console.log(value)
|
379
|
-
|
380
375
|
if (typeof (value) === 'boolean') {
|
381
376
|
return query.concat(`${key}=${value}&`)
|
382
|
-
|
383
377
|
} else if (Array.isArray(value)) {
|
384
378
|
const param = value.length === 0 ? '' : value.reduce((param,item) => {
|
385
379
|
param = param.concat(`${key}=${item}&`)
|
386
|
-
console.log(item, param)
|
387
380
|
return param
|
388
381
|
}, "")
|
389
382
|
console.log(param)
|
@@ -392,8 +385,6 @@ const TableAPI = (url) => {
|
|
392
385
|
return query.concat(`${key}=%${filters[key]}%&`)
|
393
386
|
}
|
394
387
|
}, "")
|
395
|
-
|
396
|
-
console.log('filterQuery')
|
397
388
|
queryParams = queryParams.concat(filterQuery)
|
398
389
|
}
|
399
390
|
return http.GET(url + queryParams)
|
package/src/upload/UploadArea.js
CHANGED
@@ -59,4 +59,22 @@ const UploadIcon = ({ resumable }) => {
|
|
59
59
|
<Icon icon="folder_open" clickable/>
|
60
60
|
</div>
|
61
61
|
)
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Upload Button
|
66
|
+
*/
|
67
|
+
export function UploadButton({ resumable, icon="file_upload", label="Upload"}) {
|
68
|
+
|
69
|
+
const buttonElement = useRef();
|
70
|
+
|
71
|
+
useEffect(() => {
|
72
|
+
if (resumable && buttonElement) resumable.assignBrowse(buttonElement.current);
|
73
|
+
}, []);
|
74
|
+
|
75
|
+
return (
|
76
|
+
<div className="upload-button" ref={buttonElement}>
|
77
|
+
<Button icon={icon} label={label} outlined/>
|
78
|
+
</div>
|
79
|
+
)
|
62
80
|
}
|
package/src/upload/uploader.css
CHANGED
package/src/upload/uploader.js
CHANGED
@@ -1,68 +1,85 @@
|
|
1
1
|
import React, { useState, useMemo } from 'react'
|
2
2
|
import ResumableJS from 'resumablejs'
|
3
|
-
import { UploadArea } from
|
3
|
+
import { UploadArea } from "./UploadArea";
|
4
|
+
import { UploadFile } from "./UploadFile";
|
4
5
|
import './uploader.css'
|
5
6
|
|
7
|
+
const STATES = {
|
8
|
+
IDLE: 0, RUNNING: 1, SUCCESS: 2, ERROR': 3, COMPLETED: 4 }
|
6
9
|
/**
|
7
10
|
* Uploader
|
8
11
|
*/
|
9
|
-
export const Uploader = ({ label, target, accept, className, onSuccess, onError, onComplete, errors = [] }) => {
|
12
|
+
export const Uploader = ({ label, target, accept, simultaneousUploads = 1, className, onSuccess, onError, onComplete, errors = [] }) => {
|
10
13
|
|
11
|
-
const STATES = { 'IDLE': 0, 'RUNNING': 1, 'SUCCESS': 2, 'ERROR': 3, 'COMPLETED': 4 }
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
const resumable = useMemo(() => {
|
16
|
+
const config = {
|
17
|
+
target: target,
|
18
|
+
chunkSize: 1 * 1024 * 1024,
|
19
|
+
simultaneousUploads,
|
20
|
+
testChunks: false,
|
21
|
+
throttleProgressCallbacks: 1,
|
22
|
+
fileType: accept
|
23
|
+
}
|
24
|
+
const resumable = new ResumableJS(config)
|
25
|
+
resumable.on('fileAdded', onFileAdded)
|
26
|
+
resumable.on('fileProgress', onFileProgress)
|
27
|
+
resumable.on('fileSuccess', onFileSuccess)
|
28
|
+
resumable.on('fileError', onFileError)
|
29
|
+
resumable.on('complete', onAllComplete)
|
30
|
+
return resumable
|
31
|
+
}, [])
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
const [progress, setProgress] = useState(0)
|
34
|
+
const [state, setState] = useState(STATES.IDLE)
|
35
|
+
const [error, setError] = useState()
|
36
|
+
const [files, setFiles] = useState([])
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
function onFileAdded(file) {
|
39
|
+
files.push(file)
|
40
|
+
setFiles(files)
|
41
|
+
setState(STATES.RUNNING)
|
42
|
+
resumable.upload()
|
43
|
+
}
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
function onFileProgress(file) {
|
46
|
+
const progress = file.progress()
|
47
|
+
setProgress(progress)
|
48
|
+
if (onProgress) onProgress(files);
|
49
|
+
}
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
function onFileSuccess(file, message) {
|
52
|
+
setState(STATES.SUCCESS)
|
53
|
+
if (onSuccess) onSuccess(file, message)
|
54
|
+
}
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
function onFileError(file, message) {
|
57
|
+
setError(message)
|
58
|
+
setState(STATES.ERROR)
|
59
|
+
if (onError) onError(file, message)
|
60
|
+
}
|
61
|
+
|
62
|
+
function onAllComplete() {
|
63
|
+
setState(STATES.IDLE)
|
64
|
+
if (onComplete) onComplete(files)
|
65
|
+
}
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
return (
|
68
|
+
<div className={`uploader ${className}`}>
|
69
|
+
{state === STATES.IDLE ? <UploadArea resumable={resumable} state={state} label={label} error={error} progress={progress} /> : null}
|
70
|
+
{state === STATES.RUNNING || STATES.SUCCESS || STATES.ERROR ? <UploadProgress files={files} errors={errors} /> : null}
|
71
|
+
</div>
|
72
|
+
)
|
61
73
|
}
|
62
74
|
|
63
|
-
|
64
|
-
|
65
|
-
<
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
const UploadProgress = ({ files = [], errors }) => {
|
76
|
+
return (
|
77
|
+
<div>
|
78
|
+
{files.map((file) => {
|
79
|
+
const error2 = errors.some((e) => e === file.fileName) ? "Fichero Mal Nombrado" : "";
|
80
|
+
const progress = 1
|
81
|
+
return <UploadFile file={file} state={STATES.RUNNING} progress={file.progress()} />;
|
82
|
+
})}
|
83
|
+
</div>
|
84
|
+
);
|
85
|
+
};
|