2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2016-05-17 12:00:14 -04:00
|
|
|
App.controller "BinaryFileController", ["$scope", "$rootScope", "$http", "$timeout", ($scope, $rootScope, $http, $timeout) ->
|
|
|
|
|
|
|
|
$scope.bibtexPreview =
|
|
|
|
loading: false
|
|
|
|
error: false
|
|
|
|
data: ""
|
2016-05-04 04:32:59 -04:00
|
|
|
|
|
|
|
$scope.failedLoad = false
|
2016-05-04 05:08:48 -04:00
|
|
|
$rootScope.$on 'entity:selected', () ->
|
|
|
|
$scope.failedLoad = false
|
2016-05-04 04:32:59 -04:00
|
|
|
|
|
|
|
window.sl_binaryFilePreviewError = () =>
|
|
|
|
$scope.failedLoad = true
|
|
|
|
$scope.$apply()
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.extension = (file) ->
|
|
|
|
return file.name.split(".").pop()?.toLowerCase()
|
2016-05-17 12:00:14 -04:00
|
|
|
|
|
|
|
$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
|
2016-05-18 06:14:24 -04:00
|
|
|
desired_height = guide.offsetHeight - 44
|
2016-05-17 12:00:14 -04:00
|
|
|
if table_wrap.offsetHeight > desired_height
|
|
|
|
table_wrap.style.height = desired_height + 'px'
|
|
|
|
table_wrap.style['max-height'] = desired_height + 'px'
|
2016-05-04 04:32:59 -04:00
|
|
|
]
|