Commit 4c375338 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Set tree structure for groups

parent 4b488d72
<script>
import eventHub from '../event_hub';
export default {
props: {
groups: {
type: Array,
required: true,
},
},
};
</script>
<template>
<ul class="list-group">
<group-item v-for="group in groups" :group="group" />
</ul>
</template>
...@@ -10,6 +10,10 @@ export default { ...@@ -10,6 +10,10 @@ export default {
}, },
methods: { methods: {
toggleSubGroups() { toggleSubGroups() {
if (this.group.subGroups && !this.group.subGroups.length) {
return;
}
eventHub.$emit('toggleSubGroups', this.group); eventHub.$emit('toggleSubGroups', this.group);
}, },
}, },
...@@ -17,26 +21,21 @@ export default { ...@@ -17,26 +21,21 @@ export default {
</script> </script>
<template> <template>
<tr @click="toggleSubGroups"> <li @click="toggleSubGroups" class="list-group-item">
<template > <span v-show="group.subGroups && group.subGroups.length">
<td> <i
<span> v-show="group.isOpen"
<i class="fa fa-caret-down"
v-show="group.isOpen" aria-hidden="true" />
class="fa fa-caret-down" <i
aria-hidden="true" /> v-show="!group.isOpen"
<i class="fa fa-caret-right"
v-show="!group.isOpen" aria-hidden="true"/>
class="fa fa-caret-right" </span>
aria-hidden="true"/>
</span> <p><a :href="group.web_url">{{group.full_name}}</a></p>
</td> <p>{{group.description}}</p>
<td>
<div> <group-folder v-if="group.subGroups && group.isOpen" :groups="group.subGroups" />
<a :href="group.web_url">{{group.full_name}}</a> </li>
</div>
<div>{{group.description}}</div>
</td>
</template>
</tr>
</template> </template>
<script> <script>
import GroupsStore from '../stores/groups_store'; import GroupsStore from '../stores/groups_store';
import GroupsService from '../services/groups_service'; import GroupsService from '../services/groups_service';
import GroupItem from '../components/group_item.vue';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
components: {
'group-item': GroupItem,
},
data() { data() {
const store = new GroupsStore(); const store = new GroupsStore();
...@@ -39,19 +34,15 @@ export default { ...@@ -39,19 +34,15 @@ export default {
}, },
toggleSubGroups(group) { toggleSubGroups(group) {
GroupsStore.toggleSubGroups(group); GroupsStore.toggleSubGroups(group);
this.fetchGroups();
}, },
}, },
}; };
</script> </script>
<template> <template>
<table class="table table-bordered"> <div>
<template v-for="group in state.groups"> <group-folder :groups="state.groups" />
<tr is="group-item" :group="group" /> </div>
<tr v-if="group.isOpen">
<td>sub groups for {{group.name}}</td>
<td></td>
</tr>
</template>
</table>
</template> </template>
...@@ -2,15 +2,18 @@ ...@@ -2,15 +2,18 @@
import Vue from 'vue'; import Vue from 'vue';
import GroupsComponent from './components/groups.vue'; import GroupsComponent from './components/groups.vue';
import GroupFolder from './components/group_folder.vue';
import GroupItem from './components/group_item.vue';
$(() => { $(() => {
const appEl = document.querySelector('#dashboard-group-app'); const appEl = document.querySelector('#dashboard-group-app');
Vue.component('groups-component', GroupsComponent);
Vue.component('group-folder', GroupFolder);
Vue.component('group-item', GroupItem);
const GroupsApp = new Vue({ const GroupsApp = new Vue({
el: appEl, el: appEl,
components: {
'groups-component': GroupsComponent,
},
render: createElement => createElement('groups-component'), render: createElement => createElement('groups-component'),
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment