From 4ee5c015c35fcb450e7f751edd5e8b533b974d02 Mon Sep 17 00:00:00 2001 From: Dirk van der Laarse Date: Wed, 14 Jun 2023 12:45:49 +0000 Subject: [PATCH 1/4] feat: setting for force web capture mode for camera uploads --- cypress/integration/control_attach.js | 45 +++++++++++++++++++ .../system_settings/system_settings.json | 9 +++- frappe/public/js/frappe/ui/capture.js | 11 +++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index 96b8c73b6e..d6086c9ed1 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -92,4 +92,49 @@ context("Attach Control", () => { cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click(); cy.click_modal_primary_button("Yes"); }); + + it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => { + //Navigating to the new form for the newly created doctype + let doctype = "Test Attach Control" + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); + cy.visit(`/app/${dt_in_route}/new`, { + onBeforeLoad (win) { + // Mock "window.navigator.mediaDevices" property + // to return mock mediaDevices object + win.navigator.mediaDevices = { + ondevicechange: null + } + } + }); + cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should("have.attr", "data-ajax-state", "complete"); + + //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype + cy.findByRole("button", { name: "Attach" }).click(); + + //Clicking on "Camera" button + cy.findByRole("button", { name: "Camera" }).should("exist"); + + }); + + it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => { + //Navigating to the new form for the newly created doctype + let doctype = "Test Attach Control" + let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); + cy.visit(`/app/${dt_in_route}/new`, { + onBeforeLoad (win) { + // Delete "window.navigator.mediaDevices" property + delete win.navigator.mediaDevices + } + }); + cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); + cy.get("body").should("have.attr", "data-ajax-state", "complete"); + + //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype + cy.findByRole("button", { name: "Attach" }).click(); + + //Clicking on "Camera" button + cy.findByRole("button", { name: "Camera" }).should("not.exist"); + + }); }); diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index 5efe87da25..5d88a3e466 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -563,12 +563,19 @@ "fieldtype": "Link", "label": "Reset Password Template", "options": "Email Template" + }, + { + "default": "0", + "description": "When uploading files, force the use of the web-based image capture. If this is unchecked, the default behavior is to use the mobile native camera when use from a mobile is detected.", + "fieldname": "force_web_capture_mode_for_uploads", + "fieldtype": "Check", + "label": "Force web capture mode for uploads" } ], "icon": "fa fa-cog", "issingle": 1, "links": [], - "modified": "2023-05-25 13:02:54.808773", + "modified": "2023-06-14 11:19:33.429196", "modified_by": "Administrator", "module": "Core", "name": "System Settings", diff --git a/frappe/public/js/frappe/ui/capture.js b/frappe/public/js/frappe/ui/capture.js index bc7ce34149..72841885a0 100644 --- a/frappe/public/js/frappe/ui/capture.js +++ b/frappe/public/js/frappe/ui/capture.js @@ -76,11 +76,16 @@ frappe.ui.Capture = class { show() { this.build_dialog(); - if (frappe.is_mobile()) { - this.show_for_mobile(); - } else { + if (frappe.boot.sysdefaults.force_web_capture_mode_for_uploads) { this.show_for_desktop(); } + else { + if (frappe.is_mobile()) { + this.show_for_mobile(); + } else { + this.show_for_desktop(); + } + } } build_dialog() { From 93519703335a92b5e7be9acf271aa60ad4830ca9 Mon Sep 17 00:00:00 2001 From: Dirk van der Laarse Date: Wed, 14 Jun 2023 16:01:48 +0200 Subject: [PATCH 2/4] fix: cast sysdefaults setting to int --- frappe/public/js/frappe/ui/capture.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/ui/capture.js b/frappe/public/js/frappe/ui/capture.js index 72841885a0..8309ffeeb8 100644 --- a/frappe/public/js/frappe/ui/capture.js +++ b/frappe/public/js/frappe/ui/capture.js @@ -76,7 +76,7 @@ frappe.ui.Capture = class { show() { this.build_dialog(); - if (frappe.boot.sysdefaults.force_web_capture_mode_for_uploads) { + if (cint(frappe.boot.sysdefaults.force_web_capture_mode_for_uploads)) { this.show_for_desktop(); } else { From c66d7448246e9578b30c5b59eabd0624b21aa864 Mon Sep 17 00:00:00 2001 From: Dirk van der Laarse Date: Sun, 30 Jul 2023 15:36:55 +0000 Subject: [PATCH 3/4] fix: field order and change label to title case --- frappe/core/doctype/system_settings/system_settings.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index 5d88a3e466..95dc1af924 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -33,6 +33,7 @@ "apply_strict_user_permissions", "column_break_21", "allow_guests_to_upload_files", + "force_web_capture_mode_for_uploads", "security", "session_expiry", "document_share_key_expiry", @@ -569,13 +570,13 @@ "description": "When uploading files, force the use of the web-based image capture. If this is unchecked, the default behavior is to use the mobile native camera when use from a mobile is detected.", "fieldname": "force_web_capture_mode_for_uploads", "fieldtype": "Check", - "label": "Force web capture mode for uploads" + "label": "Force Web Capture Mode for Uploads" } ], "icon": "fa fa-cog", "issingle": 1, "links": [], - "modified": "2023-06-14 11:19:33.429196", + "modified": "2023-07-30 17:34:08.292152", "modified_by": "Administrator", "module": "Core", "name": "System Settings", From 6645589cdf7682c327b4015e057def2bb397ceff Mon Sep 17 00:00:00 2001 From: Dirk van der Laarse Date: Sun, 30 Jul 2023 15:48:03 +0000 Subject: [PATCH 4/4] chore: linting fixes --- cypress/integration/control_attach.js | 30 +++++++++++++-------------- frappe/public/js/frappe/ui/capture.js | 11 ++++------ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index d6086c9ed1..6714f6c24e 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -95,17 +95,17 @@ context("Attach Control", () => { it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => { //Navigating to the new form for the newly created doctype - let doctype = "Test Attach Control" + let doctype = "Test Attach Control"; let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); cy.visit(`/app/${dt_in_route}/new`, { - onBeforeLoad (win) { - // Mock "window.navigator.mediaDevices" property - // to return mock mediaDevices object - win.navigator.mediaDevices = { - ondevicechange: null - } - } - }); + onBeforeLoad(win) { + // Mock "window.navigator.mediaDevices" property + // to return mock mediaDevices object + win.navigator.mediaDevices = { + ondevicechange: null, + }; + }, + }); cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); cy.get("body").should("have.attr", "data-ajax-state", "complete"); @@ -114,19 +114,18 @@ context("Attach Control", () => { //Clicking on "Camera" button cy.findByRole("button", { name: "Camera" }).should("exist"); - }); it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => { //Navigating to the new form for the newly created doctype - let doctype = "Test Attach Control" + let doctype = "Test Attach Control"; let dt_in_route = doctype.toLowerCase().replace(/ /g, "-"); cy.visit(`/app/${dt_in_route}/new`, { - onBeforeLoad (win) { + onBeforeLoad(win) { // Delete "window.navigator.mediaDevices" property - delete win.navigator.mediaDevices - } - }); + delete win.navigator.mediaDevices; + }, + }); cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`); cy.get("body").should("have.attr", "data-ajax-state", "complete"); @@ -135,6 +134,5 @@ context("Attach Control", () => { //Clicking on "Camera" button cy.findByRole("button", { name: "Camera" }).should("not.exist"); - }); }); diff --git a/frappe/public/js/frappe/ui/capture.js b/frappe/public/js/frappe/ui/capture.js index 8309ffeeb8..dc4804be52 100644 --- a/frappe/public/js/frappe/ui/capture.js +++ b/frappe/public/js/frappe/ui/capture.js @@ -78,13 +78,10 @@ frappe.ui.Capture = class { if (cint(frappe.boot.sysdefaults.force_web_capture_mode_for_uploads)) { this.show_for_desktop(); - } - else { - if (frappe.is_mobile()) { - this.show_for_mobile(); - } else { - this.show_for_desktop(); - } + } else if (frappe.is_mobile()) { + this.show_for_mobile(); + } else { + this.show_for_desktop(); } }