debian-mirror-gitlab/app/assets/javascripts/groups/index.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-12-23 12:14:25 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2018-03-17 18:26:18 +05:30
import Translate from '../vue_shared/translate';
2017-09-10 17:25:29 +05:30
import GroupFilterableList from './groups_filterable_list';
2018-03-17 18:26:18 +05:30
import GroupsStore from './store/groups_store';
import GroupsService from './service/groups_service';
import groupsApp from './components/app.vue';
import groupFolderComponent from './components/group_folder.vue';
import groupItemComponent from './components/group_item.vue';
2018-11-20 20:47:30 +05:30
import { GROUPS_LIST_HOLDER_CLASS, CONTENT_LIST_CLASS } from './constants';
2018-03-17 18:26:18 +05:30
Vue.use(Translate);
2017-09-10 17:25:29 +05:30
2018-11-20 20:47:30 +05:30
export default (containerId = 'js-groups-tree', endpoint, action = '') => {
const containerEl = document.getElementById(containerId);
let dataEl;
2017-09-10 17:25:29 +05:30
// Don't do anything if element doesn't exist (No groups)
// This is for when the user enters directly to the page via URL
2018-11-20 20:47:30 +05:30
if (!containerEl) {
2017-09-10 17:25:29 +05:30
return;
}
2018-11-20 20:47:30 +05:30
const el = action ? containerEl.querySelector(GROUPS_LIST_HOLDER_CLASS) : containerEl;
if (action) {
dataEl = containerEl.querySelector(CONTENT_LIST_CLASS);
}
2018-03-17 18:26:18 +05:30
Vue.component('group-folder', groupFolderComponent);
Vue.component('group-item', groupItemComponent);
2017-09-10 17:25:29 +05:30
// eslint-disable-next-line no-new
new Vue({
el,
2018-03-17 18:26:18 +05:30
components: {
groupsApp,
},
2017-09-10 17:25:29 +05:30
data() {
2018-11-20 20:47:30 +05:30
const { dataset } = dataEl || this.$options.el;
2018-12-23 12:14:25 +05:30
const hideProjects = parseBoolean(dataset.hideProjects);
2018-11-20 20:47:30 +05:30
const service = new GroupsService(endpoint || dataset.endpoint);
2018-03-17 18:26:18 +05:30
const store = new GroupsStore(hideProjects);
2017-09-10 17:25:29 +05:30
return {
2018-11-20 20:47:30 +05:30
action,
2018-03-17 18:26:18 +05:30
store,
service,
hideProjects,
2017-09-10 17:25:29 +05:30
loading: true,
2018-11-20 20:47:30 +05:30
containerId,
2017-09-10 17:25:29 +05:30
};
},
beforeMount() {
2018-11-20 20:47:30 +05:30
if (this.action) {
return;
}
const { dataset } = dataEl || this.$options.el;
2017-09-10 17:25:29 +05:30
let groupFilterList = null;
2018-03-17 18:26:18 +05:30
const form = document.querySelector(dataset.formSel);
const filter = document.querySelector(dataset.filterSel);
const holder = document.querySelector(dataset.holderSel);
2017-09-10 17:25:29 +05:30
const opts = {
form,
filter,
holder,
2018-11-20 20:47:30 +05:30
filterEndpoint: endpoint || dataset.endpoint,
2018-03-17 18:26:18 +05:30
pagePath: dataset.path,
dropdownSel: dataset.dropdownSel,
filterInputField: 'filter',
2018-11-20 20:47:30 +05:30
action: this.action,
2017-09-10 17:25:29 +05:30
};
groupFilterList = new GroupFilterableList(opts);
groupFilterList.initSearch();
},
2018-03-17 18:26:18 +05:30
render(createElement) {
return createElement('groups-app', {
props: {
2018-11-20 20:47:30 +05:30
action: this.action,
2018-03-17 18:26:18 +05:30
store: this.store,
service: this.service,
hideProjects: this.hideProjects,
2018-11-20 20:47:30 +05:30
containerId: this.containerId,
2018-03-17 18:26:18 +05:30
},
});
2017-09-10 17:25:29 +05:30
},
});
2018-03-17 18:26:18 +05:30
};