Skip to content

Commit

Permalink
Merge pull request #8389 from sbwhitt/fix/readinglog-inlinejs
Browse files Browse the repository at this point in the history
Remove inline JS from readinglog_stats.html
  • Loading branch information
jimchamp authored Oct 19, 2023
2 parents d72b54b + 120675d commit a6ebcf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 4 additions & 2 deletions openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ jQuery(function () {
.then((module) => module.init());
}

if (window.READINGLOG_STATS_CONFIG) {
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(window.READINGLOG_STATS_CONFIG));
.then(module => module.init(readingLogConfig));
}

const pageEl = $('#page-barcodescanner');
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/plugins/upstream/mybooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 8 additions & 10 deletions openlibrary/templates/account/readinglog_stats.html
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -96,7 +103,7 @@ <h1>$_('My %(shelf_name)s Stats', shelf_name=shelf_name)</h1>
<p>$:_('Displaying stats about <strong>%d</strong> books. Note all charts show only the top 20 bars. Note reading log stats are private.', works_count)</p>
</div>

<div class="readinglog-charts" style="padding: 12px;">
<div class="readinglog-charts" data-config="$dumps(reading_log_stats_config)" style="padding: 12px;">

<h2>$_('Author Stats')</h2>

Expand Down Expand Up @@ -147,12 +154,3 @@ <h3>$chart['title']</h3>
</div>
</main>
</details>

<script>
window.READINGLOG_STATS_CONFIG = {
works: $:works_json,
authors: $:authors_json,
lang: $:dumps(lang),
charts_selector: '.readinglog-stats-chart',
};
</script>

0 comments on commit a6ebcf2

Please sign in to comment.