feat: Add PageContainer
This commit is contained in:
parent
a760d8cce7
commit
888dd606ff
40
erpnext/public/js/hub/PageContainer.vue
Normal file
40
erpnext/public/js/hub/PageContainer.vue
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<template>
|
||||||
|
<div class="hub-page-container">
|
||||||
|
<component :is="current_page"></component>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import Home from './pages/Home.vue';
|
||||||
|
import SavedProducts from './pages/SavedProducts.vue';
|
||||||
|
import Publish from './pages/Publish.vue';
|
||||||
|
import Category from './pages/Category.vue';
|
||||||
|
import Search from './pages/Search.vue';
|
||||||
|
import PublishedProducts from './pages/PublishedProducts.vue';
|
||||||
|
|
||||||
|
const route_map = {
|
||||||
|
'marketplace/home': Home,
|
||||||
|
'marketplace/saved-products': SavedProducts,
|
||||||
|
'marketplace/publish': Publish
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
current_page: this.get_current_page()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
frappe.route.on('change', () => {
|
||||||
|
this.set_current_page();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
set_current_page() {
|
||||||
|
this.current_page = this.get_current_page();
|
||||||
|
},
|
||||||
|
get_current_page() {
|
||||||
|
return route_map[frappe.get_route_str()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -8,6 +8,7 @@ import './pages/messages';
|
|||||||
import './pages/buying_messages';
|
import './pages/buying_messages';
|
||||||
import './pages/not_found';
|
import './pages/not_found';
|
||||||
|
|
||||||
|
import PageContainer from './PageContainer.vue';
|
||||||
import Home from './pages/Home.vue';
|
import Home from './pages/Home.vue';
|
||||||
import SavedProducts from './pages/SavedProducts.vue';
|
import SavedProducts from './pages/SavedProducts.vue';
|
||||||
import Publish from './pages/Publish.vue';
|
import Publish from './pages/Publish.vue';
|
||||||
@ -147,6 +148,13 @@ 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);
|
||||||
|
|
||||||
|
// new Vue({
|
||||||
|
// el: '.hub-page-container',
|
||||||
|
// render: h => h(PageContainer)
|
||||||
|
// });
|
||||||
|
|
||||||
erpnext.hub.on('seller-registered', () => {
|
erpnext.hub.on('seller-registered', () => {
|
||||||
this.registered = 1;
|
this.registered = 1;
|
||||||
this.make_sidebar_nav_buttons();
|
this.make_sidebar_nav_buttons();
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
import SubPage from './subpage';
|
|
||||||
import { make_search_bar } from '../components/search_bar';
|
|
||||||
import { get_item_card_container_html } from '../components/items_container';
|
|
||||||
import { get_item_card_html } from '../components/item_card';
|
|
||||||
|
|
||||||
erpnext.hub.Home = class Home extends SubPage {
|
|
||||||
make_wrapper() {
|
|
||||||
super.make_wrapper();
|
|
||||||
|
|
||||||
make_search_bar({
|
|
||||||
wrapper: this.$wrapper,
|
|
||||||
on_search: keyword => {
|
|
||||||
frappe.set_route('marketplace', 'search', keyword);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh() {
|
|
||||||
this.get_items_and_render();
|
|
||||||
}
|
|
||||||
|
|
||||||
get_items_and_render() {
|
|
||||||
this.$wrapper.find('.hub-items-container').empty();
|
|
||||||
this.get_data()
|
|
||||||
.then(data => {
|
|
||||||
this.render(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get_data() {
|
|
||||||
return hub.call('get_data_for_homepage', { country: frappe.defaults.get_user_default('country') });
|
|
||||||
}
|
|
||||||
|
|
||||||
render(data) {
|
|
||||||
let html = get_item_card_container_html(data.random_items, __('Explore'));
|
|
||||||
this.$wrapper.append(html);
|
|
||||||
|
|
||||||
if (data.items_by_country.length) {
|
|
||||||
html = get_item_card_container_html(data.items_by_country, __('Near You'));
|
|
||||||
this.$wrapper.append(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
const category_items = data.category_items;
|
|
||||||
|
|
||||||
if (category_items) {
|
|
||||||
Object.keys(category_items).map(category => {
|
|
||||||
const items = category_items[category];
|
|
||||||
const see_all_link = `<p data-route="marketplace/category/${category}">See All</p>`;
|
|
||||||
|
|
||||||
html = get_item_card_container_html(
|
|
||||||
items,
|
|
||||||
__(category),
|
|
||||||
get_item_card_html,
|
|
||||||
see_all_link
|
|
||||||
);
|
|
||||||
this.$wrapper.append(html);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user