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

129 lines
3.7 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';
2022-10-11 01:57:18 +05:30
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);
}
2022-10-11 01:57:18 +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: {
2022-10-11 01:57:18 +05:30
GroupsApp,
2018-03-17 18:26:18 +05:30
},
2022-07-23 23:45:48 +05:30
provide() {
const {
dataset: {
newSubgroupPath,
newProjectPath,
newSubgroupIllustration,
newProjectIllustration,
emptySubgroupIllustration,
canCreateSubgroups,
canCreateProjects,
2022-08-13 15:12:31 +05:30
currentGroupVisibility,
2022-07-23 23:45:48 +05:30
},
} = this.$options.el;
return {
newSubgroupPath,
newProjectPath,
newSubgroupIllustration,
newProjectIllustration,
emptySubgroupIllustration,
canCreateSubgroups: parseBoolean(canCreateSubgroups),
canCreateProjects: parseBoolean(canCreateProjects),
2022-08-13 15:12:31 +05:30
currentGroupVisibility,
2022-07-23 23:45:48 +05:30
};
},
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);
2022-10-11 01:57:18 +05:30
const renderEmptyState = parseBoolean(dataset.renderEmptyState);
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,
2022-10-11 01:57:18 +05:30
renderEmptyState,
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,
2022-10-11 01:57:18 +05:30
renderEmptyState: this.renderEmptyState,
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
};