Merge pull request #7012 from frappe/revert-7009-desk-customize

Revert "feat(desk): Link Tags, Customize Sections"
This commit is contained in:
Rushabh Mehta 2019-03-02 19:49:48 +05:30 committed by GitHub
commit 478f2edefa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 305 deletions

View file

@ -1,7 +1,7 @@
from __future__ import unicode_literals
from frappe import _
import frappe
from frappe.desk.moduleview import get_data, get_onboard_items
from frappe.desk.moduleview import get_data
from six import iteritems
def get_modules_from_all_apps_for_user(user=None):
@ -62,8 +62,6 @@ def get_modules_from_app(app):
to_add = False
if to_add:
m["shortcuts"] = get_onboard_items(app, frappe.scrub(m["module_name"]))
m["app"] = app
active_modules_list.append(m)
return active_modules_list
@ -76,6 +74,7 @@ def get_all_empty_tables_by_module():
JOIN tabDocType as d
ON i.table_name = CONCAT('tab', d.name)
WHERE table_rows = 0;
""")
empty_tables_by_module = {}

View file

@ -1601,39 +1601,6 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "{\"Modules\": {}, \"Administration\": {}}",
"fieldname": "home_settings",
"fieldtype": "Code",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Home Settings",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
@ -2336,7 +2303,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 5,
"modified": "2019-03-01 10:02:01.433443",
"modified": "2019-01-30 13:56:10.732154",
"modified_by": "Administrator",
"module": "Core",
"name": "User",

View file

@ -7,7 +7,6 @@ from frappe import _
from frappe.boot import get_allowed_pages, get_allowed_reports
from frappe.desk.doctype.desktop_icon.desktop_icon import set_hidden, clear_desktop_icons_cache
@frappe.whitelist()
def get(module):
"""Returns data (sections, list of reports, counts) to render module view in desk:
@ -20,13 +19,11 @@ def get(module):
return out
@frappe.whitelist()
def hide_module(module):
set_hidden(module, frappe.session.user, 1)
clear_desktop_icons_cache()
def get_data(module, build=True):
"""Get module data for the module view `desk/#Module/[name]`"""
doctype_info = get_doctype_info(module)
@ -83,7 +80,6 @@ def get_data(module, build=True):
return data
def build_config_from_file(module):
"""Build module info from `app/config/desktop.py` files."""
data = []
@ -97,7 +93,6 @@ def build_config_from_file(module):
return filter_by_restrict_to_domain(data)
def filter_by_restrict_to_domain(data):
""" filter Pages and DocType depending on the Active Module(s) """
mapper = {
@ -119,7 +114,6 @@ def filter_by_restrict_to_domain(data):
return data
def build_standard_config(module, doctype_info):
"""Build standard module data from DocTypes."""
if not frappe.db.get_value("Module Def", module):
@ -138,7 +132,6 @@ def build_standard_config(module, doctype_info):
return data
def add_section(data, label, icon, items):
"""Adds a section to the module data."""
if not items: return
@ -157,7 +150,6 @@ def add_custom_doctypes(data, doctype_info):
add_section(data, _("Setup"), "fa fa-cog",
[d for d in doctype_info if (d.custom and d.document_type in ("Setup", "Master", ""))])
def get_doctype_info(module):
"""Returns list of non child DocTypes for given module."""
active_domains = frappe.get_active_domains()
@ -177,7 +169,6 @@ def get_doctype_info(module):
return doctype_info
def combine_common_sections(data):
"""Combine sections declared in separate apps."""
sections = []
@ -191,7 +182,6 @@ def combine_common_sections(data):
return sections
def apply_permissions(data):
default_country = frappe.db.get_default("country")
@ -225,14 +215,11 @@ def apply_permissions(data):
return new_data
def get_config(app, module):
"""Load module info from `[app].config.[module]`."""
config = frappe.get_module("{app}.config.{module}".format(app=app, module=module))
config = config.get_data()
print(module)
sections = [s for s in config if s.get("condition", True)]
for section in sections:
@ -245,7 +232,6 @@ def get_config(app, module):
return sections
def add_setup_section(config, app, module, label, icon):
"""Add common sections to `/desk#Module/Setup`"""
try:
@ -255,7 +241,6 @@ def add_setup_section(config, app, module, label, icon):
except ImportError:
pass
def get_setup_section(app, module, label, icon):
"""Get the setup section from each module (for global Setup page)."""
config = get_config(app, module)
@ -267,46 +252,12 @@ def get_setup_section(app, module, label, icon):
"items": section["items"]
}
def get_onboard_items(app, module):
try:
sections = get_config(app, module)
except ImportError:
return []
onboard_items = []
for section in sections:
for item in section["items"]:
if item.get("onboard", 0) == 1:
onboard_items.append(item)
return onboard_items
@frappe.whitelist()
def get_links(app, module):
try:
sections = get_config(app, frappe.scrub(module))
except ImportError:
return []
link_names = []
for section in sections:
for item in section["items"]:
link_names.append(item.get("label"))
print(link_names)
return link_names
def set_last_modified(data):
for section in data:
for item in section["items"]:
if item["type"] == "doctype":
item["last_modified"] = get_last_modified(item["name"])
def get_last_modified(doctype):
def _get():
try:
@ -330,7 +281,6 @@ def get_last_modified(doctype):
return last_modified
def get_report_list(module, is_standard="No"):
"""Returns list on new style reports for modules."""
reports = frappe.get_list("Report", fields=["name", "ref_doctype", "report_type"], filters=

View file

@ -1,208 +0,0 @@
<template>
<div>
<div class="section-header level text-muted">
<div class="module-category h6 uppercase">
{{ category }}
</div>
<div>
<a class="small text-muted" @click="show_customize_dialog">{{ __("Customize") }}</a>
</div>
</div>
<div class="modules-container">
<a v-for="module in modules"
:key="module.name"
:href="module.type === 'module' ? '#modules/' + module.module_name : module.link"
class="border module-box"
>
<div class="flush-top">
<div class="module-box-content">
<h4 class="h4">
<span class="indicator" :class="module.count ? 'red' : (module.onboard_present ? 'orange' : 'grey')"></span>
{{ module.label }}
</h4>
<p
v-if="module.shortcuts.length"
class="small text-muted">
<a
v-for="shortcut in module.shortcuts"
:key="shortcut.name"
:href="shortcut.link"
class="btn btn-default btn-xs shortcut-tag" title="toggle Tag"> {{ shortcut.label }}
</a>
</p>
<p v-else class="small text-muted"> {{ module.description }} </p>
</div>
</div>
</a>
</div>
</div>
</template>
<script>
export default {
props: ['category', 'initial_modules'],
data() {
return {
modules: this.initial_modules
}
},
methods: {
show_customize_dialog() {
if(!this.dialog) {
let all_modules = this.modules;
let fields = [];
all_modules.forEach(module => {
fields.push({
label: __(module.module_name),
fieldname: module.module_name,
fieldtype: "Check",
default: 1
});
if(module.shortcuts) {
fields.push({
label: __(""),
fieldname: module.module_name + "_shortcuts",
fieldtype: "MultiSelect",
get_data: function() {
let data = [];
frappe.call({
type: "GET",
method:'frappe.desk.moduleview.get_links',
async: false,
no_spinner: true,
args: {
app: module.app,
module: module.module_name,
},
callback: function(r) {
data = r.message;
}
});
return data;
},
default: module.shortcuts.map(m => (m.name || m.label)),
depends_on: module.module_name
});
}
});
this.dialog = new frappe.ui.Dialog({
title: __("Customize " + this.category),
fields: fields,
primary_action_label: __("Update"),
primary_action: (values) => {
let settings = {};
Object.keys(values).forEach(key => {
if(!key.includes('shortcuts') && values[key]) {
settings[key] = {
links: values[key + '_shortcuts'] || []
}
}
if(!values[key]) {
let index = -1;
this.modules.map((m, i) => {
if(m.module_name === key) {
index = i;
}
})
this.modules.splice(index, 1);
}
});
const user = frappe.session.user;
const fieldname = 'home_settings';
frappe.db.get_value('User', user,fieldname)
.then((resp) => {
let home_settings = JSON.parse(resp.message[fieldname]);
home_settings[this.category] = settings;
frappe.db.set_value('User', user, fieldname, home_settings)
.then((resp) => {
this.dialog.hide();
})
.fail((err) => {
frappe.msgprint(err);
});
})
}
});
this.dialog.modal_body.find('.clearfix').css({'display': 'none'});
this.dialog.modal_body.find('.frappe-control*[data-fieldtype="MultiSelect"]').css({'margin-bottom': '30px'});
}
this.dialog.show();
}
}
}
</script>
<style lang="less" scoped>
.section-header {
margin-top: 30px;
margin-bottom: 15px;
border-bottom: 1px solid #d0d8dd;
}
.modules-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-auto-rows: minmax(72px, 1fr);
column-gap: 15px;
row-gap: 15px;
}
.module-box {
border-radius: 4px;
cursor: pointer;
padding: 5px 15px;
padding-top: 3px;
display: block;
}
.module-box:hover {
background-color: #fafbfc;
text-decoration: none;
}
.module-box-content {
width: 100%;
h4 {
margin-bottom: 5px
}
p {
margin-top: 5px;
font-size: 80%;
display: flex;
overflow: hidden;
}
}
.icon-box {
padding: 15px;
width: 54px;
display: flex;
justify-content: center;
}
.icon {
font-size: 24px;
}
.open-notification {
top: -2px;
}
.shortcut-tag {
margin-right: 5px;
}
</style>

