Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/attachments_ui.js to ES6 module.

Anders Kaseorgac65935b16bf
diff --git a/.eslintrc.json b/.eslintrc.json
index 9218722db57..76ee6d05461 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -127,7 +127,6 @@
"$": false,
"activity": false,
"admin": false,
- "attachments_ui": false,
"avatar": false,
"blueslip": false,
"bot_data": false,
diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js
index 1815a096a1d..76fadea1f79 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -23,7 +23,8 @@ set_global("setTimeout", (func) => func());
const activity = set_global("activity", {});
const alert_words_ui = {__esModule: true};
rewiremock("../../static/js/alert_words_ui").with(alert_words_ui);
-const attachments_ui = set_global("attachments_ui", {});
+const attachments_ui = {__esModule: true};
+rewiremock("../../static/js/attachments_ui").with(attachments_ui);
const bot_data = set_global("bot_data", {});
rewiremock("../../static/js/compose").with({});
const composebox_typeahead = set_global("composebox_typeahead", {});
diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js
index 94fb7ca93e6..7e1e021a4cb 100644
--- a/static/js/attachments_ui.js
+++ b/static/js/attachments_ui.js
@@ -1,17 +1,15 @@
-"use strict";
+import render_settings_upload_space_stats from "../templates/settings/upload_space_stats.hbs";
+import render_uploaded_files_list from "../templates/uploaded_files_list.hbs";
-const render_settings_upload_space_stats = require("../templates/settings/upload_space_stats.hbs");
-const render_uploaded_files_list = require("../templates/uploaded_files_list.hbs");
-
-const channel = require("./channel");
-const ListWidget = require("./list_widget");
-const loading = require("./loading");
-const ui_report = require("./ui_report");
+import * as channel from "./channel";
+import * as ListWidget from "./list_widget";
+import * as loading from "./loading";
+import * as ui_report from "./ui_report";
let attachments;
let upload_space_used;
-exports.bytes_to_size = function (bytes, kb_with_1024_bytes) {
+export function bytes_to_size(bytes, kb_with_1024_bytes) {
if (kb_with_1024_bytes === undefined) {
kb_with_1024_bytes = false;
}
@@ -26,14 +24,14 @@ exports.bytes_to_size = function (bytes, kb_with_1024_bytes) {
size = Math.round((bytes / Math.pow(kb_size, i)) * 10) / 10;
}
return size + " " + sizes[i];
-};
+}
-exports.percentage_used_space = function (uploads_size) {
+export function percentage_used_space(uploads_size) {
if (page_params.realm_upload_quota === null) {
return null;
}
return ((100 * uploads_size) / page_params.realm_upload_quota).toFixed(1);
-};
+}
function set_upload_space_stats() {
if (page_params.realm_upload_quota === null) {
@@ -41,8 +39,8 @@ function set_upload_space_stats() {
}
const args = {
show_upgrade_message: page_params.realm_plan_type === 2,
- percent_used: exports.percentage_used_space(upload_space_used),
- upload_quota: exports.bytes_to_size(page_params.realm_upload_quota, true),
+ percent_used: percentage_used_space(upload_space_used),
+ upload_quota: bytes_to_size(page_params.realm_upload_quota, true),
};
const rendered_upload_stats_html = render_settings_upload_space_stats(args);
$("#attachment-stats-holder").html(rendered_upload_stats_html);
@@ -117,11 +115,11 @@ function format_attachment_data(new_attachments) {
for (const attachment of new_attachments) {
const time = new Date(attachment.create_time);
attachment.create_time_str = timerender.render_now(time).time_str;
- attachment.size_str = exports.bytes_to_size(attachment.size);
+ attachment.size_str = bytes_to_size(attachment.size);
}
}
-exports.update_attachments = function (event) {
+export function update_attachments(event) {
if (attachments === undefined) {
// If we haven't fetched attachment data yet, there's nothing to do.
return;
@@ -137,9 +135,9 @@ exports.update_attachments = function (event) {
// TODO: This is inefficient and we should be able to do some sort
// of incremental ListWidget update instead.
render_attachments_ui();
-};
+}
-exports.set_up_attachments = function () {
+export function set_up_attachments() {
// The settings page must be rendered before this function gets called.
const status = $("#delete-upload-status");
@@ -164,6 +162,4 @@ exports.set_up_attachments = function () {
ui_report.error(i18n.t("Failed"), xhr, status);
},
});
-};
-
-window.attachments_ui = exports;
+}
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 3d7ea425239..1af2f507b39 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -30,7 +30,6 @@ import "../ui";
import "../composebox_typeahead";
import "../hotkey";
import "../notifications";
-import "../attachments_ui";
import "../message_store";
import "../message_util";
import "../message_events";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index faa34edb9c2..aa89a55aafb 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -5,7 +5,6 @@
declare let activity: any;
declare let admin: any;
-declare let attachments_ui: any;
declare let avatar: any;
declare let blueslip: any;
declare let bot_data: any;
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index 2259c2a6664..d8b09384c63 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -2,6 +2,7 @@ import * as emoji from "../shared/js/emoji";
import * as alert_words from "./alert_words";
import * as alert_words_ui from "./alert_words_ui";
+import * as attachments_ui from "./attachments_ui";
import * as compose from "./compose";
import * as compose_fade from "./compose_fade";
import * as markdown from "./markdown";
diff --git a/static/js/settings_sections.js b/static/js/settings_sections.js
index 6231ae9b1fe..743012ae956 100644
--- a/static/js/settings_sections.js
+++ b/static/js/settings_sections.js
@@ -1,6 +1,7 @@
"use strict";
const alert_words_ui = require("./alert_words_ui");
+const attachments_ui = require("./attachments_ui");
const settings_muting = require("./settings_muting");
const load_func_dict = new Map(); // group -> function