diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml index 44c5fd707..9e0d1f973 100644 --- a/.github/workflows/javascript.yml +++ b/.github/workflows/javascript.yml @@ -26,7 +26,7 @@ jobs: strategy: matrix: - node-version: [20.x, 22.x] + node-version: [20.x, 22.x, 24.x] steps: - name: Checkout current revision diff --git a/composer.json b/composer.json index 71e55ddd8..f017c58eb 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require": { "php": ">=8.3", "bedita/i18n": "^5.1.0", - "bedita/web-tools": "^5.3.3", + "bedita/web-tools": "^5.4.0", "cakephp/authentication": "^2.9", "cakephp/cakephp": "~4.5.0", "cakephp/plugin-installer": "^1.3", diff --git a/resources/js/app/components/index-cell/index-cell.vue b/resources/js/app/components/index-cell/index-cell.vue index f45291025..c18ddc2a1 100644 --- a/resources/js/app/components/index-cell/index-cell.vue +++ b/resources/js/app/components/index-cell/index-cell.vue @@ -121,7 +121,7 @@ export default { default: () => [], }, schema: { - type: Object, + type: [Object, Array], default: () => ({}), }, settings: { diff --git a/resources/js/app/pages/modules/index.js b/resources/js/app/pages/modules/index.js index 97e2e0db2..b91262f50 100644 --- a/resources/js/app/pages/modules/index.js +++ b/resources/js/app/pages/modules/index.js @@ -32,6 +32,10 @@ export default { type: String, default: () => ([]), }, + objects: { + type: String, + default: () => '[]', + }, }, /** @@ -42,6 +46,8 @@ export default { data() { return { allIds: [], + objectsList: JSON.parse(this.objects), + selectedObjects: '[]', selectedRows: [], bulkField: null, bulkValue: null, @@ -87,6 +93,8 @@ export default { } else { this.$refs.checkAllCB.indeterminate = true; } + const selectedObjects = this.objectsList.filter((o) => val.includes(o.id)); + this.selectedObjects = JSON.stringify(selectedObjects); }, }, @@ -107,6 +115,9 @@ export default { } }, checkAll() { + const oo = this.objectsList.map((o) => { return {id: o.id, type: o.type}; }); + const selectedObjects = JSON.parse(JSON.stringify(oo)); + this.selectedObjects = JSON.stringify(selectedObjects); this.selectedRows = JSON.parse(JSON.stringify(this.allIds)); for (let id of this.allIds) { let row = document.querySelector(`a[data-id="${id}"]`); @@ -114,6 +125,7 @@ export default { } }, unCheckAll() { + this.selectedObjects = '[]'; this.selectedRows = []; for (let id of this.allIds) { let row = document.querySelector(`a[data-id="${id}"]`); @@ -191,6 +203,18 @@ export default { } else { this.selectedRows.push(cb.value); } + // push into selectedObjects, if still not present + const obj = this.objectsList.find((o) => o.id == cb.value); + if (obj) { + const selectedObjects = JSON.parse(this.selectedObjects); + const objPosition = selectedObjects.findIndex((o) => o.id == cb.value); + if (objPosition == -1) { + selectedObjects.push({id: obj.id, type: obj.type}); + } else { + selectedObjects.splice(objPosition, 1); + } + this.selectedObjects = JSON.stringify(selectedObjects); + } } else { let row = event.target.closest('a.table-row'); let checked = event.target.checked; diff --git a/src/Controller/BulkController.php b/src/Controller/BulkController.php index b3850a0f9..77ee4ba08 100644 --- a/src/Controller/BulkController.php +++ b/src/Controller/BulkController.php @@ -45,6 +45,13 @@ class BulkController extends AppController */ protected $ids = []; + /** + * Selected objects (in the format [{id:, type:}, ...]) + * + * @var array + */ + protected $objects = []; + /** * Selected categories * @@ -59,6 +66,13 @@ class BulkController extends AppController */ protected $errors = []; + /** + * Saved ids + * + * @var array + */ + protected $saved = []; + /** * @inheritDoc */ @@ -78,7 +92,8 @@ public function initialize(): void public function attribute(): ?Response { $requestData = $this->getRequest()->getData(); - $this->ids = explode(',', (string)Hash::get($requestData, 'ids')); + $this->objects = $requestData['objects']; + $this->objects = is_string($this->objects) ? json_decode($this->objects, true) : $this->objects; $this->saveAttribute($requestData['attributes']); $this->showResult(); @@ -184,13 +199,13 @@ public function position(): ?Response */ protected function saveAttribute(array $attributes): void { - foreach ($this->ids as $id) { - try { - $this->apiClient->save($this->objectType, compact('id') + $attributes); - } catch (BEditaClientException $e) { - $this->errors[] = ['id' => $id, 'message' => $e->getAttributes()]; - } + $itemsMap = []; + foreach ($this->objects as $item) { + $itemsMap[$item['type']][] = $item['id']; } + $result = $this->apiClient->bulkEdit($itemsMap, $attributes); + $this->errors = (array)Hash::get($result, 'data.errors'); + $this->saved = (array)Hash::get($result, 'data.saved'); } /** @@ -298,7 +313,8 @@ protected function moveToPosition(string $position): void protected function showResult(): void { if (empty($this->errors)) { - $this->Flash->success(__('Bulk action performed on {0} objects', count($this->ids))); + $count = count($this->saved) > 0 ? count($this->saved) : count($this->ids); + $this->Flash->success(__('Bulk action performed on {0} objects', $count)); return; } diff --git a/src/View/Helper/SchemaHelper.php b/src/View/Helper/SchemaHelper.php index fa4f119de..5b82aa320 100644 --- a/src/View/Helper/SchemaHelper.php +++ b/src/View/Helper/SchemaHelper.php @@ -379,4 +379,23 @@ public function filterListByType(array $filtersByType, ?array $schemasByType): a return $list; } + + /** + * Get minimal objects list (id and type only) from full objects array + * + * @param array $objects Full objects array + * @return array + */ + public function minimalObjectsList(array $objects): array + { + $list = []; + foreach ($objects as $obj) { + $list[] = [ + 'id' => Hash::get($obj, 'id'), + 'type' => Hash::get($obj, 'type'), + ]; + } + + return $list; + } } diff --git a/templates/Element/FilterBox/filter_box_common.twig b/templates/Element/FilterBox/filter_box_common.twig index 88f759f6e..ca3bd11d1 100644 --- a/templates/Element/FilterBox/filter_box_common.twig +++ b/templates/Element/FilterBox/filter_box_common.twig @@ -58,7 +58,7 @@ {{ __('Reset') }} - {% if hideFilterRelations == '' %} + {% if hideFilterRelations == '' and schema and schema.relations %}