blob: 66c291ec52fc1b3c14e4ff370c0b7d8a2ae283b6 [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>
Faris Ansari725603c2018-08-27 19:51:36 +05309 <li class="hub-sidebar-item is-title bold text-muted">
10 {{ __('Categories') }}
11 </li>
Faris Ansari7be9c382018-09-04 00:12:47 +053012 <li class="hub-sidebar-item" v-for="category in categories" :key="category.label" v-route="category.route">
Faris Ansarif089dad2018-08-26 22:20:16 +053013 {{ category.label }}
14 </li>
15 </ul>
16 </div>
17</template>
18<script>
19export default {
20 data() {
21 return {
Faris Ansariad0be6a2018-09-03 15:42:00 +053022 hub_registered: hub.is_user_registered(),
Faris Ansarif089dad2018-08-26 22:20:16 +053023 items: [
24 {
25 label: __('Browse'),
26 route: 'marketplace/home'
27 },
28 {
Faris Ansari8e044872018-08-30 15:35:06 +053029 label: __('Saved Items'),
30 route: 'marketplace/saved-items',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053031 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053032 },
33 {
scmmishra14d70ce2019-03-14 12:31:25 +053034 label: __('Your Featured Items'),
35 route: 'marketplace/featured-items',
36 condition: () => this.hub_registered
37 },
38 {
Faris Ansarif089dad2018-08-26 22:20:16 +053039 label: __('Your Profile'),
40 route: 'marketplace/profile',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053041 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053042 },
43 {
Faris Ansari8e044872018-08-30 15:35:06 +053044 label: __('Your Items'),
45 route: 'marketplace/published-items',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053046 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053047 },
48 {
Faris Ansari8e044872018-08-30 15:35:06 +053049 label: __('Publish Items'),
Faris Ansarif089dad2018-08-26 22:20:16 +053050 route: 'marketplace/publish',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053051 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053052 },
53 {
54 label: __('Selling'),
55 route: 'marketplace/selling',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053056 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053057 },
58 {
59 label: __('Buying'),
60 route: 'marketplace/buying',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053061 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053062 },
63 ],
Faris Ansari7be9c382018-09-04 00:12:47 +053064 categories: []
Faris Ansarif089dad2018-08-26 22:20:16 +053065 }
66 },
67 created() {
68 this.get_categories()
69 .then(categories => {
70 this.categories = categories.map(c => {
71 return {
72 label: __(c.name),
73 route: 'marketplace/category/' + c.name
74 }
75 });
76 this.categories.unshift({
77 label: __('All'),
78 route: 'marketplace/home'
79 });
80 this.$nextTick(() => {
81 this.update_sidebar_state();
82 });
83 });
Suraj Shettyf994e3e2018-08-28 15:03:01 +053084
85 erpnext.hub.on('seller-registered', () => {
86 this.hub_registered = true;
87 })
Faris Ansarif089dad2018-08-26 22:20:16 +053088 },
89 mounted() {
90 this.update_sidebar_state();
91 frappe.route.on('change', () => this.update_sidebar_state());
92 },
93 methods: {
94 get_categories() {
95 return hub.call('get_categories');
96 },
97 update_sidebar_state() {
98 const container = $(this.$refs['sidebar-container']);
99 const route = frappe.get_route();
100 const route_str = route.join('/');
101 const part_route_str = route.slice(0, 2).join('/');
102 const $sidebar_item = container.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`);
103
104 const $siblings = container.find('[data-route]');
105 $siblings.removeClass('active').addClass('text-muted');
106 $sidebar_item.addClass('active').removeClass('text-muted');
Suraj Shettyf994e3e2018-08-28 15:03:01 +0530107 },
Faris Ansarif089dad2018-08-26 22:20:16 +0530108 }
109}
110</script>