diff --git a/application/Espo/Hooks/Common/Stream.php b/application/Espo/Hooks/Common/Stream.php index b21ad3def0..4e341b60cd 100644 --- a/application/Espo/Hooks/Common/Stream.php +++ b/application/Espo/Hooks/Common/Stream.php @@ -73,6 +73,12 @@ class Stream extends \Espo\Core\Hooks\Base if ($this->checkHasStream($entity)) { $this->getStreamService()->unfollowAllUsersFromEntity($entity); } + $query = $this->getEntityManager()->getQuery(); + $sql = " + DELETE FROM `note` + WHERE related_id = ".$query->quote($entity->id)." AND related_type = ".$query->quote($entity->getEntityType()) ." + "; + $this->getEntityManager()->getPDO()->query($sql); } protected function handleCreateRelated(Entity $entity) diff --git a/application/Espo/Resources/metadata/entityDefs/Note.json b/application/Espo/Resources/metadata/entityDefs/Note.json index 260a2cf6ee..b31f517b3d 100644 --- a/application/Espo/Resources/metadata/entityDefs/Note.json +++ b/application/Espo/Resources/metadata/entityDefs/Note.json @@ -4,13 +4,20 @@ "type": "text" }, "data": { - "type": "jsonObject" + "type": "jsonObject", + "readOnly": true }, "type": { - "type": "varchar" + "type": "varchar", + "readOnly": true }, "parent": { - "type": "linkParent" + "type": "linkParent", + "readOnly": true + }, + "related": { + "type": "linkParent", + "readOnly": true }, "attachments": { "type": "linkMultiple", @@ -18,7 +25,8 @@ }, "number": { "type": "autoincrement", - "index": true + "index": true, + "readOnly": true }, "createdAt": { "type": "datetime", @@ -58,6 +66,9 @@ }, "superParent": { "type": "belongsToParent" + }, + "related": { + "type": "belongsToParent" } }, "collection": { diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 84728e6f5d..07e4d5d962 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -279,6 +279,8 @@ class Stream extends \Espo\Core\Services\Base note.data AS 'data', note.parent_type AS 'parentType', note.parent_id AS 'parentId', + note.related_type AS 'relatedType', + note.related_id AS 'relatedId', note.created_at AS 'createdAt', note.created_by_id AS 'createdById', TRIM(CONCAT(createdBy.first_name, ' ', createdBy.last_name)) AS `createdByName` @@ -305,6 +307,8 @@ class Stream extends \Espo\Core\Services\Base note.data AS 'data', note.parent_type AS 'parentType', note.parent_id AS 'parentId', + note.related_type AS 'relatedType', + note.related_id AS 'relatedId', note.created_at AS 'createdAt', note.created_by_id AS 'createdById', TRIM(CONCAT(createdBy.first_name, ' ', createdBy.last_name)) AS `createdByName` @@ -357,6 +361,12 @@ class Stream extends \Espo\Core\Services\Base $e->set('parentName', $entity->get('name')); } } + if ($e->get('relatedId') && $e->get('relatedType')) { + $entity = $this->getEntityManager()->getEntity($e->get('relatedType'), $e->get('relatedId')); + if ($entity) { + $e->set('relatedName', $entity->get('name')); + } + } } if (count($collection) > $maxSize) { @@ -427,7 +437,12 @@ class Stream extends \Espo\Core\Services\Base $e->set('parentName', $parent->get('name')); } } - + } + if ($e->get('relatedId') && $e->get('relatedType')) { + $entity = $this->getEntityManager()->getEntity($e->get('relatedType'), $e->get('relatedId')); + if ($entity) { + $e->set('relatedName', $entity->get('name')); + } } } @@ -575,13 +590,13 @@ class Stream extends \Espo\Core\Services\Base $data['assignedUserName'] = $entity->get('assignedUserName'); } - $statusStyles = $this->getStatusStyles(); $statusFields = $this->getStatusFields(); if (!empty($statusFields[$entityType])) { $field = $statusFields[$entityType]; $value = $entity->get($field); if (!empty($value)) { + $statusStyles = $this->getStatusStyles(); $style = 'default'; if (!empty($statusStyles[$entityType]) && !empty($statusStyles[$entityType][$value])) { $style = $statusStyles[$entityType][$value]; @@ -597,26 +612,25 @@ class Stream extends \Espo\Core\Services\Base $this->getEntityManager()->saveEntity($note); } - public function noteCreateRelated(Entity $entity, $entityType, $id, $action = 'created') + public function noteCreateRelated(Entity $entity, $parentType, $parentId) { $note = $this->getEntityManager()->getEntity('Note'); + $entityType = $entity->getEntityType(); + $note->set('type', 'CreateRelated'); - $note->set('parentId', $id); - $note->set('parentType', $entityType); + $note->set('parentId', $parentId); + $note->set('parentType', $parentType); + $note->set(array( + 'relatedType' => $entityType, + 'relatedId' => $entity->id, + )); if ($entity->has('accountId') && $entity->get('accountId')) { $note->set('superParentId', $entity->get('accountId')); $note->set('superParentType', 'Account'); } - $note->set('data', array( - 'action' => $action, - 'entityType' => $entity->getEntityName(), - 'entityId' => $entity->id, - 'entityName' => $entity->get('name') - )); - $this->getEntityManager()->saveEntity($note); } diff --git a/frontend/client/res/templates/stream/notes/create-related.tpl b/frontend/client/res/templates/stream/notes/create-related.tpl index 94501925aa..192eb148df 100644 --- a/frontend/client/res/templates/stream/notes/create-related.tpl +++ b/frontend/client/res/templates/stream/notes/create-related.tpl @@ -13,6 +13,9 @@ {{{avatar}}}
+ {{#if statusText}} + {{statusText}} + {{/if}} {{{message}}}
diff --git a/frontend/client/src/views/stream/notes/create-related.js b/frontend/client/src/views/stream/notes/create-related.js index 7d865c2c3b..eea9e13018 100644 --- a/frontend/client/src/views/stream/notes/create-related.js +++ b/frontend/client/src/views/stream/notes/create-related.js @@ -29,10 +29,6 @@ Espo.define('Views.Stream.Notes.CreateRelated', 'Views.Stream.Note', function (D data: function () { return _.extend({ - entityType: this.entityType, - entityId: this.entityId, - entityName: this.entityName, - action: this.action, relatedTypeString: this.translate(this.entityType, 'scopeNames').toLowerCase() }, Dep.prototype.data.call(this)); }, @@ -45,17 +41,14 @@ Espo.define('Views.Stream.Notes.CreateRelated', 'Views.Stream.Note', function (D }, setup: function () { - if (this.model.get('data')) { - var data = this.model.get('data'); + var data = this.model.get('data') || {}; - this.entityType = data.entityType || null; - this.entityId = data.entityId || null; - this.entityName = data.entityName || null; - this.action = data.action || null; + this.entityType = this.model.get('relatedType') || data.entityType || null; + this.entityId = this.model.get('relatedId') || data.entityId || null; + this.entityName = this.model.get('relatedName') || data.entityName || null; - this.messageData['relatedEntityType'] = this.translate(this.entityType, 'scopeNames').toLowerCase(); - this.messageData['relatedEntity'] = '' + this.entityName +''; - } + this.messageData['relatedEntityType'] = this.translate(this.entityType, 'scopeNames').toLowerCase(); + this.messageData['relatedEntity'] = '' + this.entityName +''; this.createMessage(); },