Get basic compile/errors/autocompile working

This commit is contained in:
James Allen 2014-06-30 11:35:32 +01:00
parent 2d0264613e
commit 32d1642b9e
4 changed files with 100 additions and 26 deletions

View file

@ -14,17 +14,20 @@ div.full-size(ng-controller="PdfController")
a.log-btn( a.log-btn(
href href
ng-click="toggleLogs()" ng-click="toggleLogs()"
ng-class="{ 'active': pdf.view == 'logs' }" ng-class="{ 'active': (pdf.view == 'logs' || pdf.failure) && !pdf.error && !pdf.timeout && !pdf.uncompiled }"
tooltip="Logs" tooltip="Logs"
tooltip-placement="bottom" tooltip-placement="bottom"
) )
i.fa.fa-file-text-o i.fa.fa-file-text-o
span.label.label-danger(ng-show="pdf.logEntries.errors.length > 0") span.label(
| {{ pdf.logEntries.errors.length }} ng-show="pdf.logEntries.warnings.length + pdf.logEntries.errors.length > 0"
span.label.label-warning(ng-show="pdf.logEntries.warnings.length > 0") ng-class="{\
| {{ pdf.logEntries.warnings.length }} 'label-warning': pdf.logEntries.errors.length == 0,\
'label-danger': pdf.logEntries.errors.length > 0\
}"
) {{ pdf.logEntries.errors.length + pdf.logEntries.warnings.length }}
.pdf-viewer(ng-show="pdf.url && pdf.view == 'pdf'") .pdf-viewer(ng-show="pdf.url && pdf.view == 'pdf' && !pdf.failure && !pdf.timeout && !pdf.error")
div( div(
pdfjs pdfjs
pdf-src="pdf.url" pdf-src="pdf.url"
@ -32,7 +35,30 @@ div.full-size(ng-controller="PdfController")
resize-on="layout:main:resize,layout:pdf:resize" resize-on="layout:main:resize,layout:pdf:resize"
) )
.logs(ng-show="pdf.view == 'logs'") .pdf-uncompiled(ng-show="pdf.uncompiled && !pdf.compiling")
|  
i.fa.fa-level-up.fa-flip-horizontal.fa-2x
|   Click here to preview your work as a PDF.
.pdf-errors(ng-show="pdf.timeout || pdf.error")
.alert.alert-danger(ng-show="pdf.error")
strong Server Error.
span Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.
.alert.alert-danger(ng-show="pdf.timeout")
strong Timed out.
span Sorry, your compile was taking too long and timed out.
| This may be due to a large number of high-res images, or lots of complicated diagrams.
| Please try to make your document simpler, or contact support for help.
.pdf-logs(ng-show="(pdf.view == 'logs' || pdf.failure) && !pdf.error && !pdf.timeout && !pdf.uncompiled")
.alert.alert-success(ng-show="pdf.logEntries.all.length == 0")
| No errors, good job!
.alert.alert-danger(ng-show="pdf.failure")
strong Compile Error.
span Sorry, your LaTeX code couldn't compile for some reason. Please check the errors below for details, or view the raw log.
div(ng-repeat="entry in pdf.logEntries.all") div(ng-repeat="entry in pdf.logEntries.all")
.alert( .alert(
ng-class="{\ ng-class="{\

View file

@ -49,6 +49,8 @@ define [
@ide.showGenericServerErrorMessage() @ide.showGenericServerErrorMessage()
return return
@$scope.$broadcast "doc:opened"
@$scope.$apply () => @$scope.$apply () =>
@$scope.editor.opening = false @$scope.editor.opening = false
@$scope.editor.sharejs_doc = sharejs_doc @$scope.editor.sharejs_doc = sharejs_doc
@ -93,3 +95,9 @@ define [
lastUpdated: () -> lastUpdated: () ->
@$scope.editor.last_updated @$scope.editor.last_updated
getCurrentDocValue: () ->
@$scope.editor.sharejs_doc?.getSnapshot()
getCurrentDocId: () ->
@$scope.editor.open_doc_id

View file

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

View file

@ -1,8 +1,18 @@
.pdf-viewer, .logs { .pdf-viewer, .pdf-logs, .pdf-errors, .pdf-uncompiled {
.full-size; .full-size;
top: 58px; top: 58px;
} }
.pdf-logs, .pdf-errors, .pdf-uncompiled {
padding: @line-height-computed / 2;
}
.pdf-uncompiled {
.fa {
color: @blue;
}
}
.pdf-viewer { .pdf-viewer {
.pdfjs-viewer { .pdfjs-viewer {
.full-size; .full-size;
@ -59,16 +69,22 @@
} }
.log-btn { .log-btn {
position: relative;
.label { .label {
margin-left: .4em; position: absolute;
padding: .2em .4em .3em; top: 0;
vertical-align: text-bottom; right: 0;
line-height: inherit; padding: .15em .6em .2em;
font-size: 60%;
}
&.active, &:active {
.label {
display: none;
}
} }
} }
.logs { .pdf-logs {
padding: @line-height-computed / 2;
overflow: auto; overflow: auto;
.alert { .alert {
font-size: 0.9rem; font-size: 0.9rem;