saasufy-components 7.3.2 → 7.5.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/README.md CHANGED
@@ -445,6 +445,7 @@ OR (with confirmation step)
445
445
  - `model-id` (required): Specifies the ID of the resource to delete from the parent collection when this component is activated. This can be achieved by invoking either the `deleteItem()` or `confirmDeleteItem()` function from inside an event handler. The example above shows how to achieve deletion via the `onclick` event. You can either invoke `deleteItem()` to delete the resource immediately or you can invoke `confirmDeleteItem()` to require additional confirmation prior to deletion.
446
446
  - `onclick` (required): The logic to execute to delete the item. Should be either `deleteItem()` or `confirmDeleteItem()`.
447
447
  - `confirm-message`: The confirmation message to show the user when this component's `confirmDeleteItem()` function is invoked.
448
+ - `model-field`: If specified, this attribute can be used to delete a single field of a model instance, instead of the whole instance.
448
449
 
449
450
  If `confirmDeleteItem()` is used, then the parent `collection-viewer` must have a `confirm-modal` element slotted into it as shown here:
450
451
 
@@ -38,6 +38,29 @@ class CollectionDeleter extends HTMLElement {
38
38
  })
39
39
  )
40
40
  }
41
+
42
+ deleteItemField() {
43
+ let modelId = this.getAttribute('model-id');
44
+ let modelField = this.getAttribute('model-field');
45
+ this.dispatchEvent(
46
+ new CustomEvent('crudDelete', { detail: { id: modelId, field: modelField }, bubbles: true })
47
+ );
48
+ }
49
+
50
+ confirmDeleteItemField() {
51
+ let confirmMessage = this.getAttribute('confirm-message');
52
+ this.dispatchEvent(
53
+ new CustomEvent('showModal', {
54
+ detail: {
55
+ message: confirmMessage,
56
+ callback: () => {
57
+ this.deleteItemField();
58
+ }
59
+ },
60
+ bubbles: true
61
+ })
62
+ )
63
+ }
41
64
  }
42
65
 
43
66
  window.customElements.define('collection-deleter', CollectionDeleter);
@@ -37,10 +37,40 @@ class CollectionViewer extends SocketConsumer {
37
37
  }
38
38
  };
39
39
 
40
+ this.handleCRUDUpdateEvent = async (event) => {
41
+ event.stopPropagation();
42
+ if (this.collection) {
43
+ let detail = event.detail || {};
44
+ let modelId = detail.id;
45
+ let modelValue = detail.value;
46
+ await this.collection.update(modelId, modelValue);
47
+ this.dispatchEvent(
48
+ new CustomEvent('collectionUpdate', {
49
+ detail: {
50
+ type: this.collection.type,
51
+ id: modelId,
52
+ value: modelValue
53
+ },
54
+ bubbles: true
55
+ })
56
+ );
57
+ if (this.hasAttribute('collection-disable-realtime') && this.collection) {
58
+ this.collection.reloadCurrentPage();
59
+ }
60
+ }
61
+ };
62
+
40
63
  this.handleCRUDDeleteEvent = async (event) => {
41
64
  event.stopPropagation();
42
65
  if (this.collection) {
43
- await this.collection.delete(event.detail);
66
+ let detail = event.detail || {};
67
+ let modelId = detail.id;
68
+ let modelField = detail.field;
69
+ if (modelId != null) {
70
+ await this.collection.delete(modelId, modelField);
71
+ } else {
72
+ await this.collection.delete(event.detail);
73
+ }
44
74
  this.dispatchEvent(
45
75
  new CustomEvent('collectionDelete', {
46
76
  detail: {
@@ -83,6 +113,7 @@ class CollectionViewer extends SocketConsumer {
83
113
  this.shadowRoot.addEventListener('slotchange', this.handleSlotChangeEvent);
84
114
  this.addEventListener('showModal', this.handleShowModalEvent);
85
115
  this.addEventListener('crudCreate', this.handleCRUDCreateEvent);
116
+ this.addEventListener('crudUpdate', this.handleCRUDUpdateEvent);
86
117
  this.addEventListener('crudDelete', this.handleCRUDDeleteEvent);
87
118
  this.addEventListener('goToPreviousPage', this.handleGoToPreviousPageEvent);
88
119
  this.addEventListener('goToNextPage', this.handleGoToNextPageEvent);
@@ -95,6 +126,7 @@ class CollectionViewer extends SocketConsumer {
95
126
  this.shadowRoot.removeEventListener('slotchange', this.handleSlotChangeEvent);
96
127
  this.removeEventListener('showModal', this.handleShowModalEvent);
97
128
  this.removeEventListener('crudCreate', this.handleCRUDCreateEvent);
129
+ this.removeEventListener('crudUpdate', this.handleCRUDUpdateEvent);
98
130
  this.removeEventListener('crudDelete', this.handleCRUDDeleteEvent);
99
131
  this.removeEventListener('goToPreviousPage', this.handleGoToPreviousPageEvent);
100
132
  this.removeEventListener('goToNextPage', this.handleGoToNextPageEvent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.3.2",
3
+ "version": "7.5.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "author": "Jonathan Gros-Dubois",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "ag-collection": "^5.3.0",
20
+ "ag-collection": "^5.3.1",
21
21
  "ag-model": "^3.1.0",
22
22
  "capitalisk-auth-client": "^1.5.1",
23
23
  "socketcluster-client": "^19.2.1",