Implement the option to sort the notes. Issue #85

This commit is contained in:
Matias De lellis
2023-06-14 22:42:06 -03:00
parent 8bff0fb364
commit 47a9bdacf2
4 changed files with 56 additions and 9 deletions

View File

@@ -201,6 +201,7 @@ View.prototype = {
updateSort: function() { updateSort: function() {
this._isotope.updateSortData(); this._isotope.updateSortData();
this._isotope.layout(); this._isotope.layout();
this._isotope.arrange({sortBy: ['pinned', getSortBy()]})
}, },
editNote: function (id) { editNote: function (id) {
// Get selected note and sync content // Get selected note and sync content
@@ -306,20 +307,35 @@ View.prototype = {
// Init masonty grid to notes. // Init masonty grid to notes.
if (this._notes.isLoaded() && this._notes.length() > 0) { if (this._notes.isLoaded() && this._notes.length() > 0) {
this._isotope = new Isotope(document.querySelector('.notes-grid'), { this._isotope = new Isotope(document.querySelector('.notes-grid'), {
itemSelector: '.note-grid-item',
layoutMode: 'masonry', layoutMode: 'masonry',
masonry: { masonry: {
isFitWidth: true, isFitWidth: true,
fitWidth: true, fitWidth: true,
gutter: 14, gutter: 14,
}, },
sortBy: 'pinnedNote', itemSelector: '.note-grid-item',
getSortData: { getSortData: {
pinnedNote: function(itemElem) { pinned: function(itemElem) {
return itemElem.firstElementChild.getAttribute('data-pinned');
},
title: function(itemElem) {
var $item = $(itemElem); var $item = $(itemElem);
return $item.find('.icon-pinned').hasClass('fixed-header-icon') ? -1 : $item.index(); return $item.find('.note-title').text().trim();
},
created: function(itemElem) {
return itemElem.firstElementChild.getAttribute('data-id');
},
updated: function(itemElem) {
return itemElem.firstElementChild.getAttribute('data-timestamp');
} }
} },
sortAscending: {
pinned: false,
title: true,
created: true,
updated: false
},
sortBy: ['pinned', getSortBy()]
}); });
this._colorPick = new QnColorPick(".modal-content", function (color) { this._colorPick = new QnColorPick(".modal-content", function (color) {
@@ -407,7 +423,7 @@ View.prototype = {
$('#notes-grid-div').on("click", ".icon-pin", function (event) { $('#notes-grid-div').on("click", ".icon-pin", function (event) {
event.stopPropagation(); event.stopPropagation();
var icon = $(this); var icon = $(this);
var gridNote = icon.parent().parent(); var gridNote = icon.parent().parent();
var id = parseInt(gridNote.attr('data-id'), 10); var id = parseInt(gridNote.attr('data-id'), 10);
@@ -420,6 +436,7 @@ View.prototype = {
icon.removeClass("icon-pin"); icon.removeClass("icon-pin");
icon.addClass("icon-pinned"); icon.addClass("icon-pinned");
icon.attr('title', t('quicknotes', 'Unpin note')); icon.attr('title', t('quicknotes', 'Unpin note'));
gridNote.attr('data-pinned', 1);
self._isotope.updateSortData(); self._isotope.updateSortData();
self._isotope.arrange(); self._isotope.arrange();
}).fail(function () { }).fail(function () {
@@ -431,7 +448,7 @@ View.prototype = {
$('#notes-grid-div').on("click", ".icon-pinned", function (event) { $('#notes-grid-div').on("click", ".icon-pinned", function (event) {
event.stopPropagation(); event.stopPropagation();
var icon = $(this); var icon = $(this);
var gridNote = icon.parent().parent(); var gridNote = icon.parent().parent();
var id = parseInt(gridNote.attr('data-id'), 10); var id = parseInt(gridNote.attr('data-id'), 10);
@@ -443,6 +460,7 @@ View.prototype = {
icon.removeClass("icon-pinned"); icon.removeClass("icon-pinned");
icon.addClass("icon-pin"); icon.addClass("icon-pin");
icon.attr('title', t('quicknotes', 'Pin note')); icon.attr('title', t('quicknotes', 'Pin note'));
gridNote.attr('data-pinned', 0);
self._isotope.updateSortData(); self._isotope.updateSortData();
self._isotope.arrange(); self._isotope.arrange();
}).fail(function () { }).fail(function () {
@@ -761,7 +779,9 @@ View.prototype = {
/* Render view */ /* Render view */
var html = Handlebars.templates['settings']({}); var html = Handlebars.templates['settings']({});
$('#app-settings-content').html(html); $('#app-settings-content').html(html);
var self = this; var self = this;
$.get(OC.generateUrl('apps/quicknotes/getuservalue'), {'type': 'default_color'}) $.get(OC.generateUrl('apps/quicknotes/getuservalue'), {'type': 'default_color'})
.done(function (response) { .done(function (response) {
var color = response.value;; var color = response.value;;
@@ -773,6 +793,9 @@ View.prototype = {
}); });
}); });
let sortBy = getSortBy();
$("#sort-select option[value='" + sortBy + "']").attr("selected", true);
$('#app-settings-content #explicit-save-notes').prop('checked', getExplicitSaveSetting()); $('#app-settings-content #explicit-save-notes').prop('checked', getExplicitSaveSetting());
/* Settings */ /* Settings */
@@ -784,6 +807,12 @@ View.prototype = {
setExplicitSaveSetting($(this).is(':checked')); setExplicitSaveSetting($(this).is(':checked'));
}); });
$('#app-settings-content').on( "change", "#sort-select", function() {
let sortBy = $("#sort-select option:selected")[0].value
self._isotope.arrange({sortBy: ['pinned', sortBy]});
setSortBy(sortBy);
});
$('#app-settings-content').on('click', '.circle-toolbar', function (event) { $('#app-settings-content').on('click', '.circle-toolbar', function (event) {
event.stopPropagation(); event.stopPropagation();
@@ -1165,6 +1194,16 @@ var setExplicitSaveSetting = function (explicit) {
localStorage.setItem('explicit-save', explicit ? 'true' : 'false'); localStorage.setItem('explicit-save', explicit ? 'true' : 'false');
} }
var getSortBy = function () {
var sortBy = localStorage.getItem('quicknotes-sort-by');
if (sortBy === null) return 'title';
return sortBy;
}
var setSortBy = function (sortBy) {
localStorage.setItem('quicknotes-sort-by', sortBy);
}
/** /**
* Get the filter as URL parameter * Get the filter as URL parameter
*/ */

View File

@@ -1,5 +1,5 @@
<div class="note-grid-item"> <div class="note-grid-item">
<div class="quicknote noselect {{#if sharedBy.length}}shared{{/if}} {{#if sharedWith.length}}shareowner{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-timestamp="{{ timestamp }}" > <div class="quicknote noselect {{#if sharedBy.length}}shared{{/if}} {{#if sharedWith.length}}shareowner{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-pinned={{#if isPinned}}1{{else}}0{{/if}} data-timestamp="{{ timestamp }}" >
<div class='note-header'> <div class='note-header'>
<div class='note-attachts'> <div class='note-attachts'>
{{#each attachments}} {{#each attachments}}

View File

@@ -2,7 +2,7 @@
<div id="notes-grid-div" class="notes-grid"> <div id="notes-grid-div" class="notes-grid">
{{#each notes}} {{#each notes}}
<div class="note-grid-item"> <div class="note-grid-item">
<div class="quicknote noselect {{#if sharedBy.length}}shared{{/if}} {{#if sharedWith.length}}shareowner{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-timestamp="{{ timestamp }}" > <div class="quicknote noselect {{#if sharedBy.length}}shared{{/if}} {{#if sharedWith.length}}shareowner{{/if}}" style="background-color: {{color}}" data-id="{{ id }}" data-pinned={{#if isPinned}}1{{else}}0{{/if}} data-timestamp="{{ timestamp }}" >
<div class='note-header'> <div class='note-header'>
<div class='note-attachts'> <div class='note-attachts'>
{{#each attachments}} {{#each attachments}}

View File

@@ -2,6 +2,14 @@
<input id="explicit-save-notes" type="checkbox" class="checkbox"> <input id="explicit-save-notes" type="checkbox" class="checkbox">
<label for="explicit-save-notes">{{t "quicknotes" "When editing notes, show Save and Cancel buttons to save them explicitly"}}</label> <label for="explicit-save-notes">{{t "quicknotes" "When editing notes, show Save and Cancel buttons to save them explicitly"}}</label>
</p> </p>
<div>
<label for="sort-select">{{t "quicknotes" "Sort by:"}}</label>
<select name="sort-select" id="sort-select">
<option value="title">{{t "quicknotes" "Title"}}</option>
<option value="created">{{t "quicknotes" "Newest first"}}</option>
<option value="updated">{{t "quicknotes" "Updated first"}}</option>
</select>
</div>
<div> <div>
<label>{{t "quicknotes" "Default color for new notes"}}</label> <label>{{t "quicknotes" "Default color for new notes"}}</label>
</div> </div>