From d35e6e71c96443281f90ebcc6e06f3052345d4d3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 6 Aug 2024 19:59:30 -0500 Subject: [PATCH] feat: expose Web Libraries in app info config page get away from that CDN, hopefully speeds things up etc. --- src/wuttaweb/templates/appinfo/configure.mako | 156 ++++++++++++++++++ src/wuttaweb/util.py | 68 +++++--- src/wuttaweb/views/settings.py | 76 +++++++++ tests/test_util.py | 21 +++ tests/views/test_settings.py | 9 +- 5 files changed, 306 insertions(+), 24 deletions(-) diff --git a/src/wuttaweb/templates/appinfo/configure.mako b/src/wuttaweb/templates/appinfo/configure.mako index 218d092..1ea6481 100644 --- a/src/wuttaweb/templates/appinfo/configure.mako +++ b/src/wuttaweb/templates/appinfo/configure.mako @@ -13,8 +13,164 @@ + + + Production Mode + + + +

Web Libraries

+
+ + <${b}-table :data="weblibs"> + + <${b}-table-column field="title" + label="Name" + v-slot="props"> + {{ props.row.title }} + + + <${b}-table-column field="configured_version" + label="Version" + v-slot="props"> + {{ props.row.configured_version || props.row.default_version }} + + + <${b}-table-column field="configured_url" + label="URL Override" + v-slot="props"> + {{ props.row.configured_url }} + + + <${b}-table-column field="live_url" + label="Effective (Live) URL" + v-slot="props"> + + save settings and refresh page to see new URL + + + {{ props.row.live_url }} + + + + <${b}-table-column field="actions" + label="Actions" + v-slot="props"> + + % if request.use_oruga: + + % else: + + % endif + Edit + + + + + + % for weblib in weblibs or []: + ${h.hidden('wuttaweb.libver.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.libver.{}']".format(weblib['key'])})} + ${h.hidden('wuttaweb.liburl.{}'.format(weblib['key']), **{':value': "simpleSettings['wuttaweb.liburl.{}']".format(weblib['key'])})} + % endfor + + <${b}-modal has-modal-card + % if request.use_oruga: + v-model:active="editWebLibraryShowDialog" + % else: + :active.sync="editWebLibraryShowDialog" + % endif + > + + + +
+ + +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + diff --git a/src/wuttaweb/util.py b/src/wuttaweb/util.py index 85cfd70..61614ad 100644 --- a/src/wuttaweb/util.py +++ b/src/wuttaweb/util.py @@ -53,6 +53,7 @@ def get_form_data(request): def get_libver( request, key, + configured_only=False, default_only=False, prefix='wuttaweb', ): @@ -78,13 +79,11 @@ def get_libver( :param key: Unique key for the library, as string. Possibilities are the same as for :func:`get_liburl()`. - :param default_only: If this flag is ``True``, the logic will - *not* look for a "configured" version but rather will *only* - return the "default" version regardless of config. + :param configured_only: Pass ``True`` here if you only want the + configured version and ignore the default version. - If the flag is ``False`` (which it is by default) then the - config value will be used if present, and a default version is - used only if the config does not have a value. + :param default_only: Pass ``True`` here if you only want the + default version and ignore the configured version. :param prefix: If specified, will override the prefix used for config lookups. @@ -95,7 +94,7 @@ def get_libver( be removed in the future. :returns: The appropriate version string, e.g. ``'1.2.3'`` or - ``'latest'`` etc. + ``'latest'`` etc. Can also return ``None`` in some cases. """ config = request.wutta_config @@ -115,11 +114,14 @@ def get_libver( version = config.get(f'{prefix}.buefy_version') if version: return version - return 'latest' + if not configured_only: + return 'latest' elif key == 'buefy.css': # nb. this always returns something - return get_libver(request, 'buefy', default_only=default_only) + return get_libver(request, 'buefy', + default_only=default_only, + configured_only=configured_only) elif key == 'vue': if not default_only: @@ -127,36 +129,47 @@ def get_libver( version = config.get(f'{prefix}.vue_version') if version: return version - return '2.6.14' + if not configured_only: + return '2.6.14' elif key == 'vue_resource': - return 'latest' + if not configured_only: + return 'latest' elif key == 'fontawesome': - return '5.3.1' + if not configured_only: + return '5.3.1' elif key == 'bb_vue': - return '3.4.31' + if not configured_only: + return '3.4.31' elif key == 'bb_oruga': - return '0.8.12' + if not configured_only: + return '0.8.12' elif key in ('bb_oruga_bulma', 'bb_oruga_bulma_css'): - return '0.3.0' + if not configured_only: + return '0.3.0' elif key == 'bb_fontawesome_svg_core': - return '6.5.2' + if not configured_only: + return '6.5.2' elif key == 'bb_free_solid_svg_icons': - return '6.5.2' + if not configured_only: + return '6.5.2' elif key == 'bb_vue_fontawesome': - return '3.0.6' + if not configured_only: + return '3.0.6' def get_liburl( request, key, + configured_only=False, + default_only=False, prefix='wuttaweb', ): """ @@ -206,6 +219,12 @@ def get_liburl( * ``bb_free_solid_svg_icons`` * ``bb_vue_fontawesome`` + :param configured_only: Pass ``True`` here if you only want the + configured URL and ignore the default URL. + + :param default_only: Pass ``True`` here if you only want the + default URL and ignore the configured URL. + :param prefix: If specified, will override the prefix used for config lookups. @@ -214,13 +233,18 @@ def get_liburl( This ``prefix`` param is for backward compatibility and may be removed in the future. - :returns: The appropriate URL as string. + :returns: The appropriate URL as string. Can also return ``None`` + in some cases. """ config = request.wutta_config - url = config.get(f'{prefix}.liburl.{key}') - if url: - return url + if not default_only: + url = config.get(f'{prefix}.liburl.{key}') + if url: + return url + + if configured_only: + return version = get_libver(request, key, prefix=prefix) diff --git a/src/wuttaweb/views/settings.py b/src/wuttaweb/views/settings.py index f07524c..bfe6830 100644 --- a/src/wuttaweb/views/settings.py +++ b/src/wuttaweb/views/settings.py @@ -24,7 +24,10 @@ Views for app settings """ +from collections import OrderedDict + from wuttaweb.views import MasterView +from wuttaweb.util import get_libver, get_liburl class AppInfoView(MasterView): @@ -47,9 +50,82 @@ class AppInfoView(MasterView): # basics {'name': f'{self.app.appname}.app_title'}, + {'name': f'{self.app.appname}.production', + 'type': bool}, + + # web libs + {'name': 'wuttaweb.libver.vue'}, + {'name': 'wuttaweb.liburl.vue'}, + {'name': 'wuttaweb.libver.vue_resource'}, + {'name': 'wuttaweb.liburl.vue_resource'}, + {'name': 'wuttaweb.libver.buefy'}, + {'name': 'wuttaweb.liburl.buefy'}, + {'name': 'wuttaweb.libver.buefy.css'}, + {'name': 'wuttaweb.liburl.buefy.css'}, + {'name': 'wuttaweb.libver.fontawesome'}, + {'name': 'wuttaweb.liburl.fontawesome'}, + {'name': 'wuttaweb.libver.bb_vue'}, + {'name': 'wuttaweb.liburl.bb_vue'}, + {'name': 'wuttaweb.libver.bb_oruga'}, + {'name': 'wuttaweb.liburl.bb_oruga'}, + {'name': 'wuttaweb.libver.bb_oruga_bulma'}, + {'name': 'wuttaweb.liburl.bb_oruga_bulma'}, + {'name': 'wuttaweb.libver.bb_oruga_bulma_css'}, + {'name': 'wuttaweb.liburl.bb_oruga_bulma_css'}, + {'name': 'wuttaweb.libver.bb_fontawesome_svg_core'}, + {'name': 'wuttaweb.liburl.bb_fontawesome_svg_core'}, + {'name': 'wuttaweb.libver.bb_free_solid_svg_icons'}, + {'name': 'wuttaweb.liburl.bb_free_solid_svg_icons'}, + {'name': 'wuttaweb.libver.bb_vue_fontawesome'}, + {'name': 'wuttaweb.liburl.bb_vue_fontawesome'}, ] + def configure_get_context(self, **kwargs): + """ """ + + # normal context + context = super().configure_get_context(**kwargs) + + # we will add `weblibs` to context, based on config values + weblibs = OrderedDict([ + ('vue', "Vue"), + ('vue_resource', "vue-resource"), + ('buefy', "Buefy"), + ('buefy.css', "Buefy CSS"), + ('fontawesome', "FontAwesome"), + ('bb_vue', "(BB) vue"), + ('bb_oruga', "(BB) @oruga-ui/oruga-next"), + ('bb_oruga_bulma', "(BB) @oruga-ui/theme-bulma (JS)"), + ('bb_oruga_bulma_css', "(BB) @oruga-ui/theme-bulma (CSS)"), + ('bb_fontawesome_svg_core', "(BB) @fortawesome/fontawesome-svg-core"), + ('bb_free_solid_svg_icons', "(BB) @fortawesome/free-solid-svg-icons"), + ('bb_vue_fontawesome', "(BB) @fortawesome/vue-fontawesome"), + ]) + + # import ipdb; ipdb.set_trace() + + for key in weblibs: + title = weblibs[key] + weblibs[key] = { + 'key': key, + 'title': title, + + # nb. these values are exactly as configured, and are + # used for editing the settings + 'configured_version': get_libver(self.request, key, + configured_only=True), + 'configured_url': get_liburl(self.request, key, + configured_only=True), + + # nb. these are for display only + 'default_version': get_libver(self.request, key, default_only=True), + 'live_url': get_liburl(self.request, key), + } + + context['weblibs'] = list(weblibs.values()) + return context + def defaults(config, **kwargs): base = globals() diff --git a/tests/test_util.py b/tests/test_util.py index 742ef91..44817e5 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -30,6 +30,10 @@ class TestGetLibVer(TestCase): version = util.get_libver(self.request, 'buefy') self.assertEqual(version, '0.9.29') + def test_buefy_configured_only(self): + version = util.get_libver(self.request, 'buefy', configured_only=True) + self.assertIsNone(version) + def test_buefy_default_only(self): self.config.setdefault('wuttaweb.libver.buefy', '0.9.29') version = util.get_libver(self.request, 'buefy', default_only=True) @@ -51,6 +55,10 @@ class TestGetLibVer(TestCase): version = util.get_libver(self.request, 'buefy.css') self.assertEqual(version, '0.9.29') + def test_buefy_css_configured_only(self): + version = util.get_libver(self.request, 'buefy.css', configured_only=True) + self.assertIsNone(version) + def test_buefy_css_default_only(self): self.config.setdefault('wuttaweb.libver.buefy', '0.9.29') version = util.get_libver(self.request, 'buefy.css', default_only=True) @@ -70,6 +78,10 @@ class TestGetLibVer(TestCase): version = util.get_libver(self.request, 'vue') self.assertEqual(version, '3.4.31') + def test_vue_configured_only(self): + version = util.get_libver(self.request, 'vue', configured_only=True) + self.assertIsNone(version) + def test_vue_default_only(self): self.config.setdefault('wuttaweb.libver.vue', '3.4.31') version = util.get_libver(self.request, 'vue', default_only=True) @@ -166,6 +178,15 @@ class TestGetLibUrl(TestCase): url = util.get_liburl(self.request, 'buefy') self.assertEqual(url, '/lib/buefy.js') + def test_buefy_default_only(self): + self.config.setdefault('wuttaweb.liburl.buefy', '/lib/buefy.js') + url = util.get_liburl(self.request, 'buefy', default_only=True) + self.assertEqual(url, 'https://unpkg.com/buefy@latest/dist/buefy.min.js') + + def test_buefy_configured_only(self): + url = util.get_liburl(self.request, 'buefy', configured_only=True) + self.assertIsNone(url) + def test_buefy_css_default(self): url = util.get_liburl(self.request, 'buefy.css') self.assertEqual(url, 'https://unpkg.com/buefy@latest/dist/buefy.min.css') diff --git a/tests/views/test_settings.py b/tests/views/test_settings.py index 0968052..310c214 100644 --- a/tests/views/test_settings.py +++ b/tests/views/test_settings.py @@ -8,11 +8,16 @@ from wuttaweb.views import settings class TestAppInfoView(WebTestCase): def test_index(self): - # just a sanity check + # sanity/coverage check view = settings.AppInfoView(self.request) response = view.index() def test_configure_get_simple_settings(self): - # just a sanity check + # sanity/coverage check view = settings.AppInfoView(self.request) simple = view.configure_get_simple_settings() + + def test_configure_get_context(self): + # sanity/coverage check + view = settings.AppInfoView(self.request) + context = view.configure_get_context()