From 6a1bbb2ff3b32430a4d69e9d4de6b1b1e26be11f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 18 May 2021 11:37:40 +0530 Subject: [PATCH 1/7] feat: Add document actions in mobile view --- frappe/public/js/frappe/form/form.js | 13 ++++++++++--- frappe/public/scss/desk/global.scss | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 6d8a6b1cb4..325bf52f05 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -1125,9 +1125,16 @@ frappe.ui.form.Form = class FrappeForm { add_custom_button(label, fn, group) { // temp! old parameter used to be icon - if(group && group.indexOf("fa fa-")!==-1) group = null; - var btn = this.page.add_inner_button(label, fn, group); - if(btn) { + if (group && group.indexOf("fa fa-") !== -1) + group = null; + + let btn = this.page.add_inner_button(label, fn, group); + + if (btn) { + // Add actions as menu item in Mobile View + let menu_item = this.page.add_menu_item(label, fn, false); + menu_item.parent().addClass("hidden-lg"); + this.custom_buttons[label] = btn; } return btn; diff --git a/frappe/public/scss/desk/global.scss b/frappe/public/scss/desk/global.scss index 4442795c62..afcf2957cc 100644 --- a/frappe/public/scss/desk/global.scss +++ b/frappe/public/scss/desk/global.scss @@ -120,6 +120,12 @@ pre { } } +.hidden-lg { + @include media-breakpoint-up(md) { + display: none !important; + } +} + .visible-xs { @include media-breakpoint-up(sm) { display: none !important; From 14cc6fd54684067b2f942908e30c4327b019f7db Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 18 May 2021 11:58:09 +0530 Subject: [PATCH 2/7] fix: Show button group hierarchy in menu item label --- frappe/public/js/frappe/form/form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 325bf52f05..083dc48e38 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -1132,7 +1132,8 @@ frappe.ui.form.Form = class FrappeForm { if (btn) { // Add actions as menu item in Mobile View - let menu_item = this.page.add_menu_item(label, fn, false); + let menu_item_label = group ? `${group} > ${label}` : label; + let menu_item = this.page.add_menu_item(menu_item_label, fn, false); menu_item.parent().addClass("hidden-lg"); this.custom_buttons[label] = btn; From 2dde3a9b0132f48b683520c3cd18ed503ebe09e9 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 2 Apr 2021 01:12:19 +0530 Subject: [PATCH 3/7] fix: Hide all warnings in frappe commands Hide all warnings when triggered via frappe.utils.bench_helper --- frappe/commands/utils.py | 3 --- frappe/utils/bench_helper.py | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 1ee2a7ec00..8ae55ae9c7 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -501,8 +501,6 @@ frappe.db.connect() @pass_context def console(context): "Start ipython console for a site" - import warnings - site = get_site(context) frappe.init(site=site) frappe.connect() @@ -523,7 +521,6 @@ def console(context): if failed_to_import: print("\nFailed to import:\n{}".format(", ".join(failed_to_import))) - warnings.simplefilter('ignore') IPython.embed(display_banner="", header="", colors="neutral") diff --git a/frappe/utils/bench_helper.py b/frappe/utils/bench_helper.py index 633d867306..e1ae7931d6 100644 --- a/frappe/utils/bench_helper.py +++ b/frappe/utils/bench_helper.py @@ -6,6 +6,7 @@ import json import importlib import frappe.utils import traceback +import warnings click.disable_unicode_literals_warning = True @@ -98,5 +99,5 @@ def get_apps(): return frappe.get_all_apps(with_internal_apps=False, sites_path='.') if __name__ == "__main__": + warnings.simplefilter('ignore') main() - From 8cc68048502e93947b6ca8ae45e43d2bdce99da9 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 19 May 2021 13:16:16 +0530 Subject: [PATCH 4/7] fix: Show deprecation warnings only if DEV_SERVER is set This will show warnings in bench start commands by default as this envvar is set. --- frappe/__init__.py | 13 +++++++++---- frappe/utils/bench_helper.py | 3 ++- frappe/utils/safe_exec.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 02b8d71e40..9b208f7c2d 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -10,9 +10,16 @@ be used to build database driven apps. Read the documentation: https://frappeframework.com/docs """ +import os, warnings + +_dev_server = os.environ.get('DEV_SERVER', False) + +if _dev_server: + warnings.simplefilter('always', DeprecationWarning) + warnings.simplefilter('always', PendingDeprecationWarning) from werkzeug.local import Local, release_local -import os, sys, importlib, inspect, json, warnings +import sys, importlib, inspect, json import typing from past.builtins import cmp import click @@ -31,8 +38,6 @@ __title__ = "Frappe Framework" local = Local() controllers = {} -warnings.simplefilter('always', DeprecationWarning) -warnings.simplefilter('always', PendingDeprecationWarning) class _dict(dict): """dict like object that exposes keys as attributes""" @@ -197,7 +202,7 @@ def init(site, sites_path=None, new_site=False): local.meta_cache = {} local.form_dict = _dict() local.session = _dict() - local.dev_server = os.environ.get('DEV_SERVER', False) + local.dev_server = _dev_server setup_module_map() diff --git a/frappe/utils/bench_helper.py b/frappe/utils/bench_helper.py index e1ae7931d6..2fb0bda058 100644 --- a/frappe/utils/bench_helper.py +++ b/frappe/utils/bench_helper.py @@ -99,5 +99,6 @@ def get_apps(): return frappe.get_all_apps(with_internal_apps=False, sites_path='.') if __name__ == "__main__": - warnings.simplefilter('ignore') + if not frappe._dev_server: + warnings.simplefilter('ignore') main() diff --git a/frappe/utils/safe_exec.py b/frappe/utils/safe_exec.py index 6c1fa21685..643812b226 100644 --- a/frappe/utils/safe_exec.py +++ b/frappe/utils/safe_exec.py @@ -119,7 +119,7 @@ def get_safe_globals(): scrub=scrub, guess_mimetype=mimetypes.guess_type, html2text=html2text, - dev_server=1 if os.environ.get('DEV_SERVER', False) else 0, + dev_server=1 if frappe._dev_server else 0, run_script=run_script ) From 8328e03d0d3f4426f250b3051c11723fafce1519 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 19 May 2021 13:17:29 +0530 Subject: [PATCH 5/7] fix: Unstrip better to handle multi line outputs in smaller terminal sizes --- frappe/build.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frappe/build.py b/frappe/build.py index 321a9bf734..5885243158 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -312,13 +312,20 @@ def clear_broken_symlinks(): -def unstrip(message): +def unstrip(message: str) -> str: + """Pads input string on the right side until the last available column in the terminal + """ + _len = len(message) try: max_str = os.get_terminal_size().columns except Exception: max_str = 80 - _len = len(message) - _rem = max_str - _len + + if _len < max_str: + _rem = max_str - _len + else: + _rem = max_str % _len + return f"{message}{' ' * _rem}" @@ -331,6 +338,7 @@ def make_asset_dirs(hard_link=False): start_message = unstrip(f"{'Copying assets from' if hard_link else 'Linking'} {source} to {target}") fail_message = unstrip(f"Cannot {'copy' if hard_link else 'link'} {source} to {target}") + # Used '\r' instead of '\x1b[1K\r' to print entire lines in smaller terminal sizes try: print(start_message, end="\r") link_assets_dir(source, target, hard_link=hard_link) From 42f2d87a684b3ef00ef3f8694caab940ebc24f16 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 19 May 2021 15:36:46 +0530 Subject: [PATCH 6/7] fix: Set home workspace as first available for user The default Build Workspace may not be available for all users depending on Role/Permissions settings. To handle this, instead of assuming everyone gets Build, we'll dynamically pick from the available workspaces instead (cherry picked from commit 3b427389473fc4fbf3e31e3c936dd6023427ab36) --- frappe/public/js/frappe/desk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index b7681a8f1a..46812f5fb6 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -289,7 +289,7 @@ frappe.Application = class Application { } if (!frappe.workspaces['home']) { // default workspace is settings for Frappe - frappe.workspaces['home'] = frappe.workspaces['build']; + frappe.workspaces['home'] = frappe.workspaces[Object.keys(frappe.workspaces)[0]]; } } From fc86458d3e4c1b706dbbafce915250fbe138dabb Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 19 May 2021 19:58:42 +0530 Subject: [PATCH 7/7] fix: Increase timeout for window close On mobile view, window.close would block rendering the print view. Increasing the timeout to 10s from 1s helps (cherry picked from commit b341167ffc37b1b93bdf1d712406c1d730746fd6) --- frappe/www/printview.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/www/printview.py b/frappe/www/printview.py index 3ddf032e9e..132d863375 100644 --- a/frappe/www/printview.py +++ b/frappe/www/printview.py @@ -505,8 +505,9 @@ window.print(); // close the window after print // NOTE: doesn't close if print is cancelled in Chrome +// Changed timeout to 5s from 1s because it blocked mobile view rendering setTimeout(function() { window.close(); -}, 1000); +}, 5000); """