View file

@ -4,12 +4,27 @@
<div v-for="category in module_categories"
:key="category">
<desk-section
v-if="modules.filter(m => m.category === category).length"
:category="category"
:initial_modules="modules.filter(m => m.category === category)"
>
</desk-section>
<div v-if="modules.filter(m => m.category === category).length" class="module-category h6 uppercase">
{{ category }}
</div>
<div class="modules-container">
<a v-for="module in modules.filter(m => m.category === category )"
:key="module.name"
:href="module.type === 'module' ? '#modules/' + module.module_name : module.link"
class="border module-box"
>
<div class="flush-top">
<div class="module-box-content">
<h4 class="h4">
<span class="indicator" :class="module.count ? 'red' : (module.onboard_present ? 'orange' : 'grey')"></span>
{{ module.label }}
</h4>
<p class="small text-muted"> {{ module.description }} </p>
</div>
</div>
</a>
</div>
</div>
@ -17,12 +32,8 @@
</template>
<script>
import DeskSection from './DeskSection.vue';
export default {
components: {
DeskSection
},
data() {
let modules_list = frappe.boot.allowed_modules
.filter(d => (d.type==='module' || d.category==='Places') && !d.blocked);
@ -86,5 +97,58 @@ export default {
margin: 70px;
}
.module-category {
margin-top: 30px;
margin-bottom: 15px;
border-bottom: 1px solid #d0d8dd;
}
.modules-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-auto-rows: minmax(72px, 1fr);
column-gap: 15px;
row-gap: 15px;
}
.module-box {
border-radius: 4px;
cursor: pointer;
padding: 5px 15px;
padding-top: 3px;
display: block;
}
.module-box:hover {
background-color: #fafbfc;
text-decoration: none;
}
.module-box-content {
h4 {
margin-bottom: 5px
}
p {
margin-top: 5px;
font-size: 80%;
}
}
.icon-box {
padding: 15px;
width: 54px;
display: flex;
justify-content: center;
}
.icon {
font-size: 24px;
}
.open-notification {
top: -2px;
}
</style>