ywana-core8 0.0.573 → 0.0.576

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.573",
3
+ "version": "0.0.576",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -47,3 +47,4 @@ main.collection-page>.content-editor {
47
47
  flex: 1;
48
48
  }
49
49
 
50
+
@@ -0,0 +1,33 @@
1
+ import { FORMATS } from "./FORMATS";
2
+
3
+ /**
4
+ * Content
5
+ */
6
+ class Content {
7
+
8
+ constructor(schema, value) {
9
+ this.schema = schema;
10
+ this.value = value;
11
+ }
12
+
13
+ }
14
+
15
+ const ADDRESS_SCHEMA = {
16
+ id : { type: TYPES.STRING },
17
+ street : { type: TYPES.STRING, default: '' },
18
+ city : { type: TYPES.STRING, default: '' },
19
+ state : { type: TYPES.STRING, default: '' },
20
+ zip : { type: TYPES.STRING, default: '' },
21
+ country: { type: TYPES.STRING, default: '' },
22
+ }
23
+
24
+ const PERSON_SCHEMA = {
25
+ id : { type: TYPES.STRING },
26
+ name : { type: TYPES.STRING , format: FORMATS.NONE, label: 'Name' },
27
+ address : { type: TYPES.ENTITY, item: ADDRESS_SCHEMA, format: FORMATS.NONE, label: 'Address' },
28
+ age : { type: TYPES.NUMBER , format: FORMATS.NONE, label: 'Age' , default: 0 },
29
+ married : { type: TYPES.BOOLEAN , format: FORMATS.NONE, label: 'Married' , default: false },
30
+ children: { type: TYPES.ARRAY , item: TYPES.STRING , format: FORMATS.NONE, label: 'Children', default: [] },
31
+ }
32
+
33
+ const person = new Content(PERSON_SCHEMA, {})
@@ -0,0 +1,74 @@
1
+ export const ContentFilters = (props) => {
2
+
3
+ const [pageContext, setPageContext] = useContext(PageContext)
4
+ const { filters } = pageContext
5
+ const { schema, onSave } = props
6
+ const [form, setForm] = useState({})
7
+
8
+ const filterSchema = useMemo(() => {
9
+ const filterSchema = Object.assign({}, schema)
10
+ for (var key in filterSchema) {
11
+ if (filterSchema[key].filter === false) {
12
+ delete filterSchema[key]
13
+ } else {
14
+ if (filterSchema[key].type === TYPES.ENTITY) {
15
+ const fs = filterSchema[key].item
16
+ for (var key in fs) {
17
+ if (fs[key].filter === false) delete fs[key]
18
+ }
19
+ }
20
+ }
21
+ }
22
+ //Object.values(filterSchema).forEach(field => field.section = null)
23
+ delete filterSchema.flows
24
+ return filterSchema
25
+ }, [schema])
26
+
27
+ const likes = useMemo(() => {
28
+ const fields = Object.values(schema)
29
+ return fields.reduce((likes, field) => {
30
+ if (field.like === true) likes.push(field.id)
31
+ return likes
32
+ }, [])
33
+ }, [schema])
34
+
35
+ useEffect(() => {
36
+ if (filters) setForm(filters)
37
+ }, [filters])
38
+
39
+ useEffect(() => {
40
+ reload()
41
+ }, [form])
42
+
43
+ async function change(next) {
44
+ setForm(next)
45
+ }
46
+
47
+ async function reload() {
48
+ await pageContext.load(form, likes)
49
+ setPageContext(Object.assign({}, pageContext))
50
+ }
51
+
52
+ function clear() {
53
+ change({})
54
+ }
55
+
56
+ function save() {
57
+ if (onSave) {
58
+ onSave(form)
59
+ }
60
+ }
61
+
62
+ const content = new Content(filterSchema, form)
63
+ return (
64
+ <Fragment>
65
+ <Header className="table-filters" title={<Text>Filters</Text>} >
66
+ <Icon icon="filter_list_off" size="small" clickable action={clear} />
67
+ {onSave ? <Icon icon="save" size="small" clickable action={save} /> : null}
68
+ </Header>
69
+ <main className="table-filters">
70
+ <ContentEditor content={content} onChange={change} />
71
+ </main>
72
+ </Fragment>
73
+ )
74
+ }
@@ -0,0 +1,96 @@
1
+ export const ContentPage = (props) => {
2
+
3
+ const {
4
+ icon, title, className,
5
+ schema, url,
6
+ } = props
7
+
8
+ return (
9
+ <>
10
+ <header className="content-page"></header>
11
+ <nav className="content-page"></nav>
12
+ <menu className="content-page">
13
+
14
+ </menu>
15
+ <main className="content-page">
16
+
17
+ </main>
18
+ <aside className="content-page"></aside>
19
+ <footer className="content-page"></footer>
20
+ </>
21
+ )
22
+ }
23
+
24
+
25
+
26
+ /**
27
+ * Content API
28
+ */
29
+ const ContentAPI = (url, host) => {
30
+
31
+ const http = HTTPClient(host || window.API || process.env.REACT_APP_API, Session);
32
+
33
+ return {
34
+ all(filters = [], likes = [], page) {
35
+ let queryParams = page ? `?page=${page}&` : "?"
36
+ const filterQuery = Object.keys(filters).reduce((query, key) => {
37
+ const value = filters[key]
38
+ if (typeof (value) === 'boolean') return query.concat(`${key}=${value}&`)
39
+ if (Array.isArray(value)) {
40
+ const param = value.length === 0 ? '' : value.reduce((param, item) => {
41
+ param = param.concat(`${key}=${item}&`)
42
+ return param
43
+ }, "")
44
+ return query.concat(param)
45
+ }
46
+ const likeSymbol = likes.includes(key) ? '%' : ''
47
+ return query.concat(`${key}=${likeSymbol}${value}${likeSymbol}&`)
48
+ }, "")
49
+ queryParams = queryParams.concat(filterQuery)
50
+ return http.GET(url + queryParams)
51
+ },
52
+
53
+ find(id) {
54
+ return http.GET(`${url}/${id}`)
55
+ },
56
+
57
+ create(form) {
58
+ const body = JSON.stringify(form)
59
+ return http.POST(url, body)
60
+ },
61
+
62
+ update(form) {
63
+ const body = JSON.stringify(form)
64
+ return http.PUT(`${url}/${form.id}`, body)
65
+ },
66
+
67
+ updateProperty(id, propertyName, form) {
68
+ const body = JSON.stringify(form)
69
+ return http.PUT(`${url}/${id}/${propertyName}`, body)
70
+ },
71
+
72
+ patch(id, form) {
73
+ const body = JSON.stringify(form)
74
+ return http.PATCH(`${url}/${id}`, body)
75
+ },
76
+
77
+ remove(id) {
78
+ return http.DELETE(`${url}/${id}`)
79
+ },
80
+
81
+ queries(user) {
82
+ const queryParams = user ? `?user=${user}` : ""
83
+ return http.GET(`/queries/${url}${queryParams}`)
84
+ },
85
+
86
+ createQuery(form) {
87
+ const body = JSON.stringify(form)
88
+ return http.POST(`/queries/${url}`, body)
89
+ },
90
+
91
+ removeQuery(id) {
92
+ return http.DELETE(`/queries/${url}/${id}`)
93
+ },
94
+
95
+ }
96
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * FORMATS
3
+ */
4
+ export const FORMATS = {
5
+ NONE: '',
6
+ DATE: 'date',
7
+ DATERANGE: 'DATERANGE',
8
+ TIME: 'time',
9
+ EMAIL: 'email',
10
+ HTML: 'HTML',
11
+ URL: 'URL',
12
+ IMG: 'IMG',
13
+ COLOR: 'COLOR',
14
+ TOKENS: 'TOKENS'
15
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * TYPES
3
+ */
4
+ export const TYPES = {
5
+ STRING: 'String',
6
+ NUMBER: 'Number',
7
+ BOOLEAN: 'Boolean',
8
+ ARRAY: 'Array',
9
+ ENTITY: 'Object',
10
+ FUNCTION: 'Function',
11
+ }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useMemo, useState } from "react";
1
+ import React, { useEffect, useMemo, useState, useRef } from "react";
2
2
  import { DropDown, Header, Icon, Text, TextField, Button } from "../../html";
3
3
  import moment from "moment";
4
4
  import { extendMoment } from "moment-range";
@@ -15,15 +15,16 @@ const DATE_RANGE = [
15
15
  /**
16
16
  * Planner
17
17
  */
18
- export const Planner = ({ title, events = [], lanes = [], navigation = true, onSelectCell, focusEvent, config = { range: "year", from: "2022-01-01", to: "2022-12-30"}, onChange }) => {
18
+ export const Planner = ({ title, events = [], lanes = [], navigation = true, onSelectCell, focusEvent, config = { range: "year", from: "2022-01-01", to: "2022-12-30" }, onChange }) => {
19
19
 
20
20
  const [dateRange, setDateRange] = useState(config.range);
21
21
  const [from, setFrom] = useState(config.from);
22
22
  const [to, setTo] = useState(config.to);
23
-
23
+ const thisMondayElement = useRef(null)
24
+
24
25
  useEffect(() => {
25
- showThisWeek()
26
- }, [])
26
+ if (thisMondayElement.current) { showThisWeek() }
27
+ }, [thisMondayElement])
27
28
 
28
29
  useEffect(() => {
29
30
  const element = document.getElementById(focusEvent)
@@ -65,7 +66,8 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
65
66
  }
66
67
 
67
68
  function showThisWeek() {
68
- const element = document.querySelector(".thisMonday")
69
+ const element = thisMondayElement.current
70
+ //const element = document.querySelector(".thisMonday")
69
71
  if (element) element.scrollIntoView({
70
72
  behavior: 'smooth',
71
73
  block: 'start',
@@ -93,7 +95,7 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
93
95
  {navigation ? (
94
96
  <Header title={label}>
95
97
  &nbsp;&nbsp;
96
- <Button label="Esta Semana" outlined action={showThisWeek}/>
98
+ <Button label="Esta Semana" outlined action={showThisWeek} />
97
99
  <Icon icon="chevron_right" clickable action={next} />
98
100
  <TextField id="to" type="date" label="Hasta" value={to} onChange={(id, value) => setTo(value)} />
99
101
  <div className="expand"></div>
@@ -108,11 +110,7 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
108
110
 
109
111
  <div className="column0">
110
112
  <div className="column-header"></div>
111
- {lanes.map((lane) => (
112
- <div className="row-header">
113
- {lane.label}
114
- </div>
115
- ))}
113
+ {lanes.map((lane) => <div className="row-header">{lane.label}</div>)}
116
114
  </div>
117
115
 
118
116
  <div className="rows">
@@ -133,8 +131,13 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
133
131
  const isWekend = [0, 6].includes(date.moment.day());
134
132
  const weekend = isWekend ? "weekend" : "";
135
133
  const thisWeek = moment().startOf('week').isSame(date.moment, "week") ? "thisWeek" : "";
134
+
135
+ const today = moment()
136
+ var weekStart = today.clone().startOf('week')
137
+ const isThisMonday = (date.moment.isSame(weekStart))
138
+
136
139
  return (
137
- <div className="column-header">
140
+ <div className="column-header" ref={isThisMonday ? thisMondayElement : null}>
138
141
  <div className={`date-header ${weekend} ${thisWeek}`}>
139
142
  <Text use="headline6">{date.moment.format("DD")}</Text>
140
143
  &nbsp;
@@ -145,7 +148,7 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
145
148
  })}
146
149
  </div>
147
150
 
148
- {lanes.map((lane) => <PlannerRow key={lane.id} lane={lane} events={events} period={period} onSelectCell={selectCell} onChange={onChange}/>)}
151
+ {lanes.map((lane) => <PlannerRow key={lane.id} lane={lane} events={events} period={period} onSelectCell={selectCell} onChange={onChange} />)}
149
152
 
150
153
  </div>
151
154
  </main>
@@ -177,7 +180,7 @@ const PlannerRow = (props) => {
177
180
  return eventDate.getTime() === slotDate.getTime();
178
181
  })
179
182
  return (
180
- <PlannerCell key={`${lane.id}-${slotDate.toString()}`} lane={lane} date={date} events={cellEvents} onSelect={onSelectCell} onDrop={change}/>
183
+ <PlannerCell key={`${lane.id}-${slotDate.toString()}`} lane={lane} date={date} events={cellEvents} onSelect={onSelectCell} onDrop={change} />
181
184
  );
182
185
  })}
183
186
  </div>
@@ -227,7 +230,7 @@ const PlannerCell = ({ lane, events, date, disabled = false, onAdd, onDelete, on
227
230
  var weekStart = today.clone().startOf('week')
228
231
  const thisMonday = (date.moment.isSame(weekStart)) ? "thisMonday" : ""
229
232
  const dragOverStyle = dragOver ? "drag-over" : ""
230
- return (
233
+ return (
231
234
  <div className={`cell ${thisMonday} ${weekend} ${dragOverStyle}`} onDragOver={onDragOver} onDragLeave={onDragLeave} onDrop={drop} onClick={select}>
232
235
  {events.map(event => {
233
236
  const { Renderer = EventCard } = event