Skip to content

Commit

Permalink
CLDR-14802 add a user Recent Changes .xlsx (#1388)
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 authored Aug 5, 2021
1 parent 0b7b4d7 commit 28a41e6
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 1 deletion.
106 changes: 106 additions & 0 deletions tools/cldr-apps/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tools/cldr-apps/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"private": true,
"dependencies": {
"ant-design-vue": "^2.0.1",
"vue": "^3.0.7"
"vue": "^3.0.7",
"xlsx": "^0.17.0"
}
}
16 changes: 16 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrRecentActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as cldrRetry from "./cldrRetry.js";
import * as cldrStatus from "./cldrStatus.js";
import * as cldrSurvey from "./cldrSurvey.js";
import * as cldrText from "./cldrText.js";
import * as cldrUserListExport from "../esm/cldrUserListExport";

/**
* The id of the user in question; not necessarily the current user
Expand Down Expand Up @@ -49,6 +50,21 @@ function loadWithJson(json) {
cldrLoad.setLoading(false);
cldrGui.hideRightPanel();
const frag = cldrDom.construct(getHtml(json));

// Add a button for recent activity download
const recentActivityButton = document.createElement("button");
recentActivityButton.appendChild(
document.createTextNode("Download User Activity… (.xlsx)")
);
recentActivityButton.onclick = () =>
cldrUserListExport.downloadUserActivity(
json.user,
cldrStatus.getSessionId()
);
frag.appendChild(document.createElement("p"));
frag.appendChild(document.createElement("hr"));
frag.appendChild(recentActivityButton);

cldrLoad.flipToOtherDiv(frag);
if (Number(json.user) === Number(userId)) {
showRecent();
Expand Down
62 changes: 62 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrUserListExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import XLSX from "xlsx";
import * as cldrAjax from "./cldrAjax.js";
// shim global fetch
const fetch = cldrAjax.doFetch;

/**
* Download the user activity database
*/
async function downloadUserActivity(userId /*, session*/) {
// http://127.0.0.1:9080/cldr-apps/SurveyAjax?what=recent_items&user=1289&limit=16777216
const limit = 16_777_216; // big limit
// const limit = 3; // testing
const url = `SurveyAjax?what=recent_items&user=${userId}&limit=${limit}`;
const result = await fetch(url, {
headers: {
Accept: "application/json",
},
});
const json = await result.json();
const { data, header } = json.recent;

const wb = XLSX.utils.book_new();

var ws_name = `SurveyTool#${userId}`;

/* make worksheet */
var ws_data = [
[
"Locale", // 0
"XpathId", // 1
"XpathCode", // 2
"Value", // 3
"When", // 4
],
];
for (const r of data) {
ws_data.push([
r[header.LOCALE_NAME],
r[header.XPATH_STRHASH],
r[header.XPATH_CODE],
r[header.VALUE],
new Date(r[header.LAST_MOD]), // TODO: convert to 'date'
]);
}
var ws = XLSX.utils.aoa_to_sheet(ws_data);

function pushComment(where, t) {
ws[where].c = ws[where].c || [];
ws[where].c.hidden = true;
ws[where].c.push({ a: "SurveyTool", t });
}
pushComment("A1", "Locale Name in English");
pushComment("B1", "XPath String ID");
pushComment("C1", "XPath Code");
// D1 = Value
pushComment("E1", "Date of last vote");

XLSX.utils.book_append_sheet(wb, ws, ws_name);
XLSX.writeFile(wb, `survey_recent_activity${userId}.xlsx`);
}

export { downloadUserActivity };

0 comments on commit 28a41e6

Please sign in to comment.