From 18b3651b46c5459fb856fafc47bd92432cfe33cb Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 20 Oct 2021 17:20:59 +0530 Subject: [PATCH] feat: Google font selection google_fonts.json with a decent selection of fonts --- frappe/data/google_fonts.json | 56 +++++++++++++++++++ .../print_format_builder_beta.py | 15 +++++ .../js/print_format_builder/Preview.vue | 8 ++- .../PrintFormatControls.vue | 32 +++++++---- .../public/js/print_format_builder/store.js | 17 ++++-- 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 frappe/data/google_fonts.json create mode 100644 frappe/printing/page/print_format_builder_beta/print_format_builder_beta.py diff --git a/frappe/data/google_fonts.json b/frappe/data/google_fonts.json new file mode 100644 index 0000000000..232e509e77 --- /dev/null +++ b/frappe/data/google_fonts.json @@ -0,0 +1,56 @@ +[ + "Alegreya Sans", + "Alegreya", + "Andada Pro", + "Anton", + "Archivo Narrow", + "Archivo", + "BioRhyme", + "Cardo", + "Chivo", + "Cormorant", + "Crimson Text", + "DM Sans", + "Eczar", + "Encode Sans", + "Epilogue ", + "Fira Sans", + "Hahmlet", + "IBM Plex Sans", + "Inconsolata", + "Inknut Antiqua", + "Inter", + "JetBrains Mono", + "Karla", + "Lato", + "Libre Baskerville", + "Libre Franklin", + "Lora", + "Manrope", + "Merriweather", + "Montserrat", + "Neuton", + "Nunito", + "Old Standard TT", + "Open Sans", + "Oswald", + "Oxygen", + "Playfair Display", + "Poppins", + "Proza Libre", + "PT Sans", + "PT Serif", + "Raleway", + "Roboto Slab", + "Roboto", + "Rubik", + "Sora", + "Source Sans Pro", + "Source Serif Pro", + "Space Grotesk", + "Space Mono", + "Spectral", + "Syne", + "Work Sans" +] + diff --git a/frappe/printing/page/print_format_builder_beta/print_format_builder_beta.py b/frappe/printing/page/print_format_builder_beta/print_format_builder_beta.py new file mode 100644 index 0000000000..6ef4395958 --- /dev/null +++ b/frappe/printing/page/print_format_builder_beta/print_format_builder_beta.py @@ -0,0 +1,15 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + + +@frappe.whitelist() +def get_google_fonts(): + return frappe.cache().get_value("google_fonts", generator=_get_google_fonts) + + +def _get_google_fonts(): + file_path = frappe.get_app_path("frappe", "data", "google_fonts.json") + return frappe.parse_json(frappe.read_file(file_path)) diff --git a/frappe/public/js/print_format_builder/Preview.vue b/frappe/public/js/print_format_builder/Preview.vue index 1d795f27d7..91103cc6b7 100644 --- a/frappe/public/js/print_format_builder/Preview.vue +++ b/frappe/public/js/print_format_builder/Preview.vue @@ -19,7 +19,7 @@ @@ -79,8 +79,14 @@ export default { this.get_default_docname().then( docname => docname && this.doc_select.set_value(docname) ); + this.$store.$on("after_save", () => { + this.refresh(); + }); }, methods: { + refresh() { + this.$refs.iframe.contentWindow.location.reload(); + }, get_default_docname() { return frappe.db.get_list(this.doctype, { limit: 1 }).then(doc => { return doc.length > 0 ? doc[0].name : null; diff --git a/frappe/public/js/print_format_builder/PrintFormatControls.vue b/frappe/public/js/print_format_builder/PrintFormatControls.vue index eb37fc53f8..ce04395744 100644 --- a/frappe/public/js/print_format_builder/PrintFormatControls.vue +++ b/frappe/public/js/print_format_builder/PrintFormatControls.vue @@ -39,16 +39,17 @@
- + v-model="print_format.font" + > + +
@@ -133,12 +134,23 @@ export default { mixins: [storeMixin], data() { return { - search_text: "" + search_text: "", + google_fonts: [] }; }, components: { draggable }, + mounted() { + let method = + "frappe.printing.page.print_format_builder_beta.print_format_builder_beta.get_google_fonts"; + frappe.call(method).then(r => { + this.google_fonts = r.message || []; + if (!this.google_fonts.includes(this.print_format.font)) { + this.google_fonts.push(this.print_format.font); + } + }); + }, methods: { update_margin(fieldname, value) { value = parseFloat(value); diff --git a/frappe/public/js/print_format_builder/store.js b/frappe/public/js/print_format_builder/store.js index 5de2c1c61b..f531a4a7e0 100644 --- a/frappe/public/js/print_format_builder/store.js +++ b/frappe/public/js/print_format_builder/store.js @@ -89,7 +89,7 @@ export function getStore(print_format_name) { "fieldtype", "options", "width", - "field_template", + "field_template" ]); } ); @@ -101,7 +101,7 @@ export function getStore(print_format_name) { "options", "table_columns", "html", - "field_template", + "field_template" ]); }); return column; @@ -125,7 +125,10 @@ export function getStore(print_format_name) { } }) .then(() => this.fetch()) - .always(() => frappe.dom.unfreeze()); + .always(() => { + frappe.dom.unfreeze(); + this.$emit("after_save"); + }); }, reset_changes() { this.fetch(); @@ -143,9 +146,11 @@ export function getStore(print_format_name) { return create_default_layout(this.meta, this.print_format); }, change_letterhead(letterhead) { - return frappe.db.get_doc("Letter Head", letterhead).then(doc => { - this.letterhead = doc; - }); + return frappe.db + .get_doc("Letter Head", letterhead) + .then(doc => { + this.letterhead = doc; + }); } } };