Skip to content

Commit 2cfcae6

Browse files
committed
Support pinning note in history
1 parent 5ed3951 commit 2cfcae6

3 files changed

Lines changed: 85 additions & 7 deletions

File tree

public/css/cover.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ input {
257257
.ui-history-close:hover {
258258
opacity: 1;
259259
}
260+
.ui-history-pin {
261+
position: absolute;
262+
left: 14px;
263+
top: 15px;
264+
font-size: 16px;
265+
opacity: 0.2;
266+
transition: opacity 0.2s ease-in-out;
267+
-webkit-transition: opacity 0.2s ease-in-out;
268+
}
269+
.item:hover .ui-history-pin:hover {
270+
opacity: 1;
271+
}
272+
.item .ui-history-pin.active {
273+
opacity: 1;
274+
color: #d43f3a;
275+
}
260276
.ui-or {
261277
margin-top: 5px;
262278
margin-bottom: 5px;

public/js/cover.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var options = {
2-
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags'],
2+
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
33
item: '<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">\
44
<span class="id" style="display:none;"></span>\
55
<a href="#">\
66
<div class="item">\
7+
<div class="ui-history-pin fa fa-thumb-tack fa-fw"></div>\
78
<div class="ui-history-close fa fa-close fa-fw" data-toggle="modal" data-target=".delete-modal"></div>\
89
<div class="content">\
910
<h4 class="text"></h4>\
@@ -83,17 +84,41 @@ function checkHistoryList() {
8384

8485
function parseHistoryCallback(list, notehistory) {
8586
checkHistoryList();
86-
list.sort('timestamp', {
87-
order: "desc"
88-
});
87+
//sort by pinned then timestamp
88+
list.sort('', {
89+
sortFunction: function (a, b) {
90+
var notea = a.values();
91+
var noteb = b.values();
92+
if (notea.pinned && !noteb.pinned) {
93+
return -1;
94+
} else if (!notea.pinned && noteb.pinned) {
95+
return 1;
96+
} else {
97+
if (notea.timestamp > noteb.timestamp) {
98+
return -1;
99+
} else if (notea.timestamp < noteb.timestamp) {
100+
return 1;
101+
} else {
102+
return 0;
103+
}
104+
}
105+
}
106+
});
89107
var filtertags = [];
90108
$(".item").each(function (key, value) {
91109
var a = $(this).closest("a");
110+
var pin = $(this).find(".ui-history-pin");
92111
var id = a.siblings("span").html();
93112
var tagsEl = $(this).find(".tags");
94113
var item = historyList.get('id', id);
95114
if (item.length > 0 && item[0]) {
96115
var values = item[0].values();
116+
//parse pinned
117+
if (values.pinned) {
118+
pin.addClass('active');
119+
} else {
120+
pin.removeClass('active');
121+
}
97122
//parse link to element a
98123
a.attr('href', '/' + values.id);
99124
//parse tags
@@ -124,6 +149,34 @@ function parseHistoryCallback(list, notehistory) {
124149
$('.ui-delete-modal-item').html('<i class="fa fa-file-text"></i> ' + value.text + '<br><i class="fa fa-clock-o"></i> ' + value.time);
125150
clearHistory = false;
126151
deleteId = id;
152+
});
153+
$(".ui-history-pin").click(function (e) {
154+
e.preventDefault();
155+
var $this = $(this);
156+
var id = $this.closest("a").siblings("span").html();
157+
var item = list.get('id', id)[0];
158+
var values = item.values();
159+
var pinned = values.pinned;
160+
if (!values.pinned) {
161+
pinned = true;
162+
item._values.pinned = true;
163+
} else {
164+
pinned = false;
165+
item._values.pinned = false;
166+
}
167+
getHistory(function (notehistory) {
168+
for(var i = 0; i < notehistory.length; i++) {
169+
if (notehistory[i].id == id) {
170+
notehistory[i].pinned = pinned;
171+
break;
172+
}
173+
}
174+
saveHistory(notehistory);
175+
if (pinned)
176+
$this.addClass('active');
177+
else
178+
$this.removeClass('active');
179+
});
127180
});
128181
buildTagsFilter(filtertags);
129182
}

public/js/history.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ function clearDuplicatedHistory(notehistory) {
111111
return newnotehistory;
112112
}
113113

114-
function addHistory(id, text, time, tags, notehistory) {
114+
function addHistory(id, text, time, tags, pinned, notehistory) {
115115
notehistory.push({
116116
id: id,
117117
text: text,
118118
time: time,
119-
tags: tags
119+
tags: tags,
120+
pinned: pinned
120121
});
121122
return notehistory;
122123
}
@@ -232,8 +233,16 @@ function renderHistory(view) {
232233

233234
function generateHistory(view, notehistory) {
234235
var info = renderHistory(view);
236+
//keep any pinned data
237+
var pinned = false;
238+
for (var i = 0; i < notehistory.length; i++) {
239+
if (notehistory[i].id == info.id && notehistory[i].pinned) {
240+
pinned = true;
241+
break;
242+
}
243+
}
235244
notehistory = removeHistory(info.id, notehistory);
236-
notehistory = addHistory(info.id, info.text, info.time, info.tags, notehistory);
245+
notehistory = addHistory(info.id, info.text, info.time, info.tags, pinned, notehistory);
237246
notehistory = clearDuplicatedHistory(notehistory);
238247
return notehistory;
239248
}

0 commit comments

Comments
 (0)