Group by 'userlist' in history

pull/1/head
yflory 4 years ago
parent 74577b54e4
commit 3c5eed5939

@ -695,6 +695,7 @@ define([
onLocal: onLocal, onLocal: onLocal,
onRemote: onRemote, onRemote: onRemote,
setHistory: setHistoryMode, setHistory: setHistoryMode,
extractMetadata: extractMetadata,
applyVal: function (val) { applyVal: function (val) {
var newContent = JSON.parse(val); var newContent = JSON.parse(val);
var meta = extractMetadata(newContent); var meta = extractMetadata(newContent);

@ -108,7 +108,6 @@ define([
var states = []; var states = [];
var c = 0;//states.length - 1; var c = 0;//states.length - 1;
var semantic = false;
var $hist = $toolbar.find('.cp-toolbar-history'); var $hist = $toolbar.find('.cp-toolbar-history');
var $bottom = $toolbar.find('.cp-toolbar-bottom'); var $bottom = $toolbar.find('.cp-toolbar-bottom');
@ -166,8 +165,24 @@ define([
var getRank = function (idx) { var getRank = function (idx) {
return idx - states.length + 1; return idx - states.length + 1;
}; };
var getAuthor = function (idx, semantic) {
if (semantic === 1 || !config.extractMetadata) {
return states[idx].author;
}
try {
var val = JSON.parse(states[idx].getContent().doc);
var md = config.extractMetadata(val);
var users = Object.keys(md.users).sort();
return users.join();
} catch (e) {
console.error(e);
return states[idx].author;
}
};
get = function (i, blockOnly) { // semantic === 1 : group by user
// semantic === 2 : group by "group of users"
get = function (i, blockOnly, semantic) {
i = parseInt(i); i = parseInt(i);
if (isNaN(i)) { return; } if (isNaN(i)) { return; }
if (i > 0) { i = 0; } if (i > 0) { i = 0; }
@ -179,11 +194,11 @@ define([
var idx = getIndex(i); var idx = getIndex(i);
if (semantic) { if (semantic) {
// If semantic is truc, jump to the next patch from a different netflux ID // If semantic is truc, jump to the next patch from a different netflux ID
var author = states[idx].author; var author = getAuthor(idx, semantic);
for (var j = idx; (j > 1 && j < (states.length - 1)); ((i > c) ? j++ : j--)) { for (var j = idx; (j > 1 && j < (states.length - 1)); ((i > c) ? j++ : j--)) {
idx = j; idx = j;
i = getRank(idx); i = getRank(idx);
if (author !== states[j].author) { if (author !== getAuthor(j, semantic)) {
break; break;
} }
} }
@ -229,12 +244,14 @@ define([
return val || ''; return val || '';
}; };
/*
var getNext = function (step) { var getNext = function (step) {
return typeof step === "number" ? get(c + step) : get(c + 1); return typeof step === "number" ? get(c + step) : get(c + 1);
}; };
var getPrevious = function (step) { var getPrevious = function (step) {
return typeof step === "number" ? get(c - step) : get(c - 1); return typeof step === "number" ? get(c - step) : get(c - 1);
}; };
*/
// Create the history toolbar // Create the history toolbar
var display = function () { var display = function () {
@ -247,14 +264,15 @@ define([
if (History.readOnly) { $rev.css('visibility', 'hidden'); } if (History.readOnly) { $rev.css('visibility', 'hidden'); }
Messages.history_session = "Group by user"; // XXX Messages.history_session = "Group by user"; // XXX
var $cbox = $(UI.createCheckbox('cp-history-session',
Messages.history_session,
false, { label: { class: 'noTitle' } })).appendTo($hist);
$('<span>', {'class': 'cp-history-filler'}).appendTo($hist); $('<span>', {'class': 'cp-history-filler'}).appendTo($hist);
var $fastPrev = $('<button>', { var $fastPrev = $('<button>', {
'class': 'cp-toolbar-history-fast-previous fa fa-fast-backward buttonPrimary', 'class': 'cp-toolbar-history-fast-previous fa fa-fast-backward buttonPrimary',
title: Messages.history_prev title: Messages.history_prev
}).appendTo($hist); }).appendTo($hist);
var $userPrev =$('<button>', {
'class': 'cp-toolbar-history-previous fa fa-backward buttonPrimary',
title: Messages.history_prev
}).appendTo($hist);
var $prev =$('<button>', { var $prev =$('<button>', {
'class': 'cp-toolbar-history-previous fa fa-step-backward buttonPrimary', 'class': 'cp-toolbar-history-previous fa fa-step-backward buttonPrimary',
title: Messages.history_prev title: Messages.history_prev
@ -264,6 +282,10 @@ define([
'class': 'cp-toolbar-history-next fa fa-step-forward buttonPrimary', 'class': 'cp-toolbar-history-next fa fa-step-forward buttonPrimary',
title: Messages.history_next title: Messages.history_next
}).appendTo($hist); }).appendTo($hist);
var $userNext =$('<button>', {
'class': 'cp-toolbar-history-next fa fa-forward buttonPrimary',
title: Messages.history_next
}).appendTo($hist);
var $fastNext = $('<button>', { var $fastNext = $('<button>', {
'class': 'cp-toolbar-history-fast-next fa fa-fast-forward buttonPrimary', 'class': 'cp-toolbar-history-fast-next fa fa-fast-forward buttonPrimary',
title: Messages.history_next title: Messages.history_next
@ -318,26 +340,19 @@ define([
$(window).off('keyup', onKeyUp); $(window).off('keyup', onKeyUp);
}; };
var $checkbox = $cbox.find('input').on('change', function () {
semantic = $checkbox.is(':checked');
if (semantic) {
$fastPrev.hide();
$fastNext.hide();
} else {
$fastPrev.show();
$fastNext.show();
}
});
// Version buttons // Version buttons
$prev.click(function () { render(getPrevious()); }); $prev.click(function () { render(get(c - 1)); });
$next.click(function () { render(getNext()); }); $next.click(function () { render(get(c + 1)); });
$fastPrev.click(function () { render(getPrevious(10)); }); $userPrev.click(function () { render(get(c - 1, false, 1)); });
$fastNext.click(function () { render(getNext(10)); }); $userNext.click(function () { render(get(c + 1, false, 1)); });
$fastPrev.click(function () { render(get(c - 1, false, 2)); });
$fastNext.click(function () { render(get(c + 1, false, 2)); });
onKeyDown = function (e) { onKeyDown = function (e) {
var p = function () { e.preventDefault(); }; var p = function () { e.preventDefault(); };
if ([37, 40].indexOf(e.which) >= 0) { p(); return $prev.click(); } // Left if (e.which === 39) { p(); return $next.click(); } // Right
if ([38, 39].indexOf(e.which) >= 0) { p(); return $next.click(); } // Right if (e.which === 37) { p(); return $prev.click(); } // Left
if (e.which === 38) { p(); return $userNext.click(); } // Up
if (e.which === 40) { p(); return $userPrev.click(); } // Down
if (e.which === 33) { p(); return $fastNext.click(); } // PageUp if (e.which === 33) { p(); return $fastNext.click(); } // PageUp
if (e.which === 34) { p(); return $fastPrev.click(); } // PageUp if (e.which === 34) { p(); return $fastPrev.click(); } // PageUp
if (e.which === 27) { p(); $close.click(); } if (e.which === 27) { p(); $close.click(); }

Loading…
Cancel
Save