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