Bug 42150: add sort direction

This commit is contained in:
Julia Radzhabova 2021-07-12 00:30:52 +03:00
parent 88d883163e
commit cc271cd723
5 changed files with 47 additions and 20 deletions

View file

@ -210,19 +210,24 @@ define([
if (this.collection) { if (this.collection) {
var sort = (type !== undefined); var sort = (type !== undefined);
if (type === undefined) { if (type === undefined) {
type = Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date'; type = Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date-desc';
} }
Common.localStorage.setItem(this.appPrefix + "comments-sort", type); Common.localStorage.setItem(this.appPrefix + "comments-sort", type);
Common.Utils.InternalSettings.set(this.appPrefix + "comments-sort", type); Common.Utils.InternalSettings.set(this.appPrefix + "comments-sort", type);
if (type=='position') { if (type=='position') {
} else if (type=='author') { } else if (type=='author-asc' || type=='author-desc') {
this.collection.comparator = function (collection) { var direction = (type=='author-asc') ? 1 : -1;
return collection.get('parsedName').toLowerCase(); this.collection.comparator = function(item1, item2) {
var n1 = item1.get('parsedName').toLowerCase(),
n2 = item2.get('parsedName').toLowerCase();
if (n1==n2) return 0;
return (n1<n2) ? -direction : direction;
}; };
} else { // date } else { // date
var direction = (type=='date-asc') ? 1 : -1;
this.collection.comparator = function (collection) { this.collection.comparator = function (collection) {
return -collection.get('time'); return direction * collection.get('time');
}; };
} }
sort && this.updateComments(true); sort && this.updateComments(true);
@ -805,7 +810,7 @@ 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')); var needSort = (this.getComparator() == 'author-asc' || this.getComparator() == 'author-desc') && (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());

View file

@ -342,17 +342,31 @@ define([
// toggleGroup: 'sortcomments' // toggleGroup: 'sortcomments'
// }, // },
{ {
caption: this.mniAuthor, caption: this.mniDateDesc,
value: 'author', value: 'date-desc',
checkable: true, checkable: true,
checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'author', checked: (Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date-desc') === 'date-desc',
toggleGroup: 'sortcomments' toggleGroup: 'sortcomments'
}, },
{ {
caption: this.mniDate, caption: this.mniDateAsc,
value: 'date', value: 'date-asc',
checkable: true, checkable: true,
checked: (Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date') === 'date', checked: (Common.localStorage.getItem(this.appPrefix + "comments-sort") || 'date-desc') === 'date-asc',
toggleGroup: 'sortcomments'
},
{
caption: this.mniAuthorAsc,
value: 'author-asc',
checkable: true,
checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'author-asc',
toggleGroup: 'sortcomments'
},
{
caption: this.mniAuthorDesc,
value: 'author-desc',
checkable: true,
checked: Common.localStorage.getItem(this.appPrefix + "comments-sort") === 'author-desc',
toggleGroup: 'sortcomments' toggleGroup: 'sortcomments'
} }
] ]
@ -805,8 +819,10 @@ define([
textHintAddComment : 'Add Comment', textHintAddComment : 'Add Comment',
textSort: 'Sort comments', textSort: 'Sort comments',
mniPosition: 'Sort by Position', mniPosition: 'Sort by Position',
mniAuthor: 'Sort by Authors', mniAuthorAsc: 'Sort by Author A to Z',
mniDate: 'Sort by Date', mniAuthorDesc: 'Sort by Author Z to A',
mniDateDesc: 'Sort by Newest',
mniDateAsc: 'Sort by Oldest',
textClosePanel: 'Close comments' textClosePanel: 'Close comments'
}, Common.Views.Comments || {})) }, Common.Views.Comments || {}))
}); });

View file

@ -248,8 +248,10 @@
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position", "Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors", "Common.Views.Comments.mniAuthorAsc": "Sort by Author A to Z",
"Common.Views.Comments.mniDate": "Sort by Date", "Common.Views.Comments.mniAuthorDesc": "Sort by Author Z to A",
"Common.Views.Comments.mniDateDesc": "Sort by Newest",
"Common.Views.Comments.mniDateAsc": "Sort by Oldest",
"Common.Views.Comments.textClosePanel": "Close comments", "Common.Views.Comments.textClosePanel": "Close comments",
"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:",

View file

@ -141,8 +141,10 @@
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position", "Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors", "Common.Views.Comments.mniAuthorAsc": "Sort by Author A to Z",
"Common.Views.Comments.mniDate": "Sort by Date", "Common.Views.Comments.mniAuthorDesc": "Sort by Author Z to A",
"Common.Views.Comments.mniDateDesc": "Sort by Newest",
"Common.Views.Comments.mniDateAsc": "Sort by Oldest",
"Common.Views.Comments.textClosePanel": "Close comments", "Common.Views.Comments.textClosePanel": "Close comments",
"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:",

View file

@ -189,8 +189,10 @@
"Common.Views.Comments.textResolved": "Resolved", "Common.Views.Comments.textResolved": "Resolved",
"Common.Views.Comments.textSort": "Sort comments", "Common.Views.Comments.textSort": "Sort comments",
"Common.Views.Comments.mniPosition": "Sort by Position", "Common.Views.Comments.mniPosition": "Sort by Position",
"Common.Views.Comments.mniAuthor": "Sort by Authors", "Common.Views.Comments.mniAuthorAsc": "Sort by Author A to Z",
"Common.Views.Comments.mniDate": "Sort by Date", "Common.Views.Comments.mniAuthorDesc": "Sort by Author Z to A",
"Common.Views.Comments.mniDateDesc": "Sort by Newest",
"Common.Views.Comments.mniDateAsc": "Sort by Oldest",
"Common.Views.Comments.textClosePanel": "Close comments", "Common.Views.Comments.textClosePanel": "Close comments",
"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:",