Commit 7b2b281d authored by Jacob Schatz's avatar Jacob Schatz

Adds support for SVG because that's why. Does binary right.

parent 6f88402f
...@@ -7,7 +7,18 @@ const RepoBinaryViewer = { ...@@ -7,7 +7,18 @@ const RepoBinaryViewer = {
computed: { computed: {
pngBlobWithDataURI() { pngBlobWithDataURI() {
if(this.binaryTypes.png){
return `data:image/png;base64,${this.blobRaw}`; return `data:image/png;base64,${this.blobRaw}`;
}
return '';
},
svgBlobWithDataURI() {
if(this.binaryTypes.svg){
return `data:image/svg+xml;utf8,${this.blobRaw}`;
}
return '';
}, },
}, },
...@@ -20,29 +31,24 @@ const RepoBinaryViewer = { ...@@ -20,29 +31,24 @@ const RepoBinaryViewer = {
Store.binaryLoaded = true; Store.binaryLoaded = true;
}, },
isMarkdown() { getBinaryType() {
return this.activeFile.extension === 'md'; if(this.binaryTypes.hasOwnProperty(this.activeFile.extension)) {
}, return this.activeFile.extension;
}
return 'unknown';
}
}, },
watch: { watch: {
blobRaw() { blobRaw() {
if (this.isMarkdown()) { Store.resetBinaryTypes();
this.binaryTypes.markdown = true; if (RepoHelper.isKindaBinary()) {
this.activeFile.raw = false; this.activeFile.raw = false;
// counts as binaryish so we use the binary viewer in this case. // counts as binaryish so we use the binary viewer in this case.
this.binary = true; this.binary = true;
return;
} }
if (!this.binary) return; if (!this.binary) return;
switch (this.binaryMimeType) { this.binaryTypes[this.getBinaryType()] = true;
case 'image/png':
this.binaryTypes.png = true;
break;
default:
RepoHelper.loadingError();
break;
}
}, },
}, },
}; };
...@@ -53,6 +59,10 @@ export default RepoBinaryViewer; ...@@ -53,6 +59,10 @@ export default RepoBinaryViewer;
<template> <template>
<div id="binary-viewer" v-if="binary && !activeFile.raw"> <div id="binary-viewer" v-if="binary && !activeFile.raw">
<img v-show="binaryTypes.png && binaryLoaded" @error="errored" @load="loaded" :src="pngBlobWithDataURI" :alt="activeFile.name"/> <img v-show="binaryTypes.png && binaryLoaded" @error="errored" @load="loaded" :src="pngBlobWithDataURI" :alt="activeFile.name"/>
<img v-show="binaryTypes.svg" @error="errored" @load="loaded" :src="svgBlobWithDataURI" :alt="activeFile.name"/>
<div v-if="binaryTypes.markdown" v-html="activeFile.html"></div> <div v-if="binaryTypes.markdown" v-html="activeFile.html"></div>
<div class="binary-unknown" v-if="binaryTypes.unknown">
<span>Binary Unloadable</span>
</div>
</div> </div>
</template> </template>
...@@ -19,7 +19,7 @@ const RepoFileButtons = { ...@@ -19,7 +19,7 @@ const RepoFileButtons = {
}, },
canPreview() { canPreview() {
return this.activeFile.extension === 'md'; return Helper.isKindaBinary();
}, },
rawFileURL() { rawFileURL() {
......
...@@ -58,7 +58,7 @@ const RepoHelper = { ...@@ -58,7 +58,7 @@ const RepoHelper = {
file.opened = true; file.opened = true;
file.icon = 'fa-folder-open'; file.icon = 'fa-folder-open';
RepoHelper.toURL(file.url) RepoHelper.toURL(file.url, file.name)
return file; return file;
}, },
...@@ -66,6 +66,11 @@ const RepoHelper = { ...@@ -66,6 +66,11 @@ const RepoHelper = {
return url.replace('blob', 'raw'); return url.replace('blob', 'raw');
}, },
isKindaBinary() {
const okExts = ['md', 'svg'];
return okExts.indexOf(Store.activeFile.extension) > -1;
},
getBlameURLFromBlobURL(url) { getBlameURLFromBlobURL(url) {
return url.replace('blob', 'blame'); return url.replace('blob', 'blame');
}, },
...@@ -269,12 +274,16 @@ const RepoHelper = { ...@@ -269,12 +274,16 @@ const RepoHelper = {
RepoHelper.key = key; RepoHelper.key = key;
}, },
toURL(url) { toURL(url, title) {
const history = window.history; const history = window.history;
RepoHelper.key = RepoHelper.genKey(); RepoHelper.key = RepoHelper.genKey();
history.pushState({ key: RepoHelper.key }, '', url); history.pushState({ key: RepoHelper.key }, '', url);
if(title) {
document.title = `${title} · GitLab`;
}
}, },
loadingError() { loadingError() {
......
...@@ -48,7 +48,9 @@ const RepoStore = { ...@@ -48,7 +48,9 @@ const RepoStore = {
scrollWidth: 0, scrollWidth: 0,
binaryTypes: { binaryTypes: {
png: false, png: false,
markdown: false, md: false,
svg: false,
unknown: false,
}, },
loading: { loading: {
tree: false, tree: false,
...@@ -56,6 +58,13 @@ const RepoStore = { ...@@ -56,6 +58,13 @@ const RepoStore = {
}, },
readOnly: true, readOnly: true,
resetBinaryTypes() {
let s = '';
for(s in RepoStore.binaryTypes){
RepoStore.binaryTypes[s] = false;
}
},
// mutations // mutations
checkIsCommitable() { checkIsCommitable() {
RepoStore.service.checkCurrentBranchIsCommitable() RepoStore.service.checkCurrentBranchIsCommitable()
...@@ -86,11 +95,12 @@ const RepoStore = { ...@@ -86,11 +95,12 @@ const RepoStore = {
if (file.binary) { if (file.binary) {
RepoStore.blobRaw = file.base64; RepoStore.blobRaw = file.base64;
RepoStore.binaryMimeType = file.mime_type;
} else { } else {
RepoStore.blobRaw = file.plain; RepoStore.blobRaw = file.plain;
} }
if (!file.loading) RepoHelper.toURL(file.url); if (!file.loading) RepoHelper.toURL(file.url, file.name);
RepoStore.binary = file.binary; RepoStore.binary = file.binary;
}, },
......
...@@ -140,15 +140,27 @@ ...@@ -140,15 +140,27 @@
} }
#binary-viewer { #binary-viewer {
height: 70vh; height: 80vh;
overflow: auto; overflow: auto;
margin-top: 5px; margin: 0;
margin-left: 10px;
.blob-viewer { .blob-viewer {
padding-top: 20px; padding-top: 20px;
padding-left: 20px; padding-left: 20px;
} }
.binary-unknown {
text-align: center;
padding-top: 100px;
background: #FAFAFA;
height: 100%;
text-shadow: 0px 7px #DDDDDD, 0 9px #CCCCCC,0 11px #FFF, 0 13px #000;
font-size: 17px;
font-weight: 900;
span {
display: block;
}
}
} }
} }
......
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