From 27fbdbb9555730c7b16a684b981f5cb451518202 Mon Sep 17 00:00:00 2001 From: Samuel Whittenberger Date: Fri, 6 Oct 2023 09:27:40 -0400 Subject: [PATCH 1/2] remove inline js from reading log --- openlibrary/plugins/openlibrary/js/index.js | 4 ++-- openlibrary/plugins/upstream/mybooks.py | 4 ++-- .../templates/account/readinglog_stats.html | 18 ++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/openlibrary/plugins/openlibrary/js/index.js b/openlibrary/plugins/openlibrary/js/index.js index d3b7dec127f..12a3df63d9c 100644 --- a/openlibrary/plugins/openlibrary/js/index.js +++ b/openlibrary/plugins/openlibrary/js/index.js @@ -251,9 +251,9 @@ jQuery(function () { .then((module) => module.init()); } - if (window.READINGLOG_STATS_CONFIG) { + if ($('div.readinglog-charts').length) { import(/* webpackChunkName: "readinglog-stats" */ './readinglog_stats') - .then(module => module.init(window.READINGLOG_STATS_CONFIG)); + .then(module => module.init($('div.readinglog-charts').data('config'))); } const pageEl = $('#page-barcodescanner'); diff --git a/openlibrary/plugins/upstream/mybooks.py b/openlibrary/plugins/upstream/mybooks.py index 3265108673c..3a659574cfe 100644 --- a/openlibrary/plugins/upstream/mybooks.py +++ b/openlibrary/plugins/upstream/mybooks.py @@ -155,8 +155,8 @@ def GET(self, username, key='want-to-read'): for a in web.ctx.site.get_many(list(author_keys)) ] return render['account/readinglog_stats']( - json.dumps(works_json), - json.dumps(authors_json), + works_json, + authors_json, len(works_json), user.key, user.displayname, diff --git a/openlibrary/templates/account/readinglog_stats.html b/openlibrary/templates/account/readinglog_stats.html index 792f10bc11f..8b76a4bb059 100644 --- a/openlibrary/templates/account/readinglog_stats.html +++ b/openlibrary/templates/account/readinglog_stats.html @@ -1,5 +1,12 @@ $def with (works_json, authors_json, works_count, owner_key, owner_name, shelf_path, shelf_key, lang='en') +$ reading_log_stats_config = { +$ 'works': works_json, +$ 'authors': authors_json, +$ 'lang': lang, +$ 'charts_selector': '.readinglog-stats-chart' +$ } + $ shelf_name = unicode(render_template('account/readinglog_shelf_name', shelf_key)).strip(); $var title: $_('My %(shelf_name)s Stats', shelf_name=shelf_name) @@ -96,7 +103,7 @@

$_('My %(shelf_name)s Stats', shelf_name=shelf_name)

$:_('Displaying stats about %d books. Note all charts show only the top 20 bars. Note reading log stats are private.', works_count)

-
+

$_('Author Stats')

@@ -147,12 +154,3 @@

$chart['title']

- - From 120675d9ed714dd5772b4bc367deb894b8491a1c Mon Sep 17 00:00:00 2001 From: Samuel Whittenberger Date: Wed, 18 Oct 2023 08:09:57 -0400 Subject: [PATCH 2/2] commit suggestions --- openlibrary/plugins/openlibrary/js/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openlibrary/plugins/openlibrary/js/index.js b/openlibrary/plugins/openlibrary/js/index.js index 12a3df63d9c..6349c605e82 100644 --- a/openlibrary/plugins/openlibrary/js/index.js +++ b/openlibrary/plugins/openlibrary/js/index.js @@ -251,9 +251,11 @@ jQuery(function () { .then((module) => module.init()); } - if ($('div.readinglog-charts').length) { + const readingLogCharts = document.querySelector('.readinglog-charts') + if (readingLogCharts) { + const readingLogConfig = JSON.parse(readingLogCharts.dataset.config) import(/* webpackChunkName: "readinglog-stats" */ './readinglog_stats') - .then(module => module.init($('div.readinglog-charts').data('config'))); + .then(module => module.init(readingLogConfig)); } const pageEl = $('#page-barcodescanner');