Commit b6770b3d authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

[ci skip] WIP dynamically switch between preview and repo-editor, disable edit...

[ci skip] WIP dynamically switch between preview and repo-editor, disable edit button and editor for binary files
parent 03716dd3
...@@ -7,6 +7,7 @@ import RepoBinaryViewer from './repo_binary_viewer.vue'; ...@@ -7,6 +7,7 @@ import RepoBinaryViewer from './repo_binary_viewer.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 +21,16 @@ export default { ...@@ -20,6 +21,16 @@ export default {
'repo-editor': MonacoLoaderHelper.repoEditorLoader, 'repo-editor': MonacoLoaderHelper.repoEditorLoader,
'repo-commit-section': RepoCommitSection, 'repo-commit-section': RepoCommitSection,
'popup-dialog': PopupDialog, 'popup-dialog': PopupDialog,
preview: { // POC
data: () => Store,
template: '<div v-html="activeFile.html"></div>',
},
},
mounted() {
RepoHelper.getContent().then(() => {
}).catch(RepoHelper.loadingError);
}, },
methods: { methods: {
...@@ -31,6 +42,8 @@ export default { ...@@ -31,6 +42,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 +53,8 @@ export default { ...@@ -40,8 +53,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>
...@@ -17,14 +17,12 @@ const RepoEditor = { ...@@ -17,14 +17,12 @@ 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);
}, },
methods: { methods: {
......
...@@ -166,6 +166,7 @@ const RepoHelper = { ...@@ -166,6 +166,7 @@ const RepoHelper = {
const rawUrl = RepoHelper.getRawURLFromBlobURL(file.url || Service.url); const rawUrl = RepoHelper.getRawURLFromBlobURL(file.url || Service.url);
RepoHelper.setBinaryDataAsBase64(rawUrl, data); RepoHelper.setBinaryDataAsBase64(rawUrl, data);
data.binary = true; data.binary = true;
Store.currentBlobView = 'preview';
} else { } else {
Service.getRaw(data.raw_path) Service.getRaw(data.raw_path)
.then(response => { .then(response => {
......
...@@ -20,6 +20,7 @@ const RepoStore = { ...@@ -20,6 +20,7 @@ const RepoStore = {
submodules: [], submodules: [],
blobRaw: '', blobRaw: '',
blobRendered: '', blobRendered: '',
currentBlobView: 'preview',
openedFiles: [], openedFiles: [],
tabSize: 100, tabSize: 100,
defaultTabSize: 100, defaultTabSize: 100,
...@@ -211,6 +212,11 @@ const RepoStore = { ...@@ -211,6 +212,11 @@ const RepoStore = {
currentFile.newContent = contents; currentFile.newContent = contents;
}, },
toggleBlobView() {
console.log('toggleBlobView');
RepoStore.currentBlobView = RepoStore.currentBlobView === 'preview' ? 'repo-editor' : 'preview';
},
// getters // getters
isActiveFile(file) { isActiveFile(file) {
......
...@@ -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