From 81e7a1cfc8a3da2def4c76431601d1c0a7db4eb4 Mon Sep 17 00:00:00 2001 From: Alex Lubbock Date: Wed, 4 Sep 2024 10:55:41 +0100 Subject: [PATCH] refactor: commonJS to ESM, fix Sentry export (#86) --- thunorweb/templates/base-inner.html | 12 +---- thunorweb/templates/plotly_plot.html | 10 +--- thunorweb/templates/sentry_init.html | 10 ++++ thunorweb/webpack/Dockerfile | 1 + thunorweb/webpack/sentry.js | 1 + thunorweb/webpack/thunorweb/js/dataset.js | 28 ++++++----- .../thunorweb/js/dataset_permissions.js | 14 ++---- thunorweb/webpack/thunorweb/js/home.js | 24 +++++----- .../webpack/thunorweb/js/modules/ajax.js | 7 +-- .../thunorweb/js/modules/dataset_table.js | 12 ++--- thunorweb/webpack/thunorweb/js/modules/ui.js | 4 +- .../webpack/thunorweb/js/modules/util.js | 5 +- .../webpack/thunorweb/js/plate_mapper.js | 28 +++++------ .../webpack/thunorweb/js/plate_upload.js | 12 ++--- thunorweb/webpack/thunorweb/js/plots.js | 31 +++++++------ thunorweb/webpack/thunorweb/js/pyhts.js | 31 +++++++------ thunorweb/webpack/thunorweb/js/tag_editor.js | 46 +++++++++---------- thunorweb/webpack/webpack.config.js | 2 +- 18 files changed, 130 insertions(+), 148 deletions(-) create mode 100644 thunorweb/templates/sentry_init.html create mode 100644 thunorweb/webpack/sentry.js diff --git a/thunorweb/templates/base-inner.html b/thunorweb/templates/base-inner.html index e6bde669..6a970bd5 100644 --- a/thunorweb/templates/base-inner.html +++ b/thunorweb/templates/base-inner.html @@ -112,16 +112,8 @@
Powered by Thunor
-{% load webpack_loader %}{% get_files 'sentry' 'js' as sentry_js %} - - - - +{% load webpack_loader %} +{% include "sentry_init.html" %} {% render_bundle 'vendor' 'js' %} - +{% load webpack_loader %} +{% include "sentry_init.html" %} {% render_bundle 'vendor' 'js' %} {% render_bundle 'app' 'js' %} {% render_bundle 'plots' 'js' %} diff --git a/thunorweb/templates/sentry_init.html b/thunorweb/templates/sentry_init.html new file mode 100644 index 00000000..ecc3187d --- /dev/null +++ b/thunorweb/templates/sentry_init.html @@ -0,0 +1,10 @@ +{% load webpack_loader %} +{% get_files 'sentry' 'js' as sentry_js %} + + + diff --git a/thunorweb/webpack/Dockerfile b/thunorweb/webpack/Dockerfile index b153b217..ac90511e 100644 --- a/thunorweb/webpack/Dockerfile +++ b/thunorweb/webpack/Dockerfile @@ -11,6 +11,7 @@ COPY package.json $BUILD_DIR RUN npm install COPY webpack.config.js $BUILD_DIR +COPY sentry.js $BUILD_DIR COPY plotly.js $BUILD_DIR COPY .bootstraprc $BUILD_DIR COPY bootstrap-customisations.scss $BUILD_DIR diff --git a/thunorweb/webpack/sentry.js b/thunorweb/webpack/sentry.js new file mode 100644 index 00000000..7f65d7d6 --- /dev/null +++ b/thunorweb/webpack/sentry.js @@ -0,0 +1 @@ +export * from "@sentry/browser" diff --git a/thunorweb/webpack/thunorweb/js/dataset.js b/thunorweb/webpack/thunorweb/js/dataset.js index 88ed79be..d97a7e31 100644 --- a/thunorweb/webpack/thunorweb/js/dataset.js +++ b/thunorweb/webpack/thunorweb/js/dataset.js @@ -1,9 +1,7 @@ -"use strict"; +import { ajax } from './modules/ajax' +import { ui } from './modules/ui' -var ui = require("./modules/ui"), - ajax = require("./modules/ajax"); - -var delete_dataset = function() { +const delete_dataset = function() { ui.loadingModal.show(); $.ajax({type: 'POST', url: ajax.url("delete_dataset"), @@ -19,7 +17,7 @@ var delete_dataset = function() { dataType: 'json'}); }; -var accept_license = function() { +const accept_license = function() { ui.loadingModal.show(); $.ajax({type: 'POST', url: ajax.url("accept_license", $('#dataset-id').val()), @@ -32,7 +30,7 @@ var accept_license = function() { }; -var dataset = function(showLicense) { +const activate = function(showLicense) { $('#dataset-name-edit').click(function() { var datasetName = $('.dataset-name').first().text(); $('#dataset-name').hide(); @@ -40,15 +38,15 @@ var dataset = function(showLicense) { }); $('#dataset-rename-cancel').click(function() { - $('#dataset-rename').hide(); - $('#dataset-name').show(); + $('#dataset-rename').hide(); + $('#dataset-name').show(); }); $('#dataset-rename-form').submit(function(e) { - e.preventDefault(); - ui.loadingModal.show(); + e.preventDefault(); + ui.loadingModal.show(); - $.ajax({type: 'POST', + $.ajax({type: 'POST', url: ajax.url("rename_dataset"), headers: { 'X-CSRFToken': ajax.getCsrfToken() }, data: $(this).serialize(), @@ -108,6 +106,6 @@ var dataset = function(showLicense) { } }; -module.exports = { - activate: dataset -}; +export const dataset = { + activate: activate +} diff --git a/thunorweb/webpack/thunorweb/js/dataset_permissions.js b/thunorweb/webpack/thunorweb/js/dataset_permissions.js index 6b12f1f0..53516195 100644 --- a/thunorweb/webpack/thunorweb/js/dataset_permissions.js +++ b/thunorweb/webpack/thunorweb/js/dataset_permissions.js @@ -1,9 +1,7 @@ -"use strict"; +import { ajax } from './modules/ajax' +import { ui } from './modules/ui' -var ui = require("./modules/ui"), - ajax = require("./modules/ajax"); - -var set_dataset_group_permission = function(dataset_id, group_id, perm_id, +const set_dataset_group_permission = function(dataset_id, group_id, perm_id, state, $caller) { ui.loadingModal.show(); $.ajax({type: 'POST', @@ -27,7 +25,7 @@ var set_dataset_group_permission = function(dataset_id, group_id, perm_id, dataType: 'json'}); }; -var dataset_permissions = function() { +export const dataset_permissions = function() { $("input[type=checkbox]").bootstrapSwitch({ 'onSwitchChange': function(event, state) { var $target = $(event.currentTarget); @@ -41,7 +39,3 @@ var dataset_permissions = function() { } }); }; - -module.exports = { - activate: dataset_permissions -}; diff --git a/thunorweb/webpack/thunorweb/js/home.js b/thunorweb/webpack/thunorweb/js/home.js index f24e74e5..ff8d6c1e 100644 --- a/thunorweb/webpack/thunorweb/js/home.js +++ b/thunorweb/webpack/thunorweb/js/home.js @@ -1,14 +1,12 @@ -var ajax = require("./modules/ajax"), - datasetTable = require("./modules/dataset_table"); +import { ajax } from './modules/ajax' +import { initDatasetTable } from './modules/dataset_table' -var home = function() { - var callbackFn = function (data, type, full, meta) { - return "" + full.name + ""; - }; - datasetTable.initDatasetTable(callbackFn); -}; - -module.exports = { - activate: home -}; +export const home = { + activate: function() { + var callbackFn = function (data, type, full, meta) { + return "" + full.name + ""; + }; + initDatasetTable(callbackFn); + } +} diff --git a/thunorweb/webpack/thunorweb/js/modules/ajax.js b/thunorweb/webpack/thunorweb/js/modules/ajax.js index a7344b9a..03e9e829 100644 --- a/thunorweb/webpack/thunorweb/js/modules/ajax.js +++ b/thunorweb/webpack/thunorweb/js/modules/ajax.js @@ -1,8 +1,6 @@ -"use strict"; +import { ui } from "./ui" -var ui = require("./ui"); - -var ajax = (function () { +export const ajax = (function () { var csrfToken = null; var getCookie = function (name) { @@ -174,4 +172,3 @@ var ajax = (function () { url: url } })(); -module.exports = ajax; diff --git a/thunorweb/webpack/thunorweb/js/modules/dataset_table.js b/thunorweb/webpack/thunorweb/js/modules/dataset_table.js index 57f33aaa..cabe9730 100644 --- a/thunorweb/webpack/thunorweb/js/modules/dataset_table.js +++ b/thunorweb/webpack/thunorweb/js/modules/dataset_table.js @@ -1,11 +1,11 @@ -var ajax = require("./ajax"), - util = require("./util"); +import { ajax } from './ajax' +import { util } from './util' -var formatISODate = function(data) { +const formatISODate = function(data) { return data.replace('T', ' ').slice(0, -5) + ' UTC'; }; -var initDatasetTable = function(tableRowCallbackFn, loadingCompleteCallbackFn) { +export const initDatasetTable = function(tableRowCallbackFn, loadingCompleteCallbackFn) { var $tabContent = $(".tab-content"); $tabContent.loadingOverlay("show"); @@ -63,7 +63,3 @@ var initDatasetTable = function(tableRowCallbackFn, loadingCompleteCallbackFn) { $this.addClass("active"); }); }; - -module.exports = { - initDatasetTable: initDatasetTable -}; diff --git a/thunorweb/webpack/thunorweb/js/modules/ui.js b/thunorweb/webpack/thunorweb/js/modules/ui.js index a49c582f..781eefa0 100644 --- a/thunorweb/webpack/thunorweb/js/modules/ui.js +++ b/thunorweb/webpack/thunorweb/js/modules/ui.js @@ -1,5 +1,4 @@ -"use strict"; -var ui = (function() { +export const ui = (function() { var modalBase = $( '