EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
notificatinos: mark group as read
Yurii90aae7677c25
diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.jsonindex ac5f229f74..5a73cd4ecc 100644--- a/application/Espo/Resources/i18n/en_US/Global.json+++ b/application/Espo/Resources/i18n/en_US/Global.json@@ -273,6 +273,7 @@"Duplicate": "Duplicate","Notifications": "Notifications","Mark all read": "Mark all read",+ "Mark read": "Mark read","See more": "See more","Today": "Today","Tomorrow": "Tomorrow",diff --git a/application/Espo/Resources/routes.json b/application/Espo/Resources/routes.jsonindex 0fa01f87e4..cbe5e24523 100644--- a/application/Espo/Resources/routes.json+++ b/application/Espo/Resources/routes.json@@ -365,6 +365,11 @@"method": "delete","actionClassName": "Espo\\Tools\\Notification\\Api\\DeleteGroup"},+ {+ "route": "/Notification/group/:id/markRead",+ "method": "post",+ "actionClassName": "Espo\\Tools\\Notification\\Api\\MarkGroupRead"+ },{"route": "/EmailTemplate/:id/prepare","method": "post",diff --git a/application/Espo/Tools/Notification/Api/MarkGroupRead.php b/application/Espo/Tools/Notification/Api/MarkGroupRead.phpnew file mode 100644index 0000000000..033a9d6dcb--- /dev/null+++ b/application/Espo/Tools/Notification/Api/MarkGroupRead.php@@ -0,0 +1,56 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Tools\Notification\Api;++use Espo\Core\Api\Action;+use Espo\Core\Api\Request;+use Espo\Core\Api\Response;+use Espo\Core\Api\ResponseComposer;+use Espo\Core\Exceptions\BadRequest;+use Espo\Tools\Notification\GroupAllService;++/**+ * @noinspection PhpUnused+ */+class MarkGroupRead implements Action+{+ public function __construct(+ private GroupAllService $service,+ ) {}++ public function process(Request $request): Response+ {+ $id = $request->getRouteParam('id') ?? throw new BadRequest();++ $this->service->markRead($id);++ return ResponseComposer::json(true);+ }+}diff --git a/application/Espo/Tools/Notification/GroupAllService.php b/application/Espo/Tools/Notification/GroupAllService.phpindex 29382446ca..6795c658b7 100644--- a/application/Espo/Tools/Notification/GroupAllService.php+++ b/application/Espo/Tools/Notification/GroupAllService.php@@ -45,6 +45,7 @@ use Espo\ORM\Query\Part\Condition as Cond;use Espo\ORM\Query\Part\Expression as Expr;use Espo\ORM\Query\Select;use Espo\ORM\Query\SelectBuilder;+use Espo\ORM\Query\UpdateBuilder;class GroupAllService{@@ -157,6 +158,32 @@ class GroupAllServicereturn [$collection, $total];}+ /**+ * @throws BadRequest+ */+ public function markRead(string $groupId): void+ {+ if (substr_count($groupId, '_') < 1) {+ throw new BadRequest("Bad ID.");+ }++ [$type,] = explode('_', $groupId, 2);++ if ($type == Notification::GROUP_TYPE_NOTE) {+ $this->markReadNote($groupId);++ return;+ }++ if ($type == Notification::GROUP_TYPE_EMAIL_RECEIVED) {+ $this->markReadEmailReceived();++ return;+ }++ throw new BadRequest("Bad group type.");+ }+/*** @param string[] $ids*/@@ -278,4 +305,53 @@ class GroupAllService$this->entityManager->getQueryExecutor()->execute($query);}++ /**+ * @throws BadRequest+ */+ private function markReadNote(string $groupId): void+ {+ if (substr_count($groupId, '_') < 2) {+ throw new BadRequest("Bad ID.");+ }++ [, $entityType, $id] = explode('_', $groupId, 3);++ $query = UpdateBuilder::create()+ ->in(Notification::ENTITY_TYPE)+ ->where([+ Notification::ATTR_USER_ID => $this->user->getId(),+ ])+ ->where([+ Notification::FIELD_TYPE => Notification::TYPE_NOTE,+ Notification::ATTR_RELATED_PARENT_TYPE => $entityType,+ Notification::ATTR_RELATED_PARENT_ID => $id,+ Notification::ATTR_READ => false,+ ])+ ->set([+ Notification::ATTR_READ => true,+ ])+ ->build();++ $this->entityManager->getQueryExecutor()->execute($query);+ }++ private function markReadEmailReceived(): void+ {+ $query = UpdateBuilder::create()+ ->in(Notification::ENTITY_TYPE)+ ->where([+ Notification::ATTR_USER_ID => $this->user->getId(),+ ])+ ->where([+ Notification::FIELD_TYPE => Notification::TYPE_EMAIL_RECEIVED,+ Notification::ATTR_READ => false,+ ])+ ->set([+ Notification::ATTR_READ => true,+ ])+ ->build();++ $this->entityManager->getQueryExecutor()->execute($query);+ }}diff --git a/client/res/templates/notification/fields/container.tpl b/client/res/templates/notification/fields/container.tplindex f62cf377de..5df99aa583 100644--- a/client/res/templates/notification/fields/container.tpl+++ b/client/res/templates/notification/fields/container.tpl@@ -8,7 +8,16 @@role="button"data-action="showGrouped"class="btn btn-sm btn-text"+ title="{{translate 'Expand'}}"><span class="fas fa-ellipsis-h fa-sm"></span></a>+ {{#if hasMarkGroupRead}}+ <a+ role="button"+ data-action="markGroupRead"+ class="btn btn-sm btn-text"+ title="{{translate 'Mark read'}}"+ ><span class="fas fa-check fa-sm"></span></a>+ {{/if}}{{/if}}</div>{{/if}}diff --git a/client/src/views/fields/base.js b/client/src/views/fields/base.jsindex e55c62e1ab..6e2a648e7c 100644--- a/client/src/views/fields/base.js+++ b/client/src/views/fields/base.js@@ -903,6 +903,7 @@ class BaseFieldView extends View {this.attributeList = this.getAttributeList(); // for backward compatibility, to be removedthis.listenTo(this.model, 'change', (model, options) => {+ console.log(this.name, this, options);if (options.ui && (!options.fromField || options.fromField === this.name)) {return;}diff --git a/client/src/views/notification/fields/container.js b/client/src/views/notification/fields/container.jsindex 9010f63451..94f8771c77 100644--- a/client/src/views/notification/fields/container.js+++ b/client/src/views/notification/fields/container.js@@ -29,6 +29,7 @@import BaseFieldView from 'views/fields/base';import NotificationListRecordView from 'views/notification/record/list';import NotificationPanelView from 'views/notification/panel';+import Ajax from 'ajax';class NotificationContainerFieldView extends BaseFieldView {@@ -59,16 +60,25 @@ class NotificationContainerFieldView extends BaseFieldView {*/isGroupExpanded = false+ /**+ * @private+ * @type {boolean}+ */+ groupingEnabled+data() {const count = this.model.attributes.groupedCount ?? 0;return {hasGrouped: count > 1 || count < 0,isGroupExpanded: this.isGroupExpanded,+ hasMarkGroupRead: this.groupingEnabled && !this.model.attributes.read,};}setup() {+ this.groupingEnabled = this.options.groupingEnabled ?? false;+if (this.model.attributes.groupType) {this.wait(this.processGroup());} else {@@ -89,6 +99,7 @@ class NotificationContainerFieldView extends BaseFieldView {}this.addActionHandler('showGrouped', () => this.showGrouped());+ this.addActionHandler('markGroupRead', () => this.markGroupRead());}process() {@@ -280,6 +291,27 @@ class NotificationContainerFieldView extends BaseFieldView {await this.reRender();+ this.triggerUpdateRead();+ }+++ /**+ * @private+ */+ async markGroupRead() {+ //await Ajax.postRequest(`Notification/group/${this.model.id}/markRead`);++ this.model.set('read', true, {sync: true});++ await this.reRender();++ this.triggerUpdateRead();+ }++ /**+ * @private+ */+ triggerUpdateRead() {let viewPointer = this;while (true) {diff --git a/client/src/views/notification/fields/read-with-menu.js b/client/src/views/notification/fields/read-with-menu.jsindex 774e1822aa..818ce73699 100644--- a/client/src/views/notification/fields/read-with-menu.js+++ b/client/src/views/notification/fields/read-with-menu.js@@ -28,7 +28,8 @@import BaseFieldView from 'views/fields/base';-class NotificationReadWithMenuFieldView extends BaseFieldView {+// noinspection JSUnusedGlobalSymbols+export default class NotificationReadWithMenuFieldView extends BaseFieldView {type = 'read'listTemplate = 'notification/fields/read-with-menu'@@ -36,11 +37,13 @@ class NotificationReadWithMenuFieldView extends BaseFieldView {inlineEditDisabled = true+ getAttributeList() {+ return ['read'];+ }+data() {return {isRead: this.model.get('read'),};}}--export default NotificationReadWithMenuFieldView;diff --git a/client/src/views/notification/fields/read.js b/client/src/views/notification/fields/read.jsindex 98a6bec173..3c95a9b8bc 100644--- a/client/src/views/notification/fields/read.js+++ b/client/src/views/notification/fields/read.js@@ -36,11 +36,19 @@ class NotificationReadFieldView extends BaseFieldView {inlineEditDisabled = true+ getAttributeList() {+ return ['read'];+ }+data() {return {isRead: this.model.get('read'),};}++ afterRender() {+ //console.log(this.element);+ }}export default NotificationReadFieldView;diff --git a/client/src/views/notification/panel.js b/client/src/views/notification/panel.jsindex e2f94d80f7..21f946f135 100644--- a/client/src/views/notification/panel.js+++ b/client/src/views/notification/panel.js@@ -32,6 +32,12 @@ class NotificationPanelView extends View {template = 'notification/panel'+ /**+ * @private+ * @type {boolean}+ */+ groupingEnabled+setup() {this.addActionHandler('markAllNotificationsRead', () => this.actionMarkAllRead());this.addActionHandler('openNotifications', () => this.actionOpenNotifications());@@ -43,6 +49,8 @@ class NotificationPanelView extends View {}})+ this.groupingEnabled = this.getPreferences().get('notificationGrouping') === true;+const promise =this.getCollectionFactory().create('Notification', collection => {this.collection = collection;@@ -95,6 +103,7 @@ class NotificationPanelView extends View {view: 'views/notification/fields/container',options: {containerSelector: this.getSelector(),+ groupingEnabled: this.groupingEnabled,},}]diff --git a/client/src/views/record/list-expanded.js b/client/src/views/record/list-expanded.jsindex cbedf164f5..a7e29e7736 100644--- a/client/src/views/record/list-expanded.js+++ b/client/src/views/record/list-expanded.js@@ -155,6 +155,7 @@ class ListExpandedRecordView extends ListRecordView {name: name,view: listLayout.right.view,options: {+ name: name,defs: {params: {width: listLayout.right.width || '7%',diff --git a/frontend/less/espo/custom.less b/frontend/less/espo/custom.lessindex 0d072dfd2e..926103c4d2 100644--- a/frontend/less/espo/custom.less+++ b/frontend/less/espo/custom.less@@ -1412,10 +1412,25 @@ section {&:has(.notification-grouped a[data-action="showGrouped"]) {padding-bottom: 0;- a[data-action="showGrouped"] {- margin: 0 auto;- display: block;- width: 36px;+ .notification-grouped {+ display: grid;+ grid-template-columns: 1fr auto 1fr;+ align-items: center;+++ a[data-action="showGrouped"] {+ grid-column: 2;+ justify-self: center;+ display: block;+ width: var(--36px);+ }++ a[data-action="markGroupRead"] {+ grid-column: 3;+ justify-self: end;+ display: block;+ width: var(--36px);+ }}}