2020-11-03 13:09:22 -05:00
|
|
|
import { GlToast } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Vue from 'vue';
|
2018-11-21 10:20:32 -05:00
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import UserCallout from '~/user_callout';
|
2017-10-04 10:10:24 -04:00
|
|
|
import Translate from '../vue_shared/translate';
|
|
|
|
|
|
|
|
import groupsApp from './components/app.vue';
|
|
|
|
import groupFolderComponent from './components/group_folder.vue';
|
|
|
|
import groupItemComponent from './components/group_item.vue';
|
2018-09-07 02:09:13 -04:00
|
|
|
import { GROUPS_LIST_HOLDER_CLASS, CONTENT_LIST_CLASS } from './constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import GroupFilterableList from './groups_filterable_list';
|
|
|
|
import GroupsService from './service/groups_service';
|
|
|
|
import GroupsStore from './store/groups_store';
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
Vue.use(Translate);
|
2017-05-04 21:49:07 -04:00
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
export default (containerId = 'js-groups-tree', endpoint, action = '') => {
|
|
|
|
const containerEl = document.getElementById(containerId);
|
|
|
|
let dataEl;
|
2017-05-04 21:49:07 -04:00
|
|
|
|
2020-11-06 10:09:14 -05:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new UserCallout();
|
|
|
|
|
2017-06-01 17:47:39 -04:00
|
|
|
// 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-09-07 02:09:13 -04:00
|
|
|
if (!containerEl) {
|
2017-06-01 17:47:39 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
const el = action ? containerEl.querySelector(GROUPS_LIST_HOLDER_CLASS) : containerEl;
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
dataEl = containerEl.querySelector(CONTENT_LIST_CLASS);
|
|
|
|
}
|
|
|
|
|
2021-01-19 22:11:13 -05:00
|
|
|
Vue.component('GroupFolder', groupFolderComponent);
|
|
|
|
Vue.component('GroupItem', groupItemComponent);
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2020-11-03 13:09:22 -05:00
|
|
|
Vue.use(GlToast);
|
|
|
|
|
2017-06-01 17:47:39 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2017-05-31 19:29:11 -04:00
|
|
|
el,
|
2017-10-04 10:10:24 -04:00
|
|
|
components: {
|
|
|
|
groupsApp,
|
|
|
|
},
|
2017-05-10 04:06:51 -04:00
|
|
|
data() {
|
2018-09-07 02:09:13 -04:00
|
|
|
const { dataset } = dataEl || this.$options.el;
|
2018-11-21 10:20:32 -05:00
|
|
|
const hideProjects = parseBoolean(dataset.hideProjects);
|
2020-11-18 19:09:41 -05:00
|
|
|
const showSchemaMarkup = parseBoolean(dataset.showSchemaMarkup);
|
2018-09-07 02:09:13 -04:00
|
|
|
const service = new GroupsService(endpoint || dataset.endpoint);
|
2020-11-18 19:09:41 -05:00
|
|
|
const store = new GroupsStore({ hideProjects, showSchemaMarkup });
|
2017-05-31 19:29:11 -04:00
|
|
|
|
2017-05-10 04:06:51 -04:00
|
|
|
return {
|
2018-09-07 02:09:13 -04:00
|
|
|
action,
|
2017-10-04 10:10:24 -04:00
|
|
|
store,
|
|
|
|
service,
|
|
|
|
hideProjects,
|
2017-06-06 10:01:42 -04:00
|
|
|
loading: true,
|
2018-09-07 02:09:13 -04:00
|
|
|
containerId,
|
2017-05-10 04:06:51 -04:00
|
|
|
};
|
|
|
|
},
|
2017-05-31 19:29:11 -04:00
|
|
|
beforeMount() {
|
2018-09-07 02:09:13 -04:00
|
|
|
if (this.action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { dataset } = dataEl || this.$options.el;
|
2017-05-29 17:52:33 -04:00
|
|
|
let groupFilterList = null;
|
2017-10-04 10:10:24 -04:00
|
|
|
const form = document.querySelector(dataset.formSel);
|
|
|
|
const filter = document.querySelector(dataset.filterSel);
|
|
|
|
const holder = document.querySelector(dataset.holderSel);
|
2017-05-29 17:52:33 -04:00
|
|
|
|
2017-06-06 01:06:08 -04:00
|
|
|
const opts = {
|
|
|
|
form,
|
|
|
|
filter,
|
|
|
|
holder,
|
2018-09-07 02:09:13 -04:00
|
|
|
filterEndpoint: endpoint || dataset.endpoint,
|
2017-10-04 10:10:24 -04:00
|
|
|
pagePath: dataset.path,
|
|
|
|
dropdownSel: dataset.dropdownSel,
|
|
|
|
filterInputField: 'filter',
|
2018-09-07 02:09:13 -04:00
|
|
|
action: this.action,
|
2017-06-06 01:06:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
groupFilterList = new GroupFilterableList(opts);
|
2017-05-10 14:30:30 -04:00
|
|
|
groupFilterList.initSearch();
|
2017-05-31 19:29:11 -04:00
|
|
|
},
|
2017-10-04 10:10:24 -04:00
|
|
|
render(createElement) {
|
|
|
|
return createElement('groups-app', {
|
|
|
|
props: {
|
2018-09-07 02:09:13 -04:00
|
|
|
action: this.action,
|
2017-10-04 10:10:24 -04:00
|
|
|
store: this.store,
|
|
|
|
service: this.service,
|
|
|
|
hideProjects: this.hideProjects,
|
2018-09-07 02:09:13 -04:00
|
|
|
containerId: this.containerId,
|
2017-10-04 10:10:24 -04:00
|
|
|
},
|
|
|
|
});
|
2017-06-07 11:05:17 -04:00
|
|
|
},
|
2017-05-04 21:49:07 -04:00
|
|
|
});
|
2018-01-23 05:02:43 -05:00
|
|
|
};
|