Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 1 | <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 Ansari | 725603c | 2018-08-27 19:51:36 +0530 | [diff] [blame] | 9 | <li class="hub-sidebar-item is-title bold text-muted"> |
| 10 | {{ __('Categories') }} |
| 11 | </li> |
Faris Ansari | 7be9c38 | 2018-09-04 00:12:47 +0530 | [diff] [blame] | 12 | <li class="hub-sidebar-item" v-for="category in categories" :key="category.label" v-route="category.route"> |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 13 | {{ category.label }} |
| 14 | </li> |
| 15 | </ul> |
| 16 | </div> |
| 17 | </template> |
| 18 | <script> |
| 19 | export default { |
| 20 | data() { |
| 21 | return { |
Faris Ansari | ad0be6a | 2018-09-03 15:42:00 +0530 | [diff] [blame] | 22 | hub_registered: hub.is_user_registered(), |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 23 | items: [ |
| 24 | { |
| 25 | label: __('Browse'), |
| 26 | route: 'marketplace/home' |
| 27 | }, |
| 28 | { |
Faris Ansari | 8e04487 | 2018-08-30 15:35:06 +0530 | [diff] [blame] | 29 | label: __('Saved Items'), |
| 30 | route: 'marketplace/saved-items', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 31 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 32 | }, |
| 33 | { |
| 34 | label: __('Your Profile'), |
| 35 | route: 'marketplace/profile', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 36 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 37 | }, |
| 38 | { |
Faris Ansari | 8e04487 | 2018-08-30 15:35:06 +0530 | [diff] [blame] | 39 | label: __('Your Items'), |
| 40 | route: 'marketplace/published-items', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 41 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 42 | }, |
| 43 | { |
Faris Ansari | 8e04487 | 2018-08-30 15:35:06 +0530 | [diff] [blame] | 44 | label: __('Publish Items'), |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 45 | route: 'marketplace/publish', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 46 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 47 | }, |
| 48 | { |
| 49 | label: __('Selling'), |
| 50 | route: 'marketplace/selling', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 51 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 52 | }, |
| 53 | { |
| 54 | label: __('Buying'), |
| 55 | route: 'marketplace/buying', |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 56 | condition: () => this.hub_registered |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 57 | }, |
| 58 | ], |
Faris Ansari | 7be9c38 | 2018-09-04 00:12:47 +0530 | [diff] [blame] | 59 | categories: [] |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 60 | } |
| 61 | }, |
| 62 | created() { |
| 63 | this.get_categories() |
| 64 | .then(categories => { |
| 65 | this.categories = categories.map(c => { |
| 66 | return { |
| 67 | label: __(c.name), |
| 68 | route: 'marketplace/category/' + c.name |
| 69 | } |
| 70 | }); |
| 71 | this.categories.unshift({ |
| 72 | label: __('All'), |
| 73 | route: 'marketplace/home' |
| 74 | }); |
| 75 | this.$nextTick(() => { |
| 76 | this.update_sidebar_state(); |
| 77 | }); |
| 78 | }); |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 79 | |
| 80 | erpnext.hub.on('seller-registered', () => { |
| 81 | this.hub_registered = true; |
| 82 | }) |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 83 | }, |
| 84 | mounted() { |
| 85 | this.update_sidebar_state(); |
| 86 | frappe.route.on('change', () => this.update_sidebar_state()); |
| 87 | }, |
| 88 | methods: { |
| 89 | get_categories() { |
| 90 | return hub.call('get_categories'); |
| 91 | }, |
| 92 | update_sidebar_state() { |
| 93 | const container = $(this.$refs['sidebar-container']); |
| 94 | const route = frappe.get_route(); |
| 95 | const route_str = route.join('/'); |
| 96 | const part_route_str = route.slice(0, 2).join('/'); |
| 97 | const $sidebar_item = container.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`); |
| 98 | |
| 99 | const $siblings = container.find('[data-route]'); |
| 100 | $siblings.removeClass('active').addClass('text-muted'); |
| 101 | $sidebar_item.addClass('active').removeClass('text-muted'); |
Suraj Shetty | f994e3e | 2018-08-28 15:03:01 +0530 | [diff] [blame] | 102 | }, |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | </script> |