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(
href
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-placement="bottom"
)
i.fa.fa-file-text-o
span.label.label-danger(ng-show="pdf.logEntries.errors.length > 0")
| {{ pdf.logEntries.errors.length }}
span.label.label-warning(ng-show="pdf.logEntries.warnings.length > 0")
| {{ pdf.logEntries.warnings.length }}
span.label(
ng-show="pdf.logEntries.warnings.length + pdf.logEntries.errors.length > 0"
ng-class="{\
'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(
pdfjs
pdf-src="pdf.url"
@ -32,7 +35,30 @@ div.full-size(ng-controller="PdfController")
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")
.alert(
ng-class="{\

View file

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

View file

@ -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,13 +10,22 @@ 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, {
settingsOverride:
rootDoc_id: options.rootDocOverride_id or null
_csrf: window.csrfToken
}
@ -26,12 +35,13 @@ define [
$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 = []
$scope.recompile = () ->
console.log "Recompiling"
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 = (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"

View file

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