Merge branch 'hub-redesign' of https://github.com/frappe/erpnext into hub-redesign

This commit is contained in:
Prateeksha Singh
2018-08-28 17:25:01 +05:30
6 changed files with 53 additions and 208 deletions

View File

@@ -19,48 +19,44 @@
export default {
data() {
return {
hub_registered: hub.settings.registered,
items: [
{
label: __('Browse'),
route: 'marketplace/home'
},
{
label: __('Become a Seller'),
action: this.show_register_dialog,
condition: () => !hub.settings.registered
},
{
label: __('Saved Products'),
route: 'marketplace/saved-products',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
{
label: __('Your Profile'),
route: 'marketplace/profile',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
{
label: __('Your Products'),
route: 'marketplace/my-products',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
{
label: __('Publish Products'),
route: 'marketplace/publish',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
{
label: __('Selling'),
route: 'marketplace/selling',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
{
label: __('Buying'),
route: 'marketplace/buying',
condition: () => hub.settings.registered
condition: () => this.hub_registered
},
],
categories: []
categories: [],
}
},
created() {
@@ -80,6 +76,10 @@ export default {
this.update_sidebar_state();
});
});
erpnext.hub.on('seller-registered', () => {
this.hub_registered = true;
})
},
mounted() {
this.update_sidebar_state();
@@ -99,7 +99,7 @@ export default {
const $siblings = container.find('[data-route]');
$siblings.removeClass('active').addClass('text-muted');
$sidebar_item.addClass('active').removeClass('text-muted');
}
},
}
}
</script>

View File

@@ -21,15 +21,17 @@ erpnext.hub.Marketplace = class Marketplace {
this.page = parent.page;
frappe.db.get_doc('Hub Settings')
.then(doc => {
.then(doc => {
hub.settings = doc;
this.registered = doc.registered;
const is_registered = hub.settings.registered
this.setup_header();
this.make_sidebar();
this.make_body();
this.setup_events();
this.refresh();
if (!is_registered) {
this.page.set_primary_action('Become A Seller', this.show_register_dialog.bind(this))
}
});
}
@@ -74,8 +76,10 @@ erpnext.hub.Marketplace = class Marketplace {
});
erpnext.hub.on('seller-registered', () => {
this.registered = 1;
this.make_sidebar_nav_buttons();
this.page.clear_primary_action()
frappe.db.get_doc('Hub Settings').then((doc)=> {
hub.settings = doc;
});
});
}
@@ -83,86 +87,6 @@ erpnext.hub.Marketplace = class Marketplace {
}
_refresh() {
const route = frappe.get_route();
this.subpages = this.subpages || {};
for (let page in this.subpages) {
this.subpages[page].hide();
}
if (route[1] === 'home' && !this.subpages.home) {
this.subpages.home = new erpnext.hub.HomePage(this.$body);
}
if (route[1] === 'search' && !this.subpages.search) {
this.subpages.search = new erpnext.hub.SearchPage(this.$body);
}
if (route[1] === 'category' && route[2] && !this.subpages.category) {
this.subpages.category = new erpnext.hub.CategoryPage(this.$body);
}
if (route[1] === 'item' && route[2] && !this.subpages.item) {
this.subpages.item = new erpnext.hub.ItemPage(this.$body);
}
if (route[1] === 'seller' && !this.subpages['seller']) {
this.subpages['seller'] = new erpnext.hub.SellerPage(this.$body);
}
if (route[1] === 'register' && !this.subpages.register) {
if (this.registered) {
frappe.set_route('marketplace', 'home');
return;
}
this.subpages.register = new erpnext.hub.Register(this.$body);
}
// registered seller routes
if (route[1] === 'saved-products' && !this.subpages['saved-products']) {
this.subpages['saved-products'] = new erpnext.hub.SavedProductsPage(this.$body);
}
if (route[1] === 'profile' && !this.subpages.profile) {
this.subpages.profile = new erpnext.hub.ProfilePage(this.$body);
}
if (route[1] === 'publish' && !this.subpages.publish) {
this.subpages.publish = new erpnext.hub.PublishPage(this.$body);
}
if (route[1] === 'my-products' && !this.subpages['my-products']) {
this.subpages['my-products'] = new erpnext.hub.PublishedProductsPage(this.$body);
}
if (route[1] === 'buying' && !this.subpages['buying']) {
this.subpages['buying'] = new erpnext.hub.Buying(this.$body);
}
if (route[1] === 'selling' && !this.subpages['selling']) {
this.subpages['selling'] = new erpnext.hub.Selling(this.$body, 'Selling');
}
// dont allow unregistered users to access registered routes
const registered_routes = ['saved-products', 'profile', 'publish', 'my-products', 'messages'];
if (!hub.settings.registered && registered_routes.includes(route[1])) {
frappe.set_route('marketplace', 'home');
return;
}
if (!Object.keys(this.subpages).includes(route[1])) {
if (!this.subpages.not_found) {
this.subpages.not_found = new erpnext.hub.NotFoundPage(this.$body);
}
route[1] = 'not_found';
}
this.update_sidebar();
frappe.utils.scroll_to(0);
this.subpages[route[1]].show();
}
show_register_dialog() {
this.register_dialog = ProfileDialog(
__('Become a Seller'),
@@ -186,4 +110,5 @@ erpnext.hub.Marketplace = class Marketplace {
erpnext.hub.trigger('seller-registered');
});
}
}

