Sort comments by date and author

This commit is contained in:
Julia Radzhabova 2021-07-06 22:58:36 +03:00
parent a0ee0e909f
commit 79dbe85bdf
7 changed files with 124 additions and 8 deletions

View file

@ -102,7 +102,8 @@ define([
// work handlers // work handlers
'comment:closeEditing': _.bind(this.closeEditing, this) 'comment:closeEditing': _.bind(this.closeEditing, this),
'comment:sort': _.bind(this.setComparator, this)
}, },
'Common.Views.ReviewPopover': { 'Common.Views.ReviewPopover': {
@ -144,10 +145,11 @@ define([
}.bind(this)); }.bind(this));
}, },
onLaunch: function () { onLaunch: function () {
var filter = Common.localStorage.getKeysFilter();
this.appPrefix = (filter && filter.length) ? filter.split(',')[0] : '';
this.collection = this.getApplication().getCollection('Common.Collections.Comments'); this.collection = this.getApplication().getCollection('Common.Collections.Comments');
if (this.collection) { this.setComparator();
this.collection.comparator = function (collection) { return -collection.get('time'); };
}
this.popoverComments = new Common.Collections.Comments(); this.popoverComments = new Common.Collections.Comments();
if (this.popoverComments) { if (this.popoverComments) {
@ -204,6 +206,33 @@ define([
}, },
// //
setComparator: function(type) {
if (this.collection) {
var sort = (type !== undefined);
if (type === undefined) {
type = Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date';
}
Common.localStorage.setItem(this.appPrefix + "comments-sort", type);
Common.Utils.InternalSettings.set(this.appPrefix + "comments-sort", type);
if (type=='position') {
} else if (type=='author') {
this.collection.comparator = function (collection) {
return collection.get('parsedName').toLowerCase();
};
} else { // date
this.collection.comparator = function (collection) {
return -collection.get('time');
};
}
sort && this.updateComments(true);
}
},
getComparator: function() {
return Common.Utils.InternalSettings.get(this.appPrefix + "comments-sort") || 'date';
},
onCreateComment: function (panel, commentVal, editMode, hidereply, documentFlag) { onCreateComment: function (panel, commentVal, editMode, hidereply, documentFlag) {
if (this.api && commentVal && commentVal.length > 0) { if (this.api && commentVal && commentVal.length > 0) {
var comment = buildCommentData(); // new asc_CCommentData(null); var comment = buildCommentData(); // new asc_CCommentData(null);
@ -776,9 +805,11 @@ define([
((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); ((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime())));
var user = this.userCollection.findOriginalUser(data.asc_getUserId()); var user = this.userCollection.findOriginalUser(data.asc_getUserId());
var needSort = (this.getComparator() == 'author') && (data.asc_getUserName() !== comment.get('username'));
comment.set('comment', data.asc_getText()); comment.set('comment', data.asc_getText());
comment.set('userid', data.asc_getUserId()); comment.set('userid', data.asc_getUserId());
comment.set('username', data.asc_getUserName()); comment.set('username', data.asc_getUserName());
comment.set('parsedName', AscCommon.UserInfoParser.getParsedName(data.asc_getUserName()));
comment.set('usercolor', (user) ? user.get('color') : null); comment.set('usercolor', (user) ? user.get('color') : null);
comment.set('resolved', data.asc_getSolved()); comment.set('resolved', data.asc_getSolved());
comment.set('quote', data.asc_getQuoteText()); comment.set('quote', data.asc_getQuoteText());
@ -804,6 +835,7 @@ define([
id : Common.UI.getId(), id : Common.UI.getId(),
userid : data.asc_getReply(i).asc_getUserId(), userid : data.asc_getReply(i).asc_getUserId(),
username : data.asc_getReply(i).asc_getUserName(), username : data.asc_getReply(i).asc_getUserName(),
parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()),
usercolor : (user) ? user.get('color') : null, usercolor : (user) ? user.get('color') : null,
date : t.dateToLocaleTimeString(dateReply), date : t.dateToLocaleTimeString(dateReply),
reply : data.asc_getReply(i).asc_getText(), reply : data.asc_getReply(i).asc_getText(),
@ -825,7 +857,7 @@ define([
} }
if (!silentUpdate) { if (!silentUpdate) {
this.updateComments(false, true); this.updateComments(needSort, !needSort);
// if (this.getPopover() && this.getPopover().isVisible()) { // if (this.getPopover() && this.getPopover().isVisible()) {
// this._dontScrollToComment = true; // this._dontScrollToComment = true;
@ -1089,7 +1121,7 @@ define([
var i, end = true; var i, end = true;
if (_.isUndefined(disableSort)) { if (!disableSort) {
this.collection.sort(); this.collection.sort();
} }
@ -1253,6 +1285,7 @@ define([
guid : data.asc_getGuid(), guid : data.asc_getGuid(),
userid : data.asc_getUserId(), userid : data.asc_getUserId(),
username : data.asc_getUserName(), username : data.asc_getUserName(),
parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getUserName()),
usercolor : (user) ? user.get('color') : null, usercolor : (user) ? user.get('color') : null,
date : this.dateToLocaleTimeString(date), date : this.dateToLocaleTimeString(date),
quote : data.asc_getQuoteText(), quote : data.asc_getQuoteText(),
@ -1299,6 +1332,7 @@ define([
id : Common.UI.getId(), id : Common.UI.getId(),
userid : data.asc_getReply(i).asc_getUserId(), userid : data.asc_getReply(i).asc_getUserId(),
username : data.asc_getReply(i).asc_getUserName(), username : data.asc_getReply(i).asc_getUserName(),
parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()),
usercolor : (user) ? user.get('color') : null, usercolor : (user) ? user.get('color') : null,
date : this.dateToLocaleTimeString(date), date : this.dateToLocaleTimeString(date),
reply : data.asc_getReply(i).asc_getText(), reply : data.asc_getReply(i).asc_getText(),

View file

@ -10,4 +10,8 @@
<button class="btn add normal dlg-btn primary"><%=textAddComment%></button> <button class="btn add normal dlg-btn primary"><%=textAddComment%></button>
<button class="btn cancel normal dlg-btn"><%=textCancel%></button> <button class="btn cancel normal dlg-btn"><%=textCancel%></button>
</div> </div>
<div id="comments-header" class="">
<label><%=textComments%></label>
<div id="comments-btn-sort" style="float:right;"></div>
</div>
</div> </div>

View file

@ -293,6 +293,9 @@ define([
Common.UI.BaseView.prototype.initialize.call(this, options); Common.UI.BaseView.prototype.initialize.call(this, options);
this.store = this.options.store; this.store = this.options.store;
var filter = Common.localStorage.getKeysFilter();
this.appPrefix = (filter && filter.length) ? filter.split(',')[0] : '';
}, },
render: function () { render: function () {
@ -304,7 +307,8 @@ define([
textAddComment: me.textAddComment, textAddComment: me.textAddComment,
textCancel: me.textCancel, textCancel: me.textCancel,
textEnterCommentHint: me.textEnterCommentHint, textEnterCommentHint: me.textEnterCommentHint,
maxCommLength: Asc.c_oAscMaxCellOrCommentLength maxCommLength: Asc.c_oAscMaxCellOrCommentLength,
textComments: me.textComments
})); }));
this.buttonAddCommentToDoc = new Common.UI.Button({ this.buttonAddCommentToDoc = new Common.UI.Button({
@ -321,9 +325,44 @@ define([
enableToggle: false enableToggle: false
}); });
this.buttonSort = new Common.UI.Button({
parentEl: $('#comments-btn-sort', this.$el),
cls: 'btn-toolbar',
iconCls: 'toolbar__icon btn-rotate-270',
hint: this.textSort,
menu: new Common.UI.Menu({
menuAlign: 'tr-br',
style: 'min-width: auto;',
items: [
// {
// caption: this.mniPosition,
// value: 'position',
// checkable: true,
// checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'position',
// toggleGroup: 'sortcomments'
// },
{
caption: this.mniAuthor,
value: 'author',
checkable: true,
checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'author',
toggleGroup: 'sortcomments'
},
{
caption: this.mniDate,
value: 'date',
checkable: true,
checked: (Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date') === 'date',
toggleGroup: 'sortcomments'
}
]
})
});
this.buttonAddCommentToDoc.on('click', _.bind(this.onClickShowBoxDocumentComment, this)); this.buttonAddCommentToDoc.on('click', _.bind(this.onClickShowBoxDocumentComment, this));
this.buttonAdd.on('click', _.bind(this.onClickAddDocumentComment, this)); this.buttonAdd.on('click', _.bind(this.onClickAddDocumentComment, this));
this.buttonCancel.on('click', _.bind(this.onClickCancelDocumentComment, this)); this.buttonCancel.on('click', _.bind(this.onClickCancelDocumentComment, this));
this.buttonSort.menu.on('item:toggle', _.bind(this.onSortClick, this));
this.txtComment = $('#comment-msg-new', this.el); this.txtComment = $('#comment-msg-new', this.el);
this.txtComment.keydown(function (event) { this.txtComment.keydown(function (event) {
@ -730,6 +769,10 @@ define([
}); });
}, },
onSortClick: function(menu, item, state) {
state && this.fireEvent('comment:sort', [item.value]);
},
textComments : 'Comments', textComments : 'Comments',
textAnonym : 'Guest', textAnonym : 'Guest',
textAddCommentToDoc : 'Add Comment to Document', textAddCommentToDoc : 'Add Comment to Document',
@ -744,6 +787,10 @@ define([
textEdit : 'Edit', textEdit : 'Edit',
textAdd : "Add", textAdd : "Add",
textOpenAgain : "Open Again", textOpenAgain : "Open Again",
textHintAddComment : 'Add Comment' textHintAddComment : 'Add Comment',
textSort: 'Sort comments',
mniPosition: 'Sort by Position',
mniAuthor: 'Sort by Authors',
mniDate: 'Sort by Date'
}, Common.Views.Comments || {})) }, Common.Views.Comments || {}))
}); });

View file

@ -7,6 +7,24 @@
display: table-row; display: table-row;
} }
#comments-header {
position: absolute;
height: 45px;
left: 0;
top: 0;
right: 0;
padding: 12px;
overflow: hidden;
border-bottom: @scaled-one-px-value-ie solid @border-toolbar-ie;
border-bottom: @scaled-one-px-value solid @border-toolbar;
label {
font-size: 12px;
font-weight: bold;
margin-top: 2px;
}
}
.messages-ct { .messages-ct {
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
@ -14,6 +32,7 @@
right: 0; right: 0;
bottom: 45px; bottom: 45px;
height: 300px; height: 300px;
padding-top: 45px;
border-bottom: @scaled-one-px-value-ie solid @border-toolbar-ie; border-bottom: @scaled-one-px-value-ie solid @border-toolbar-ie;
border-bottom: @scaled-one-px-value solid @border-toolbar; border-bottom: @scaled-one-px-value solid @border-toolbar;

View file

@ -246,6 +246,10 @@
"Common.Views.Comments.textReply": "Reply", "Common.Views.Comments.textReply": "Reply",
"Common.Views.Comments.textResolve": "Resolve", "Common.Views.Comments.textResolve": "Resolve",
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors",
"Common.Views.Comments.mniDate": "Sort by Date",
"Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "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.<br><br>To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "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.<br><br>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", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions",

View file

@ -139,6 +139,10 @@
"Common.Views.Comments.textReply": "Reply", "Common.Views.Comments.textReply": "Reply",
"Common.Views.Comments.textResolve": "Resolve", "Common.Views.Comments.textResolve": "Resolve",
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors",
"Common.Views.Comments.mniDate": "Sort by Date",
"Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "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.<br><br>To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "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.<br><br>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", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions",

View file

@ -187,6 +187,10 @@
"Common.Views.Comments.textReply": "Reply", "Common.Views.Comments.textReply": "Reply",
"Common.Views.Comments.textResolve": "Resolve", "Common.Views.Comments.textResolve": "Resolve",
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors",
"Common.Views.Comments.mniDate": "Sort by Date",
"Common.Views.CopyWarningDialog.textDontShow": "Don't show this message again", "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.<br><br>To copy or paste to or from applications outside the editor tab use the following keyboard combinations:", "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.<br><br>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", "Common.Views.CopyWarningDialog.textTitle": "Copy, Cut and Paste Actions",