From 371966e2cf542ec5fc3ef5a75c968f0a044c9ebd Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 24 Mar 2015 17:24:38 +0200 Subject: [PATCH] add super parent for note --- .../Resources/metadata/entityDefs/Note.json | 3 ++ application/Espo/Services/Stream.php | 38 +++++++++++++++-- frontend/client/src/views/stream/list.js | 1 + frontend/client/src/views/stream/note.js | 23 ++++++++-- .../client/src/views/stream/notes/create.js | 42 +++++++++---------- .../src/views/stream/notes/email-received.js | 2 +- .../src/views/stream/notes/email-sent.js | 2 +- .../src/views/stream/notes/mention-in-post.js | 23 +++++----- .../client/src/views/stream/notes/post.js | 2 +- frontend/client/src/views/stream/panel.js | 1 + 10 files changed, 94 insertions(+), 43 deletions(-) diff --git a/application/Espo/Resources/metadata/entityDefs/Note.json b/application/Espo/Resources/metadata/entityDefs/Note.json index 2c1abb1407..43b03e0d6b 100644 --- a/application/Espo/Resources/metadata/entityDefs/Note.json +++ b/application/Espo/Resources/metadata/entityDefs/Note.json @@ -55,6 +55,9 @@ "parent": { "type": "belongsToParent", "foreign": "notes" + }, + "superParent": { + "type": "belongsToParent" } }, "collection": { diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 3df9ff42b6..d3e0ae624f 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -264,8 +264,16 @@ class Stream extends \Espo\Core\Services\Base 'order' => 'DESC', 'customJoin' => " JOIN subscription ON - note.parent_type = subscription.entity_type AND - note.parent_id = subscription.entity_id AND + ( + ( + note.parent_type = subscription.entity_type AND + note.parent_id = subscription.entity_id + ) OR + ( + note.super_parent_type = subscription.entity_type AND + note.super_parent_id = subscription.entity_id + ) + ) AND subscription.user_id = '" . $this->getUser()->id . "' " ); @@ -322,8 +330,16 @@ class Stream extends \Espo\Core\Services\Base } $where = array( - 'parentType' => $scope, - 'parentId' => $id + 'OR' => array( + array( + 'parentType' => $scope, + 'parentId' => $id + ), + array( + 'superParentType' => $scope, + 'superParentId' => $id + ) + ) ); if (!empty($params['after'])) { @@ -342,6 +358,20 @@ class Stream extends \Espo\Core\Services\Base if ($e->get('type') == 'Post' || $e->get('type') == 'EmailReceived') { $e->loadAttachments(); } + + if ($e->get('parentId') && $e->get('parentType')) { + if ( + ($e->get('parentId') != $id) || + ($e->get('parentType') != $scope) + ) { + $parent = $this->getEntityManager()->getEntity($e->get('parentType'), $e->get('parentId')); + if ($parent) { + $e->set('parentName', $parent->get('name')); + } + } + + } + } unset($where['createdAt>']); diff --git a/frontend/client/src/views/stream/list.js b/frontend/client/src/views/stream/list.js index e8ed50cabe..b171c100d0 100644 --- a/frontend/client/src/views/stream/list.js +++ b/frontend/client/src/views/stream/list.js @@ -36,6 +36,7 @@ Espo.define('Views.Stream.List', 'Views.Record.ListExpanded', function (Dep) { this.createView(key, viewName, { model: model, + parentModel: this.model, acl: { edit: this.getAcl().checkModel(model) }, diff --git a/frontend/client/src/views/stream/note.js b/frontend/client/src/views/stream/note.js index f738e71602..be189e5f12 100644 --- a/frontend/client/src/views/stream/note.js +++ b/frontend/client/src/views/stream/note.js @@ -46,17 +46,32 @@ Espo.define('Views.Stream.Note', 'View', function (Dep) { init: function () { this.createField('createdAt', null, null, 'Fields.DatetimeShort'); this.isUserStream = this.options.isUserStream; + this.isThis = !this.isUserStream; + + this.parentModel = this.options.parentModel; + - if (this.isUserStream) { - this.createField('parent'); - } if (this.messageName) { if (!this.isUserStream) { - this.messageName += 'This'; + if (this.parentModel) { + if ( + this.parentModel.name != this.model.get('parentType') || + this.parentModel.id != this.model.get('parentId') + ) { + this.isThis = false; + } + } + if (this.isThis) { + this.messageName += 'This'; + } } } + if (!this.isThis) { + this.createField('parent'); + } + this.messageData = { 'user': 'field:createdBy', 'entity': 'field:parent', diff --git a/frontend/client/src/views/stream/notes/create.js b/frontend/client/src/views/stream/notes/create.js index aa3640282c..8abf8517e6 100644 --- a/frontend/client/src/views/stream/notes/create.js +++ b/frontend/client/src/views/stream/notes/create.js @@ -17,57 +17,57 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ Espo.define('Views.Stream.Notes.Create', 'Views.Stream.Note', function (Dep) { return Dep.extend({ template: 'stream.notes.create', - + assigned: false, - + messageName: 'create', - + data: function () { return _.extend({ statusText: this.statusText, statusStyle: this.statusStyle }, Dep.prototype.data.call(this)); }, - - setup: function () { - if (this.model.get('data')) { + + setup: function () { + if (this.model.get('data')) { var data = this.model.get('data'); - + this.assignedUserId = data.assignedUserId || null; this.assignedUserName = data.assignedUserName || null; - + this.messageData['assignee'] = '' + this.assignedUserName + ''; - + if (this.assignedUserId) { this.messageName = 'createAssigned'; - if (!this.isUserStream) { - this.messageName += 'This'; + if (this.isThis) { + this.messageName += 'This'; } } - + if (this.isUserStream) { if (this.assignedUserId == this.getUser().id) { this.messageData['assignee'] = this.translate('you'); } - } - + } + if (data.statusField) { var statusField = this.statusField = data.statusField; - var statusValue = data.statusValue; - this.statusStyle = data.statusStyle || 'default'; + var statusValue = data.statusValue; + this.statusStyle = data.statusStyle || 'default'; this.statusText = this.getLanguage().translateOption(statusValue, statusField, this.model.get('parentType')); - } + } } - - this.createMessage(); - }, + + this.createMessage(); + }, }); }); diff --git a/frontend/client/src/views/stream/notes/email-received.js b/frontend/client/src/views/stream/notes/email-received.js index 0c13ed9f5c..e8f881c87b 100644 --- a/frontend/client/src/views/stream/notes/email-received.js +++ b/frontend/client/src/views/stream/notes/email-received.js @@ -60,7 +60,7 @@ Espo.define('Views.Stream.Notes.EmailReceived', 'Views.Stream.Note', function (D this.messageData['from'] = '' + data.personEntityName + ''; } - if (!this.isUserStream) { + if (this.isThis) { this.messageName += 'This'; } diff --git a/frontend/client/src/views/stream/notes/email-sent.js b/frontend/client/src/views/stream/notes/email-sent.js index 420685d86e..3a2729cd2d 100644 --- a/frontend/client/src/views/stream/notes/email-sent.js +++ b/frontend/client/src/views/stream/notes/email-sent.js @@ -54,7 +54,7 @@ Espo.define('Views.Stream.Notes.EmailSent', 'Views.Stream.Note', function (Dep) this.messageData['by'] = '' + data.personEntityName + ''; - if (!this.isUserStream) { + if (this.isThis) { this.messageName += 'This'; } diff --git a/frontend/client/src/views/stream/notes/mention-in-post.js b/frontend/client/src/views/stream/notes/mention-in-post.js index 7ab2e29fb6..de21ed96fa 100644 --- a/frontend/client/src/views/stream/notes/mention-in-post.js +++ b/frontend/client/src/views/stream/notes/mention-in-post.js @@ -17,36 +17,37 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ Espo.define('Views.Stream.Notes.MentionInPost', 'Views.Stream.Note', function (Dep) { return Dep.extend({ - + template: 'stream.notes.post', - + messageName: 'mentionInPost', - - setup: function () { + + setup: function () { if (this.model.get('post')) { this.createField('post', null, null, 'Stream.Fields.Post'); - } + } if ((this.model.get('attachmentsIds') || []).length) { this.createField('attachments', 'attachmentMultiple', {}, 'Stream.Fields.AttachmentMultiple'); } - + var data = this.model.get('data'); - + this.messageData['mentioned'] = this.options.userId; - + if (this.isUserStream) { if (this.options.userId == this.getUser().id) { this.messageData['mentioned'] = this.translate('you'); } } - + this.createMessage(); - }, + } + }); }); diff --git a/frontend/client/src/views/stream/notes/post.js b/frontend/client/src/views/stream/notes/post.js index 2403eeedb8..2ca41dbf57 100644 --- a/frontend/client/src/views/stream/notes/post.js +++ b/frontend/client/src/views/stream/notes/post.js @@ -40,7 +40,7 @@ Espo.define('Views.Stream.Notes.Post', 'Views.Stream.Note', function (Dep) { if (!this.model.get('post')) { this.messageName = 'attach'; - if (!this.isUserStream) { + if (this.isThis) { this.messageName += 'This'; } } diff --git a/frontend/client/src/views/stream/panel.js b/frontend/client/src/views/stream/panel.js index dffffd79a2..34ce3a5747 100644 --- a/frontend/client/src/views/stream/panel.js +++ b/frontend/client/src/views/stream/panel.js @@ -122,6 +122,7 @@ Espo.define('Views.Stream.Panel', ['Views.Record.Panels.Relationship', 'lib!Text this.createView('list', 'Stream.List', { el: this.options.el + ' > .list-container', collection: collection, + model: this.model }, function (view) { view.render(); });