mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Preview bib files.
This commit is contained in:
parent
4f533147b1
commit
eae82a2b20
3 changed files with 66 additions and 2 deletions
|
@ -10,6 +10,7 @@ div.binary-file.full-size(
|
|||
onerror="sl_binaryFilePreviewError()"
|
||||
onabort="sl_binaryFilePreviewError()"
|
||||
)
|
||||
|
||||
img(
|
||||
ng-show="!failedLoad"
|
||||
ng-src="/project/{{ project_id }}/file/{{ openFile.id }}?format=png"
|
||||
|
@ -17,9 +18,24 @@ div.binary-file.full-size(
|
|||
onerror="sl_binaryFilePreviewError()"
|
||||
onabort="sl_binaryFilePreviewError()"
|
||||
)
|
||||
|
||||
p(
|
||||
ng-if="(['bib'].indexOf(extension(openFile)) > -1) && !bibtex.error"
|
||||
ng-init="loadBibtexFilePreview()"
|
||||
)
|
||||
div(ng-if="bibtex.loading")
|
||||
| #{translate('loading')}...
|
||||
div.bib-preview(ng-if="!bibtex.loading && !bibtex.error")
|
||||
div.scroll-container
|
||||
p
|
||||
| {{ bibtexPreview.data }}
|
||||
p
|
||||
| ...
|
||||
|
||||
p.no-preview(
|
||||
ng-if="failedLoad || ['png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1"
|
||||
ng-if="failedLoad || bibtex.error || ['bib', 'png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1"
|
||||
) #{translate("no_preview_available")}
|
||||
|
||||
a.btn.btn-info(
|
||||
ng-href="/project/{{ project_id }}/file/{{ openFile.id }}"
|
||||
) #{translate("download")} {{ openFile.name }}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
App.controller "BinaryFileController", ["$scope", "$rootScope", ($scope, $rootScope) ->
|
||||
App.controller "BinaryFileController", ["$scope", "$rootScope", "$http", "$timeout", ($scope, $rootScope, $http, $timeout) ->
|
||||
|
||||
$scope.bibtexPreview =
|
||||
loading: false
|
||||
error: false
|
||||
data: ""
|
||||
|
||||
$scope.failedLoad = false
|
||||
$rootScope.$on 'entity:selected', () ->
|
||||
|
@ -13,4 +18,31 @@ define [
|
|||
|
||||
$scope.extension = (file) ->
|
||||
return file.name.split(".").pop()?.toLowerCase()
|
||||
|
||||
$scope.loadBibtexFilePreview = () ->
|
||||
url = "/project/#{project_id}/file/#{$scope.openFile.id}?range=0-5000"
|
||||
$scope.bibtexPreview.loading = true
|
||||
$http.get(url)
|
||||
.success (data) ->
|
||||
$scope.bibtexPreview.loading = false
|
||||
$scope.bibtexPreview.error = false
|
||||
try
|
||||
# remove last partial line
|
||||
data = data.replace(/\n.*$/, '')
|
||||
finally
|
||||
$scope.bibtexPreview.data = data
|
||||
$timeout($scope.setHeight, 0)
|
||||
.error (err) ->
|
||||
$scope.bibtexPreview.error = true
|
||||
$scope.bibtexPreview.loading = false
|
||||
|
||||
$scope.setHeight = () ->
|
||||
# Behold, a ghastly hack
|
||||
guide = document.querySelector('.file-tree-inner')
|
||||
table_wrap = document.querySelector('.bib-preview .scroll-container')
|
||||
if table_wrap
|
||||
desired_height = guide.offsetHeight - 60
|
||||
if table_wrap.offsetHeight > desired_height
|
||||
table_wrap.style.height = desired_height + 'px'
|
||||
table_wrap.style['max-height'] = desired_height + 'px'
|
||||
]
|
||||
|
|
|
@ -17,5 +17,21 @@
|
|||
font-size: 24px;
|
||||
color: @gray;
|
||||
}
|
||||
.bib-preview {
|
||||
margin-bottom: 12px;
|
||||
.scroll-container {
|
||||
font-size: 0.8em;
|
||||
line-height: 1.1em;
|
||||
overflow: auto;
|
||||
border: 1px solid @gray-lighter;
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue