2017-08-03 11:20:23 -04:00
|
|
|
import Vue from 'vue';
|
2017-10-26 06:14:31 -04:00
|
|
|
import { mapActions } from 'vuex';
|
2017-10-13 05:08:10 -04:00
|
|
|
import { convertPermissionToBoolean } from '../lib/utils/common_utils';
|
2017-08-02 15:09:26 -04:00
|
|
|
import Service from './services/repo_service';
|
|
|
|
import Store from './stores/repo_store';
|
2017-08-03 11:20:23 -04:00
|
|
|
import Repo from './components/repo.vue';
|
|
|
|
import RepoEditButton from './components/repo_edit_button.vue';
|
2017-10-23 06:57:23 -04:00
|
|
|
import newBranchForm from './components/new_branch_form.vue';
|
2017-10-12 05:55:11 -04:00
|
|
|
import newDropdown from './components/new_dropdown/index.vue';
|
2017-10-26 06:14:31 -04:00
|
|
|
import vStore from './stores';
|
2017-08-03 11:20:23 -04:00
|
|
|
import Translate from '../vue_shared/translate';
|
2017-07-31 05:48:22 -04:00
|
|
|
|
2017-08-02 15:30:13 -04:00
|
|
|
function setInitialStore(data) {
|
2017-07-24 13:42:11 -04:00
|
|
|
Store.service = Service;
|
2017-08-02 15:30:13 -04:00
|
|
|
Store.service.refsUrl = data.refsUrl;
|
2017-10-19 03:58:06 -04:00
|
|
|
Store.path = data.currentPath;
|
2017-08-02 15:30:13 -04:00
|
|
|
Store.projectId = data.projectId;
|
|
|
|
Store.projectName = data.projectName;
|
|
|
|
Store.projectUrl = data.projectUrl;
|
2017-08-15 15:53:41 -04:00
|
|
|
Store.canCommit = data.canCommit;
|
|
|
|
Store.onTopOfBranch = data.onTopOfBranch;
|
2017-10-12 17:04:17 -04:00
|
|
|
Store.newMrTemplateUrl = decodeURIComponent(data.newMrTemplateUrl);
|
|
|
|
Store.customBranchURL = decodeURIComponent(data.blobUrl);
|
2017-10-13 05:08:10 -04:00
|
|
|
Store.isRoot = convertPermissionToBoolean(data.root);
|
2017-10-16 09:19:22 -04:00
|
|
|
Store.isInitialRoot = convertPermissionToBoolean(data.root);
|
2017-07-28 10:24:01 -04:00
|
|
|
Store.currentBranch = $('button.dropdown-menu-toggle').attr('data-ref');
|
|
|
|
Store.checkIsCommitable();
|
2017-10-12 17:04:17 -04:00
|
|
|
Store.setBranchHash();
|
2017-08-02 15:30:13 -04:00
|
|
|
}
|
2017-07-24 13:42:11 -04:00
|
|
|
|
2017-08-03 11:20:23 -04:00
|
|
|
function initRepo(el) {
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2017-10-26 06:14:31 -04:00
|
|
|
store: vStore,
|
2017-08-03 11:20:23 -04:00
|
|
|
components: {
|
|
|
|
repo: Repo,
|
|
|
|
},
|
2017-10-26 06:14:31 -04:00
|
|
|
methods: {
|
|
|
|
...mapActions([
|
|
|
|
'setInitialData',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
const data = el.dataset;
|
|
|
|
|
|
|
|
this.setInitialData({
|
|
|
|
project: {
|
|
|
|
id: data.projectId,
|
|
|
|
name: data.projectName,
|
|
|
|
},
|
|
|
|
endpoints: {
|
|
|
|
rootEndpoint: data.url,
|
|
|
|
newMergeRequestUrl: data.newMergeRequestUrl,
|
|
|
|
rootUrl: data.rootUrl,
|
|
|
|
},
|
|
|
|
canCommit: convertPermissionToBoolean(data.canCommit),
|
|
|
|
onTopOfBranch: convertPermissionToBoolean(data.onTopOfBranch),
|
|
|
|
currentRef: data.ref,
|
|
|
|
// TODO: get through data attribute
|
|
|
|
currentBranch: document.querySelector('.js-project-refs-dropdown').dataset.ref,
|
|
|
|
isRoot: convertPermissionToBoolean(data.root),
|
|
|
|
isInitialRoot: convertPermissionToBoolean(data.root),
|
|
|
|
});
|
|
|
|
},
|
2017-08-15 14:16:42 -04:00
|
|
|
render(createElement) {
|
|
|
|
return createElement('repo');
|
|
|
|
},
|
2017-08-03 11:20:23 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initRepoEditButton(el) {
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2017-10-26 06:14:31 -04:00
|
|
|
store: vStore,
|
2017-08-03 11:20:23 -04:00
|
|
|
components: {
|
|
|
|
repoEditButton: RepoEditButton,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-12 05:55:11 -04:00
|
|
|
function initNewDropdown(el) {
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
components: {
|
|
|
|
newDropdown,
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('new-dropdown');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-23 06:57:23 -04:00
|
|
|
function initNewBranchForm() {
|
|
|
|
const el = document.querySelector('.js-new-branch-dropdown');
|
|
|
|
|
|
|
|
if (!el) return null;
|
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
components: {
|
|
|
|
newBranchForm,
|
|
|
|
},
|
2017-10-26 06:14:31 -04:00
|
|
|
store: vStore,
|
2017-10-23 06:57:23 -04:00
|
|
|
render(createElement) {
|
2017-10-26 06:14:31 -04:00
|
|
|
return createElement('new-branch-form');
|
2017-10-23 06:57:23 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-26 06:14:31 -04:00
|
|
|
const repo = document.getElementById('repo');
|
|
|
|
const editButton = document.querySelector('.editable-mode');
|
|
|
|
const newDropdownHolder = document.querySelector('.js-new-dropdown');
|
|
|
|
setInitialStore(repo.dataset);
|
2017-07-19 16:45:39 -04:00
|
|
|
|
2017-10-26 06:14:31 -04:00
|
|
|
Vue.use(Translate);
|
2017-07-19 16:45:39 -04:00
|
|
|
|
2017-10-26 06:14:31 -04:00
|
|
|
initRepo(repo);
|
|
|
|
initRepoEditButton(editButton);
|
|
|
|
initNewBranchForm();
|
|
|
|
initNewDropdown(newDropdownHolder);
|