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

126 lines
3.5 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlToast } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2021-03-11 19:13:27 +05:30
import UserCallout from '~/user_callout';
2018-03-17 18:26:18 +05:30
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-11-20 20:47:30 +05:30
import { GROUPS_LIST_HOLDER_CLASS, CONTENT_LIST_CLASS } from './constants';
2021-03-11 19:13:27 +05:30
import GroupFilterableList from './groups_filterable_list';
import GroupsService from './service/groups_service';
import GroupsStore from './store/groups_store';
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
2021-01-29 00:20:46 +05:30
// eslint-disable-next-line no-new
new UserCallout();
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);
}
2021-03-11 19:13:27 +05:30
Vue.component('GroupFolder', groupFolderComponent);
Vue.component('GroupItem', groupItemComponent);
2017-09-10 17:25:29 +05:30
2021-01-29 00:20:46 +05:30
Vue.use(GlToast);
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,
},
2022-07-23 23:45:48 +05:30
provide() {
const {
dataset: {
newSubgroupPath,
newProjectPath,
newSubgroupIllustration,
newProjectIllustration,
emptySubgroupIllustration,
renderEmptyState,
canCreateSubgroups,
canCreateProjects,
},
} = this.$options.el;
return {
newSubgroupPath,
newProjectPath,
newSubgroupIllustration,
newProjectIllustration,
emptySubgroupIllustration,
renderEmptyState: parseBoolean(renderEmptyState),
canCreateSubgroups: parseBoolean(canCreateSubgroups),
canCreateProjects: parseBoolean(canCreateProjects),
};
},
2017-09-10 17:25:29 +05:30
data() {
2018-11-20 20:47:30 +05:30
const { dataset } = dataEl || this.$options.el;
2019-02-15 15:39:39 +05:30
const hideProjects = parseBoolean(dataset.hideProjects);
2021-02-22 17:27:13 +05:30
const showSchemaMarkup = parseBoolean(dataset.showSchemaMarkup);
2018-11-20 20:47:30 +05:30
const service = new GroupsService(endpoint || dataset.endpoint);
2021-02-22 17:27:13 +05:30
const store = new GroupsStore({ hideProjects, showSchemaMarkup });
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
};