2018-08-26 07:11:02 +00:00
|
|
|
<template>
|
|
|
|
<div class="hub-page-container">
|
2018-11-05 10:17:26 +00:00
|
|
|
<component :is="current_page.component" :key="current_page.key"></component>
|
2018-08-26 07:11:02 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
2018-08-27 04:42:45 +00:00
|
|
|
|
2018-08-26 07:11:02 +00:00
|
|
|
<script>
|
2018-08-27 04:42:45 +00:00
|
|
|
|
2018-08-26 07:11:02 +00:00
|
|
|
import Home from './pages/Home.vue';
|
|
|
|
import Search from './pages/Search.vue';
|
2018-08-27 04:42:45 +00:00
|
|
|
import Category from './pages/Category.vue';
|
2018-08-30 10:05:06 +00:00
|
|
|
import SavedItems from './pages/SavedItems.vue';
|
2019-01-31 12:17:06 +00:00
|
|
|
import FeaturedItems from './pages/FeaturedItems.vue';
|
2018-08-30 10:05:06 +00:00
|
|
|
import PublishedItems from './pages/PublishedItems.vue';
|
2018-08-27 04:42:45 +00:00
|
|
|
import Item from './pages/Item.vue';
|
|
|
|
import Seller from './pages/Seller.vue';
|
2019-02-08 12:21:01 +00:00
|
|
|
import SellerItems from './pages/SellerItems.vue';
|
2018-08-27 04:42:45 +00:00
|
|
|
import Publish from './pages/Publish.vue';
|
2018-08-26 14:18:52 +00:00
|
|
|
import Buying from './pages/Buying.vue';
|
2018-08-27 14:21:36 +00:00
|
|
|
import Selling from './pages/Selling.vue';
|
|
|
|
import Messages from './pages/Messages.vue';
|
2018-08-27 04:42:45 +00:00
|
|
|
import NotFound from './pages/NotFound.vue';
|
2018-08-26 07:11:02 +00:00
|
|
|
|
2018-09-03 09:52:13 +00:00
|
|
|
function get_route_map() {
|
|
|
|
const read_only_routes = {
|
|
|
|
'marketplace/home': Home,
|
2019-11-28 13:27:42 +00:00
|
|
|
'marketplace/search/:category/:keyword': Search,
|
2018-09-03 09:52:13 +00:00
|
|
|
'marketplace/category/:category': Category,
|
|
|
|
'marketplace/item/:item': Item,
|
|
|
|
'marketplace/seller/:seller': Seller,
|
2019-02-08 12:21:01 +00:00
|
|
|
'marketplace/seller/:seller/items': SellerItems,
|
2018-09-03 09:52:13 +00:00
|
|
|
'marketplace/not-found': NotFound,
|
|
|
|
}
|
|
|
|
const registered_routes = {
|
2019-02-08 12:21:01 +00:00
|
|
|
'marketplace/profile': Seller,
|
2018-09-03 09:52:13 +00:00
|
|
|
'marketplace/saved-items': SavedItems,
|
2019-01-31 12:17:06 +00:00
|
|
|
'marketplace/featured-items': FeaturedItems,
|
2018-09-03 09:52:13 +00:00
|
|
|
'marketplace/publish': Publish,
|
|
|
|
'marketplace/published-items': PublishedItems,
|
|
|
|
'marketplace/buying': Buying,
|
|
|
|
'marketplace/buying/:item': Messages,
|
|
|
|
'marketplace/selling': Selling,
|
|
|
|
'marketplace/selling/:buyer/:item': Messages
|
|
|
|
}
|
2018-09-03 11:09:59 +00:00
|
|
|
|
|
|
|
return hub.is_seller_registered()
|
2018-09-03 09:52:13 +00:00
|
|
|
? Object.assign({}, read_only_routes, registered_routes)
|
|
|
|
: read_only_routes;
|
2018-08-26 07:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
current_page: this.get_current_page()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
frappe.route.on('change', () => {
|
2018-09-11 12:08:31 +00:00
|
|
|
if (frappe.get_route()[0] === 'marketplace') {
|
|
|
|
this.set_current_page();
|
|
|
|
frappe.utils.scroll_to(0);
|
|
|
|
}
|
2018-08-26 07:11:02 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
set_current_page() {
|
|
|
|
this.current_page = this.get_current_page();
|
|
|
|
},
|
|
|
|
get_current_page() {
|
2018-09-03 09:52:13 +00:00
|
|
|
const route_map = get_route_map();
|
2018-08-26 14:18:52 +00:00
|
|
|
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];
|
2018-08-30 09:06:05 +00:00
|
|
|
if (part === curr_route_part || part.includes(':')) {
|
2018-08-26 14:18:52 +00:00
|
|
|
weight += 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
obj[key] = weight;
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
// get the route with the highest weight
|
|
|
|
for (let key in weighted_routes) {
|
|
|
|
const route_weight = weighted_routes[key];
|
2018-08-30 09:06:05 +00:00
|
|
|
if (route_weight === curr_route_parts.length) {
|
2018-08-26 14:18:52 +00:00
|
|
|
route = key;
|
2018-08-30 09:06:05 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
route = null;
|
2018-08-26 14:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 16:50:16 +00:00
|
|
|
if (!route) {
|
2018-11-05 10:17:26 +00:00
|
|
|
return {
|
|
|
|
key: 'not-found',
|
|
|
|
component: NotFound
|
|
|
|
};
|
2018-08-26 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 10:17:26 +00:00
|
|
|
return {
|
|
|
|
key: curr_route,
|
|
|
|
component: route_map[route]
|
|
|
|
}
|
2018-08-26 07:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|