@cocreate/organizations 1.28.0 → 1.28.2
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/CHANGELOG.md +14 -0
- package/demo/industries/industry-datatable.html +137 -137
- package/demo/industries/industry-documents-datatable.1.html +129 -129
- package/package.json +1 -1
- package/src/client.js +250 -224
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.28.2](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.28.1...v1.28.2) (2025-04-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* dispatch end event on action element rather than document ([dd5ea2a](https://github.com/CoCreate-app/CoCreate-organizations/commit/dd5ea2a43c00418448189369c39f72f83f0206b6))
|
|
7
|
+
|
|
8
|
+
## [1.28.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.28.0...v1.28.1) (2024-12-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* filter-query-key ([0950df1](https://github.com/CoCreate-app/CoCreate-organizations/commit/0950df1884c1e6001b258758611bea2b7151da0f))
|
|
14
|
+
|
|
1
15
|
# [1.28.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.27.5...v1.28.0) (2024-11-04)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,144 +1,144 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<title>Industry Datatables | CoCreateJS</title>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
6
|
+
<!-- CoCreate Favicon -->
|
|
7
|
+
<link
|
|
8
|
+
rel="icon"
|
|
9
|
+
type="image/png"
|
|
10
|
+
sizes="32x32"
|
|
11
|
+
href="../assets/favicon.ico" />
|
|
12
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
13
|
+
</head>
|
|
14
|
+
<body class="width:fit-content overflow:auto">
|
|
15
|
+
<!-- Main Content -->
|
|
16
|
+
<div content_id="content" class="padding:5px">
|
|
17
|
+
<table class="width:100% border-collapse:collapse">
|
|
18
|
+
<tr class="border-bottom:1px_solid_darkgray">
|
|
19
|
+
<td
|
|
20
|
+
class="position:sticky top:0 background:white padding:0px_10px_10px">
|
|
21
|
+
<input
|
|
22
|
+
type="text"
|
|
23
|
+
class="floating-label"
|
|
24
|
+
filter-query-key="name"
|
|
25
|
+
filter-closest="table; tbody"
|
|
26
|
+
placeholder="Industry Name" />
|
|
27
|
+
<span
|
|
28
|
+
class="position:absolute bottom:22px right:20px float:right z-index:6">
|
|
29
|
+
<!-- need a solution to update toggle value="desc|asc" and define and upadte icons... show hide works great but to much html and orderby only has 2 values -->
|
|
30
|
+
<a
|
|
31
|
+
filter-sort-key="name"
|
|
32
|
+
filter-sort-toggle
|
|
33
|
+
filter-closest="table; tbody">
|
|
34
|
+
<i></i>
|
|
35
|
+
</a>
|
|
36
|
+
</span>
|
|
37
|
+
</td>
|
|
38
|
+
<td
|
|
39
|
+
class="position:sticky top:0 background:white padding:0px_10px_10px">
|
|
40
|
+
<input
|
|
41
|
+
type="text"
|
|
42
|
+
class="floating-label"
|
|
43
|
+
filter-query-key="_id"
|
|
44
|
+
filter-closest="table; tbody"
|
|
45
|
+
placeholder="Industry_id" />
|
|
46
|
+
<span
|
|
47
|
+
class="position:absolute bottom:22px right:20px float:right z-index:6">
|
|
48
|
+
<a
|
|
49
|
+
filter-sort-key="_id"
|
|
50
|
+
value=""
|
|
51
|
+
filter-sort-direction="asc"
|
|
52
|
+
click-value="desc, asc"
|
|
53
|
+
click-attribute="filter-sort-direction"
|
|
54
|
+
filter-closest="table; tbody">
|
|
55
|
+
</a>
|
|
56
|
+
</span>
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
60
|
+
<tbody
|
|
61
|
+
array="industries"
|
|
62
|
+
key=""
|
|
63
|
+
filter-query-value=""
|
|
64
|
+
filter-sort-key="name"
|
|
65
|
+
filter-sort-direction="asc"
|
|
66
|
+
render-selector="[template]">
|
|
67
|
+
<tr template class="border-bottom:1px_solid_darkgray">
|
|
68
|
+
<td class="padding:10px">
|
|
69
|
+
<div class="min-width:200px">
|
|
70
|
+
<div class="icon-wrapper">
|
|
71
|
+
<span state_id="me1234" key="icon"></span>
|
|
72
|
+
</div>
|
|
73
|
+
<div>
|
|
74
|
+
<a
|
|
75
|
+
actions="state, openModal"
|
|
76
|
+
modal-src="render.html"
|
|
77
|
+
state-array="module_activity"
|
|
78
|
+
state-object="{{object._id}}"
|
|
79
|
+
state_to="form-fields"
|
|
80
|
+
modal-width="320px"
|
|
81
|
+
modal-color="#229954">
|
|
82
|
+
<h4
|
|
83
|
+
array="{{object.array}}"
|
|
84
|
+
state-object="{{object._id}}"
|
|
85
|
+
key="name">
|
|
86
|
+
Name
|
|
87
|
+
</h4>
|
|
88
|
+
<div
|
|
89
|
+
state-array="modules"
|
|
90
|
+
state-object=""
|
|
91
|
+
state_to="render"
|
|
92
|
+
state_id="render"></div>
|
|
93
|
+
</a>
|
|
94
|
+
<h5
|
|
95
|
+
array="{{object.array}}"
|
|
96
|
+
state-object="{{object._id}}"
|
|
97
|
+
key="description"></h5>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
</td>
|
|
101
|
+
<td class="padding:10px">
|
|
102
|
+
<a
|
|
103
|
+
actions="state, openModal"
|
|
104
|
+
modal-src="render.html"
|
|
105
|
+
state-object=""
|
|
106
|
+
state-array="module_activity"
|
|
107
|
+
state_to="form-fields"
|
|
108
|
+
modal-width="320px"
|
|
109
|
+
modal-color="#229954">
|
|
110
|
+
<b
|
|
111
|
+
array="{{object.array}}"
|
|
112
|
+
state-object="{{object._id}}"
|
|
113
|
+
key="_id"
|
|
114
|
+
>Industry Id</b
|
|
115
|
+
>
|
|
116
|
+
<div
|
|
117
|
+
state-array="module_activity"
|
|
118
|
+
state-object=""
|
|
119
|
+
state_to="render"></div>
|
|
120
|
+
</a>
|
|
121
|
+
</td>
|
|
122
|
+
</tr>
|
|
123
|
+
</tbody>
|
|
124
|
+
</table>
|
|
125
|
+
</div>
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
<button
|
|
128
|
+
actions="state, openModal"
|
|
129
|
+
modal-src="render.html"
|
|
130
|
+
state-array="modules"
|
|
131
|
+
state-object=""
|
|
132
|
+
state_to="render"
|
|
133
|
+
modal-width="320px"
|
|
134
|
+
modal-height="100%"
|
|
135
|
+
modal-color="#229954"
|
|
136
|
+
class="position:fixed bottom:15px right:15px padding:15px background:dodgerblue color:#fff font-size:1.5rem grow-hover border-radius:50% border-width:0 box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4) z-index:8"
|
|
137
|
+
state_id="render">
|
|
138
|
+
<i src="/assets/svg/plus.svg"></i>
|
|
139
|
+
</button>
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
<!-- CoCreate JS CDN -->
|
|
142
|
+
<script src="https://cdn.cocreate.app/organizations/latest/CoCreate-organizations.min.js"></script>
|
|
143
|
+
</body>
|
|
144
144
|
</html>
|
|
@@ -1,136 +1,136 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<head>
|
|
4
|
+
<title>Industry Documents Datatable | CoCreateJS</title>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
6
|
+
<!-- CoCreate Favicon -->
|
|
7
|
+
<link
|
|
8
|
+
rel="icon"
|
|
9
|
+
type="image/png"
|
|
10
|
+
sizes="32x32"
|
|
11
|
+
href="../assets/favicon.ico" />
|
|
12
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
13
|
+
</head>
|
|
14
|
+
<body class="width:fit-content overflow:auto">
|
|
15
|
+
<!-- Main Content -->
|
|
16
|
+
<div content_id="content" class="padding:5px">
|
|
17
|
+
<table class="width:100% border-collapse:collapse">
|
|
18
|
+
<tr class="border-bottom:1px_solid_darkgray">
|
|
19
|
+
<td
|
|
20
|
+
class="position:sticky top:0 background:white padding:0px_10px_10px">
|
|
21
|
+
<input
|
|
22
|
+
type="text"
|
|
23
|
+
class="floating-label"
|
|
24
|
+
filter-query-key="name"
|
|
25
|
+
filter-closest="table; tbody"
|
|
26
|
+
placeholder="Industry Name" />
|
|
27
|
+
<span
|
|
28
|
+
class="position:absolute bottom:22px right:20px float:right z-index:6">
|
|
29
|
+
<!-- need a solution to update toggle value="desc|asc" and define and upadte icons... show hide works great but to much html and orderby only has 2 values -->
|
|
30
|
+
<a
|
|
31
|
+
filter-sort-key="name"
|
|
32
|
+
filter-sort-toggle
|
|
33
|
+
filter-closest="table; tbody">
|
|
34
|
+
<i></i>
|
|
35
|
+
</a>
|
|
36
|
+
</span>
|
|
37
|
+
</td>
|
|
38
|
+
<td
|
|
39
|
+
class="position:sticky top:0 background:white padding:0px_10px_10px">
|
|
40
|
+
<input
|
|
41
|
+
type="text"
|
|
42
|
+
class="floating-label"
|
|
43
|
+
filter-query-key="_id"
|
|
44
|
+
filter-closest="table; tbody"
|
|
45
|
+
placeholder="Industry_id" />
|
|
46
|
+
<span
|
|
47
|
+
class="position:absolute bottom:22px right:20px float:right z-index:6">
|
|
48
|
+
<a
|
|
49
|
+
filter-sort-key="_id"
|
|
50
|
+
value=""
|
|
51
|
+
filter-sort-direction="asc"
|
|
52
|
+
click-value="desc, asc"
|
|
53
|
+
click-attribute="filter-sort-direction"
|
|
54
|
+
filter-closest="table; tbody">
|
|
55
|
+
</a>
|
|
56
|
+
</span>
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
60
|
+
<tbody
|
|
61
|
+
array="industry_documents"
|
|
62
|
+
key=""
|
|
63
|
+
filter-query-value=""
|
|
64
|
+
filter-value-type="or"
|
|
65
|
+
filter-limit=""
|
|
66
|
+
filter-sort-key="name"
|
|
67
|
+
filter-sort-direction="asc"
|
|
68
|
+
render-selector="[template]"
|
|
69
|
+
state_to="me1234">
|
|
70
|
+
<tr template class="border-bottom:1px_solid_darkgray">
|
|
71
|
+
<td class="padding:10px">
|
|
72
|
+
<div class="min-width:200px">
|
|
73
|
+
<div class="icon-wrapper">
|
|
74
|
+
<span state_id="me1234" key="icon"></span>
|
|
75
|
+
</div>
|
|
76
|
+
<div>
|
|
77
|
+
<a
|
|
78
|
+
actions="state, openModal"
|
|
79
|
+
modal-src="render.html"
|
|
80
|
+
state-array="module_activity"
|
|
81
|
+
state-object=""
|
|
82
|
+
state_to="form-fields"
|
|
83
|
+
modal-width="320px"
|
|
84
|
+
modal-color="#229954">
|
|
85
|
+
<h4 state_id="me1234" key="name">
|
|
86
|
+
Name
|
|
87
|
+
</h4>
|
|
88
|
+
<div
|
|
89
|
+
state-array="modules"
|
|
90
|
+
state-object=""
|
|
91
|
+
state_to="render"
|
|
92
|
+
state_id="render"></div>
|
|
93
|
+
</a>
|
|
94
|
+
<h5 key="description"></h5>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</td>
|
|
98
|
+
<td class="padding:10px">
|
|
99
|
+
<a
|
|
100
|
+
actions="state, openModal"
|
|
101
|
+
modal-src="render.html"
|
|
102
|
+
state-object=""
|
|
103
|
+
state-array="module_activity"
|
|
104
|
+
state_to="form-fields"
|
|
105
|
+
modal-width="320px"
|
|
106
|
+
modal-color="#229954">
|
|
107
|
+
<b state_id="me1234" key="_id">Document Id</b>
|
|
108
|
+
<div
|
|
109
|
+
state-array="module_activity"
|
|
110
|
+
state-object=""
|
|
111
|
+
state_to="render"></div>
|
|
112
|
+
</a>
|
|
113
|
+
</td>
|
|
114
|
+
</tr>
|
|
115
|
+
</tbody>
|
|
116
|
+
</table>
|
|
117
|
+
</div>
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
<button
|
|
120
|
+
actions="state, openModal"
|
|
121
|
+
modal-src="render.html"
|
|
122
|
+
state-array="modules"
|
|
123
|
+
state-object=""
|
|
124
|
+
state_to="render"
|
|
125
|
+
modal-width="320px"
|
|
126
|
+
modal-height="100%"
|
|
127
|
+
modal-color="#229954"
|
|
128
|
+
class="position:fixed bottom:15px right:15px padding:15px background:dodgerblue color:#fff font-size:1.5rem grow-hover border-radius:50% border-width:0 box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4) z-index:8"
|
|
129
|
+
state_id="render">
|
|
130
|
+
<i src="/assets/svg/plus.svg"></i>
|
|
131
|
+
</button>
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
<!-- CoCreate JS CDN -->
|
|
134
|
+
<script src="https://cdn.cocreate.app/organizations/latest/CoCreate-organizations.min.js"></script>
|
|
135
|
+
</body>
|
|
136
136
|
</html>
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,253 +1,279 @@
|
|
|
1
|
-
import Crud from
|
|
2
|
-
import Action from
|
|
3
|
-
import Elements from
|
|
4
|
-
import Config from
|
|
5
|
-
import Indexeddb from
|
|
6
|
-
import uuid from
|
|
7
|
-
|
|
8
|
-
async function generateDB(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
import Crud from "@cocreate/crud-client";
|
|
2
|
+
import Action from "@cocreate/actions";
|
|
3
|
+
import Elements from "@cocreate/elements";
|
|
4
|
+
import Config from "@cocreate/config";
|
|
5
|
+
import Indexeddb from "@cocreate/indexeddb";
|
|
6
|
+
import uuid from "@cocreate/uuid";
|
|
7
|
+
|
|
8
|
+
async function generateDB(
|
|
9
|
+
organization = { object: {} },
|
|
10
|
+
user = { object: {} }
|
|
11
|
+
) {
|
|
12
|
+
const organization_id =
|
|
13
|
+
organization.object._id || Crud.ObjectId().toString();
|
|
14
|
+
const apikey = organization.object.key || uuid.generate();
|
|
15
|
+
const user_id = user.object._id || Crud.ObjectId().toString();
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Create organization
|
|
19
|
+
organization.method = "object.create";
|
|
20
|
+
organization.storage = "indexeddb";
|
|
21
|
+
organization.database = organization_id;
|
|
22
|
+
organization.array = "organizations";
|
|
23
|
+
organization.object._id = organization_id;
|
|
24
|
+
organization.object.name = organization.object.name || "untitiled";
|
|
25
|
+
organization.organization_id = organization_id;
|
|
26
|
+
Indexeddb.send(organization);
|
|
27
|
+
|
|
28
|
+
// Create user
|
|
29
|
+
user.method = "object.create";
|
|
30
|
+
user.storage = "indexeddb";
|
|
31
|
+
user.database = organization_id;
|
|
32
|
+
user.array = "users";
|
|
33
|
+
user.object._id = user_id;
|
|
34
|
+
user.object.firstname = user.object.firstname || "untitiled";
|
|
35
|
+
user.object.lastname = user.object.lastname || "untitiled";
|
|
36
|
+
user.organization_id = organization_id;
|
|
37
|
+
Indexeddb.send(user);
|
|
38
|
+
|
|
39
|
+
// Create default key
|
|
40
|
+
let key = {
|
|
41
|
+
method: "object.create",
|
|
42
|
+
storage: "indexeddb",
|
|
43
|
+
database: organization_id,
|
|
44
|
+
array: "keys",
|
|
45
|
+
object: {
|
|
46
|
+
_id: Crud.ObjectId().toString(),
|
|
47
|
+
type: "key",
|
|
48
|
+
key: apikey,
|
|
49
|
+
actions: {
|
|
50
|
+
signIn: true,
|
|
51
|
+
signUp: true
|
|
52
|
+
},
|
|
53
|
+
default: true
|
|
54
|
+
},
|
|
55
|
+
organization_id
|
|
56
|
+
};
|
|
57
|
+
Indexeddb.send(key);
|
|
58
|
+
|
|
59
|
+
// Create role
|
|
60
|
+
let role_id = Crud.ObjectId().toString();
|
|
61
|
+
let role = {
|
|
62
|
+
method: "object.create",
|
|
63
|
+
storage: "indexeddb",
|
|
64
|
+
database: organization_id,
|
|
65
|
+
array: "keys",
|
|
66
|
+
object: {
|
|
67
|
+
_id: role_id,
|
|
68
|
+
type: "role",
|
|
69
|
+
name: "admin",
|
|
70
|
+
admin: "true"
|
|
71
|
+
},
|
|
72
|
+
organization_id
|
|
73
|
+
};
|
|
74
|
+
Indexeddb.send(role);
|
|
75
|
+
|
|
76
|
+
// Create user key
|
|
77
|
+
let userKey = {
|
|
78
|
+
method: "object.create",
|
|
79
|
+
storage: "indexeddb",
|
|
80
|
+
database: organization_id,
|
|
81
|
+
array: "keys",
|
|
82
|
+
object: {
|
|
83
|
+
_id: Crud.ObjectId().toString(),
|
|
84
|
+
type: "user",
|
|
85
|
+
key: user_id,
|
|
86
|
+
array: "users", // could be any array
|
|
87
|
+
roles: [role_id],
|
|
88
|
+
email: user.object.email,
|
|
89
|
+
password: user.object.password || btoa("0000")
|
|
90
|
+
},
|
|
91
|
+
organization_id
|
|
92
|
+
};
|
|
93
|
+
Indexeddb.send(userKey);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
organization: organization.object,
|
|
97
|
+
apikey,
|
|
98
|
+
user: user.object,
|
|
99
|
+
role: role.object,
|
|
100
|
+
userKey: userKey.object
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
async function get() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return organization_id
|
|
122
|
-
|
|
108
|
+
let organization_id = await getOrganizationFromServiceWorker();
|
|
109
|
+
if (!organization_id) {
|
|
110
|
+
let data = await Indexeddb.send({ method: "database.read" });
|
|
111
|
+
for (let database of data.database) {
|
|
112
|
+
let name = database.name;
|
|
113
|
+
if (name.match(/^[0-9a-fA-F]{24}$/)) {
|
|
114
|
+
organization_id = name;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!organization_id) {
|
|
120
|
+
let file = await fetch("/");
|
|
121
|
+
organization_id = file.headers.get("organization");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!organization_id) organization_id = await createOrganization();
|
|
125
|
+
|
|
126
|
+
if (organization_id) Config.set("organization_id", organization_id);
|
|
127
|
+
|
|
128
|
+
return organization_id;
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
async function getOrganizationFromServiceWorker() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
if (!navigator.serviceWorker) return resolve();
|
|
134
|
+
|
|
135
|
+
const handleMessage = (event) => {
|
|
136
|
+
if (event.data.action === "getOrganization") {
|
|
137
|
+
navigator.serviceWorker.removeEventListener(
|
|
138
|
+
"message",
|
|
139
|
+
handleMessage
|
|
140
|
+
); // Remove the event listener
|
|
141
|
+
resolve(event.data.organization_id);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
navigator.serviceWorker.addEventListener("message", handleMessage);
|
|
146
|
+
|
|
147
|
+
// Send message to Service Worker
|
|
148
|
+
const msg = new MessageChannel();
|
|
149
|
+
|
|
150
|
+
navigator.serviceWorker.ready
|
|
151
|
+
.then((registration) => {
|
|
152
|
+
if (navigator.serviceWorker.controller) {
|
|
153
|
+
// If there's an active controller, send the message
|
|
154
|
+
navigator.serviceWorker.controller.postMessage(
|
|
155
|
+
{ action: "getOrganization" },
|
|
156
|
+
[msg.port1]
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
// Listen for a new service worker to start controlling the page
|
|
160
|
+
navigator.serviceWorker.addEventListener(
|
|
161
|
+
"controllerchange",
|
|
162
|
+
() => {
|
|
163
|
+
if (navigator.serviceWorker.controller) {
|
|
164
|
+
navigator.serviceWorker.controller.postMessage(
|
|
165
|
+
{ action: "getOrganization" },
|
|
166
|
+
[msg.port1]
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
.catch((error) => {
|
|
174
|
+
console.error(reject);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
158
177
|
}
|
|
159
178
|
|
|
160
179
|
let organizationPromise = null;
|
|
161
180
|
async function createOrganizationPromise() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
181
|
+
let createOrganization = document.querySelector(
|
|
182
|
+
'[actions*="createOrganization"]'
|
|
183
|
+
);
|
|
184
|
+
if (createOrganization) return (Crud.socket.organization = "canceled");
|
|
185
|
+
|
|
186
|
+
if (
|
|
187
|
+
Crud.socket.organization == "canceled" ||
|
|
188
|
+
Crud.socket.organization == "pending"
|
|
189
|
+
)
|
|
190
|
+
return;
|
|
191
|
+
|
|
192
|
+
const organization_id = prompt(
|
|
193
|
+
"An organization_id could not be found, if you already have an organization_id input it now.\n\nOr leave blank and click 'OK' to create a new organization"
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
if (organization_id) return organization_id;
|
|
197
|
+
if (organization_id === null)
|
|
198
|
+
return (Crud.socket.organization = "canceled");
|
|
199
|
+
|
|
200
|
+
Crud.socket.organization = "pending";
|
|
201
|
+
if (Indexeddb) {
|
|
202
|
+
try {
|
|
203
|
+
let org = { object: {} };
|
|
204
|
+
if (organization_id) org.object._id = organization_id;
|
|
205
|
+
let { organization, apikey, user } = await generateDB(org);
|
|
206
|
+
if (organization && apikey && user) {
|
|
207
|
+
Crud.socket.apikey = apikey;
|
|
208
|
+
Crud.socket.user_id = user._id;
|
|
209
|
+
Config.set("organization_id", organization._id);
|
|
210
|
+
Config.set("apikey", apikey);
|
|
211
|
+
Config.set("user_id", user._id);
|
|
212
|
+
Crud.socket.organization = true;
|
|
213
|
+
return organization._id;
|
|
214
|
+
}
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error("Failed to load the script:", error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
195
219
|
}
|
|
196
220
|
|
|
197
|
-
|
|
198
221
|
async function createOrganization() {
|
|
199
|
-
|
|
222
|
+
return (
|
|
223
|
+
organizationPromise ||
|
|
224
|
+
(organizationPromise = createOrganizationPromise())
|
|
225
|
+
);
|
|
200
226
|
}
|
|
201
227
|
|
|
202
|
-
async function create(
|
|
203
|
-
|
|
228
|
+
async function create(action) {
|
|
229
|
+
let form = action.form;
|
|
230
|
+
if (!form) return;
|
|
204
231
|
|
|
205
|
-
|
|
206
|
-
|
|
232
|
+
let organization = Elements.getData(form, "organizations");
|
|
233
|
+
let user = Elements.getData(form, "users");
|
|
207
234
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (!user || !user.object)
|
|
211
|
-
return
|
|
235
|
+
if (!organization || !organization.object) return;
|
|
236
|
+
if (!user || !user.object) return;
|
|
212
237
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
238
|
+
if (!organization.object._id && !user.object._id) {
|
|
239
|
+
let objects = await generateDB(organization, user);
|
|
240
|
+
if (!objects) return;
|
|
241
|
+
}
|
|
218
242
|
|
|
219
|
-
|
|
220
|
-
|
|
243
|
+
Elements.setTypeValue(form, organization);
|
|
244
|
+
Elements.setTypeValue(form, user);
|
|
221
245
|
|
|
222
|
-
|
|
223
|
-
|
|
246
|
+
organization = organization.object[0];
|
|
247
|
+
user = user.object[0];
|
|
224
248
|
|
|
225
|
-
|
|
249
|
+
let organization_id = organization._id;
|
|
226
250
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
if (Crud.socket.organization !== true) {
|
|
252
|
+
Crud.socket.organization = true;
|
|
253
|
+
Crud.socket.create({ organization_id });
|
|
254
|
+
}
|
|
231
255
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
256
|
+
let response = await Crud.socket.send({
|
|
257
|
+
method: "createOrganization",
|
|
258
|
+
organization,
|
|
259
|
+
user,
|
|
260
|
+
broadcastBrowser: false,
|
|
261
|
+
organization_id
|
|
262
|
+
});
|
|
239
263
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
264
|
+
action.element.dispatchEvent(
|
|
265
|
+
new CustomEvent("createdOrganization", {
|
|
266
|
+
detail: response
|
|
267
|
+
})
|
|
268
|
+
);
|
|
243
269
|
}
|
|
244
270
|
|
|
245
271
|
Action.init({
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
name: "createOrganization",
|
|
273
|
+
endEvent: "createdOrganization",
|
|
274
|
+
callback: (action) => {
|
|
275
|
+
create(action);
|
|
276
|
+
}
|
|
251
277
|
});
|
|
252
278
|
|
|
253
|
-
export default { generateDB, create, get };
|
|
279
|
+
export default { generateDB, create, get };
|