Merge branch 'form-poll-ui'

This commit is contained in:
yflory 2023-01-23 17:50:11 +01:00
commit 508a07200c
10 changed files with 151 additions and 90 deletions

View File

@ -779,12 +779,14 @@ var commands = {
// addFirstAdmin is an anon_rpc command
Admin.addFirstAdmin = function (Env, data, cb) {
if (!Env.installToken) { return void cb('EINVAL'); }
var token = data.token;
if (!token || !data.edPublic) { return void cb('MISSING_ARGS'); }
if (token.length !== 64 || data.edPublic.length !== 44) { return void cb('INVALID_ARGS'); }
if (token !== Env.installToken) { return void cb('FORBIDDEN'); }
if (Array.isArray(Env.admins) && Env.admins.length) { return void cb('EEXISTS'); }
var key = data.edPublic;
if (token.length !== 64 || data.edPublic.length !== 44) { return void cb('INVALID_ARGS'); }
adminDecree(Env, null, function (err) {
if (err) { return void cb(err); }

View File

@ -167,6 +167,7 @@ module.exports.create = function (config) {
limits: {},
admins: [],
installToken: undefined,
WARN: function (e, output) { // TODO deprecate this
if (!Env.Log) { return; }
if (e && output) {

View File

@ -74,7 +74,7 @@ Stats.instanceData = function (Env) {
}
// Admins can opt-in to providing more detailed information about the extent of the instance's usage
if (!Env.provideAggregateStatistics) {
if (Env.provideAggregateStatistics) {
// check how many instances provide stats before we put more work into it
data.providesAggregateStatistics = true;
}

View File

@ -1,19 +1,12 @@
var prompt = require('prompt-confirm');
const p = new prompt('Are you sure? This will permanently delete all existing data on your instance.');
//const nThen = require("nthen");
const Fs = require("fs");
//const Path = require("path");
var config = require("../lib/load-config");
//var Hash = require('../www/common/common-hash');
var Env = require("../lib/env").create(config);
Env.Log = { error: console.log };
/*
var keyOrDefaultString = function (key, def) {
return Path.resolve(typeof(config[key]) === 'string'? config[key]: def);
}; */
var paths = Env.paths;
p.ask(function (answer) {
if (!answer) {
@ -21,7 +14,6 @@ p.ask(function (answer) {
return;
}
console.log('Deleting all data...');
//var n = nThen;
Object.values(paths).forEach(function (path) {
console.log(`Deleting ${path}`);
Fs.rmSync(path, { recursive: true, force: true });

View File

@ -2320,7 +2320,6 @@ define([
localStorage.setItem(Constants.tokenKey, data[Constants.tokenKey]);
}
}
initFeedback(data.feedback);
};
@ -2729,6 +2728,7 @@ define([
if (data.error) { throw new Error(data.error); }
if (data.state === 'ALREADY_INIT') {
data = data.returned;
initFeedback(data.feedback);
}
if (data.loggedIn) {

View File

@ -111,7 +111,7 @@ var init = function (client, cb) {
if (data && data.state === "ALREADY_INIT") {
debug('Store already exists!');
self.store = data.returned;
return void cb(data.returned);
return void cb(data);
}
self.store = data;
cb(data);

View File

@ -148,7 +148,7 @@ define([
// if metadata is too large, drop the thumbnail.
if (plaintext.length > 65535) {
var temp = JSON.parse(JSON.stringify(metadata));
delete metadata.thumbnail;
delete temp.thumbnail;
plaintext = Nacl.util.decodeUTF8(JSON.stringify(temp));
}

View File

@ -792,6 +792,13 @@
margin-top: 100px;
padding-bottom: 20px;
}
.cp-form-submit-success {
div.cp-form-submit-success-actions {
button:not(:last-child) {
margin-right: 10px;
}
}
}
}
div.cp-form-creator-results {
display: flex;
@ -1037,7 +1044,7 @@
}
.cp-form-poll-body {
flex-flow: column;
max-height: 225px;
// max-height: 225px;
& > div {
display: flex;
@ -1167,11 +1174,16 @@
flex-flow: column;
&.cp-form-poll-body {
flex-flow: row;
max-height: unset;
& > div {
flex-flow: column;
}
flex: 1;
min-width: 0;
overflow: auto;
}
}
.cp-poll-total {
flex-flow: column;
}
@ -1194,7 +1206,8 @@
width: auto !important;
}
.cp-poll-time-day {
flex-basis: 40px;
flex-basis: 40px !important;
flex-grow: 0;
border-right: none;
border-right: 1px solid @cryptpad_text_col;
border-bottom: 0px;

View File

@ -14,6 +14,24 @@ define([
return value;
};
// Get all responses
var sortAnswers = function (answers) {
var allUnsorted = {};
Object.keys(answers).forEach(function (curve) {
var userAnswers = answers[curve];
Object.keys(userAnswers).forEach(function (uid) {
allUnsorted[curve + '|' + uid] = userAnswers[uid];
});
});
var sorted = Object.keys(allUnsorted).sort(function (uid1, uid2) {
return (allUnsorted[uid1].time || 0) - (allUnsorted[uid2].time || 0);
});
return {
answers: allUnsorted,
sortedKeys: sorted
};
};
var exportJSON = function (content, answers, TYPES, order) {
var form = content.form;
var res = {
@ -23,6 +41,10 @@ define([
var q = res.questions;
var r = res.responses;
var sortObj = sortAnswers(answers);
answers = sortObj.answers;
var sortedKeys = sortObj.sortedKeys;
// Add questions
var i = 1;
order.forEach(function (key) {
@ -45,10 +67,8 @@ define([
}
});
Object.keys(answers || {}).forEach(function (key) {
var userObj = answers[key];
Object.keys(userObj).forEach(function (k) {
var obj = userObj[k];
sortedKeys.forEach(function (k) {
var obj = answers[k];
var time = new Date(obj.time).toISOString();
var msg = obj.msg || {};
var user = msg._userdata || {};
@ -71,7 +91,6 @@ define([
});
r.push(data);
});
});
return JSON.stringify(res, 0, 2);
};
@ -80,6 +99,10 @@ define([
if (format === "json") { return exportJSON(content, answers, TYPES, order); }
var sortObj = sortAnswers(answers);
answers = sortObj.answers;
var sortedKeys = sortObj.sortedKeys;
var isArray = format === "array";
var csv = "";
var array = [];
@ -104,10 +127,8 @@ define([
});
array.push(questions);
Object.keys(answers || {}).forEach(function (key) {
var _obj = answers[key];
Object.keys(_obj).forEach(function (uid) {
var obj = _obj[uid];
sortedKeys.forEach(function (k) {
var obj = answers[k];
csv += '\n';
var time = new Date(obj.time).toISOString();
var msg = obj.msg || {};
@ -131,7 +152,6 @@ define([
});
array.push(line);
});
});
if (isArray) { return array; }
return csv;
};

View File

@ -968,15 +968,24 @@ define([
if (!answers) { return; }
return Object.keys(answers || {}).map(function (key) {
var user = key.split('|')[0];
if (filterCurve && user === filterCurve) { return; }
if (filterCurve && user === filterCurve) {
var obj = answers[key];
// Only hide the current response (APP.editingUid), not all our responses
if (APP.editingUid && Util.find(obj, ['msg', '_uid']) === APP.editingUid) {
return;
}
}
try {
return {
curve: user,
user: answers[key].msg._userdata,
results: answers[key].msg[uid]
results: answers[key].msg[uid],
time: answers[key].time
};
} catch (e) { console.error(e); }
}).filter(Boolean);
}).filter(Boolean).sort(function (obj1, obj2) {
return obj1.time - obj2.time;
});
};
// When there is a change to the form, we need to check if we can still add
@ -1603,6 +1612,12 @@ define([
return rows;
};
var getSortedKeys = function (answers) {
return Object.keys(answers).sort(function (uid1, uid2) {
return (answers[uid1].time || 0) - (answers[uid2].time || 0);
});
};
var TYPES = APP.TYPES = {
input: {
defaultOpts: {
@ -1651,7 +1666,7 @@ define([
return !answer || !answer.trim();
};
Object.keys(answers).forEach(function (author) {
getSortedKeys(answers).forEach(function (author) {
var obj = answers[author];
var answer = obj.msg[uid];
if (isEmpty(answer)) { return empty++; }
@ -1662,7 +1677,7 @@ define([
//if (max < 2) { // there are no duplicates, so just return text
results.push(getEmpty(empty));
Object.keys(answers).forEach(function (author) {
getSortedKeys(answers).forEach(function (author) {
var obj = answers[author];
var answer = obj.msg[uid];
if (!answer || !answer.trim()) { return empty++; }
@ -1732,7 +1747,7 @@ define([
printResults: function (answers, uid) { // results textarea
var results = [];
var empty = 0;
Object.keys(answers).forEach(function (author) { // TODO deduplicate these
getSortedKeys(answers).forEach(function (author) { // TODO deduplicate these
var obj = answers[author];
var answer = obj.msg[uid];
if (!answer || !answer.trim()) { return empty++; }
@ -2827,10 +2842,20 @@ define([
};
var els = [];
// Get all responses
var allUnsorted = {};
Object.keys(answers).forEach(function (curve) {
var userAnswers = answers[curve];
Object.keys(userAnswers).forEach(function (uid) {
var obj = userAnswers[uid];
allUnsorted[curve + '|' + uid] = userAnswers[uid];
});
});
// Sort them by date and print
getSortedKeys(allUnsorted).forEach(function (curveUid) {
var obj = allUnsorted[curveUid];
var uid = curveUid.split('|')[1];
var curve = curveUid.split('|')[0];
var answer = obj.msg;
var date = new Date(obj.time).toLocaleString();
var text, warning, badge;
@ -2887,7 +2912,6 @@ define([
}
els.push(div);
});
});
$results.append(els);
});
if (showUser) {
@ -3021,7 +3045,10 @@ define([
}
var entries = [];
Object.keys(answers).forEach(function (uid) {
var sorted = Object.keys(answers).sort(function (uid1, uid2) {
return answers[uid1]._time - answers[uid2]._time;
});
sorted.forEach(function (uid) {
var answer = answers[uid];
var viewOnly = content.answers.cantEdit || APP.isClosed;
@ -3074,8 +3101,12 @@ define([
});
}
var name = (answer._isAnon || !answer._userdata || !answer._userdata.name) ?
Messages.anonymous : Util.fixHTML(answer._userdata.name);
entries.push(h('div.cp-form-submit-actions', [
h('span.cp-form-submit-time', date),
h('span.cp-form-submit-time', '-'),
h('span.cp-form-submit-time', name),
h('span.cp-form-submit-action', action),
h('span.cp-form-submit-del', del),
]));
@ -3091,8 +3122,10 @@ define([
description,
h('div', Messages.form_alreadyAnsweredMult),
table,
h('div.cp-form-submit-success-actions', [
newAnswer,
responses ? h('div', responses) : undefined
responses || undefined
])
]));
$container.append(getLogo());
};