View File

@@ -3,7 +3,7 @@
<section-header>
<h4>{{ __('Buying') }}</h4>
</section-header>
<div class="row" v-if="items">
<div class="row" v-if="items && items.length">
<div class="col-md-7 margin-bottom"
v-for="item of items"
:key="item.name"

View File

@@ -3,7 +3,7 @@
<section-header>
<h4>{{ __('Selling') }}</h4>
</section-header>
<div class="row" v-if="items">
<div class="row" v-if="items && items.length">
<div class="col-md-7"
style="margin-bottom: 30px;"
v-for="item of items"

View File

@@ -1,104 +0,0 @@
import SubPage from './subpage';
// import { get_item_card_container_html } from '../components/items_container';
import { get_buying_item_message_card_html } from '../components/item_card';
import { get_selling_item_message_card_html } from '../components/item_card';
// import { get_empty_state } from '../components/empty_state';
erpnext.hub.Buying = class Buying extends SubPage {
refresh() {
this.get_items_for_messages().then((items) => {
this.empty();
if (items.length) {
items.map(item => {
item.route = `marketplace/buying/${item.hub_item_code}`
})
this.render(items, __('Buying'));
}
if (!items.length && !items.length) {
this.render_empty_state();
}
});
}
render(items = [], title) {
// const html = get_item_card_container_html(items, title, get_buying_item_message_card_html);
this.$wrapper.append(html);
}
render_empty_state() {
// const empty_state = get_empty_state(__('You haven\'t interacted with any seller yet.'));
// this.$wrapper.html(empty_state);
}
get_items_for_messages() {
return hub.call('get_buying_items_for_messages', {}, 'action:send_message');
}
}
erpnext.hub.Selling = class Selling extends SubPage {
refresh() {
this.get_items_for_messages().then((items) => {
this.empty();
if (items.length) {
items.map(item => {
item.route = `marketplace/selling/${item.hub_item_code}`
})
this.render(items, __('Selling'));
}
if (!items.length && !items.length) {
this.render_empty_state();
}
});
}
render(items = [], title) {
// const html = get_item_card_container_html(items, title, get_selling_item_message_card_html);
this.$wrapper.append(html);
}
render_empty_state() {
const empty_state = get_empty_state(__('You haven\'t interacted with any seller yet.'));
this.$wrapper.html(empty_state);
}
get_items_for_messages() {
return hub.call('get_selling_items_for_messages', {});
}
}
function get_message_area_html() {
return `
<div class="message-area border padding flex flex-column">
<div class="message-list">
</div>
<div class="message-input">
</div>
</div>
`;
}
function get_list_item_html(seller) {
const active_class = frappe.get_route()[2] === seller.email ? 'active' : '';
return `
<div class="message-list-item ${active_class}" data-route="marketplace/messages/${seller.email}">
<div class="list-item-left">
<img src="${seller.image || 'https://picsum.photos/200?random'}">
</div>
<div class="list-item-body">
${seller.company}
</div>
</div>
`;
}
function get_message_html(message) {
return `
<div>
<h5>${message.sender}</h5>
<p>${message.content}</p>
</div>
`;
}