From 07142bbd132ce71281e0e0d851fe09cb3b843136 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Sun, 31 Mar 2019 18:25:28 +0530 Subject: [PATCH 01/11] feat: Added template for imageview_fields --- frappe/public/js/frappe/list/list_view.js | 1 + frappe/public/js/frappe/views/image/image_view.js | 8 ++++++++ frappe/public/less/list.less | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index 8278ad8526..bdd047853a 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -149,6 +149,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { this.get_fields_in_list_view(), [this.meta.title_field, this.meta.image_field], (this.settings.add_fields || []), + (this.settings.imageview_fields || []), this.meta.track_seen ? '_seen' : null, this.sort_by, 'enabled', diff --git a/frappe/public/js/frappe/views/image/image_view.js b/frappe/public/js/frappe/views/image/image_view.js index 3c2b5e7ce1..f633d57f85 100644 --- a/frappe/public/js/frappe/views/image/image_view.js +++ b/frappe/public/js/frappe/views/image/image_view.js @@ -23,6 +23,7 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { set_fields() { this.fields = [ 'name', + ...this.settings.imageview_fields, this.meta.title_field, this.meta.image_field ]; @@ -65,12 +66,18 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { item._name = encodeURI(item.name); const encoded_name = item._name; const title = strip_html(item[this.meta.title_field || 'name']); + const info_fields = this.settings.imageview_fields || [] const _class = !item._image_url ? 'no-image' : ''; const _html = item._image_url ? `${ title }` : ` ${ frappe.get_abbr(title) } `; + let info_html = `
` return `
@@ -94,6 +101,7 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView {
+ ${info_html} `; } diff --git a/frappe/public/less/list.less b/frappe/public/less/list.less index 71c3be4250..c0f9199d85 100644 --- a/frappe/public/less/list.less +++ b/frappe/public/less/list.less @@ -321,6 +321,10 @@ input.list-check-all, input.list-row-checkbox { margin-bottom: 10px; } + .image-view-info { + margin-top: 10px; + } + .image-view-body { &:hover .zoom-view { opacity: 0.7; From 5804e32d3f1a234eb55910fae45d0f701097f302 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Wed, 10 Apr 2019 21:00:49 +0530 Subject: [PATCH 02/11] fix: inconsistent padding in employee image view --- frappe/public/css/list.css | 1 - frappe/public/less/list.less | 1 - 2 files changed, 2 deletions(-) diff --git a/frappe/public/css/list.css b/frappe/public/css/list.css index 3befc646be..2d95b5c83f 100644 --- a/frappe/public/css/list.css +++ b/frappe/public/css/list.css @@ -297,7 +297,6 @@ input.list-row-checkbox { justify-content: center; position: relative; height: 200px; - padding: 15px; } .image-view-container .image-field img { max-height: 100%; diff --git a/frappe/public/less/list.less b/frappe/public/less/list.less index c0f9199d85..66c2bc8af4 100644 --- a/frappe/public/less/list.less +++ b/frappe/public/less/list.less @@ -342,7 +342,6 @@ input.list-check-all, input.list-row-checkbox { justify-content: center; position: relative; height: 200px; - padding: 15px; img { max-height: 100%; From 378e51dbb93946df70c9bb9c2c086f7e608f6afa Mon Sep 17 00:00:00 2001 From: scmmishra Date: Wed, 10 Apr 2019 21:04:01 +0530 Subject: [PATCH 03/11] fix: Template for image view details --- frappe/public/js/frappe/views/image/image_view.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/views/image/image_view.js b/frappe/public/js/frappe/views/image/image_view.js index f633d57f85..f1eedf14c8 100644 --- a/frappe/public/js/frappe/views/image/image_view.js +++ b/frappe/public/js/frappe/views/image/image_view.js @@ -74,8 +74,11 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { ${ frappe.get_abbr(title) } `; let info_html = `
    ` - info_fields.forEach((field) => { - if (item[field]) info_html += `
  • ${item[field]}
  • ` + info_fields.forEach((field, index) => { + if (item[field]) { + if (index == 0) info_html += `
  • ${item[field]}
  • ` + else info_html += `
  • ${item[field]}
  • ` + } }) info_html += `
` From 914dada4b9ad76c0e99e9669f87dd7f39d832273 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Mon, 15 Apr 2019 13:49:43 +0530 Subject: [PATCH 04/11] feat: Refactored image view details - Now "Show in List View" marked fields are shown in the image view --- frappe/public/js/frappe/list/list_view.js | 1 - .../js/frappe/views/image/image_view.js | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index bdd047853a..8278ad8526 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -149,7 +149,6 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { this.get_fields_in_list_view(), [this.meta.title_field, this.meta.image_field], (this.settings.add_fields || []), - (this.settings.imageview_fields || []), this.meta.track_seen ? '_seen' : null, this.sort_by, 'enabled', diff --git a/frappe/public/js/frappe/views/image/image_view.js b/frappe/public/js/frappe/views/image/image_view.js index f1eedf14c8..20e53950fa 100644 --- a/frappe/public/js/frappe/views/image/image_view.js +++ b/frappe/public/js/frappe/views/image/image_view.js @@ -23,7 +23,7 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { set_fields() { this.fields = [ 'name', - ...this.settings.imageview_fields, + ...this.get_fields_in_list_view().map((el)=> el.fieldname), this.meta.title_field, this.meta.image_field ]; @@ -62,17 +62,8 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { `); } - item_html(item) { - item._name = encodeURI(item.name); - const encoded_name = item._name; - const title = strip_html(item[this.meta.title_field || 'name']); - const info_fields = this.settings.imageview_fields || [] - const _class = !item._image_url ? 'no-image' : ''; - const _html = item._image_url ? - `${ title }` : - ` - ${ frappe.get_abbr(title) } - `; + item_details_html(item) { + const info_fields = this.get_fields_in_list_view().map((el)=> el.fieldname) || [] let info_html = `
    ` info_fields.forEach((field, index) => { if (item[field]) { @@ -81,6 +72,21 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { } }) info_html += `
` + return info_html + } + + item_html(item) { + item._name = encodeURI(item.name); + const encoded_name = item._name; + const title = strip_html(item[this.meta.title_field || 'name']); + const _class = !item._image_url ? 'no-image' : ''; + const _html = item._image_url ? + `${ title }` : + ` + ${ frappe.get_abbr(title) } + `; + + let details = this.item_details_html(item) return `
@@ -104,7 +110,7 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView {
- ${info_html} + ${details} `; } From 396c0f4b8a34293da37715b18b217aee62585e2d Mon Sep 17 00:00:00 2001 From: scmmishra Date: Mon, 15 Apr 2019 13:57:11 +0530 Subject: [PATCH 05/11] fix: Bottom border not visible for single item in image view --- frappe/public/less/list.less | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frappe/public/less/list.less b/frappe/public/less/list.less index 66c2bc8af4..31984f08c9 100644 --- a/frappe/public/less/list.less +++ b/frappe/public/less/list.less @@ -312,10 +312,6 @@ input.list-check-all, input.list-row-checkbox { .image-view-item:nth-child(4n) { border-right: none; } - .image-view-item:nth-last-child(-n + 4):nth-child(4n + 1), - .image-view-item:nth-last-child(-n + 4):nth-child(4n + 1) ~ .image-view-item { - border-bottom: none; - } .image-view-header { margin-bottom: 10px; From a3ee5ab6df9dffb3c8b38693a389acd7703f107a Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 15 Apr 2019 14:38:09 +0530 Subject: [PATCH 06/11] fix: save button should not remain disabled when the system is offline --- frappe/public/js/frappe/request.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/request.js b/frappe/public/js/frappe/request.js index cd102117d7..dd92e4109c 100644 --- a/frappe/public/js/frappe/request.js +++ b/frappe/public/js/frappe/request.js @@ -30,7 +30,8 @@ frappe.call = function(opts) { indicator: 'orange', message: __('You are not connected to Internet. Retry after sometime.') }, 3); - return; + opts.always && opts.always(); + return $.ajax(); } if (typeof arguments[0]==='string') { opts = { From 8fb86cc1eb952c6d7c18d6c2e1f9f1dd851a396b Mon Sep 17 00:00:00 2001 From: scmmishra Date: Mon, 15 Apr 2019 16:19:49 +0530 Subject: [PATCH 07/11] fix (codacy): Fixed linting issues --- frappe/public/js/frappe/views/image/image_view.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frappe/public/js/frappe/views/image/image_view.js b/frappe/public/js/frappe/views/image/image_view.js index 20e53950fa..a82e5802f1 100644 --- a/frappe/public/js/frappe/views/image/image_view.js +++ b/frappe/public/js/frappe/views/image/image_view.js @@ -63,16 +63,16 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { } item_details_html(item) { - const info_fields = this.get_fields_in_list_view().map((el)=> el.fieldname) || [] - let info_html = `
    ` + const info_fields = this.get_fields_in_list_view().map((el)=> el.fieldname) || []; + let info_html = `
      `; info_fields.forEach((field, index) => { if (item[field]) { - if (index == 0) info_html += `
    • ${item[field]}
    • ` - else info_html += `
    • ${item[field]}
    • ` + if (index == 0) info_html += `
    • ${item[field]}
    • `; + else info_html += `
    • ${item[field]}
    • `; } }) - info_html += `
    ` - return info_html + info_html += `
`; + return info_html; } item_html(item) { @@ -86,7 +86,7 @@ frappe.views.ImageView = class ImageView extends frappe.views.ListView { ${ frappe.get_abbr(title) } `; - let details = this.item_details_html(item) + let details = this.item_details_html(item); return `
From f34363956cf8bf0dd1c390096848c2eb1e919b18 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Apr 2019 11:11:58 +0530 Subject: [PATCH 08/11] feat(get_period_beginning): in frappe.desk.doctype.dashboard_chart.dashboard_chart --- .../dashboard_chart/dashboard_chart.py | 20 ++++++++++++++++++- .../dashboard_chart/test_dashboard_chart.py | 11 +++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py index 4cdf29b758..a6c8288559 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py @@ -145,7 +145,9 @@ def get_next_expected_date(date, timegrain): def get_period_ending(date, timegrain): date = getdate(date) - if timegrain=='Weekly': + if timegrain=='Daily': + pass + elif timegrain=='Weekly': date = get_week_ending(date) elif timegrain=='Monthly': date = get_month_ending(date) @@ -154,6 +156,22 @@ def get_period_ending(date, timegrain): return getdate(date) +def get_period_beginning(date, timegrain): + if timegrain=='Daily': + return getdate(date) + + ending = get_period_ending(date, timegrain) + beginning = None + + if timegrain=='Weekly': + beginning = add_to_date(add_to_date(ending, weeks=-1), days = 1) + elif timegrain=='Monthly': + beginning = add_to_date(add_to_date(ending, months=-1), days = 1) + elif timegrain=='Quarterly': + beginning = add_to_date(add_to_date(ending, months=-3), days = 1) + + return getdate(beginning) + def get_week_ending(date): # fun fact: week ends on the day before 1st Jan of the year. # for 2019 it is Monday diff --git a/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py index ca55d9254a..d92c1a120c 100644 --- a/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest, frappe from frappe.utils import getdate from frappe.desk.doctype.dashboard_chart.dashboard_chart import (get, - get_period_ending) + get_period_ending, get_period_beginning) class TestDashboardChart(unittest.TestCase): def test_period_ending(self): @@ -32,6 +32,15 @@ class TestDashboardChart(unittest.TestCase): self.assertEqual(get_period_ending('2019-10-01', 'Quarterly'), getdate('2019-12-31')) + def test_get_period_beginning(self): + self.assertEqual(get_period_beginning('2019-02-02', 'Monthly'), + getdate('2019-02-01')) + self.assertEqual(get_period_beginning('2019-02-02', 'Quarterly'), + getdate('2019-01-01')) + self.assertEqual(get_period_beginning('2019-01-29', 'Weekly'), + getdate('2019-02-01')) + + def test_dashboard_chart(self): if frappe.db.exists('Dashboard Chart', 'Test Dashboard Chart'): frappe.delete_doc('Dashboard Chart', 'Test Dashboard Chart') From 64187bb451d57384100c5e8e206524e7b59bab21 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Tue, 16 Apr 2019 12:53:37 +0530 Subject: [PATCH 09/11] fix: Custom columns handling for prepared report --- frappe/core/doctype/prepared_report/prepared_report.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frappe/core/doctype/prepared_report/prepared_report.py b/frappe/core/doctype/prepared_report/prepared_report.py index 1cd106dabd..5217a6537d 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.py +++ b/frappe/core/doctype/prepared_report/prepared_report.py @@ -37,6 +37,15 @@ class PreparedReport(Document): def run_background(instance): report = frappe.get_doc("Report", instance.ref_report_doctype) + + report.custom_columns = [] + + if report.report_type == 'Custom Report': + custom_report_doc = report + reference_report = custom_report_doc.reference_report + report = frappe.get_doc("Report", reference_report) + report.custom_columns = custom_report_doc.json + result = generate_report_result(report, filters=instance.filters, user=instance.owner) create_json_gz_file(result['result'], 'Prepared Report', instance.name) From f5b459c4c83cfe166ee84fb779d1b2e111d29091 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Apr 2019 15:10:55 +0530 Subject: [PATCH 10/11] fix(test): comments --- frappe/core/doctype/comment/test_comment.py | 2 +- .../doctype/dashboard_chart/dashboard_chart.py | 16 ---------------- .../dashboard_chart/test_dashboard_chart.py | 11 +---------- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/frappe/core/doctype/comment/test_comment.py b/frappe/core/doctype/comment/test_comment.py index 0f46f0b3b5..2f6583b7ba 100644 --- a/frappe/core/doctype/comment/test_comment.py +++ b/frappe/core/doctype/comment/test_comment.py @@ -35,7 +35,7 @@ class TestComment(unittest.TestCase): frappe.db.sql("delete from `tabComment` where reference_doctype = 'Blog Post'") from frappe.templates.includes.comments.comments import add_comment - add_comment('hello', 'test@test.com', 'Good Tester', + add_comment('Good comment with 10 chars', 'test@test.com', 'Good Tester', 'Blog Post', test_blog.name, test_blog.route) self.assertEqual(frappe.get_all('Comment', fields = ['*'], filters = dict( diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py index a6c8288559..217b456349 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py @@ -156,22 +156,6 @@ def get_period_ending(date, timegrain): return getdate(date) -def get_period_beginning(date, timegrain): - if timegrain=='Daily': - return getdate(date) - - ending = get_period_ending(date, timegrain) - beginning = None - - if timegrain=='Weekly': - beginning = add_to_date(add_to_date(ending, weeks=-1), days = 1) - elif timegrain=='Monthly': - beginning = add_to_date(add_to_date(ending, months=-1), days = 1) - elif timegrain=='Quarterly': - beginning = add_to_date(add_to_date(ending, months=-3), days = 1) - - return getdate(beginning) - def get_week_ending(date): # fun fact: week ends on the day before 1st Jan of the year. # for 2019 it is Monday diff --git a/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py index d92c1a120c..ca55d9254a 100644 --- a/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/test_dashboard_chart.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest, frappe from frappe.utils import getdate from frappe.desk.doctype.dashboard_chart.dashboard_chart import (get, - get_period_ending, get_period_beginning) + get_period_ending) class TestDashboardChart(unittest.TestCase): def test_period_ending(self): @@ -32,15 +32,6 @@ class TestDashboardChart(unittest.TestCase): self.assertEqual(get_period_ending('2019-10-01', 'Quarterly'), getdate('2019-12-31')) - def test_get_period_beginning(self): - self.assertEqual(get_period_beginning('2019-02-02', 'Monthly'), - getdate('2019-02-01')) - self.assertEqual(get_period_beginning('2019-02-02', 'Quarterly'), - getdate('2019-01-01')) - self.assertEqual(get_period_beginning('2019-01-29', 'Weekly'), - getdate('2019-02-01')) - - def test_dashboard_chart(self): if frappe.db.exists('Dashboard Chart', 'Test Dashboard Chart'): frappe.delete_doc('Dashboard Chart', 'Test Dashboard Chart') From 2155c52d3601e0fec033d18878fb37388a82f1a5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Apr 2019 15:37:44 +0530 Subject: [PATCH 11/11] fix: link selection relevance --- frappe/desk/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/desk/search.py b/frappe/desk/search.py index 04caf36754..61b0cf2905 100644 --- a/frappe/desk/search.py +++ b/frappe/desk/search.py @@ -137,7 +137,7 @@ def search_widget(doctype, txt, query=None, searchfield=None, start=0, from frappe.model.db_query import get_order_by order_by_based_on_meta = get_order_by(doctype, meta) # 2 is the index of _relevance column - order_by = "2 , {0}, `tab{1}`.idx desc".format(order_by_based_on_meta, doctype) + order_by = "_relevance, {0}, `tab{1}`.idx desc".format(order_by_based_on_meta, doctype) ignore_permissions = True if doctype == "DocType" else (cint(ignore_user_permissions) and has_permission(doctype))