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

Prepare groups components for subgroups

parent 5e0e3971
<script> <script>
import eventHub from '../event_hub';
export default { export default {
props: { props: {
group: { group: {
type: Object, type: Object,
required: true, required: true,
} },
} },
methods: {
toggleSubGroups() {
eventHub.$emit('toggleSubGroups', this.group);
},
},
}; };
</script> </script>
<template> <template>
<tr> <tr @click="toggleSubGroups">
<template >
<td>
<span>
<i
v-show="group.isOpen"
class="fa fa-caret-down"
aria-hidden="true" />
<i
v-show="!group.isOpen"
class="fa fa-caret-right"
aria-hidden="true"/>
</span>
</td>
<td> <td>
<div> <div>
<a :href="group.web_url">{{group.full_name}}</a> <a :href="group.web_url">{{group.full_name}}</a>
</div> </div>
<div>{{group.description}}</div> <div>{{group.description}}</div>
</td> </td>
</template>
</tr> </tr>
</template> </template>
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
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 GroupItem from '../components/group_item.vue';
import eventHub from '../event_hub';
export default { export default {
components: { components: {
...@@ -14,7 +15,7 @@ export default { ...@@ -14,7 +15,7 @@ export default {
return { return {
store, store,
state: store.state, state: store.state,
} };
}, },
created() { created() {
...@@ -22,6 +23,8 @@ export default { ...@@ -22,6 +23,8 @@ export default {
this.service = new GroupsService(appEl.dataset.endpoint); this.service = new GroupsService(appEl.dataset.endpoint);
this.fetchGroups(); this.fetchGroups();
eventHub.$on('toggleSubGroups', this.toggleSubGroups);
}, },
methods: { methods: {
...@@ -34,12 +37,21 @@ export default { ...@@ -34,12 +37,21 @@ export default {
// TODO: Handler error // TODO: Handler error
}); });
}, },
} toggleSubGroups(group) {
GroupsStore.toggleSubGroups(group);
},
},
}; };
</script> </script>
<template> <template>
<table class="table table-bordered"> <table class="table table-bordered">
<group-item :group="group" v-for="group in state.groups" /> <template v-for="group in state.groups">
<tr is="group-item" :group="group" />
<tr v-if="group.isOpen">
<td>sub groups for {{group.name}}</td>
<td></td>
</tr>
</template>
</table> </table>
</template> </template>
import Vue from 'vue';
export default new Vue();
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
import Vue from 'vue'; import Vue from 'vue';
import GroupsComponent from './components/groups.vue' import GroupsComponent from './components/groups.vue';
$(() => { $(() => {
const appEl = document.querySelector('#dashboard-group-app'); const appEl = document.querySelector('#dashboard-group-app');
...@@ -9,7 +9,7 @@ $(() => { ...@@ -9,7 +9,7 @@ $(() => {
const GroupsApp = new Vue({ const GroupsApp = new Vue({
el: appEl, el: appEl,
components: { components: {
'groups-component': GroupsComponent 'groups-component': GroupsComponent,
}, },
render: createElement => createElement('groups-component'), render: createElement => createElement('groups-component'),
}); });
......
...@@ -7,8 +7,25 @@ export default class GroupsStore { ...@@ -7,8 +7,25 @@ export default class GroupsStore {
} }
setGroups(groups) { setGroups(groups) {
this.state.groups = groups; this.state.groups = this.decorateGroups(groups);
return groups; return groups;
} }
decorateGroups(rawGroups) {
this.groups = rawGroups.map(GroupsStore.decorateGroup);
return this.groups;
}
static decorateGroup(rawGroup) {
const group = rawGroup;
group.isOpen = false;
return group;
}
static toggleSubGroups(toggleGroup) {
const group = toggleGroup;
group.isOpen = !group.isOpen;
return group;
}
} }
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