diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 3ce2ccf3f2..65bcb0e228 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(); @@ -695,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.get('filtered')) { + 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(); @@ -820,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()); @@ -830,6 +834,14 @@ 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())); + 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')); replies.length = 0; @@ -1148,14 +1160,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.get('filtered')) { + 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(); @@ -1306,6 +1319,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(), @@ -1329,6 +1343,13 @@ define([ groupName : (groupname && groupname.length>1) ? groupname[1] : null }); if (comment) { + 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); @@ -1639,6 +1660,64 @@ define([ clearCollections: function() { this.collection.reset(); this.groupCollection = []; + }, + + fillUserGroups: function(usergroups) { + if (!this.mode.canUseCommentPermissions) return; + + var 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); + 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 fbe2664748..9c570db916 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 : '', @@ -79,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) { %>
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",