|
|
@@ -2,7 +2,7 @@ define [
|
|
|
"base"
|
|
|
"libs/latex-log-parser"
|
|
|
], (App, LogParser) ->
|
|
|
- App.controller "PdfController", ["$scope", "$http", ($scope, $http) ->
|
|
|
+ App.controller "PdfController", ["$scope", "$http", "ide", ($scope, $http, ide) ->
|
|
|
$scope.pdf =
|
|
|
url: null # Pdf Url
|
|
|
view: null # 'pdf' 'logs'
|
|
|
@@ -10,28 +10,38 @@ define [
|
|
|
timeout: false # Server timed out
|
|
|
failure: false # PDF failed to compile
|
|
|
compiling: false
|
|
|
+ uncompiled: true
|
|
|
logEntries: []
|
|
|
|
|
|
+ autoCompile = true
|
|
|
+ $scope.$on "doc:opened", () ->
|
|
|
+ console.log "DOC OPENED"
|
|
|
+ return if !autoCompile
|
|
|
+ autoCompile = false
|
|
|
+ $scope.recompile(isAutoCompile: true)
|
|
|
+
|
|
|
sendCompileRequest = (options = {}) ->
|
|
|
url = "/project/#{$scope.project_id}/compile"
|
|
|
if options.isAutoCompile
|
|
|
url += "?auto_compile=true"
|
|
|
return $http.post url, {
|
|
|
- rootDoc_id: options.rootDocOverride_id or null
|
|
|
+ settingsOverride:
|
|
|
+ rootDoc_id: options.rootDocOverride_id or null
|
|
|
_csrf: window.csrfToken
|
|
|
}
|
|
|
|
|
|
parseCompileResponse = (response) ->
|
|
|
# Reset everything
|
|
|
- $scope.pdf.error = false
|
|
|
- $scope.pdf.timedout = false
|
|
|
- $scope.pdf.failure = false
|
|
|
- $scope.pdf.url = null
|
|
|
+ $scope.pdf.error = false
|
|
|
+ $scope.pdf.timedout = false
|
|
|
+ $scope.pdf.failure = false
|
|
|
+ $scope.pdf.uncompiled = false
|
|
|
+ $scope.pdf.url = null
|
|
|
|
|
|
if response.status == "timedout"
|
|
|
$scope.pdf.timedout = true
|
|
|
else if response.status == "autocompile-backoff"
|
|
|
- # Nothing to do
|
|
|
+ $scope.pdf.uncompiled = true
|
|
|
else if response.status == "failure"
|
|
|
$scope.pdf.failure = true
|
|
|
fetchLogs()
|
|
|
@@ -48,14 +58,28 @@ define [
|
|
|
for entry in logEntries.all
|
|
|
entry.file = entry.file.replace(/^(.*)\/compiles\/[0-9a-f]{24}\/(\.\/)?/, "")
|
|
|
entry.file = entry.file.replace(/^\/compile\//, "")
|
|
|
- console.log "LOG", logEntries
|
|
|
+ .error () ->
|
|
|
+ $scope.pdf.logEntries = []
|
|
|
+
|
|
|
+ getRootDocOverride_id = () ->
|
|
|
+ doc = ide.editorManager.getCurrentDocValue()
|
|
|
+ return null if !doc?
|
|
|
+ for line in doc.split("\n")
|
|
|
+ match = line.match /(.*)\\documentclass/
|
|
|
+ if match and !match[1].match /%/
|
|
|
+ return ide.editorManager.getCurrentDocId()
|
|
|
+ return null
|
|
|
|
|
|
- $scope.recompile = () ->
|
|
|
- console.log "Recompiling"
|
|
|
+ $scope.recompile = (options = {}) ->
|
|
|
+ console.log "Recompiling", options
|
|
|
return if $scope.pdf.compiling
|
|
|
$scope.pdf.compiling = true
|
|
|
- sendCompileRequest()
|
|
|
+
|
|
|
+ options.rootDocOverride_id = getRootDocOverride_id()
|
|
|
+
|
|
|
+ sendCompileRequest(options)
|
|
|
.success (data) ->
|
|
|
+ $scope.pdf.view = "pdf"
|
|
|
$scope.pdf.compiling = false
|
|
|
parseCompileResponse(data)
|
|
|
.error () ->
|
|
|
@@ -63,7 +87,7 @@ define [
|
|
|
$scope.pdf.error = true
|
|
|
|
|
|
$scope.toggleLogs = () ->
|
|
|
- if $scope.pdf.view == "pdf"
|
|
|
+ if !$scope.pdf.view? or $scope.pdf.view == "pdf"
|
|
|
$scope.pdf.view = "logs"
|
|
|
else
|
|
|
$scope.pdf.view = "pdf"
|