ywana-core8 0.0.674 → 0.0.676
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/TablePage.js +1 -1
- package/src/incubator/task.css +31 -0
- package/src/incubator/task.js +189 -0
- package/src/site/site.js +0 -1
package/package.json
CHANGED
package/src/domain/TablePage.js
CHANGED
@@ -433,7 +433,7 @@ export const TableEditor = (props) => {
|
|
433
433
|
|
434
434
|
const groups = items.reduce((groups, item) => {
|
435
435
|
let groupName = item[groupBy]
|
436
|
-
if (!groupName) groupName=`
|
436
|
+
if (!groupName) groupName=`NO ${groupBy}`.toUpperCase()
|
437
437
|
if (groupName === false) groupName = `NO ${groupBy}`.toUpperCase()
|
438
438
|
if (groupName === true) groupName = `SI ${groupBy}`.toUpperCase()
|
439
439
|
const group = groups[groupName]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
.task-manager {
|
2
|
+
flex: 1;
|
3
|
+
display: flex;
|
4
|
+
flex-direction: column;
|
5
|
+
}
|
6
|
+
|
7
|
+
.task-manager>header {
|
8
|
+
|
9
|
+
}
|
10
|
+
|
11
|
+
.task-manager>main {
|
12
|
+
overflow: auto;
|
13
|
+
min-height: 20rem;
|
14
|
+
display: flex;
|
15
|
+
flex-direction: column;
|
16
|
+
background-color: var(--paper-color);
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
.linear-progress>progress {
|
21
|
+
-webkit-appearance: none;
|
22
|
+
}
|
23
|
+
|
24
|
+
.linear-progress>progress::-webkit-progress-bar {
|
25
|
+
background-color: #eee;
|
26
|
+
}
|
27
|
+
|
28
|
+
.linear-progress>progress::-webkit-progress-value {
|
29
|
+
background-color: #2196f3;
|
30
|
+
}
|
31
|
+
|
@@ -0,0 +1,189 @@
|
|
1
|
+
import React, { useEffect, useContext, useState } from 'react'
|
2
|
+
import { LinearProgress, Header, DataTable, Icon } from '../html'
|
3
|
+
import { HTTPClient, Session } from '../http'
|
4
|
+
import "./task.css"
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Task Context
|
8
|
+
*/
|
9
|
+
export const TaskContext = React.createContext({})
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Task Provider
|
13
|
+
*/
|
14
|
+
export const TaskContextProvider = (props) => {
|
15
|
+
|
16
|
+
const { host, url, children } = props
|
17
|
+
const API = TaskAPI(url, host)
|
18
|
+
|
19
|
+
async function tasks() {
|
20
|
+
try {
|
21
|
+
const response = await API.tasks();
|
22
|
+
return response;
|
23
|
+
} catch (error) {
|
24
|
+
console.log("tasks error", error);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
async function task(id) {
|
29
|
+
try {
|
30
|
+
const response = await API.task(id);
|
31
|
+
return response;
|
32
|
+
} catch (error) {
|
33
|
+
console.log("task error", error);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
async function createTask(task) {
|
38
|
+
try {
|
39
|
+
const response = await API.createTask(task);
|
40
|
+
return response;
|
41
|
+
} catch (error) {
|
42
|
+
console.log("createTask error", error);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
async function removeTask(id) {
|
47
|
+
try {
|
48
|
+
const response = await API.removeTask(id);
|
49
|
+
return response;
|
50
|
+
} catch (error) {
|
51
|
+
console.log("removeTask error", error);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
const value = {
|
56
|
+
tasks,
|
57
|
+
task,
|
58
|
+
createTask,
|
59
|
+
removeTask,
|
60
|
+
};
|
61
|
+
|
62
|
+
return (
|
63
|
+
<TaskContext.Provider value={value}>
|
64
|
+
{children}
|
65
|
+
</TaskContext.Provider>
|
66
|
+
)
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* API
|
71
|
+
*/
|
72
|
+
const TaskAPI = (url = "/tasks", host) => {
|
73
|
+
|
74
|
+
const http = HTTPClient(host || window.API || process.env.REACT_APP_API, Session);
|
75
|
+
|
76
|
+
return {
|
77
|
+
|
78
|
+
tasks() {
|
79
|
+
return http.GET(url)
|
80
|
+
},
|
81
|
+
|
82
|
+
task(id) {
|
83
|
+
return http.GET(`${url}/${id}`)
|
84
|
+
},
|
85
|
+
|
86
|
+
createTask(task) {
|
87
|
+
const body = JSON.stringify(task)
|
88
|
+
return http.POST(url, body)
|
89
|
+
},
|
90
|
+
|
91
|
+
removeTask(id) {
|
92
|
+
return http.DELETE(`${url}/${id}`)
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* TaskProgress
|
100
|
+
*/
|
101
|
+
export const TaskProgress = (props) => {
|
102
|
+
|
103
|
+
const context = useContext(TaskContext)
|
104
|
+
const { task, timeout = 500, autoreload = true, onComplete } = props
|
105
|
+
const [progress, setProgress] = useState(0)
|
106
|
+
|
107
|
+
useEffect(() => {
|
108
|
+
if (autoreload) {
|
109
|
+
const interval = setInterval(() => refresh(task.id), timeout)
|
110
|
+
return () => { clearInterval(interval) }
|
111
|
+
}
|
112
|
+
}, [task, autoreload])
|
113
|
+
|
114
|
+
async function refresh(id) {
|
115
|
+
const next = await context.task(id)
|
116
|
+
setProgress(next.percentage)
|
117
|
+
if (next.percentage === 100) {
|
118
|
+
if (onComplete) onComplete(next)
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
return task ? <LinearProgress progress={progress} /> : null
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Task Monitor
|
127
|
+
*/
|
128
|
+
export const TaskMonitor = (props) => {
|
129
|
+
|
130
|
+
const context = useContext(TaskContext)
|
131
|
+
const [tasks = [], setTasks] = useState([])
|
132
|
+
|
133
|
+
useEffect(() => {
|
134
|
+
refresh()
|
135
|
+
const interval = setInterval(() => {
|
136
|
+
refresh()
|
137
|
+
}, 5000)
|
138
|
+
return () => { clearInterval(interval) }
|
139
|
+
}, [])
|
140
|
+
|
141
|
+
async function refresh() {
|
142
|
+
const tasks = await context.tasks()
|
143
|
+
setTasks(tasks)
|
144
|
+
}
|
145
|
+
|
146
|
+
async function remove(task) {
|
147
|
+
await context.removeTask(task.id)
|
148
|
+
refresh()
|
149
|
+
}
|
150
|
+
|
151
|
+
if (!tasks.length) return null
|
152
|
+
|
153
|
+
const table = {
|
154
|
+
columns: [
|
155
|
+
{ id: "state", label: "Estado" },
|
156
|
+
{ id: "description", label: "Descripcion" },
|
157
|
+
{ id: "progress", label: "%" },
|
158
|
+
{ id: "percentage", label: "" },
|
159
|
+
{ id: "init", label: "Inicio" },
|
160
|
+
{ id: "end", label: "Fin" },
|
161
|
+
{ id: "resourceID", label: "Recurso" },
|
162
|
+
{ id: "owner", label: "Propietario" },
|
163
|
+
{ id: "actions", label: "" }
|
164
|
+
],
|
165
|
+
rows: tasks.map(task => {
|
166
|
+
return {
|
167
|
+
id: task.id,
|
168
|
+
resourceID: task.resourceID,
|
169
|
+
init: task.init,
|
170
|
+
end: task.end,
|
171
|
+
owner: task.owner,
|
172
|
+
description: task.description,
|
173
|
+
percentage: task.percentage,
|
174
|
+
progress: <LinearProgress progress={task.percentage} />,
|
175
|
+
state: task.state,
|
176
|
+
actions: <Icon size="small" icon="cancel" clickable action={() => remove(task)} />
|
177
|
+
}
|
178
|
+
})
|
179
|
+
}
|
180
|
+
|
181
|
+
return (
|
182
|
+
<div className="task-manager">
|
183
|
+
<Header icon="list" title="Task Manager" />
|
184
|
+
<main>
|
185
|
+
<DataTable {...table} />
|
186
|
+
</main>
|
187
|
+
</div>
|
188
|
+
)
|
189
|
+
}
|