blob: 208d8fe34c85cf81554e0dad9c60511cc42266a2 [file] [log] [blame]
Faris Ansarif089dad2018-08-26 22:20:16 +05301<template>
2 <div ref="sidebar-container">
3 <ul class="list-unstyled hub-sidebar-group" data-nav-buttons>
4 <li class="hub-sidebar-item" v-for="item in items" :key="item.label" v-route="item.route" v-show="item.condition === undefined || item.condition()">
5 {{ item.label }}
6 </li>
7 </ul>
8 <ul class="list-unstyled hub-sidebar-group" data-categories>
9 <li class="hub-sidebar-item" v-for="category in categories" :key="category.label" v-route="category.route">
10 {{ category.label }}
11 </li>
12 </ul>
13 </div>
14</template>
15<script>
16export default {
17 data() {
18 return {
19 items: [
20 {
21 label: __('Browse'),
22 route: 'marketplace/home'
23 },
24 {
25 label: __('Become a Seller'),
26 action: this.show_register_dialog,
27 condition: () => !hub.settings.registered
28 },
29 {
30 label: __('Saved Products'),
31 route: 'marketplace/saved-products',
32 condition: () => hub.settings.registered
33 },
34 {
35 label: __('Your Profile'),
36 route: 'marketplace/profile',
37 condition: () => hub.settings.registered
38 },
39 {
40 label: __('Your Products'),
41 route: 'marketplace/my-products',
42 condition: () => hub.settings.registered
43 },
44 {
45 label: __('Publish Products'),
46 route: 'marketplace/publish',
47 condition: () => hub.settings.registered
48 },
49 {
50 label: __('Selling'),
51 route: 'marketplace/selling',
52 condition: () => hub.settings.registered
53 },
54 {
55 label: __('Buying'),
56 route: 'marketplace/buying',
57 condition: () => hub.settings.registered
58 },
59 ],
60 categories: []
61 }
62 },
63 created() {
64 this.get_categories()
65 .then(categories => {
66 this.categories = categories.map(c => {
67 return {
68 label: __(c.name),
69 route: 'marketplace/category/' + c.name
70 }
71 });
72 this.categories.unshift({
73 label: __('All'),
74 route: 'marketplace/home'
75 });
76 this.$nextTick(() => {
77 this.update_sidebar_state();
78 });
79 });
80 },
81 mounted() {
82 this.update_sidebar_state();
83 frappe.route.on('change', () => this.update_sidebar_state());
84 },
85 methods: {
86 get_categories() {
87 return hub.call('get_categories');
88 },
89 update_sidebar_state() {
90 const container = $(this.$refs['sidebar-container']);
91 const route = frappe.get_route();
92 const route_str = route.join('/');
93 const part_route_str = route.slice(0, 2).join('/');
94 const $sidebar_item = container.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`);
95
96 const $siblings = container.find('[data-route]');
97 $siblings.removeClass('active').addClass('text-muted');
98 $sidebar_item.addClass('active').removeClass('text-muted');
99 }
100 }
101}
102</script>