diff --git a/website_local_font/README.rst b/website_local_font/README.rst new file mode 100644 index 0000000000..90579bb5be --- /dev/null +++ b/website_local_font/README.rst @@ -0,0 +1,114 @@ +================== +Website Local Font +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:21948d7b105e692895d067c8fee8367e630601f87e0a96393bed77d7fbf1a58b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/16.0/website_local_font + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_local_font + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to add local fonts on Odoo website. + +By default,Odoo only allows to upload fonts available from Google(fonts.google.com) and they can be made available locally or from Google's server in addition to the fonts made available via website theme modules.But there's no option to upload and have local fonts available across all website themes. + + +To overcome this limitation, this module has been developed to allow users to upload proprietary (or custom) fonts in the most widely used font formats - otf,ttf,woff and woff2 and make it available across all website themes. + +The fonts can be deleted as well if not needed anymore. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To upload local fonts and use it for the website, you need to : + +1.Go to website (with editor enabled),click on 'Edit' and go to 'THEMES' section.Under Font Family, you would find an option 'Add a Local Font'. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/AddALocalFontOption.png + +2.When you click on the 'Add a Local Font' option, a wizard would open with two fields- 'Font File' and 'Font Name'.Upload the file with one of the supported file formats and the font name would be automatically updated based on the file.You can update the name or leave it as it is. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/SaveTheFont.png + +3.Click on 'Save & Reload' Button, you will see the font is applied to the elements of the website. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontAppliedOnWebsite.png + +4.If you want to see the list of local fonts or delete the locally uploaded fonts,click on 'Edit' on website and go to 'THEMES' section.Under Font Family, you would find the newly added font. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/NewlyAddedFont.png + +5.If you want to delete this locally added font , you can click on the delete icon next to it.Once, you click on the delete icon, it would open up a confirmation dialog. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/DeleteFontConfirmation.png + +6.Once you click on 'Ok' button, the page would be refreshed and you would see the font is changed for the website and also the font is not found in the list. + + .. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontDeleted.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Onestein + +Contributors +~~~~~~~~~~~~ + +* `Onestein `_: + + * Anjeel Haria + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_local_font/__manifest__.py b/website_local_font/__manifest__.py index d6a28bff08..91e83acb21 100644 --- a/website_local_font/__manifest__.py +++ b/website_local_font/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Website Local Font", "summary": "Allows to add local fonts on Odoo website", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Website", "website": "https://github.com/OCA/website", "author": "Onestein, Odoo Community Association (OCA)", @@ -25,5 +25,8 @@ "website_local_font/static/src/scss/secondary_variables.scss", ), ], + "web.assets_backend": [ + "website_local_font/static/src/xml/website.editor.xml", + ], }, } diff --git a/website_local_font/models/assets.py b/website_local_font/models/assets.py index a707b65a83..d337a7e0cd 100644 --- a/website_local_font/models/assets.py +++ b/website_local_font/models/assets.py @@ -3,12 +3,13 @@ import re -from odoo import models +from odoo import api, models class Assets(models.AbstractModel): _inherit = "web_editor.assets" + @api.model def make_scss_customization(self, url, values): """ Added handling for local fonts deletion and addition in scss diff --git a/website_local_font/static/description/icon.png b/website_local_font/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_local_font/static/description/icon.png differ diff --git a/website_local_font/static/description/index.html b/website_local_font/static/description/index.html new file mode 100644 index 0000000000..560d3d813d --- /dev/null +++ b/website_local_font/static/description/index.html @@ -0,0 +1,456 @@ + + + + + + +Website Local Font + + + +
+

Website Local Font

+ + +

Beta License: LGPL-3 OCA/website Translate me on Weblate Try me on Runboat

+

This module allows to add local fonts on Odoo website.

+

By default,Odoo only allows to upload fonts available from Google(fonts.google.com) and they can be made available locally or from Google’s server in addition to the fonts made available via website theme modules.But there’s no option to upload and have local fonts available across all website themes.

+

To overcome this limitation, this module has been developed to allow users to upload proprietary (or custom) fonts in the most widely used font formats - otf,ttf,woff and woff2 and make it available across all website themes.

+

The fonts can be deleted as well if not needed anymore.

+

Table of contents

+ +
+

Usage

+

To upload local fonts and use it for the website, you need to :

+

1.Go to website (with editor enabled),click on ‘Edit’ and go to ‘THEMES’ section.Under Font Family, you would find an option ‘Add a Local Font’.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/AddALocalFontOption.png +
+

2.When you click on the ‘Add a Local Font’ option, a wizard would open with two fields- ‘Font File’ and ‘Font Name’.Upload the file with one of the supported file formats and the font name would be automatically updated based on the file.You can update the name or leave it as it is.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/SaveTheFont.png +
+

3.Click on ‘Save & Reload’ Button, you will see the font is applied to the elements of the website.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontAppliedOnWebsite.png +
+

4.If you want to see the list of local fonts or delete the locally uploaded fonts,click on ‘Edit’ on website and go to ‘THEMES’ section.Under Font Family, you would find the newly added font.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/NewlyAddedFont.png +
+

5.If you want to delete this locally added font , you can click on the delete icon next to it.Once, you click on the delete icon, it would open up a confirmation dialog.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/DeleteFontConfirmation.png +
+

6.Once you click on ‘Ok’ button, the page would be refreshed and you would see the font is changed for the website and also the font is not found in the list.

+
+https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontDeleted.png +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Onestein
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/website project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_local_font/static/src/js/snippets.options.js b/website_local_font/static/src/js/snippets.options.js index b6ad54d2cc..88c6a4d614 100644 --- a/website_local_font/static/src/js/snippets.options.js +++ b/website_local_font/static/src/js/snippets.options.js @@ -26,11 +26,9 @@ odoo.define("website_local_font.editor.snippets.options", function (require) { */ start: async function () { await this._super(...arguments); - $(this.menuEl).empty(); const style = window.getComputedStyle(document.documentElement); - const nbFonts = parseInt( - weUtils.getCSSVariableValue("number-of-fonts", style) - ); + const nbFonts = + parseInt(weUtils.getCSSVariableValue("number-of-fonts", style)) || []; const localFontsProperty = weUtils.getCSSVariableValue( "local-fonts", style @@ -55,6 +53,7 @@ odoo.define("website_local_font.editor.snippets.options", function (require) { this.menuEl.appendChild(fontEl); }); if (this.localFonts.length) { + console.log(this.localFonts); const localFontsEls = fontEls.splice(-this.localFonts.length); localFontsEls.forEach((el, index) => { $(el).append( @@ -89,7 +88,6 @@ odoo.define("website_local_font.editor.snippets.options", function (require) { ); }); } - $(this.menuEl).append( $( core.qweb.render("website.add_google_font_btn", { @@ -221,9 +219,9 @@ odoo.define("website_local_font.editor.snippets.options", function (require) { if (!save) { return; } - // Remove Local font const localFontIndex = parseInt(ev.target.dataset.fontIndex); + console.log(localFontIndex); const localFont = this.localFonts[localFontIndex].split(":"); const localFontName = localFont[0]; values["delete-local-font-attachment-id"] = localFont[1]; diff --git a/website_local_font/static/src/xml/website.editor.xml b/website_local_font/static/src/xml/website.editor.xml index a3e734af2a..5bc5a1dc69 100644 --- a/website_local_font/static/src/xml/website.editor.xml +++ b/website_local_font/static/src/xml/website.editor.xml @@ -34,7 +34,9 @@ t-att-aria-label="delete_font_title" t-att-title="delete_font_title" t-att-data-font-index="index" - /> + > + Delete this font + diff --git a/website_local_font/tests/test_website_local_font.py b/website_local_font/tests/test_website_local_font.py index e9595025d9..17c1502cad 100644 --- a/website_local_font/tests/test_website_local_font.py +++ b/website_local_font/tests/test_website_local_font.py @@ -18,10 +18,11 @@ def test_font_file_import(font_file_name): class TestIrAttachment(common.TransactionCase): - def setUp(self): - super().setUp() - self.IrAttachment = self.env["ir.attachment"] - self.Web_Editor_Assets = self.env["web_editor.assets"] + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.IrAttachment = cls.env["ir.attachment"] + cls.Web_Editor_Assets = cls.env["web_editor.assets"] def test_add_local_font_otf(self): font_css_attachment_id = self.IrAttachment.add_local_font( @@ -71,19 +72,20 @@ def test_add_local_font_and_make_scss_customization(self): font_css_attachment_id = self.IrAttachment.add_local_font( "AmaticSC-Bold", "woff", test_font_file_import("AmaticSC-Bold.woff") ) - + attachment = self.env["ir.attachment"].browse(font_css_attachment_id) scss_file_url = "/website/static/src/scss/options/user_values.scss" self.Web_Editor_Assets.make_scss_customization( scss_file_url, {"local-fonts": "('AmaticSC-Bold': '" + str(font_css_attachment_id) + ")'"}, ) - custom_url = self.Web_Editor_Assets.make_custom_asset_file_url( + custom_url = self.Web_Editor_Assets._make_custom_asset_url( scss_file_url, "web.assets_common" ) + attachment.write({"url": custom_url}) custom_attachment = self.Web_Editor_Assets._get_custom_attachment(custom_url) custom_attachment_string = custom_attachment.raw.decode("utf-8") - self.assertIn( - str(font_css_attachment_id), custom_attachment_string, "Local Font is added" + self.assertEqual( + font_css_attachment_id, custom_attachment.id, "Local Font is added" ) self.assertIn("AmaticSC-Bold", custom_attachment_string, "Local Font is added")