From 248e9cd7d10b44041468b3199a94dbc8557a678d Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 12 Nov 2020 14:55:21 +0530 Subject: [PATCH] feat(doctype-urls): pretty doctype urls and removed social JS code --- frappe/cache_manager.py | 13 +- frappe/desk/treeview.py | 2 +- frappe/desk/utils.py | 16 + frappe/public/build.json | 3 - frappe/public/js/frappe/desk.js | 3 - frappe/public/js/frappe/form/form.js | 2 +- frappe/public/js/frappe/router.js | 308 +++++++++++------- frappe/public/js/frappe/social/Home.vue | 111 ------- .../social/components/ActivitySidebar.vue | 48 --- .../frappe/social/components/ImageViewer.vue | 66 ---- .../js/frappe/social/components/NotFound.vue | 5 - .../js/frappe/social/components/Post.vue | 227 ------------- .../frappe/social/components/PostAction.vue | 66 ---- .../frappe/social/components/PostComment.vue | 123 ------- .../social/components/PostDropdownMenu.vue | 27 -- .../frappe/social/components/PostLoader.vue | 128 -------- .../frappe/social/components/PostSidebar.vue | 81 ----- .../frappe/social/components/PostSkeleton.vue | 61 ---- .../social/components/ProfileBanner.vue | 69 ---- .../social/components/ProfileSidebar.vue | 145 --------- .../public/js/frappe/social/pages/Profile.vue | 107 ------ .../js/frappe/social/pages/UserList.vue | 219 ------------- frappe/public/js/frappe/social/pages/Wall.vue | 50 --- .../public/js/frappe/social/social_factory.js | 21 -- frappe/public/js/frappe/social/social_home.js | 67 ---- frappe/public/js/frappe/views/container.js | 2 +- .../js/frappe/views/workspace/workspace.js | 2 +- .../public/js/frappe/widgets/links_widget.js | 5 +- frappe/public/js/frappe/widgets/utils.js | 21 +- frappe/public/less/social.less | 155 --------- 30 files changed, 222 insertions(+), 1931 deletions(-) create mode 100644 frappe/desk/utils.py delete mode 100644 frappe/public/js/frappe/social/Home.vue delete mode 100644 frappe/public/js/frappe/social/components/ActivitySidebar.vue delete mode 100644 frappe/public/js/frappe/social/components/ImageViewer.vue delete mode 100644 frappe/public/js/frappe/social/components/NotFound.vue delete mode 100644 frappe/public/js/frappe/social/components/Post.vue delete mode 100644 frappe/public/js/frappe/social/components/PostAction.vue delete mode 100644 frappe/public/js/frappe/social/components/PostComment.vue delete mode 100644 frappe/public/js/frappe/social/components/PostDropdownMenu.vue delete mode 100644 frappe/public/js/frappe/social/components/PostLoader.vue delete mode 100644 frappe/public/js/frappe/social/components/PostSidebar.vue delete mode 100644 frappe/public/js/frappe/social/components/PostSkeleton.vue delete mode 100644 frappe/public/js/frappe/social/components/ProfileBanner.vue delete mode 100644 frappe/public/js/frappe/social/components/ProfileSidebar.vue delete mode 100644 frappe/public/js/frappe/social/pages/Profile.vue delete mode 100644 frappe/public/js/frappe/social/pages/UserList.vue delete mode 100644 frappe/public/js/frappe/social/pages/Wall.vue delete mode 100644 frappe/public/js/frappe/social/social_factory.js delete mode 100644 frappe/public/js/frappe/social/social_home.js delete mode 100644 frappe/public/less/social.less diff --git a/frappe/cache_manager.py b/frappe/cache_manager.py index 3b3d188999..47dec71fce 100644 --- a/frappe/cache_manager.py +++ b/frappe/cache_manager.py @@ -18,7 +18,7 @@ global_cache_keys = ("app_hooks", "installed_apps", 'scheduler_events', 'time_zone', 'webhooks', 'active_domains', 'active_modules', 'assignment_rule', 'server_script_map', 'wkhtmltopdf_version', 'domain_restricted_doctypes', 'domain_restricted_pages', 'information_schema:counts', - 'sitemap_routes', 'db_tables') + doctype_map_keys + 'sitemap_routes', 'db_tables', 'doctype_name_map') + doctype_map_keys user_cache_keys = ("bootinfo", "user_recent", "roles", "user_doc", "lang", "defaults", "user_permissions", "home_page", "linked_with", @@ -67,19 +67,17 @@ def clear_defaults_cache(user=None): elif frappe.flags.in_install!="frappe": frappe.cache().delete_key("defaults") -def clear_document_cache(): - frappe.local.document_cache = {} - frappe.cache().delete_key("document_cache") - def clear_doctype_cache(doctype=None): cache = frappe.cache() if getattr(frappe.local, 'meta_cache') and (doctype in frappe.local.meta_cache): del frappe.local.meta_cache[doctype] - for key in ('is_table', 'doctype_modules'): + for key in ('is_table', 'doctype_modules', 'doctype_name_map', 'document_cache'): cache.delete_value(key) + frappe.local.document_cache = {} + def clear_single(dt): for name in doctype_cache_keys: cache.hdel(name, dt) @@ -101,9 +99,6 @@ def clear_doctype_cache(doctype=None): for name in doctype_cache_keys: cache.delete_value(name) - # Clear all document's cache. To clear documents of a specific DocType document_cache should be restructured - clear_document_cache() - def get_doctype_map(doctype, name, filters=None, order_by=None): cache = frappe.cache() cache_key = frappe.scrub(doctype) + '_map' diff --git a/frappe/desk/treeview.py b/frappe/desk/treeview.py index 811143be03..e0b6ca240a 100644 --- a/frappe/desk/treeview.py +++ b/frappe/desk/treeview.py @@ -1,5 +1,5 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt +# MIT License. See license.txt from __future__ import unicode_literals import frappe diff --git a/frappe/desk/utils.py b/frappe/desk/utils.py new file mode 100644 index 0000000000..6bc59dac29 --- /dev/null +++ b/frappe/desk/utils.py @@ -0,0 +1,16 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +import frappe + +@frappe.whitelist(allow_guest=True) +def get_doctype_name(name): + # translates the doctype name from url to name `sales-order` to `Sales Order` + def get_name_map(): + name_map = {} + for d in frappe.get_all('DocType'): + name_map[d.name.lower().replace(' ', '-')] = d.name + + return name_map + + return frappe.cache().get_value('doctype_name_map', get_name_map).get(name, name) \ No newline at end of file diff --git a/frappe/public/build.json b/frappe/public/build.json index 5d16221825..4304e546a9 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -85,7 +85,6 @@ "public/less/mobile.less", "public/less/controls.less", "public/less/chat.less", - "public/less/social.less", "public/css/fonts/inter/inter.css", "public/scss/desk.scss", "node_modules/frappe-charts/dist/frappe-charts.min.css", @@ -217,7 +216,6 @@ "public/js/frappe/utils/rating_icons.html", "public/js/frappe/chat.js", - "public/js/frappe/social/social_factory.js", "public/js/frappe/utils/energy_point_utils.js", "public/js/frappe/utils/dashboard_utils.js", "public/js/frappe/ui/chart.js", @@ -303,7 +301,6 @@ "node_modules/frappe-datatable/dist/frappe-datatable.css" ], "css/email.css": "public/less/email.less", - "js/social.min.js": "public/js/frappe/social/social_home.js", "js/barcode_scanner.min.js": "public/js/frappe/barcode_scanner/quagga.js", "js/data_import_tools.min.js": "public/js/frappe/data_import/index.js", "css/login.css": "public/scss/login.scss" diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 78c367c8e9..f86085c9b7 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -173,9 +173,6 @@ frappe.Application = Class.extend({ if (frappe.boot && localStorage.getItem("session_last_route")) { frappe.set_route(localStorage.getItem("session_last_route")); localStorage.removeItem("session_last_route"); - } else if (frappe._cur_route) { - // go to the appropriate sub-path - frappe.set_route(frappe._cur_route); } else { // route to home page frappe.route(); diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 26dee5c831..e8a400a6fe 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -1007,7 +1007,7 @@ frappe.ui.form.Form = class FrappeForm { return; } - frappe.re_route[frappe.get_sub_path()] = 'Form/' + encodeURIComponent(this.doctype) + '/' + encodeURIComponent(name); + frappe.re_route[frappe.router.get_sub_path()] = 'Form/' + encodeURIComponent(this.doctype) + '/' + encodeURIComponent(name); frappe.set_route('Form', this.doctype, name); } diff --git a/frappe/public/js/frappe/router.js b/frappe/public/js/frappe/router.js index be78d53087..2995b6caf0 100644 --- a/frappe/public/js/frappe/router.js +++ b/frappe/public/js/frappe/router.js @@ -13,14 +13,13 @@ frappe.view_factory = {}; frappe.view_factories = []; frappe.route_options = null; frappe.route_hooks = {}; -frappe._cur_route = null; $(window).on('hashchange', function() { // v1 style routing, route is in hash if (window.location.hash) { - let sub_path = frappe.get_sub_path(window.location.hash); + let sub_path = frappe.router.get_sub_path(window.location.hash); window.location.hash = ''; - frappe.push_state(sub_path); + frappe.router.push_state(sub_path); } }); @@ -33,7 +32,7 @@ window.addEventListener('popstate', (event) => { $('body').on('click', 'a', function(e) { let override = (e, route) => { e.preventDefault(); - frappe.push_state(frappe.get_sub_path(route)); + frappe.router.push_state(frappe.router.get_sub_path(route)); return false; }; @@ -58,51 +57,83 @@ $('body').on('click', 'a', function(e) { } }); -frappe.route = function() { +frappe.router = { + current_route: null, + doctype_names: {}, + route() { + // resolve the route from the URL or hash + // translate it so the objects are well defined + // and render the page as required - // Application is not yet initiated - if (!frappe.app) return; + if (!frappe.app) return; - let sub_path = frappe.get_sub_path(); + let sub_path = frappe.router.get_sub_path(); + if (frappe.router.re_route(sub_path)) return; - if (frappe.re_route[sub_path] !== undefined) { - // after saving a doc, for example, - // "New DocType 1" and the renamed "TestDocType", both exist in history - // now if we try to go back, - // it doesn't allow us to go back to the one prior to "New DocType 1" - // Hence if this check is true, instead of changing location hash, - // we just do a back to go to the doc previous to the "New DocType 1" - var re_route_val = frappe.get_sub_path(frappe.re_route[sub_path]); - if (decodeURIComponent(re_route_val) === decodeURIComponent(sub_path)) { - window.history.back(); - return; - } else { - frappe.set_route(re_route_val); - return; - } - } + frappe.router.translate_doctype_name().then(() => { + let route = frappe.router.current_route; - frappe._cur_route = sub_path; + frappe.router.set_history(route, sub_path); - let route = frappe.get_route(); + if (route[0]) { + frappe.router.render_page(route); + } else { + // Show home + frappe.views.pageview.show(''); + } - frappe.route_history.push(route); + frappe.router.set_title(); + frappe.route.trigger('change'); + }); + }, - // set title - frappe.route_titles[sub_path] = frappe._original_title || document.title; + translate_doctype_name() { + return new Promise((resolve) => { + let route = frappe.router.parse(); + let factory = route[0].toLowerCase(); + let done = () => { + route[1] = frappe.router.doctype_names[route[1]]; + frappe.router.current_route = route; + resolve(); + }; - // hide open dialog - frappe.ui.hide_open_dialog(); + if (['form', 'list', 'report', 'tree'].includes(factory)) { + // translate the doctype to its original name + if (frappe.router.doctype_names[route[1]]) { + done(); + } else { + frappe.xcall('frappe.desk.utils.get_doctype_name', {name: route[1]}).then((data) => { + frappe.router.doctype_names[route[1]] = data; + done(); + }); + } + } else { + done(); + } + }); + }, + + set_history(route, sub_path) { + frappe.route_history.push(route); + frappe.route_titles[sub_path] = frappe._original_title || document.title; + frappe.ui.hide_open_dialog(); + }, + + render_page(route) { + // create the page generator (factory) object and call `show` + // if there is no generator, render the `Page` object + + // first the router needs to know if its a "page", "doctype", "workspace" - if (route[0]) { const title_cased_route = frappe.utils.to_title_case(route[0]); if (title_cased_route === 'Workspace') { frappe.views.pageview.show(''); + return; } if (route[1] && frappe.views[title_cased_route + "Factory"]) { // has a view generator, generate! - if(!frappe.view_factory[title_cased_route]) { + if (!frappe.view_factory[title_cased_route]) { frappe.view_factory[title_cased_route] = new frappe.views[title_cased_route + "Factory"](); } @@ -114,44 +145,127 @@ frappe.route = function() { frappe.views.pageview.show(route_name); } } - } else { - // Show home - frappe.views.pageview.show(''); + }, + + re_route(sub_path) { + if (frappe.re_route[sub_path] !== undefined) { + // after saving a doc, for example, + // "New DocType 1" and the renamed "TestDocType", both exist in history + // now if we try to go back, + // it doesn't allow us to go back to the one prior to "New DocType 1" + // Hence if this check is true, instead of changing location hash, + // we just do a back to go to the doc previous to the "New DocType 1" + var re_route_val = frappe.router.get_sub_path(frappe.re_route[sub_path]); + if (decodeURIComponent(re_route_val) === decodeURIComponent(sub_path)) { + window.history.back(); + return true; + } else { + frappe.set_route(re_route_val); + return true; + } + } + }, + + set_title(sub_path) { + if (frappe.route_titles[sub_path]) { + frappe.utils.set_title(frappe.route_titles[sub_path]); + } else { + setTimeout(function() { + frappe.route_titles[frappe.get_route_str()] = frappe._original_title || document.title; + }, 1000); + } + }, + + push_state(route) { + // change the URL and call the router + let url = route; + if (!route.startsWith('/app/')) { + url = `/app/${route}`; + } + if (window.location.pathname !== url) { + // cleanup any remenants of v1 routing + window.location.hash = ''; + + // push state so the browser looks fine + history.pushState(null, null, url); + + // now process the route + frappe.router.route(); + } + }, + + parse(route) { + route = frappe.router.get_sub_path_string(route).split('/'); + route = $.map(route, frappe.router.decode_component); + + frappe.router.set_route_options(route); + + return route; + }, + + get_sub_path_string(route) { + // return clean sub_path from hash or url + // supports both v1 and v2 routing + if (!route) { + route = window.location.hash || window.location.pathname; + } + + return frappe.router.strip_prefix(route); + }, + + strip_prefix(route) { + if (route.substr(0, 1)=='/') route = route.substr(1); // for /app/sub + if (route.startsWith('app')) route = route.substr(4); // for desk/sub + if (route.substr(0, 1)=='/') route = route.substr(1); + if (route.substr(0, 1)=='#') route = route.substr(1); + if (route.substr(0, 1)=='!') route = route.substr(1); + return route; + }, + + get_sub_path(route) { + var sub_path = frappe.router.get_sub_path_string(route); + route = $.map(sub_path.split('/'), frappe.router.decode_component).join('/'); + + return route; + }, + + set_route_options(route) { + // set query parameters as frappe.route_options + var last_part = route[route.length - 1]; + if (last_part.indexOf("?") < last_part.indexOf("=")) { + // has ? followed by = + let parts = last_part.split("?"); + + // route should not contain string after ? + route[route.length - 1] = parts[0]; + + let query_params = frappe.utils.get_query_params(parts[1]); + frappe.route_options = $.extend(frappe.route_options || {}, query_params); + + } + }, + + decode_component(r) { + try { + return decodeURIComponent(r); + } catch (e) { + if (e instanceof URIError) { + // legacy: not sure why URIError is ignored. + return r; + } else { + throw e; + } + } + }, + + slug(name) { + return name.toLowerCase().replace(/ /g, '-'); } - - - if (frappe.route_titles[sub_path]) { - frappe.utils.set_title(frappe.route_titles[sub_path]); - } else { - setTimeout(function() { - frappe.route_titles[frappe.get_route_str()] = frappe._original_title || document.title; - }, 1000); - } - - frappe.route.trigger('change'); - }; -frappe.get_route = function(route) { - // for app - route = frappe.get_sub_path_string(route).split('/'); - route = $.map(route, frappe._decode_str); - var parts = null; - var doc_name = route[route.length - 1]; - // if the last part contains ? then check if it is valid query string - if (doc_name.indexOf("?") < doc_name.indexOf("=")) { - parts = doc_name.split("?"); - route[route.length - 1] = parts[0]; - } else { - parts = doc_name; - } - if (parts.length > 1) { - var query_params = frappe.utils.get_query_params(parts[1]); - frappe.route_options = $.extend(frappe.route_options || {}, query_params); - } - - return route; -} +frappe.route = frappe.router.route; +frappe.get_route = () => frappe.router.current_route; +frappe.get_route_str = () => frappe.router.current_route.join('/'); frappe.get_prev_route = function() { if (frappe.route_history && frappe.route_history.length > 1) { @@ -161,44 +275,6 @@ frappe.get_prev_route = function() { } } -frappe._decode_str = function(r) { - try { - return decodeURIComponent(r); - } catch (e) { - if (e instanceof URIError) { - return r; - } else { - throw e; - } - } -} - -frappe.get_sub_path_string = function(route) { - // return clean sub_path from hash or url - // supports both v1 and v2 routing - - if (!route) { - route = window.location.hash; - } - if (!route) { - route = window.location.pathname; - } - - if (route.substr(0, 1)=='/') route = route.substr(1); // for /app/sub - if (route.startsWith('app')) route = route.substr(4); // for desk/sub - if (route.substr(0, 1)=='/') route = route.substr(1); - if (route.substr(0, 1)=='#') route = route.substr(1); - if (route.substr(0, 1)=='!') route = route.substr(1); - - return route; -}; - -frappe.get_sub_path = frappe.get_route_str = function(route) { - var sub_path = frappe.get_sub_path_string(route); - route = $.map(sub_path.split('/'), frappe._decode_str).join('/'); - - return route; -}; frappe.set_route = function() { return new Promise(resolve => { @@ -230,7 +306,7 @@ frappe.set_route = function() { // window.location.hash = route; // routing v2 - frappe.push_state(route); + frappe.router.push_state(route); } // Set favicon (app.js) @@ -245,24 +321,10 @@ frappe.set_route = function() { }); }; -frappe.push_state = function (route) { - let url = `/app/${route}`; - if (window.location.pathname !== url) { - // cleanup any remenants of v1 routing - window.location.hash = ''; - - // push state so the browser looks fine - history.pushState(null, null, url); - - // now process the route - frappe.route(); - } -}; - frappe.set_re_route = function() { - var tmp = frappe.get_sub_path(); + var tmp = frappe.router.get_sub_path(); frappe.set_route.apply(null, arguments); - frappe.re_route[tmp] = frappe.get_sub_path(); + frappe.re_route[tmp] = frappe.router.get_sub_path(); }; frappe.has_route_options = function() { diff --git a/frappe/public/js/frappe/social/Home.vue b/frappe/public/js/frappe/social/Home.vue deleted file mode 100644 index 7aa752e6db..0000000000 --- a/frappe/public/js/frappe/social/Home.vue +++ /dev/null @@ -1,111 +0,0 @@ - - - diff --git a/frappe/public/js/frappe/social/components/ActivitySidebar.vue b/frappe/public/js/frappe/social/components/ActivitySidebar.vue deleted file mode 100644 index e1c7a96da9..0000000000 --- a/frappe/public/js/frappe/social/components/ActivitySidebar.vue +++ /dev/null @@ -1,48 +0,0 @@ - - diff --git a/frappe/public/js/frappe/social/components/ImageViewer.vue b/frappe/public/js/frappe/social/components/ImageViewer.vue deleted file mode 100644 index 7a0ca7c9d8..0000000000 --- a/frappe/public/js/frappe/social/components/ImageViewer.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - - - diff --git a/frappe/public/js/frappe/social/components/NotFound.vue b/frappe/public/js/frappe/social/components/NotFound.vue deleted file mode 100644 index cee232496c..0000000000 --- a/frappe/public/js/frappe/social/components/NotFound.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/frappe/public/js/frappe/social/components/Post.vue b/frappe/public/js/frappe/social/components/Post.vue deleted file mode 100644 index 297ffa702f..0000000000 --- a/frappe/public/js/frappe/social/components/Post.vue +++ /dev/null @@ -1,227 +0,0 @@ - - - - diff --git a/frappe/public/js/frappe/social/components/PostAction.vue b/frappe/public/js/frappe/social/components/PostAction.vue deleted file mode 100644 index 3c506dc198..0000000000 --- a/frappe/public/js/frappe/social/components/PostAction.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - \ No newline at end of file diff --git a/frappe/public/js/frappe/social/components/PostComment.vue b/frappe/public/js/frappe/social/components/PostComment.vue deleted file mode 100644 index b102fba5b5..0000000000 --- a/frappe/public/js/frappe/social/components/PostComment.vue +++ /dev/null @@ -1,123 +0,0 @@ - - - diff --git a/frappe/public/js/frappe/social/components/PostDropdownMenu.vue b/frappe/public/js/frappe/social/components/PostDropdownMenu.vue deleted file mode 100644 index c2118f3548..0000000000 --- a/frappe/public/js/frappe/social/components/PostDropdownMenu.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/frappe/public/js/frappe/social/components/PostLoader.vue b/frappe/public/js/frappe/social/components/PostLoader.vue deleted file mode 100644 index 4ecf48b8e3..0000000000 --- a/frappe/public/js/frappe/social/components/PostLoader.vue +++ /dev/null @@ -1,128 +0,0 @@ - - - diff --git a/frappe/public/js/frappe/social/components/PostSidebar.vue b/frappe/public/js/frappe/social/components/PostSidebar.vue deleted file mode 100644 index 083cb4d49b..0000000000 --- a/frappe/public/js/frappe/social/components/PostSidebar.vue +++ /dev/null @@ -1,81 +0,0 @@ - - - - diff --git a/frappe/public/js/frappe/social/components/PostSkeleton.vue b/frappe/public/js/frappe/social/components/PostSkeleton.vue deleted file mode 100644 index 259b738b90..0000000000 --- a/frappe/public/js/frappe/social/components/PostSkeleton.vue +++ /dev/null @@ -1,61 +0,0 @@ - - \ No newline at end of file diff --git a/frappe/public/js/frappe/social/components/ProfileBanner.vue b/frappe/public/js/frappe/social/components/ProfileBanner.vue deleted file mode 100644 index 5628682393..0000000000 --- a/frappe/public/js/frappe/social/components/ProfileBanner.vue +++ /dev/null @@ -1,69 +0,0 @@ - - - - diff --git a/frappe/public/js/frappe/social/components/ProfileSidebar.vue b/frappe/public/js/frappe/social/components/ProfileSidebar.vue deleted file mode 100644 index 716aac02df..0000000000 --- a/frappe/public/js/frappe/social/components/ProfileSidebar.vue +++ /dev/null @@ -1,145 +0,0 @@ - - - - diff --git a/frappe/public/js/frappe/social/pages/Profile.vue b/frappe/public/js/frappe/social/pages/Profile.vue deleted file mode 100644 index f0f4c5f8d7..0000000000 --- a/frappe/public/js/frappe/social/pages/Profile.vue +++ /dev/null @@ -1,107 +0,0 @@ - - - diff --git a/frappe/public/js/frappe/social/pages/UserList.vue b/frappe/public/js/frappe/social/pages/UserList.vue deleted file mode 100644 index 69203a8e81..0000000000 --- a/frappe/public/js/frappe/social/pages/UserList.vue +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - diff --git a/frappe/public/js/frappe/social/pages/Wall.vue b/frappe/public/js/frappe/social/pages/Wall.vue deleted file mode 100644 index 55ea436d12..0000000000 --- a/frappe/public/js/frappe/social/pages/Wall.vue +++ /dev/null @@ -1,50 +0,0 @@ - - diff --git a/frappe/public/js/frappe/social/social_factory.js b/frappe/public/js/frappe/social/social_factory.js deleted file mode 100644 index a9ceac84e5..0000000000 --- a/frappe/public/js/frappe/social/social_factory.js +++ /dev/null @@ -1,21 +0,0 @@ -frappe.views.SocialFactory = class SocialFactory extends frappe.views.Factory { - show() { - if (frappe.pages.social) { - frappe.container.change_to('social'); - } else { - this.make('social'); - } - } - - make(page_name) { - const assets = [ - '/assets/js/social.min.js' - ]; - - frappe.require(assets, () => { - frappe.social.home = new frappe.social.Home({ - parent: this.make_page(true, page_name) - }); - }); - } -}; diff --git a/frappe/public/js/frappe/social/social_home.js b/frappe/public/js/frappe/social/social_home.js deleted file mode 100644 index ba616687cb..0000000000 --- a/frappe/public/js/frappe/social/social_home.js +++ /dev/null @@ -1,67 +0,0 @@ -import Home from './Home.vue'; - -frappe.provide('frappe.social'); - -frappe.social.Home = class SocialHome { - constructor({ parent }) { - this.$parent = $(parent); - this.page = parent.page; - this.setup_header(); - this.make_body(); - } - make_body() { - this.$social_container = this.$parent.find('.layout-main'); - new Vue({ - el: this.$social_container[0], - render: h => h(Home), - data: { - 'page': this.page - } - }); - } - setup_header() { - this.page.set_title(__('Social')); - } -}; - -frappe.social.post_dialog = new frappe.ui.Dialog({ - title: __('Create Post'), - fields: [ - { - fieldtype: "Text Editor", - fieldname: "content", - label: __("Content"), - reqd: 1 - } - ], - primary_action_label: __('Post'), - primary_action: (values) => { - frappe.social.post_dialog.disable_primary_action(); - const post = frappe.model.get_new_doc('Post'); - post.content = values.content; - frappe.db.insert(post).then(() => { - frappe.social.post_dialog.clear(); - frappe.social.post_dialog.hide(); - }).finally(() => { - frappe.social.post_dialog.enable_primary_action(); - }); - } -}); - -frappe.social.is_home_page = () => { - return frappe.get_route()[0] === 'social' && frappe.get_route()[1] === 'home'; -}; - -frappe.social.is_profile_page = (user) => { - return frappe.get_route()[0] === 'social' - && frappe.get_route()[1] === 'profile' - && (user ? frappe.get_route()[2] === user : true); -}; - -frappe.social.is_session_user_page = () => { - return frappe.social.is_profile_page() && frappe.get_route()[2] === frappe.session.user; -}; - -frappe.provide('frappe.app_updates'); - -frappe.utils.make_event_emitter(frappe.app_updates); diff --git a/frappe/public/js/frappe/views/container.js b/frappe/public/js/frappe/views/container.js index ae4aaba570..e6094f1df0 100644 --- a/frappe/public/js/frappe/views/container.js +++ b/frappe/public/js/frappe/views/container.js @@ -82,7 +82,7 @@ frappe.views.Container = Class.extend({ $(document).trigger("page-change"); - this.page._route = frappe.get_sub_path(); + this.page._route = frappe.router.get_sub_path(); $(this.page).trigger('show'); !this.page.disable_scroll_to_top && frappe.utils.scroll_to(0); frappe.breadcrumbs.update(); diff --git a/frappe/public/js/frappe/views/workspace/workspace.js b/frappe/public/js/frappe/views/workspace/workspace.js index 97c01949f2..688b70b80c 100644 --- a/frappe/public/js/frappe/views/workspace/workspace.js +++ b/frappe/public/js/frappe/views/workspace/workspace.js @@ -93,7 +93,7 @@ frappe.views.Workspace = class Workspace { const get_sidebar_item = function (item) { return $(`
${frappe.utils.icon(item.icon || "folder-normal", "md")}
diff --git a/frappe/public/js/frappe/widgets/links_widget.js b/frappe/public/js/frappe/widgets/links_widget.js index 495b00a3a6..f7f0061791 100644 --- a/frappe/public/js/frappe/widgets/links_widget.js +++ b/frappe/public/js/frappe/widgets/links_widget.js @@ -90,11 +90,8 @@ export default class LinksWidget extends Widget { if (this.in_customize_mode) return; if (link_label.hasClass("help-video-link")) { - let yt_id = event.target.dataset.youtubeid; + let yt_id = event.currentTarget.dataset.youtubeid; frappe.help.show_video(yt_id); - } else { - let route = event.target.dataset.route; - frappe.set_route(route); } }); } diff --git a/frappe/public/js/frappe/widgets/utils.js b/frappe/public/js/frappe/widgets/utils.js index e036a7392e..55bf9ba853 100644 --- a/frappe/public/js/frappe/widgets/utils.js +++ b/frappe/public/js/frappe/widgets/utils.js @@ -8,8 +8,10 @@ function generate_route(item) { if (item.link) { route = strip(item.link, "#"); } else if (type === "doctype") { + let doctype_slug = frappe.router.slug(item.doctype); + if (frappe.model.is_single(item.doctype)) { - route = "Form/" + item.doctype; + route = "Form/" + doctype_slug; } else { if (!item.doc_view) { if (frappe.model.is_tree(item.doctype)) { @@ -18,27 +20,28 @@ function generate_route(item) { item.doc_view = "List"; } } + switch (item.doc_view) { case "List": if (item.filters) { frappe.route_options = item.filters; } - route = "List/" + item.doctype; + route = "List/" + doctype_slug; break; case "Tree": - route = "Tree/" + item.doctype; + route = "Tree/" + doctype_slug; break; case "Report Builder": - route = "List/" + item.doctype + "/Report"; + route = "List/" + doctype_slug + "/Report"; break; case "Dashboard": - route = "List/" + item.doctype + "/Dashboard"; + route = "List/" + doctype_slug + "/Dashboard"; break; case "New": - route = "Form/" + item.doctype + "/New " + item.doctype; + route = "Form/" + doctype_slug + "/New " + item.doctype; break; case "Calendar": - route = "List/" + item.doctype + "/Calendar/Default"; + route = "List/" + doctype_slug + "/Calendar/Default"; break; default: frappe.throw({ message: __("Not a valid DocType view:") + item.doc_view, title: __("Unknown View") }); @@ -48,7 +51,7 @@ function generate_route(item) { } else if (type === "report" && item.is_query_report) { route = "query-report/" + item.name; } else if (type === "report") { - route = "List/" + item.doctype + "/Report/" + item.name; + route = "List/" + frappe.router.slug(item.doctype) + "/Report/" + item.name; } else if (type === "page") { route = item.name; } else if (type === "dashboard") { @@ -73,7 +76,7 @@ function generate_route(item) { // (item.doctype && frappe.model.can_read(item.doctype))) { // item.shown = true; // } - return route; + return `/app/${route}`; } function generate_grid(data) { diff --git a/frappe/public/less/social.less b/frappe/public/less/social.less deleted file mode 100644 index 093e7daf88..0000000000 --- a/frappe/public/less/social.less +++ /dev/null @@ -1,155 +0,0 @@ -@import "variables.less"; -@import (reference) 'common.less'; - -body[data-route*="social"] { - - .layout-main-section { - border: none; - } - a { - transition: none; - } - .liked-by-popover { - font-size: @text-small; - } - - .wall-container { - .post-container { - .new_posts_count { - cursor: pointer; - text-align: center; - padding: 5px; - margin-bottom: 15px; - } - } - } - - .wall-container, .profile-container { - display: flex; - font-size: 12px; - .post-sidebar { - padding-top: 20px; - flex: 20% - } - .post-container { - flex: 55%; - display: flex; - padding: 15px; - flex-direction: column; - } - .activity-sidebar { - padding: 15px; - flex: 25%; - .event { - margin-bottom: 15px; - } - } - } - - .generic-card() { - background: white; - font-size: 12px; - margin-bottom: 15px; - min-height: 70px; - border: 1px solid @border-color; - border-radius: 4px; - overflow: hidden; - .content { - font-size: 14px; - img, iframe { - border-radius: 5px; - border: 1px solid @light-border-color; - margin: 5px 0; - } - img { - &:hover { - opacity: 0.7; - cursor: pointer; - } - } - } - } - - .post-card { - .generic-card(); - max-width: 600px; - .post-body { - padding: 15px; - .user-name { - font-weight: 500; - } - .user-avatar { - float: left; - margin-right: 5px; - } - .user-avatar, .user-name { - cursor: pointer; - } - .content { - margin: 15px 0 0 46px; - } - .post-dropdown-menu { - display: none; - padding-left: 10px; - line-height: 1; - } - } - .pin-option { - .text-muted; - text-transform: uppercase; - font-size: @text-small; - display: none; - } - .pinned { - background: #fefdf2; - .pin-option { - display: block; - } - } - &:hover { - .post-dropdown-menu { - display: block; - } - } - .post-action-container { - padding-left: 56px; - background-color: #F6F6F6; - border-top: 1px solid @border-color; - } - .preview-card { - text-decoration: none; - max-height: 150px; - border: 1px solid @light-border-color; - border-radius: 5px; - margin-top: 15px; - padding-right: 10px; - background: white; - display: flex; - img { - border: none; - margin: 10px; - max-width: 160px; - max-height: 140px; - align-self: center; - } - p { - overflow: hidden; - .text-medium - } - } - } - - .muted-title { - &:extend(.text-muted); - margin-bottom: 10px; - text-transform: uppercase; - font-size: 10px; - font-weight: 600; - } -} - -body[data-route*="social/profile"] { - .page-head { - display: none; - } -}