@cocreate/organizations 1.6.12 → 1.7.0
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 +19 -0
- package/demo/index.html +2 -2
- package/demo/industries/industry-datatable.html +8 -8
- package/demo/industries/industry-documents-datatable.1.html +4 -4
- package/package.json +2 -2
- package/src/client.js +25 -19
- package/src/server.js +33 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.6.12...v1.7.0) (2022-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* crud.getAttr renamed to crud.getAttributes ([10ea025](https://github.com/CoCreate-app/CoCreate-organizations/commit/10ea025048686e6b3bceeb0a675d5ff0d3370ca1))
|
|
7
|
+
* filter-order attributes renamed to filter-sort ([e116902](https://github.com/CoCreate-app/CoCreate-organizations/commit/e11690208f46517364e6594b3343a76a06a89bd4))
|
|
8
|
+
* renamed {{data.key}} to {{document.key}} ([f4712a5](https://github.com/CoCreate-app/CoCreate-organizations/commit/f4712a5d77b4525ff5544315f32013dc07c13d33))
|
|
9
|
+
* renamed crud.checkAttrValue to crud.checkValue ([62e99ce](https://github.com/CoCreate-app/CoCreate-organizations/commit/62e99ce433928ce3200ba75b811e0b288f1bf964))
|
|
10
|
+
* renamed data.data to data.document ([50b924c](https://github.com/CoCreate-app/CoCreate-organizations/commit/50b924cddcf93bef9c473072967a0b2fa1dc7dd7))
|
|
11
|
+
* renamed getSocket to getSockets ([02a2dc5](https://github.com/CoCreate-app/CoCreate-organizations/commit/02a2dc583ebfe9754a2518729d998c42b9d96a2b))
|
|
12
|
+
* update crud functions to receive an array of objects as the response ([1b07d3d](https://github.com/CoCreate-app/CoCreate-organizations/commit/1b07d3d90be082114db5ac96b1d0c6c13918e0f5))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Add @cocreate/element-prototype ([a0b71df](https://github.com/CoCreate-app/CoCreate-organizations/commit/a0b71dfaed1204836eea9f32a111d6bb8b6594e4))
|
|
18
|
+
* updated to use new crud which has the abilty to use multiple databases ([b405e32](https://github.com/CoCreate-app/CoCreate-organizations/commit/b405e321d89859f624ad99d23581ca767d3eba88))
|
|
19
|
+
|
|
1
20
|
## [1.6.12](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.6.11...v1.6.12) (2022-10-02)
|
|
2
21
|
|
|
3
22
|
|
package/demo/index.html
CHANGED
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
<ul fetch-collection="industries"
|
|
77
77
|
template_id="industries"
|
|
78
78
|
class="options overflow:auto">
|
|
79
|
-
<li class="template option" template_id="industries" value="{{
|
|
80
|
-
<h4 collection="industries" document_id="{{
|
|
79
|
+
<li class="template option" template_id="industries" value="{{document._id}}">
|
|
80
|
+
<h4 collection="industries" document_id="{{document._id}}" name="name">industry name</h4>
|
|
81
81
|
</li>
|
|
82
82
|
</ul>
|
|
83
83
|
</cocreate-select>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
placeholder="Industry Name">
|
|
20
20
|
<span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6">
|
|
21
21
|
<!-- 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 -->
|
|
22
|
-
<a filter-
|
|
22
|
+
<a filter-sort-name="name" toggle-order template_id="datatable">
|
|
23
23
|
<i></i>
|
|
24
24
|
</a>
|
|
25
25
|
</span>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
template_id="datatable"
|
|
33
33
|
placeholder="Industry_id"/>
|
|
34
34
|
<span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6" >
|
|
35
|
-
<a filter-
|
|
35
|
+
<a filter-sort-name="_id" value="" toggle-order="true" template_id="datatable">
|
|
36
36
|
</a>
|
|
37
37
|
</span>
|
|
38
38
|
</td>
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
fetch-collection="industries"
|
|
43
43
|
fetch-name=""
|
|
44
44
|
filter-value=""
|
|
45
|
-
filter-
|
|
46
|
-
filter-
|
|
45
|
+
filter-sort-name="name"
|
|
46
|
+
filter-sort-type="asc"
|
|
47
47
|
template_id="datatable">
|
|
48
48
|
|
|
49
49
|
<tr class="template background:gainsboro:hover border-bottom:1px_solid_darkgray">
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
<div>
|
|
56
56
|
<a target="modal" href="render.html"
|
|
57
57
|
pass-collection="module_activity"
|
|
58
|
-
pass-document_id="{{
|
|
58
|
+
pass-document_id="{{document._id}}"
|
|
59
59
|
pass-prefix="form_"
|
|
60
60
|
pass_to="form-fields"
|
|
61
61
|
modal-width="320px"
|
|
62
62
|
modal-color="#229954">
|
|
63
|
-
<h4 collection="{{collection}}" pass-document_id="{{
|
|
63
|
+
<h4 collection="{{document.collection}}" pass-document_id="{{document._id}}" name="name">Name</h4>
|
|
64
64
|
<div pass-collection="modules"
|
|
65
65
|
pass-document_id=""
|
|
66
66
|
pass-prefix="form_"
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
|
|
70
70
|
</div>
|
|
71
71
|
</a>
|
|
72
|
-
<h5 collection="{{collection}}" pass-document_id="{{
|
|
72
|
+
<h5 collection="{{document.collection}}" pass-document_id="{{document._id}}" name="description"></h5>
|
|
73
73
|
</div>
|
|
74
74
|
</div>
|
|
75
75
|
</td>
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
pass_to="form-fields"
|
|
82
82
|
modal-width="320px"
|
|
83
83
|
modal-color="#229954">
|
|
84
|
-
<b collection="{{collection}}" pass-document_id="{{
|
|
84
|
+
<b collection="{{document.collection}}" pass-document_id="{{document._id}}" name="_id">Industry Id</b>
|
|
85
85
|
<div pass-collection="module_activity"
|
|
86
86
|
pass-document_id=""
|
|
87
87
|
pass-prefix="form_"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
placeholder="Industry Name">
|
|
22
22
|
<span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6">
|
|
23
23
|
<!-- 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 -->
|
|
24
|
-
<a filter-
|
|
24
|
+
<a filter-sort-name="name" toggle-order template_id="datatable">
|
|
25
25
|
<i></i>
|
|
26
26
|
</a>
|
|
27
27
|
</span>
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
template_id="datatable"
|
|
35
35
|
placeholder="Industry_id"/>
|
|
36
36
|
<span class="position:absolute bottom:18px right:20px float:right font-size:18px z-index:6" >
|
|
37
|
-
<a filter-
|
|
37
|
+
<a filter-sort-name="_id" value="" toggle-order="true" template_id="datatable">
|
|
38
38
|
</a>
|
|
39
39
|
</span>
|
|
40
40
|
</td>
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
filter-value=""
|
|
47
47
|
filter-value-type="or"
|
|
48
48
|
fetch-count=""
|
|
49
|
-
filter-
|
|
50
|
-
filter-
|
|
49
|
+
filter-sort-name="name"
|
|
50
|
+
filter-sort-type="asc"
|
|
51
51
|
template_id="datatable"
|
|
52
52
|
pass_to="me1234">
|
|
53
53
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/organizations",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A simple organizations component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"organizations",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@cocreate/actions": "^1.5.12",
|
|
65
65
|
"@cocreate/crud-client": "^1.12.12",
|
|
66
66
|
"@cocreate/docs": "^1.3.18",
|
|
67
|
-
"@cocreate/
|
|
67
|
+
"@cocreate/element-prototype": "^1.0.0",
|
|
68
68
|
"mongodb": "^4.4.0"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/src/client.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import CRUD from '@cocreate/crud-client';
|
|
2
|
+
import '@cocreate/element-prototype';
|
|
3
3
|
import action from '@cocreate/actions';
|
|
4
4
|
import uuid from '@cocreate/uuid';
|
|
5
5
|
|
|
6
|
+
let crud
|
|
7
|
+
if(CRUD && CRUD.default)
|
|
8
|
+
crud = CRUD.default
|
|
9
|
+
else
|
|
10
|
+
crud = CRUD
|
|
11
|
+
|
|
6
12
|
const CoCreateOrganization = {
|
|
7
13
|
init: function() {
|
|
8
14
|
const self = this;
|
|
9
15
|
crud.listen('createOrg', function(data) {
|
|
10
|
-
self.setDocumentId('organizations', data.
|
|
16
|
+
self.setDocumentId('organizations', data.document[0]._id);
|
|
11
17
|
document.dispatchEvent(new CustomEvent('createdOrg', {
|
|
12
18
|
detail: data
|
|
13
19
|
}));
|
|
@@ -20,7 +26,7 @@ const CoCreateOrganization = {
|
|
|
20
26
|
|
|
21
27
|
let elements = form.querySelectorAll("[collection='organizations'][name]");
|
|
22
28
|
|
|
23
|
-
let data = {
|
|
29
|
+
let data = {document: {}};
|
|
24
30
|
//. get form data
|
|
25
31
|
elements.forEach(el => {
|
|
26
32
|
let name = el.getAttribute('name');
|
|
@@ -29,19 +35,19 @@ const CoCreateOrganization = {
|
|
|
29
35
|
if (el.getAttribute('data-type') == 'array') {
|
|
30
36
|
value = [value];
|
|
31
37
|
}
|
|
32
|
-
data.
|
|
38
|
+
data.document[name] = value;
|
|
33
39
|
});
|
|
34
40
|
|
|
35
|
-
const socket = crud.socket.
|
|
36
|
-
if (!socket || !socket.connected || window && !window.navigator.onLine) {
|
|
41
|
+
const socket = crud.socket.getSockets()
|
|
42
|
+
if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
|
|
37
43
|
data.collection = 'organizations'
|
|
38
|
-
data.
|
|
39
|
-
data.
|
|
44
|
+
data.document['_id'] = ObjectId()
|
|
45
|
+
data.document['name'] = 'untitled'
|
|
40
46
|
window.localStorage.setItem('apiKey', uuid(32));
|
|
41
47
|
window.localStorage.setItem('organization_id', data['_id']);
|
|
42
48
|
crud.createDocument(data).then((response) => {
|
|
43
|
-
data.database = data.
|
|
44
|
-
data.organization_id = data.
|
|
49
|
+
data.database = data.document[0]['_id']
|
|
50
|
+
data.organization_id = data.document[0]['_id']
|
|
45
51
|
crud.createDocument(data).then((response) => {
|
|
46
52
|
|
|
47
53
|
document.dispatchEvent(new CustomEvent('createOrg', {
|
|
@@ -51,9 +57,9 @@ const CoCreateOrganization = {
|
|
|
51
57
|
})
|
|
52
58
|
})
|
|
53
59
|
} else {
|
|
54
|
-
crud.send('createOrg', {
|
|
60
|
+
crud.socket.send('createOrg', {
|
|
55
61
|
collection: 'organizations',
|
|
56
|
-
data
|
|
62
|
+
...data
|
|
57
63
|
});
|
|
58
64
|
}
|
|
59
65
|
},
|
|
@@ -73,12 +79,12 @@ const CoCreateOrganization = {
|
|
|
73
79
|
},
|
|
74
80
|
|
|
75
81
|
deleteOrg: async function(btn) {
|
|
76
|
-
const { collection, document_id } = crud.
|
|
82
|
+
const { collection, document_id } = crud.getAttributes(btn);
|
|
77
83
|
const organization_id = document_id;
|
|
78
84
|
|
|
79
|
-
if(crud.
|
|
85
|
+
if(crud.checkValue(collection) && crud.checkValue(document_id)) {
|
|
80
86
|
|
|
81
|
-
crud.send('deleteOrg', {
|
|
87
|
+
crud.socket.send('deleteOrg', {
|
|
82
88
|
collection,
|
|
83
89
|
document_id,
|
|
84
90
|
data: {
|
|
@@ -97,7 +103,7 @@ const CoCreateOrganization = {
|
|
|
97
103
|
|
|
98
104
|
deleteOrgs: async function(btn) {
|
|
99
105
|
const collection = btn.getAttribute('collection');
|
|
100
|
-
if(crud.
|
|
106
|
+
if(crud.checkValue(collection)) {
|
|
101
107
|
const dataTemplateid = btn.getAttribute('template_id');
|
|
102
108
|
if(!dataTemplateid) return;
|
|
103
109
|
|
|
@@ -107,8 +113,8 @@ const CoCreateOrganization = {
|
|
|
107
113
|
const document_id = el.getAttribute('document_id');
|
|
108
114
|
const organization_id = document_id;
|
|
109
115
|
|
|
110
|
-
if(crud.
|
|
111
|
-
crud.send('deleteOrg', {
|
|
116
|
+
if(crud.checkValue(document_id)) {
|
|
117
|
+
crud.socket.send('deleteOrg', {
|
|
112
118
|
collection,
|
|
113
119
|
document_id,
|
|
114
120
|
data: {
|
package/src/server.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
const {ObjectId} = require("mongodb");
|
|
2
|
-
|
|
3
1
|
class CoCreateOrganization {
|
|
4
|
-
constructor(wsManager,
|
|
2
|
+
constructor(wsManager, crud) {
|
|
5
3
|
this.wsManager = wsManager
|
|
6
|
-
this.
|
|
4
|
+
this.crud = crud
|
|
7
5
|
this.init()
|
|
8
6
|
}
|
|
9
7
|
|
|
@@ -20,33 +18,24 @@ class CoCreateOrganization {
|
|
|
20
18
|
|
|
21
19
|
async createOrg(socket, data) {
|
|
22
20
|
const self = this;
|
|
23
|
-
if(!data.data) return;
|
|
24
21
|
|
|
25
22
|
try{
|
|
26
|
-
const collection = this.dbClient.db(data.organization_id).collection(data.collection);
|
|
27
23
|
// create new org in config db organization collection
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
anotherCollection.insertOne({...data.data, organization_id : orgId});
|
|
37
|
-
|
|
38
|
-
const response = { ...data, document_id: orgId }
|
|
24
|
+
this.crud.createDocument(data).then((data) => {
|
|
25
|
+
const orgId = `${data.document[0]._id}`
|
|
26
|
+
|
|
27
|
+
// Create new org db and insert organization
|
|
28
|
+
self.crud.createDocument({...data, database: orgId, organization_id: orgId}).then((data) => {
|
|
29
|
+
self.wsManager.send(socket, 'createOrg', data);
|
|
30
|
+
self.wsManager.broadcast(socket, 'createDocument', data);
|
|
31
|
+
})
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// add new org to platformDB
|
|
44
|
-
if (data.organization_id != process.env.organization_id) {
|
|
45
|
-
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
46
|
-
platformDB.insertOne({...data.data, organization_id: process.env.organization_id});
|
|
47
|
-
}
|
|
33
|
+
// add new org to platformDB
|
|
34
|
+
if (data.organization_id != process.env.organization_id) {
|
|
35
|
+
self.crud.createDocument({ ...data, database: process.env.organization_id, organization_id: process.env.organization_id })
|
|
48
36
|
}
|
|
49
|
-
|
|
37
|
+
|
|
38
|
+
})
|
|
50
39
|
}catch(error){
|
|
51
40
|
console.log('createDocument error', error);
|
|
52
41
|
}
|
|
@@ -55,33 +44,33 @@ class CoCreateOrganization {
|
|
|
55
44
|
|
|
56
45
|
async deleteOrg(socket, data) {
|
|
57
46
|
const self = this;
|
|
58
|
-
if(!data.data) return;
|
|
59
47
|
const organization_id = data.data.organization_id
|
|
60
|
-
if(!organization_id || organization_id == process.env.organization_id) return;
|
|
61
|
-
if(data.organization_id != process.env.organization_id) return;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
if (!organization_id || organization_id == process.env.organization_id) return;
|
|
49
|
+
if (data.organization_id != process.env.organization_id) return;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
this.crud.deleteDatabase(data).then((response) => {
|
|
65
53
|
if (response === true){
|
|
66
54
|
process.emit('deleteOrg', organization_id)
|
|
67
|
-
|
|
55
|
+
self.wsManager.send(socket, 'deleteOrg', data);
|
|
56
|
+
|
|
68
57
|
// delete org from platformDB
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
const request = {
|
|
59
|
+
database: process.env.organization_id,
|
|
60
|
+
collection: 'organization',
|
|
61
|
+
document: {
|
|
62
|
+
_id: organization_id
|
|
63
|
+
},
|
|
64
|
+
organization_id: process.env.organization_id
|
|
72
65
|
};
|
|
73
66
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let response = { ...data }
|
|
77
|
-
self.wsManager.send(socket, 'deleteOrg', response);
|
|
78
|
-
self.wsManager.broadcast(socket, 'deleteDocument', response);
|
|
79
|
-
} else {
|
|
80
|
-
self.wsManager.send(socket, 'ServerError', error);
|
|
81
|
-
}
|
|
67
|
+
self.crud.deleteDocument(request).then((data) => {
|
|
68
|
+
self.wsManager.broadcast(socket, 'deleteDocument', data)
|
|
82
69
|
})
|
|
83
70
|
}
|
|
71
|
+
|
|
84
72
|
})
|
|
73
|
+
|
|
85
74
|
}catch(error){
|
|
86
75
|
console.log('deleteOrg error', error);
|
|
87
76
|
}
|