From 5a89da1643bbdc6ea69c3963bb63cbe5f0e561f4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 3 Mar 2014 17:01:02 +0530 Subject: [PATCH] Standard Module View if config/{module}.py file is not found --- frappe/public/css/app.css | 13 ++++++ frappe/public/js/frappe/views/moduleview.js | 9 ++-- frappe/widgets/moduleview.py | 47 +++++++++++++++++++-- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/frappe/public/css/app.css b/frappe/public/css/app.css index ecb2cb179c..425af25f41 100644 --- a/frappe/public/css/app.css +++ b/frappe/public/css/app.css @@ -349,3 +349,16 @@ ul.linked-with-list li { margin: 0px -15px; box-shadow: 1px 1px 5px rgba(0,0,0,0.5); } + +/* on small screens, show only icons on top */ +@media (max-width: 767px) { + .module-view-layout .nav-stacked > li { + float: left; + margin-bottom: 5px; + } + + .nav-stacked > li + li { + margin-top: 0px; + margin-left: 2px; + } +} \ No newline at end of file diff --git a/frappe/public/js/frappe/views/moduleview.js b/frappe/public/js/frappe/views/moduleview.js index 418947dabd..1bb3a3ec08 100644 --- a/frappe/public/js/frappe/views/moduleview.js +++ b/frappe/public/js/frappe/views/moduleview.js @@ -101,7 +101,7 @@ frappe.views.moduleview.ModuleView = Class.extend({ }, make_layout: function(wrapper) { - return $('
\ + return $('
\
\ \
\ @@ -118,8 +118,9 @@ frappe.views.moduleview.ModuleView = Class.extend({ // if not found, add section if(!$nav.length) { // create nav tab - $nav = $('
  • ' - + frappe._(d.label)+'
  • ') + $nav = $('
  • \ +
  • ') .attr("data-label", d._label) .appendTo($sections); @@ -210,7 +211,7 @@ frappe.views.moduleview.ModuleView = Class.extend({ var reports_section = { label: __("Custom Reports"), - icon: "icon-list", + icon: "icon-list-alt", items: reports } this.add_section(reports_section, $layout); diff --git a/frappe/widgets/moduleview.py b/frappe/widgets/moduleview.py index 62718a62e9..d242221498 100644 --- a/frappe/widgets/moduleview.py +++ b/frappe/widgets/moduleview.py @@ -5,10 +5,14 @@ from __future__ import unicode_literals import frappe, json from frappe.widgets import reportview from frappe.utils import cint +from frappe import _ @frappe.whitelist() def get(module): data = get_data(module) + if not data: + data = build_standard_config(module) + doctypes = get_doctypes(data) return { @@ -29,6 +33,43 @@ def get_data(module): return data +def build_standard_config(module): + if not frappe.db.get_value("Module Def", module): + frappe.throw(_("Module Not Found")) + + data = [] + + doctypes = frappe.db.sql("""select "doctype" as type, name, description, + ifnull(document_type, "") as document_type + from `tabDocType` where module=%s and ifnull(istable, 0)=0 + order by document_type desc, name asc""", module, as_dict=True) + + documents = [d for d in doctypes if d.document_type in ("Transaction", "Master", "")] + if documents: + data.append({ + "label": _("Documents"), + "icon": "icon-star", + "items": documents + }) + + setup = [d for d in doctypes if d.document_type in ("System", "Other")] + if setup: + data.append({ + "label": _("Setup"), + "icon": "icon-cog", + "items": setup + }) + + reports = get_report_list(module, is_standard="Yes") + if reports: + data.append({ + "label": _("Standard Reports"), + "icon": "icon-list", + "items": reports + }) + + return data + def get_config(app, module): config = frappe.get_module("{app}.config.{module}".format(app=app, module=module)) return config.get_data() if hasattr(config, "get_data") else config.data @@ -63,7 +104,7 @@ def get_doctype_count_from_table(doctype): raise return cint(count) -def get_report_list(module): +def get_report_list(module, is_standard="No"): """return list on new style reports for modules""" return frappe.db.sql(""" select distinct "report" as type, tabReport.name, tabReport.ref_doctype as doctype, @@ -74,6 +115,6 @@ def get_report_list(module): where tabDocType.module=%s and tabDocType.name = tabReport.ref_doctype and tabReport.docstatus in (0, NULL) - and ifnull(tabReport.is_standard, "No")="No" + and ifnull(tabReport.is_standard, "No")=%s and ifnull(tabReport.disabled,0) != 1 - order by tabReport.name""", module, as_dict=True) \ No newline at end of file + order by tabReport.name""", (module, is_standard), as_dict=True) \ No newline at end of file