Commit b1f30151 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'ide' of gitlab.com:gitlab-org/gitlab-ce into ide

parents 82292316 2fce0c86
......@@ -4,9 +4,11 @@ import RepoCommitSection from './repo_commit_section.vue';
import RepoTabs from './repo_tabs.vue';
import RepoFileButtons from './repo_file_buttons.vue';
import RepoBinaryViewer from './repo_binary_viewer.vue';
import RepoPreview from './repo_preview.vue';
import RepoMixin from '../mixins/repo_mixin';
import PopupDialog from '../../vue_shared/components/popup_dialog.vue';
import Store from '../stores/repo_store';
import RepoHelper from '../helpers/repo_helper';
import MonacoLoaderHelper from '../helpers/monaco_loader_helper';
export default {
......@@ -20,6 +22,11 @@ export default {
'repo-editor': MonacoLoaderHelper.repoEditorLoader,
'repo-commit-section': RepoCommitSection,
'popup-dialog': PopupDialog,
'repo-preview': RepoPreview,
},
mounted() {
RepoHelper.getContent().catch(RepoHelper.loadingError);
},
methods: {
......@@ -31,6 +38,8 @@ export default {
this.dialog.open = false;
this.dialog.status = status;
},
toggleBlobView: Store.toggleBlobView,
},
};
</script>
......@@ -40,8 +49,8 @@ export default {
<repo-sidebar/><div class="panel-right" :class="{'edit-mode': editMode}">
<repo-tabs/>
<repo-file-buttons/>
<repo-editor/>
<repo-binary-viewer/>
<component :is="currentBlobView"></component>
<!-- <repo-binary-viewer/> soon™ -->
</div>
<repo-commit-section/>
<popup-dialog
......
......@@ -21,14 +21,15 @@ export default {
return;
}
this.editMode = !this.editMode;
Store.toggleBlobView();
},
},
}
</script>
<template>
<a href="#" @click.prevent="editClicked" v-cloak v-if="isCommitable">
<button class="btn btn-default" @click.prevent="editClicked" v-cloak v-if="isCommitable" :disabled="binary">
<i :class="buttonIcon"></i>
<span>{{buttonLabel}}</span>
</a>
</button>
</template>
<script>
/* global monaco */
import Store from '../stores/repo_store';
import Service from '../services/repo_service';
import Helper from '../helpers/repo_helper';
const RepoEditor = {
data: () => Store,
mounted() {
Service.getRaw(this.activeFile.raw_path)
.then((rawResponse) => {
Store.blobRaw = rawResponse.data;
const monacoInstance = this.monaco.editor.create(this.$el, {
model: null,
readOnly: true,
......@@ -17,13 +22,13 @@ const RepoEditor = {
this.addMonacoEvents();
Helper.getContent().then(() => {
const languages = this.monaco.languages.getLanguages();
const languageID = Helper.getLanguageIDForFile(this.activeFile, languages);
this.showHide();
const newModel = this.monaco.editor.createModel(this.blobRaw, languageID);
this.monacoInstance.setModel(newModel);
}).catch(Helper.loadingError);
},
......@@ -62,14 +67,6 @@ const RepoEditor = {
},
editMode() {
const readOnly = !this.editMode;
Store.readOnly = readOnly;
this.monacoInstance.updateOptions({
readOnly,
});
if (this.editMode) {
$('.project-refs-form').addClass('disabled');
$('.fa-long-arrow-right').show();
......
<script>
import RepoStore from '../stores/repo_store';
export default {
data: () => RepoStore,
}
</script>
<template>
<div v-html="activeFile.html"></div>
</template>
......@@ -160,23 +160,20 @@ const RepoHelper = {
Store.binaryMimeType = data.mime_type;
// file might be undefined
RepoHelper.setBinaryDataAsBase64(data);
data.binary = true;
} else {
const rawUrl = RepoHelper.getRawURLFromBlobURL(file.url || Service.url);
RepoHelper.setBinaryDataAsBase64(rawUrl, data);
Store.setViewToPreview();
} else if (!Store.isPreviewView()) {
Service.getRaw(data.raw_path)
.then(response => {
Store.blobRaw = response.data;
})
// Store.blobRaw = data.plain;
data.binary = false;
}
.then((rawResponse) => {
Store.blobRaw = rawResponse.data;
data.plain = rawResponse.data;
if (!file.url) file.url = location.pathname;
data.url = file.url;
data.newContent = '';
RepoHelper.setFile(data, file);
}).catch(RepoHelper.loadingError);
}
Store.addToOpenedFiles(data);
Store.setActiveFiles(data);
if (Store.isPreviewView()) RepoHelper.setFile(data, file);
// if the file tree is empty
if (Store.files.length === 0) {
......@@ -192,8 +189,18 @@ const RepoHelper = {
Store.addFilesToDirectory(file, Store.files, newDirectory);
Store.prevURL = Service.blobURLtoParentTree(Service.url);
}
})
.catch(RepoHelper.loadingError);
}).catch(RepoHelper.loadingError);
},
setFile(data, file) {
const newFile = data;
newFile.url = file.url || location.pathname;
newFile.url = file.url;
newFile.newContent = '';
Store.addToOpenedFiles(newFile);
Store.setActiveFiles(newFile);
},
toFA(icon) {
......
......@@ -19,7 +19,9 @@ const RepoService = {
},
getRaw(url) {
return axios.get(url);
return axios.get(url, {
transformResponse: [res => res],
});
},
buildParams(url = this.url) {
......
......@@ -20,6 +20,7 @@ const RepoStore = {
submodules: [],
blobRaw: '',
blobRendered: '',
currentBlobView: 'repo-preview',
openedFiles: [],
tabSize: 100,
defaultTabSize: 100,
......@@ -211,10 +212,22 @@ const RepoStore = {
currentFile.newContent = contents;
},
toggleBlobView() {
RepoStore.currentBlobView = RepoStore.isPreviewView() ? 'repo-editor' : 'repo-preview';
},
setViewToPreview() {
RepoStore.currentBlobView = 'repo-preview';
},
// getters
isActiveFile(file) {
return file && file.url === RepoStore.activeFile.url;
},
isPreviewView() {
return RepoStore.currentBlobView === 'repo-preview';
},
};
export default RepoStore;
......@@ -38,6 +38,10 @@
@include truncate(250px);
}
#editable-mode {
display: inline-block;
}
.tree-content-holder {
border: 1px solid $border-color;
border-radius: $border-radius-default;
......
%a.btn.btn-default#editable-mode
#editable-mode
%repo-edit-button
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment