2018-03-25 13:41:29 -04:00
|
|
|
import linkService from '../services/link.js';
|
2018-03-25 13:02:39 -04:00
|
|
|
import utils from '../services/utils.js';
|
2018-03-25 14:49:20 -04:00
|
|
|
import server from '../services/server.js';
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
const $dialog = $("#recent-changes-dialog");
|
2018-11-06 17:47:40 +01:00
|
|
|
const $content = $("#recent-changes-content");
|
2017-11-04 17:03:15 -04:00
|
|
|
|
2019-08-20 21:40:47 +02:00
|
|
|
export async function showDialog() {
|
2019-06-10 22:45:03 +02:00
|
|
|
utils.closeActiveDialog();
|
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
glob.activeDialog = $dialog;
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-11-06 17:47:40 +01:00
|
|
|
$dialog.modal();
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-11-06 17:47:40 +01:00
|
|
|
const result = await server.get('recent-changes');
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-11-06 17:47:40 +01:00
|
|
|
$content.empty();
|
2018-08-18 15:21:44 +02:00
|
|
|
|
|
|
|
if (result.length === 0) {
|
2018-11-06 17:47:40 +01:00
|
|
|
$content.append("No changes yet ...");
|
2018-08-18 15:21:44 +02:00
|
|
|
}
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
const groupedByDate = groupByDate(result);
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
for (const [dateDay, dayChanges] of groupedByDate) {
|
|
|
|
const changesListEl = $('<ul>');
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
const dayEl = $('<div>').append($('<b>').html(utils.formatDate(dateDay))).append(changesListEl);
|
2017-10-06 22:46:30 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
for (const change of dayChanges) {
|
2019-03-12 20:58:31 +01:00
|
|
|
const formattedTime = utils.formatTime(utils.parseDate(change.utcDateModifiedTo));
|
2017-11-04 11:32:05 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
let noteLink;
|
2017-12-03 17:46:56 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
if (change.current_isDeleted) {
|
|
|
|
noteLink = change.current_title;
|
2017-11-04 13:39:26 -04:00
|
|
|
}
|
|
|
|
else {
|
2018-04-19 20:59:44 -04:00
|
|
|
noteLink = await linkService.createNoteLink(change.noteId, change.title);
|
2017-11-04 13:39:26 -04:00
|
|
|
}
|
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
changesListEl.append($('<li>')
|
|
|
|
.append(formattedTime + ' - ')
|
2018-11-06 17:47:40 +01:00
|
|
|
.append(noteLink));
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
|
|
|
|
2018-11-06 17:47:40 +01:00
|
|
|
$content.append(dayEl);
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function groupByDate(result) {
|
|
|
|
const groupedByDate = new Map();
|
|
|
|
const dayCache = {};
|
|
|
|
|
|
|
|
for (const row of result) {
|
2019-03-12 20:58:31 +01:00
|
|
|
let dateDay = utils.parseDate(row.utcDateModifiedTo);
|
2018-03-25 11:09:17 -04:00
|
|
|
dateDay.setHours(0);
|
|
|
|
dateDay.setMinutes(0);
|
|
|
|
dateDay.setSeconds(0);
|
|
|
|
dateDay.setMilliseconds(0);
|
|
|
|
|
|
|
|
// this stupidity is to make sure that we always use the same day object because Map uses only
|
|
|
|
// reference equality
|
|
|
|
if (dayCache[dateDay]) {
|
|
|
|
dateDay = dayCache[dateDay];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dayCache[dateDay] = dateDay;
|
|
|
|
}
|
2017-11-04 13:39:26 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
if (!groupedByDate.has(dateDay)) {
|
|
|
|
groupedByDate.set(dateDay, []);
|
2017-11-04 11:32:05 -04:00
|
|
|
}
|
2018-03-25 11:09:17 -04:00
|
|
|
|
|
|
|
groupedByDate.get(dateDay).push(row);
|
2017-11-04 11:32:05 -04:00
|
|
|
}
|
2018-03-25 11:09:17 -04:00
|
|
|
return groupedByDate;
|
|
|
|
}
|