2021-02-28 01:20:19 +01:00
|
|
|
import render_admin_export_list from "../templates/admin_export_list.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:20:19 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as ListWidget from "./list_widget";
|
|
|
|
import * as loading from "./loading";
|
|
|
|
import * as people from "./people";
|
|
|
|
import * as timerender from "./timerender";
|
2021-02-28 21:33:10 +01:00
|
|
|
import * as ui from "./ui";
|
2021-02-28 01:20:19 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2020-08-20 21:24:06 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const meta = {
|
2019-04-09 21:49:07 +02:00
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2021-02-28 01:20:19 +01:00
|
|
|
export function reset() {
|
2019-04-09 21:49:07 +02:00
|
|
|
meta.loaded = false;
|
2021-02-28 01:20:19 +01:00
|
|
|
}
|
2019-04-09 21:49:07 +02:00
|
|
|
|
2020-04-12 12:13:47 +02:00
|
|
|
function sort_user(a, b) {
|
|
|
|
const a_name = people.get_full_name(a.acting_user_id).toLowerCase();
|
|
|
|
const b_name = people.get_full_name(b.acting_user_id).toLowerCase();
|
|
|
|
if (a_name > b_name) {
|
|
|
|
return 1;
|
|
|
|
} else if (a_name === b_name) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:19 +01:00
|
|
|
export function populate_exports_table(exports) {
|
2019-04-09 21:49:07 +02:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const exports_table = $("#admin_exports_table").expectOne();
|
2021-01-29 10:27:56 +01:00
|
|
|
ListWidget.create(exports_table, Object.values(exports), {
|
2019-08-23 02:16:15 +02:00
|
|
|
name: "admin_exports_list",
|
2020-07-20 22:18:43 +02:00
|
|
|
modifier(data) {
|
2020-04-20 21:25:20 +02:00
|
|
|
let failed_timestamp = data.failed_timestamp;
|
2020-04-20 23:02:45 +02:00
|
|
|
let deleted_timestamp = data.deleted_timestamp;
|
|
|
|
|
2020-04-20 21:25:20 +02:00
|
|
|
if (failed_timestamp !== null) {
|
|
|
|
failed_timestamp = timerender.last_seen_status_from_date(
|
2021-02-05 21:20:14 +01:00
|
|
|
new Date(failed_timestamp * 1000),
|
2020-04-20 21:25:20 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:02:45 +02:00
|
|
|
if (deleted_timestamp !== null) {
|
|
|
|
deleted_timestamp = timerender.last_seen_status_from_date(
|
2021-02-05 21:20:14 +01:00
|
|
|
new Date(deleted_timestamp * 1000),
|
2020-04-20 23:02:45 +02:00
|
|
|
);
|
2019-08-22 08:20:20 +02:00
|
|
|
}
|
2020-04-20 23:02:45 +02:00
|
|
|
|
|
|
|
return render_admin_export_list({
|
|
|
|
realm_export: {
|
|
|
|
id: data.id,
|
|
|
|
acting_user: people.get_full_name(data.acting_user_id),
|
|
|
|
// Convert seconds -> milliseconds
|
|
|
|
event_time: timerender.last_seen_status_from_date(
|
2021-02-05 21:20:14 +01:00
|
|
|
new Date(data.export_time * 1000),
|
2020-04-20 23:02:45 +02:00
|
|
|
),
|
|
|
|
url: data.export_url,
|
|
|
|
time_failed: failed_timestamp,
|
|
|
|
pending: data.pending,
|
|
|
|
time_deleted: deleted_timestamp,
|
|
|
|
},
|
|
|
|
});
|
2019-08-22 08:20:20 +02:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: exports_table.closest(".settings-section").find(".search"),
|
2020-07-20 22:18:43 +02:00
|
|
|
predicate(item, value) {
|
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 04:55:06 +01:00
|
|
|
return people.get_full_name(item.acting_user_id).toLowerCase().includes(value);
|
2019-08-22 08:20:20 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
onupdate() {
|
2019-08-22 08:20:20 +02:00
|
|
|
ui.reset_scrollbar(exports_table);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
parent_container: $("#data-exports").expectOne(),
|
2020-04-11 16:23:29 +02:00
|
|
|
init_sort: [sort_user],
|
|
|
|
sort_fields: {
|
|
|
|
user: sort_user,
|
|
|
|
},
|
2020-07-15 01:29:15 +02:00
|
|
|
simplebar_container: $("#data-exports .progressive-table-wrapper"),
|
2020-04-11 16:23:29 +02:00
|
|
|
});
|
2020-04-20 21:25:20 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const spinner = $(".export_row .export_url_spinner");
|
2020-04-20 21:25:20 +02:00
|
|
|
if (spinner.length) {
|
|
|
|
loading.make_indicator(spinner);
|
|
|
|
} else {
|
|
|
|
loading.destroy_indicator(spinner);
|
|
|
|
}
|
2021-02-28 01:20:19 +01:00
|
|
|
}
|
2019-04-09 21:49:07 +02:00
|
|
|
|
2021-02-28 01:20:19 +01:00
|
|
|
export function set_up() {
|
2019-04-09 21:49:07 +02:00
|
|
|
meta.loaded = true;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#export-data").on("click", (e) => {
|
2019-04-09 21:49:07 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2020-07-15 01:29:15 +02:00
|
|
|
const export_status = $("#export_status");
|
2019-04-09 21:49:07 +02:00
|
|
|
|
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/export/realm",
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2020-07-15 00:34:28 +02:00
|
|
|
ui_report.success(
|
|
|
|
i18n.t("Export started. Check back in a few minutes."),
|
|
|
|
export_status,
|
|
|
|
4000,
|
|
|
|
);
|
2019-04-09 21:49:07 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2019-04-09 21:49:07 +02:00
|
|
|
ui_report.error(i18n.t("Export failed"), xhr, export_status);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Do an initial population of the table
|
|
|
|
channel.get({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/export/realm",
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data) {
|
2021-02-28 01:20:19 +01:00
|
|
|
populate_exports_table(data.exports);
|
2019-04-09 21:49:07 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".admin_exports_table").on("click", ".delete", function (e) {
|
2019-04-09 21:49:07 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const btn = $(this);
|
2019-04-09 21:49:07 +02:00
|
|
|
|
|
|
|
channel.del({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/export/realm/" + encodeURIComponent(btn.attr("data-export-id")),
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2019-04-09 21:49:07 +02:00
|
|
|
ui_report.generic_row_button_error(xhr, btn);
|
|
|
|
},
|
|
|
|
// No success function, since UI updates are done via server_events
|
|
|
|
});
|
|
|
|
});
|
2021-02-28 01:20:19 +01:00
|
|
|
}
|