From d0f3011e6cba8682a8c8d90d5a713df0743c3f5e Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 24 Nov 2021 21:21:24 +0300 Subject: [PATCH 1/4] [Comments] Fill user groups --- apps/common/main/lib/controller/Comments.js | 50 ++++++++++++++++++++- apps/common/main/lib/view/Comments.js | 25 ++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 3ce2ccf3f2..bb103b0c69 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -103,7 +103,8 @@ define([ // work handlers 'comment:closeEditing': _.bind(this.closeEditing, this), - 'comment:sort': _.bind(this.setComparator, this) + 'comment:sort': _.bind(this.setComparator, this), + 'comment:filtergroups': _.bind(this.setFilterGroups, this) }, 'Common.Views.ReviewPopover': { @@ -157,6 +158,7 @@ define([ } this.groupCollection = []; + this.userGroups = []; // for filtering comments this.view = this.createView('Common.Views.Comments', { store: this.collection }); this.view.render(); @@ -830,6 +832,8 @@ define([ comment.set('removable', (t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName())); comment.set('hide', !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName())); + !comment.get('hide') && t.fillUserGroups(data.asc_getUserName()); + replies = _.clone(comment.get('replys')); replies.length = 0; @@ -1329,6 +1333,7 @@ define([ groupName : (groupname && groupname.length>1) ? groupname[1] : null }); if (comment) { + !comment.get('hide') && this.fillUserGroups(data.asc_getUserName()); var replies = this.readSDKReplies(data); if (replies.length) { comment.set('replys', replies); @@ -1639,6 +1644,49 @@ define([ clearCollections: function() { this.collection.reset(); this.groupCollection = []; + }, + + fillUserGroups: function(username) { + if (!this.mode.canUseCommentPermissions) return; + + var usergroups = AscCommon.UserInfoParser.getParsedGroups(username), + viewgroups = AscCommon.UserInfoParser.getCommentPermissions('view'); + if (usergroups && usergroups.length>0) { + if (viewgroups) { + usergroups = _.intersection(usergroups, viewgroups); + usergroups = _.uniq(this.userGroups.concat(usergroups)); + } + } + if (this.view && this.view.buttonSort && _.difference(usergroups, this.userGroups).length>0) { + this.userGroups = usergroups; + var menu = this.view.buttonSort.menu; + menu.items[menu.items.length-1].setVisible(this.userGroups.length>0); + menu.items[menu.items.length-2].setVisible(this.userGroups.length>0); + menu = menu.items[menu.items.length-1].menu; + menu.removeAll(); + + var last = Common.Utils.InternalSettings.get(this.appPrefix + "comments-filtergroups"); + menu.addItem(new Common.UI.MenuItem({ + checkable: true, + checked: last===-1 || last===undefined, + toggleGroup: 'filtercomments', + caption: this.view.textAll, + value: -1 + })); + this.userGroups.forEach(function(item){ + menu.addItem(new Common.UI.MenuItem({ + checkable: true, + checked: last === item, + toggleGroup: 'filtercomments', + caption: Common.Utils.String.htmlEncode(item), + value: item + })); + }); + } + }, + + setFilterGroups: function (group) { + Common.Utils.InternalSettings.set(this.appPrefix + "comments-filtergroups", group) } }, Common.Controllers.Comments || {})); diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index 99f8dd3f79..c7811026b6 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -377,7 +377,21 @@ define([ visible: this.appPrefix==='de-', checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'position-desc', toggleGroup: 'sortcomments' - } + }, + { + caption: '--', + visible: false + }, + this.menuFilterGroups = new Common.UI.MenuItem({ + caption: this.mniFilterGroups, + checkable: false, + visible: false, + menu: new Common.UI.Menu({ + menuAlign: 'tl-tr', + style: 'min-width: auto;', + items: [] + }) + }) ] }) }); @@ -394,6 +408,7 @@ define([ this.buttonCancel.on('click', _.bind(this.onClickCancelDocumentComment, this)); this.buttonClose.on('click', _.bind(this.onClickClosePanel, this)); this.buttonSort.menu.on('item:toggle', _.bind(this.onSortClick, this)); + this.menuFilterGroups.on('item:toggle', _.bind(this.onFilterGroupsClick, this)); this.txtComment = $('#comment-msg-new', this.el); this.txtComment.keydown(function (event) { @@ -812,6 +827,10 @@ define([ state && this.fireEvent('comment:sort', [item.value]); }, + onFilterGroupsClick: function(menu, item, state) { + state && this.fireEvent('comment:filtergroups', [item.value]); + }, + onClickClosePanel: function() { Common.NotificationCenter.trigger('leftmenu:change', 'hide'); }, @@ -839,6 +858,8 @@ define([ mniDateDesc: 'Newest', mniDateAsc: 'Oldest', textClosePanel: 'Close comments', - textViewResolved: 'You have not permission for reopen comment' + textViewResolved: 'You have not permission for reopen comment', + mniFilterGroups: 'Filter by Group', + textAll: 'All' }, Common.Views.Comments || {})) }); \ No newline at end of file From 5995a0045a5c203006ae3d731b6440e01a770dda Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Nov 2021 00:43:25 +0300 Subject: [PATCH 2/4] [Comments] Fix sort --- apps/common/main/lib/controller/Comments.js | 39 +++++++++++---------- apps/common/main/lib/model/Comment.js | 1 + 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index bb103b0c69..162902da17 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -697,14 +697,15 @@ define([ var end = true; for (var i = this.collection.length - 1; i >= 0; --i) { - if (end) { - this.collection.at(i).set('last', true, {silent: true}); + var item = this.collection.at(i); + if (end && !item.get('hide')) { + item.set('last', true, {silent: true}); + end = false; } else { - if (this.collection.at(i).get('last')) { - this.collection.at(i).set('last', false, {silent: true}); + if (item.get('last')) { + item.set('last', false, {silent: true}); } } - end = false; } this.view.render(); this.view.update(); @@ -822,6 +823,7 @@ define([ comment.set('userid', data.asc_getUserId()); comment.set('username', data.asc_getUserName()); comment.set('parsedName', AscCommon.UserInfoParser.getParsedName(data.asc_getUserName())); + comment.set('parsedGroups', AscCommon.UserInfoParser.getParsedGroups(data.asc_getUserName())); comment.set('usercolor', (user) ? user.get('color') : null); comment.set('resolved', data.asc_getSolved()); comment.set('quote', data.asc_getQuoteText()); @@ -832,7 +834,7 @@ define([ comment.set('removable', (t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName())); comment.set('hide', !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName())); - !comment.get('hide') && t.fillUserGroups(data.asc_getUserName()); + !comment.get('hide') && t.fillUserGroups(comment.get('parsedGroups')); replies = _.clone(comment.get('replys')); @@ -1152,14 +1154,15 @@ define([ this.onUpdateFilter(this.filter, true); for (i = this.collection.length - 1; i >= 0; --i) { - if (end) { - this.collection.at(i).set('last', true, {silent: true}); + var item = this.collection.at(i); + if (end && !item.get('hide')) { + item.set('last', true, {silent: true}); + end = false; } else { - if (this.collection.at(i).get('last')) { - this.collection.at(i).set('last', false, {silent: true}); + if (item.get('last')) { + item.set('last', false, {silent: true}); } } - end = false; } this.view.render(); @@ -1310,6 +1313,7 @@ define([ userid : data.asc_getUserId(), username : data.asc_getUserName(), parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getUserName()), + parsedGroups : AscCommon.UserInfoParser.getParsedGroups(data.asc_getUserName()), usercolor : (user) ? user.get('color') : null, date : this.dateToLocaleTimeString(date), quote : data.asc_getQuoteText(), @@ -1333,7 +1337,7 @@ define([ groupName : (groupname && groupname.length>1) ? groupname[1] : null }); if (comment) { - !comment.get('hide') && this.fillUserGroups(data.asc_getUserName()); + !comment.get('hide') && this.fillUserGroups(comment.get('parsedGroups')); var replies = this.readSDKReplies(data); if (replies.length) { comment.set('replys', replies); @@ -1646,16 +1650,14 @@ define([ this.groupCollection = []; }, - fillUserGroups: function(username) { + fillUserGroups: function(usergroups) { if (!this.mode.canUseCommentPermissions) return; - var usergroups = AscCommon.UserInfoParser.getParsedGroups(username), - viewgroups = AscCommon.UserInfoParser.getCommentPermissions('view'); + var viewgroups = AscCommon.UserInfoParser.getCommentPermissions('view'); if (usergroups && usergroups.length>0) { - if (viewgroups) { + if (viewgroups) usergroups = _.intersection(usergroups, viewgroups); - usergroups = _.uniq(this.userGroups.concat(usergroups)); - } + usergroups = _.uniq(this.userGroups.concat(usergroups)); } if (this.view && this.view.buttonSort && _.difference(usergroups, this.userGroups).length>0) { this.userGroups = usergroups; @@ -1687,6 +1689,7 @@ define([ setFilterGroups: function (group) { Common.Utils.InternalSettings.set(this.appPrefix + "comments-filtergroups", group) + } }, Common.Controllers.Comments || {})); diff --git a/apps/common/main/lib/model/Comment.js b/apps/common/main/lib/model/Comment.js index fbe2664748..c9cafa1f7d 100644 --- a/apps/common/main/lib/model/Comment.js +++ b/apps/common/main/lib/model/Comment.js @@ -57,6 +57,7 @@ define([ userid : 0, username : 'Guest', parsedName : 'Guest', + parsedGroups : undefined, usercolor : null, date : undefined, quote : '', From 83b2ef677b961d28bd09840e2937cbc7d3c0c916 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Nov 2021 01:39:43 +0300 Subject: [PATCH 3/4] [Comments] Filter comments by group --- apps/common/main/lib/controller/Comments.js | 40 ++++++++++++++++--- apps/common/main/lib/model/Comment.js | 1 + .../main/lib/template/Comments.template | 2 +- apps/common/main/lib/view/Comments.js | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 162902da17..65bcb0e228 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -698,7 +698,7 @@ define([ var end = true; for (var i = this.collection.length - 1; i >= 0; --i) { var item = this.collection.at(i); - if (end && !item.get('hide')) { + if (end && !item.get('hide') && !item.get('filtered')) { item.set('last', true, {silent: true}); end = false; } else { @@ -834,7 +834,13 @@ define([ comment.set('removable', (t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName())); comment.set('hide', !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName())); - !comment.get('hide') && t.fillUserGroups(comment.get('parsedGroups')); + if (!comment.get('hide')) { + var usergroups = comment.get('parsedGroups'); + t.fillUserGroups(usergroups); + var group = Common.Utils.InternalSettings.get(t.appPrefix + "comments-filtergroups"); + var filter = !!group && (group!==-1) && (!usergroups || usergroups.length<1 || usergroups.indexOf(group)<0); + comment.set('filtered', filter); + } replies = _.clone(comment.get('replys')); @@ -1155,7 +1161,7 @@ define([ for (i = this.collection.length - 1; i >= 0; --i) { var item = this.collection.at(i); - if (end && !item.get('hide')) { + if (end && !item.get('hide') && !item.get('filtered')) { item.set('last', true, {silent: true}); end = false; } else { @@ -1337,7 +1343,13 @@ define([ groupName : (groupname && groupname.length>1) ? groupname[1] : null }); if (comment) { - !comment.get('hide') && this.fillUserGroups(comment.get('parsedGroups')); + if (!comment.get('hide')) { + var usergroups = comment.get('parsedGroups'); + this.fillUserGroups(usergroups); + var group = Common.Utils.InternalSettings.get(this.appPrefix + "comments-filtergroups"); + var filter = !!group && (group!==-1) && (!usergroups || usergroups.length<1 || usergroups.indexOf(group)<0); + comment.set('filtered', filter); + } var replies = this.readSDKReplies(data); if (replies.length) { comment.set('replys', replies); @@ -1688,8 +1700,24 @@ define([ }, setFilterGroups: function (group) { - Common.Utils.InternalSettings.set(this.appPrefix + "comments-filtergroups", group) - + Common.Utils.InternalSettings.set(this.appPrefix + "comments-filtergroups", group); + var i, end = true; + for (i = this.collection.length - 1; i >= 0; --i) { + var item = this.collection.at(i); + if (!item.get('hide')) { + var usergroups = item.get('parsedGroups'); + item.set('filtered', !!group && (group!==-1) && (!usergroups || usergroups.length<1 || usergroups.indexOf(group)<0), {silent: true}); + } + if (end && !item.get('hide') && !item.get('filtered')) { + item.set('last', true, {silent: true}); + end = false; + } else { + if (item.get('last')) { + item.set('last', false, {silent: true}); + } + } + } + this.updateComments(true); } }, Common.Controllers.Comments || {})); diff --git a/apps/common/main/lib/model/Comment.js b/apps/common/main/lib/model/Comment.js index c9cafa1f7d..9c570db916 100644 --- a/apps/common/main/lib/model/Comment.js +++ b/apps/common/main/lib/model/Comment.js @@ -80,6 +80,7 @@ define([ hideAddReply : false, scope : null, hide : false, + filtered : false, hint : false, dummy : undefined, editable : true, diff --git a/apps/common/main/lib/template/Comments.template b/apps/common/main/lib/template/Comments.template index 5e6440929a..165196d6f8 100644 --- a/apps/common/main/lib/template/Comments.template +++ b/apps/common/main/lib/template/Comments.template @@ -1,4 +1,4 @@ -<% if (!hide) { %> +<% if (!hide && !filtered) { %>
diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index c7811026b6..d3fefb8347 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -408,7 +408,7 @@ define([ this.buttonCancel.on('click', _.bind(this.onClickCancelDocumentComment, this)); this.buttonClose.on('click', _.bind(this.onClickClosePanel, this)); this.buttonSort.menu.on('item:toggle', _.bind(this.onSortClick, this)); - this.menuFilterGroups.on('item:toggle', _.bind(this.onFilterGroupsClick, this)); + this.menuFilterGroups.menu.on('item:toggle', _.bind(this.onFilterGroupsClick, this)); this.txtComment = $('#comment-msg-new', this.el); this.txtComment.keydown(function (event) { From 033a57d418a77337052b8e9c28fa89b7aba1a3c4 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Nov 2021 18:17:37 +0300 Subject: [PATCH 4/4] Add translation --- apps/documenteditor/main/locale/en.json | 2 ++ apps/presentationeditor/main/locale/en.json | 2 ++ apps/spreadsheeteditor/main/locale/en.json | 2 ++ 3 files changed, 6 insertions(+) diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 33efb8c9c3..3dc8b42542 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -259,6 +259,8 @@ "Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textViewResolved": "You have not permission for reopen comment", + "Common.Views.Comments.mniFilterGroups": "Filter by Group", + "Common.Views.Comments.textAll": "All", "Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "Common.Views.CopyWarningDialog.textMsg": "Copy, cut and paste actions using the editor toolbar buttons and context menu actions will be performed within this editor tab only.

To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions", diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index a08e80504c..1b6e6efe24 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -152,6 +152,8 @@ "Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textViewResolved": "You have not permission for reopen comment", + "Common.Views.Comments.mniFilterGroups": "Filter by Group", + "Common.Views.Comments.textAll": "All", "Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "Common.Views.CopyWarningDialog.textMsg": "Copy, cut and paste actions using the editor toolbar buttons and context menu actions will be performed within this editor tab only.

To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions", diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index babc9a8124..b2b5fa6d18 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -200,6 +200,8 @@ "Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textViewResolved": "You have not permission for reopen comment", + "Common.Views.Comments.mniFilterGroups": "Filter by Group", + "Common.Views.Comments.textAll": "All", "Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "Common.Views.CopyWarningDialog.textMsg": "Copy, cut and paste actions using the editor toolbar buttons and context menu actions will be performed within this editor tab only.

To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions",