From 3c5eed593928ac091d56c3458e39e528c8ec1345 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 24 Sep 2020 10:59:31 +0200 Subject: [PATCH] Group by 'userlist' in history --- www/common/sframe-app-framework.js | 1 + www/common/sframe-common-history.js | 63 ++++++++++++++++++----------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 83a261970..d62a90397 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -695,6 +695,7 @@ define([ onLocal: onLocal, onRemote: onRemote, setHistory: setHistoryMode, + extractMetadata: extractMetadata, applyVal: function (val) { var newContent = JSON.parse(val); var meta = extractMetadata(newContent); diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 2cb6e5962..76094f3ae 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -108,7 +108,6 @@ define([ var states = []; var c = 0;//states.length - 1; - var semantic = false; var $hist = $toolbar.find('.cp-toolbar-history'); var $bottom = $toolbar.find('.cp-toolbar-bottom'); @@ -166,8 +165,24 @@ define([ var getRank = function (idx) { 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); if (isNaN(i)) { return; } if (i > 0) { i = 0; } @@ -179,11 +194,11 @@ define([ var idx = getIndex(i); if (semantic) { // 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--)) { idx = j; i = getRank(idx); - if (author !== states[j].author) { + if (author !== getAuthor(j, semantic)) { break; } } @@ -229,12 +244,14 @@ define([ return val || ''; }; + /* var getNext = function (step) { return typeof step === "number" ? get(c + step) : get(c + 1); }; var getPrevious = function (step) { return typeof step === "number" ? get(c - step) : get(c - 1); }; + */ // Create the history toolbar var display = function () { @@ -247,14 +264,15 @@ define([ if (History.readOnly) { $rev.css('visibility', 'hidden'); } Messages.history_session = "Group by user"; // XXX - var $cbox = $(UI.createCheckbox('cp-history-session', - Messages.history_session, - false, { label: { class: 'noTitle' } })).appendTo($hist); $('', {'class': 'cp-history-filler'}).appendTo($hist); var $fastPrev = $('