@cocreate/organizations 1.11.9 → 1.13.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.13.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.12.0...v1.13.0) (2023-05-10)
2
+
3
+
4
+ ### Features
5
+
6
+ * form getData and setDocumentId ([5ed4371](https://github.com/CoCreate-app/CoCreate-organizations/commit/5ed4371103578249764add885bcc0cd7e896ab7d))
7
+
8
+ # [1.12.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.11.9...v1.12.0) (2023-05-10)
9
+
10
+
11
+ ### Features
12
+
13
+ * createOrg in local and platform ([85f62ed](https://github.com/CoCreate-app/CoCreate-organizations/commit/85f62ed74f511f3f15acbe3aa6825c314abde46d))
14
+
1
15
  ## [1.11.9](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.11.8...v1.11.9) (2023-05-07)
2
16
 
3
17
 
@@ -33,7 +33,7 @@
33
33
  template_id="datatable"
34
34
  placeholder="Industry_id"/>
35
35
  <span class="position:absolute bottom:20px right:20px float:right z-index:6" >
36
- <a filter-sort-name="_id" value="" filter-sort-direction="asc" icon click-value="desc, asc" click-attribute="filter-sort-direction" template_id="datatable">
36
+ <a filter-sort-name="_id" value="" filter-sort-direction="asc" click-value="desc, asc" click-attribute="filter-sort-direction" template_id="datatable">
37
37
  </a>
38
38
  </span>
39
39
  </td>
@@ -35,7 +35,7 @@
35
35
  template_id="datatable"
36
36
  placeholder="Industry_id"/>
37
37
  <span class="position:absolute bottom:20px right:20px float:right z-index:6" >
38
- <a filter-sort-name="_id" value="" filter-sort-direction="asc" icon click-value="desc, asc" click-attribute="filter-sort-direction" template_id="datatable">
38
+ <a filter-sort-name="_id" value="" filter-sort-direction="asc" click-value="desc, asc" click-attribute="filter-sort-direction" template_id="datatable">
39
39
  </a>
40
40
  </span>
41
41
  </td>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.11.9",
3
+ "version": "1.13.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",
@@ -62,7 +62,7 @@
62
62
  "@cocreate/actions": "^1.8.8",
63
63
  "@cocreate/crud-client": "^1.20.4",
64
64
  "@cocreate/docs": "^1.7.8",
65
- "@cocreate/element-prototype": "^1.8.7",
66
- "@cocreate/local-storage": "^1.6.8"
65
+ "@cocreate/form": "^1.14.6",
66
+ "@cocreate/indexeddb": "^1.8.6"
67
67
  }
68
68
  }
package/src/client.js CHANGED
@@ -1,74 +1,32 @@
1
1
  import crud from '@cocreate/crud-client';
2
- import '@cocreate/element-prototype';
2
+ import indexeddb from '@cocreate/indexeddb';
3
3
  import action from '@cocreate/actions';
4
- import uuid from '@cocreate/uuid';
5
- import localStorage from '@cocreate/local-storage';
4
+ import form from '@cocreate/form';
6
5
 
7
6
  const CoCreateOrganization = {
8
- init: function() {
9
- const self = this;
10
- crud.listen('createOrg', function(data) {
11
- self.setDocumentId('organizations', data.document[0]._id);
12
- document.dispatchEvent(new CustomEvent('createdOrg', {
13
- detail: data
14
- }));
15
- });
16
- },
17
7
 
18
- createOrg: function(btn) {
19
- let form = btn.closest("form");
20
- if (!form) return;
8
+ createOrg: async function(btn) {
9
+ let formEl = btn.closest("form");
10
+ if (!formEl) return;
11
+
12
+ let organization = form.getData(formEl, 'organizations')
13
+ let user = form.getData(formEl, 'users')
21
14
 
22
- let elements = form.querySelectorAll("[collection='organizations'][name]");
15
+ let documents = indexeddb.generateDB(organization, user)
23
16
 
24
- let data = {document: {}};
25
- elements.forEach(el => {
26
- let name = el.getAttribute('name');
27
- let value = el.getValue();
28
- if (!name || !value) return;
29
- data.document[name] = value;
17
+ let response = await crud.socket.send('createOrg', {
18
+ documents,
19
+ broadcastBrowser: false
30
20
  });
31
-
32
- // const socket = crud.socket.getSockets()
33
- // if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
34
- data.collection = 'organizations'
35
- // data.document['_id'] = crud.ObjectId()
36
- // data.document['name'] = 'untitled'
37
- // localStorage.setItem('apiKey', uuid.generate(32));
38
- // localStorage.setItem('organization_id', data['_id']);
39
- crud.createDocument(data).then((response) => {
40
- // data.database = data.document[0]['_id']
41
- // data.organization_id = data.document[0]['_id']
42
- // crud.createDocument(data).then((response) => {
43
-
44
- document.dispatchEvent(new CustomEvent('createdOrg', {
45
- detail: response
46
- }));
47
-
48
- // })
49
- })
50
- // } else {
51
- // crud.socket.send('createOrg', {
52
- // collection: 'organizations',
53
- // ...data,
54
- // broadcastBrowser: false
55
- // });
56
- // }
57
- },
58
-
59
- setDocumentId: function(collection, id) {
60
- let orgIdElements = document.querySelectorAll(`[collection='${collection}']`);
61
- if (orgIdElements && orgIdElements.length > 0) {
62
- orgIdElements.forEach((el) => {
63
- if (!el.getAttribute('document_id')) {
64
- el.setAttribute('document_id', id);
65
- }
66
- if (el.getAttribute('name') == "_id") {
67
- el.value = id;
68
- }
69
- });
70
- }
71
- },
21
+
22
+ form.setDocumentId(formEl, organization)
23
+ form.setDocumentId(formEl, user)
24
+
25
+ document.dispatchEvent(new CustomEvent('createdOrg', {
26
+ detail: response
27
+ }));
28
+
29
+ },
72
30
 
73
31
  deleteOrg: async function(btn) {
74
32
  const { collection, document_id } = crud.getAttributes(btn);
@@ -149,6 +107,4 @@ action.init({
149
107
  },
150
108
  });
151
109
 
152
- CoCreateOrganization.init();
153
-
154
110
  export default CoCreateOrganization;
package/src/server.js CHANGED
@@ -17,29 +17,21 @@ class CoCreateOrganization {
17
17
  }
18
18
 
19
19
  async createOrg(socket, data) {
20
- const self = this;
21
-
22
- try{
23
- // create new org in config db organization collection
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
- // })
32
-
33
- self.wsManager.broadcast(socket, 'updateDocument', data);
34
- self.wsManager.send(socket, 'createOrg', data);
35
-
36
- // add new org to platformDB
37
- if (data.organization_id != process.env.organization_id) {
38
- self.crud.createDocument({ ...data, database: process.env.organization_id, organization_id: process.env.organization_id })
20
+ try {
21
+ const platformSocket = {
22
+ config: {
23
+ organization_id: process.env.organization_id,
39
24
  }
40
-
41
- })
42
- }catch(error){
25
+ }
26
+
27
+ for(let document of data.documents) {
28
+ document.database = process.env.organization_id
29
+ document.organization_id = process.env.organization_id
30
+ let response = await this.crud.createDocument(document)
31
+ this.wsManager.broadcast(platformSocket, 'createDocument', response);
32
+ }
33
+ this.wsManager.send(socket, 'createOrg', data);
34
+ } catch(error) {
43
35
  console.log('createDocument error', error);
44
36
  }
45
37
  }