mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
feat: Add dynamic routes in PageContainer
This commit is contained in:
@@ -10,11 +10,18 @@ import Publish from './pages/Publish.vue';
|
|||||||
import Category from './pages/Category.vue';
|
import Category from './pages/Category.vue';
|
||||||
import Search from './pages/Search.vue';
|
import Search from './pages/Search.vue';
|
||||||
import PublishedProducts from './pages/PublishedProducts.vue';
|
import PublishedProducts from './pages/PublishedProducts.vue';
|
||||||
|
import Buying from './pages/Buying.vue';
|
||||||
|
import BuyingMessages from './pages/BuyingMessages.vue';
|
||||||
|
|
||||||
const route_map = {
|
const route_map = {
|
||||||
'marketplace/home': Home,
|
'marketplace/home': Home,
|
||||||
'marketplace/saved-products': SavedProducts,
|
'marketplace/saved-products': SavedProducts,
|
||||||
'marketplace/publish': Publish
|
'marketplace/my-products': PublishedProducts,
|
||||||
|
'marketplace/publish': Publish,
|
||||||
|
'marketplace/category/:category': Category,
|
||||||
|
'marketplace/search/:keyword': Search,
|
||||||
|
'marketplace/buying': Buying,
|
||||||
|
'marketplace/buying/:item': BuyingMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -33,7 +40,41 @@ export default {
|
|||||||
this.current_page = this.get_current_page();
|
this.current_page = this.get_current_page();
|
||||||
},
|
},
|
||||||
get_current_page() {
|
get_current_page() {
|
||||||
return route_map[frappe.get_route_str()];
|
const curr_route = frappe.get_route_str();
|
||||||
|
let route = Object.keys(route_map).filter(route => route == curr_route)[0];
|
||||||
|
|
||||||
|
if (!route) {
|
||||||
|
// find route by matching it with dynamic part
|
||||||
|
const curr_route_parts = curr_route.split('/');
|
||||||
|
const weighted_routes = Object.keys(route_map)
|
||||||
|
.map(route_str => route_str.split('/'))
|
||||||
|
.filter(route_parts => route_parts.length === curr_route_parts.length)
|
||||||
|
.reduce((obj, route_parts) => {
|
||||||
|
const key = route_parts.join('/');
|
||||||
|
let weight = 0;
|
||||||
|
route_parts.forEach((part, i) => {
|
||||||
|
const curr_route_part = curr_route_parts[i];
|
||||||
|
if (part === curr_route_part || curr_route_part.includes(':')) {
|
||||||
|
weight += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
obj[key] = weight;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// get the route with the highest weight
|
||||||
|
let weight = 0
|
||||||
|
for (let key in weighted_routes) {
|
||||||
|
const route_weight = weighted_routes[key];
|
||||||
|
if (route_weight > weight) {
|
||||||
|
route = key;
|
||||||
|
weight = route_weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return route_map[route];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Vue from 'vue/dist/vue.js';
|
import Vue from 'vue/dist/vue.js';
|
||||||
|
import './vue-plugins';
|
||||||
|
|
||||||
// pages
|
// pages
|
||||||
import './pages/item';
|
import './pages/item';
|
||||||
@@ -148,12 +149,12 @@ erpnext.hub.Marketplace = class Marketplace {
|
|||||||
|
|
||||||
make_body() {
|
make_body() {
|
||||||
this.$body = this.$parent.find('.layout-main-section');
|
this.$body = this.$parent.find('.layout-main-section');
|
||||||
// this.$page_container = $('<div class="hub-page-container">').appendTo(this.$body);
|
this.$page_container = $('<div class="hub-page-container">').appendTo(this.$body);
|
||||||
|
|
||||||
// new Vue({
|
new Vue({
|
||||||
// el: '.hub-page-container',
|
el: '.hub-page-container',
|
||||||
// render: h => h(PageContainer)
|
render: h => h(PageContainer)
|
||||||
// });
|
});
|
||||||
|
|
||||||
erpnext.hub.on('seller-registered', () => {
|
erpnext.hub.on('seller-registered', () => {
|
||||||
this.registered = 1;
|
this.registered = 1;
|
||||||
@@ -174,6 +175,10 @@ erpnext.hub.Marketplace = class Marketplace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_refresh() {
|
||||||
const route = frappe.get_route();
|
const route = frappe.get_route();
|
||||||
this.subpages = this.subpages || {};
|
this.subpages = this.subpages || {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user