gitlab-org--gitlab-foss/app/assets/javascripts/groups/index.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-unused-vars */
2017-05-05 01:49:07 +00:00
import Vue from 'vue';
import GroupFilterableList from './groups_filterable_list';
import GroupsComponent from './components/groups.vue';
2017-05-09 23:10:19 +00:00
import GroupFolder from './components/group_folder.vue';
import GroupItem from './components/group_item.vue';
import GroupsStore from './stores/groups_store';
import GroupsService from './services/groups_service';
import eventHub from './event_hub';
2017-05-05 01:49:07 +00:00
2017-05-05 00:29:56 +00:00
$(() => {
const appEl = document.querySelector('#dashboard-group-app');
const form = document.querySelector('form#group-filter-form');
const filter = document.querySelector('.js-groups-list-filter');
const holder = document.querySelector('.js-groups-list-holder');
const store = new GroupsStore();
const service = new GroupsService(appEl.dataset.endpoint);
2017-05-05 01:49:07 +00:00
2017-05-09 23:10:19 +00:00
Vue.component('groups-component', GroupsComponent);
Vue.component('group-folder', GroupFolder);
Vue.component('group-item', GroupItem);
2017-05-05 01:49:07 +00:00
const GroupsApp = new Vue({
el: appEl,
data() {
return {
store,
state: store.state,
};
},
methods: {
fetchGroups(parentGroup) {
let parentId = null;
let getGroups = null;
if (parentGroup) {
parentId = parentGroup.id;
}
2017-05-22 17:47:05 +00:00
const page = gl.utils.getParameterByName('page');
getGroups = service.getGroups(parentId, page);
getGroups.then((response) => {
store.setGroups(response.json(), parentGroup);
})
.catch(() => {
// TODO: Handler error
});
return getGroups;
},
toggleSubGroups(parentGroup = null) {
2017-05-16 14:29:38 +00:00
if (!parentGroup.isOpen) {
this.fetchGroups(parentGroup);
}
GroupsStore.toggleSubGroups(parentGroup);
},
},
created() {
let groupFilterList = null;
groupFilterList = new GroupFilterableList(form, filter, holder, store);
groupFilterList.initSearch();
this.fetchGroups()
.then((response) => {
store.storePagination(response.headers);
})
.catch(() => {
// TODO: Handle error
});
eventHub.$on('toggleSubGroups', this.toggleSubGroups);
},
2017-05-05 01:49:07 +00:00
});
});