2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
2016-06-14 12:02:22 -04:00
|
|
|
"ace/ace"
|
2016-06-16 06:14:45 -04:00
|
|
|
"ide/human-readable-logs/HumanReadableLogs"
|
2016-03-08 11:18:02 -05:00
|
|
|
"libs/bib-log-parser"
|
2016-06-16 06:14:45 -04:00
|
|
|
], (App, Ace, HumanReadableLogs, BibLogParser) ->
|
2018-02-08 08:32:15 -05:00
|
|
|
AUTO_COMPILE_MAX_WAIT = 5000
|
|
|
|
# We add a 1 second debounce to sending user changes to server if they aren't
|
|
|
|
# collaborating with anyone. This needs to be higher than that, and allow for
|
|
|
|
# client to server latency, otherwise we compile before the op reaches the server
|
|
|
|
# and then again on ack.
|
|
|
|
AUTO_COMPILE_DEBOUNCE = 2000
|
2016-03-22 06:24:58 -04:00
|
|
|
|
2018-08-22 09:47:15 -04:00
|
|
|
App.filter('trusted', ['$sce', ($sce)->
|
|
|
|
return (url)-> return $sce.trustAsResourceUrl(url);
|
|
|
|
])
|
|
|
|
|
2018-08-22 15:45:08 -04:00
|
|
|
App.controller "PdfController", ($scope, $http, ide, $modal, synctex, event_tracking, localStorage) ->
|
2016-06-28 03:40:30 -04:00
|
|
|
# enable per-user containers by default
|
|
|
|
perUserCompile = true
|
2014-07-08 07:02:26 -04:00
|
|
|
autoCompile = true
|
2016-03-22 10:38:48 -04:00
|
|
|
|
|
|
|
# pdf.view = uncompiled | pdf | errors
|
|
|
|
$scope.pdf.view = if $scope?.pdf?.url then 'pdf' else 'uncompiled'
|
2016-03-22 06:24:58 -04:00
|
|
|
$scope.shouldShowLogs = false
|
2016-06-27 06:34:24 -04:00
|
|
|
$scope.wikiEnabled = window.wikiEnabled;
|
2016-03-22 05:39:33 -04:00
|
|
|
|
2016-06-28 10:48:11 -04:00
|
|
|
# view logic to check whether the files dropdown should "drop up" or "drop down"
|
|
|
|
$scope.shouldDropUp = false
|
|
|
|
|
|
|
|
logsContainerEl = document.querySelector ".pdf-logs"
|
|
|
|
filesDropdownEl = logsContainerEl?.querySelector ".files-dropdown"
|
|
|
|
|
|
|
|
# get the top coordinate of the files dropdown as a ratio (to the logs container height)
|
|
|
|
# logs container supports scrollable content, so it's possible that ratio > 1.
|
|
|
|
getFilesDropdownTopCoordAsRatio = () ->
|
|
|
|
filesDropdownEl?.getBoundingClientRect().top / logsContainerEl?.getBoundingClientRect().height
|
|
|
|
|
|
|
|
$scope.$watch "shouldShowLogs", (shouldShow) ->
|
|
|
|
if shouldShow
|
2016-10-13 08:47:05 -04:00
|
|
|
$scope.$applyAsync () ->
|
2016-06-28 10:48:11 -04:00
|
|
|
$scope.shouldDropUp = getFilesDropdownTopCoordAsRatio() > 0.65
|
|
|
|
|
2016-07-05 11:27:14 -04:00
|
|
|
$scope.trackLogHintsLearnMore = () ->
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMB "logs-hints-learn-more"
|
2016-07-05 11:27:14 -04:00
|
|
|
|
2016-06-14 12:02:22 -04:00
|
|
|
if ace.require("ace/lib/useragent").isMac
|
|
|
|
$scope.modifierKey = "Cmd"
|
|
|
|
else
|
|
|
|
$scope.modifierKey = "Ctrl"
|
|
|
|
|
2016-06-16 09:03:42 -04:00
|
|
|
# utility for making a query string from a hash, could use jquery $.param
|
|
|
|
createQueryString = (args) ->
|
|
|
|
qs_args = ("#{k}=#{v}" for k, v of args)
|
|
|
|
if qs_args.length then "?" + qs_args.join("&") else ""
|
|
|
|
|
2016-06-27 06:34:24 -04:00
|
|
|
$scope.stripHTMLFromString = (htmlStr) ->
|
2018-08-23 11:42:00 -04:00
|
|
|
tmp = document.createElement("DIV")
|
|
|
|
tmp.innerHTML = htmlStr
|
|
|
|
return tmp.textContent || tmp.innerText || ""
|
2016-06-27 06:34:24 -04:00
|
|
|
|
2014-07-22 08:38:34 -04:00
|
|
|
$scope.$on "project:joined", () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
return if !autoCompile
|
|
|
|
autoCompile = false
|
2017-10-09 10:18:55 -04:00
|
|
|
$scope.recompile(isAutoCompileOnLoad: true)
|
2014-10-20 07:21:40 -04:00
|
|
|
$scope.hasPremiumCompile = $scope.project.features.compileGroup == "priority"
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2015-01-12 11:46:17 -05:00
|
|
|
$scope.$on "pdf:error:display", () ->
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2016-03-21 09:20:03 -04:00
|
|
|
$scope.pdf.renderingError = true
|
2016-03-08 08:20:23 -05:00
|
|
|
|
2018-02-08 08:32:15 -05:00
|
|
|
autoCompileInterval = null
|
|
|
|
autoCompileIfReady = () ->
|
2018-10-11 04:30:21 -04:00
|
|
|
if $scope.pdf.compiling or !$scope.autocompile_enabled
|
2018-02-08 08:32:15 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
# Only checking linting if syntaxValidation is on and visible to the user
|
|
|
|
autoCompileLintingError = ide.$scope.hasLintingError and ide.$scope.settings.syntaxValidation
|
|
|
|
if $scope.autoCompileLintingError != autoCompileLintingError
|
|
|
|
$scope.$apply () ->
|
|
|
|
$scope.autoCompileLintingError = autoCompileLintingError
|
|
|
|
# We've likely been waiting a while until the user fixed the linting, but we
|
|
|
|
# don't want to compile as soon as it is fixed, so reset the timeout.
|
|
|
|
$scope.startedTryingAutoCompileAt = Date.now()
|
|
|
|
$scope.docLastChangedAt = Date.now()
|
2018-07-23 12:07:05 -04:00
|
|
|
if autoCompileLintingError and $scope.stop_on_validation_error
|
2018-02-08 08:32:15 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
# If there's a longish compile, don't compile immediately after if user is still typing
|
|
|
|
startedTryingAt = Math.max($scope.startedTryingAutoCompileAt, $scope.lastFinishedCompileAt || 0)
|
|
|
|
|
|
|
|
timeSinceStartedTrying = Date.now() - startedTryingAt
|
|
|
|
timeSinceLastChange = Date.now() - $scope.docLastChangedAt
|
|
|
|
|
|
|
|
shouldCompile = false
|
|
|
|
if timeSinceLastChange > AUTO_COMPILE_DEBOUNCE # Don't compile in the middle of the user typing
|
|
|
|
shouldCompile = true
|
|
|
|
else if timeSinceStartedTrying > AUTO_COMPILE_MAX_WAIT # Unless they type for a long time
|
|
|
|
shouldCompile = true
|
|
|
|
else if timeSinceStartedTrying < 0 or timeSinceLastChange < 0
|
|
|
|
# If time is non-monotonic, assume that the user's system clock has been
|
|
|
|
# changed and continue with compile
|
|
|
|
shouldCompile = true
|
|
|
|
|
|
|
|
if shouldCompile
|
|
|
|
triggerAutoCompile()
|
|
|
|
|
2017-09-05 08:57:11 -04:00
|
|
|
triggerAutoCompile = () ->
|
2018-02-08 08:32:15 -05:00
|
|
|
$scope.recompile(isAutoCompileOnChange: true)
|
|
|
|
|
|
|
|
startTryingAutoCompile = () ->
|
|
|
|
return if autoCompileInterval?
|
|
|
|
$scope.startedTryingAutoCompileAt = Date.now()
|
|
|
|
autoCompileInterval = setInterval autoCompileIfReady, 200
|
|
|
|
|
|
|
|
stopTryingAutoCompile = () ->
|
|
|
|
clearInterval autoCompileInterval
|
|
|
|
autoCompileInterval = null
|
|
|
|
|
|
|
|
$scope.$watch "uncompiledChanges", (uncompiledChanges) ->
|
|
|
|
if uncompiledChanges
|
|
|
|
startTryingAutoCompile()
|
2017-09-08 05:42:54 -04:00
|
|
|
else
|
2018-02-08 08:32:15 -05:00
|
|
|
stopTryingAutoCompile()
|
2017-09-05 08:57:11 -04:00
|
|
|
|
2018-02-08 05:24:21 -05:00
|
|
|
$scope.uncompiledChanges = false
|
|
|
|
recalculateUncompiledChanges = () ->
|
2018-10-10 10:04:18 -04:00
|
|
|
if !$scope.autocompile_enabled
|
|
|
|
# Auto-compile was disabled
|
|
|
|
$scope.uncompiledChanges = false
|
2018-02-08 08:32:15 -05:00
|
|
|
if $scope.ui.pdfHidden
|
2018-02-09 12:54:58 -05:00
|
|
|
# Don't bother auto-compiling if pdf isn't visible
|
2018-02-08 08:32:15 -05:00
|
|
|
$scope.uncompiledChanges = false
|
|
|
|
else if !$scope.docLastChangedAt?
|
|
|
|
$scope.uncompiledChanges = false
|
|
|
|
else if !$scope.lastStartedCompileAt? or $scope.docLastChangedAt > $scope.lastStartedCompileAt
|
2018-02-08 05:24:21 -05:00
|
|
|
$scope.uncompiledChanges = true
|
|
|
|
else
|
|
|
|
$scope.uncompiledChanges = false
|
|
|
|
|
2018-02-08 08:32:15 -05:00
|
|
|
_updateDocLastChangedAt = () ->
|
|
|
|
$scope.docLastChangedAt = Date.now()
|
|
|
|
recalculateUncompiledChanges()
|
|
|
|
|
2018-02-08 05:24:21 -05:00
|
|
|
onDocChanged = () ->
|
|
|
|
$scope.autoCompileLintingError = false
|
2018-02-08 08:32:15 -05:00
|
|
|
_updateDocLastChangedAt()
|
|
|
|
|
|
|
|
onDocSaved = () ->
|
|
|
|
# We use the save as a trigger too, to account for the delay between the client
|
|
|
|
# and server. Otherwise, we might have compiled after the user made
|
|
|
|
# the change on the client, but before the server had it.
|
|
|
|
_updateDocLastChangedAt()
|
2018-02-08 05:24:21 -05:00
|
|
|
|
|
|
|
onCompilingStateChanged = (compiling) ->
|
2018-02-08 08:32:15 -05:00
|
|
|
recalculateUncompiledChanges()
|
2018-02-08 05:24:21 -05:00
|
|
|
|
|
|
|
autoCompileListeners = []
|
2017-09-05 08:57:11 -04:00
|
|
|
toggleAutoCompile = (enabling) ->
|
|
|
|
if enabling
|
2018-02-08 05:24:21 -05:00
|
|
|
autoCompileListeners = [
|
|
|
|
ide.$scope.$on "doc:changed", onDocChanged
|
2018-02-08 08:32:15 -05:00
|
|
|
ide.$scope.$on "doc:saved", onDocSaved
|
2018-02-08 05:24:21 -05:00
|
|
|
$scope.$watch "pdf.compiling", onCompilingStateChanged
|
|
|
|
]
|
2017-09-05 08:57:11 -04:00
|
|
|
else
|
2018-02-08 05:24:21 -05:00
|
|
|
for unbind in autoCompileListeners
|
|
|
|
unbind()
|
|
|
|
autoCompileListeners = []
|
|
|
|
$scope.autoCompileLintingError = false
|
2017-09-05 08:57:11 -04:00
|
|
|
|
2017-09-05 07:21:23 -04:00
|
|
|
$scope.autocompile_enabled = localStorage("autocompile_enabled:#{$scope.project_id}") or false
|
|
|
|
$scope.$watch "autocompile_enabled", (newValue, oldValue) ->
|
|
|
|
if newValue? and oldValue != newValue
|
|
|
|
localStorage("autocompile_enabled:#{$scope.project_id}", newValue)
|
2017-09-05 08:57:11 -04:00
|
|
|
toggleAutoCompile(newValue)
|
2017-09-19 10:55:00 -04:00
|
|
|
event_tracking.sendMB "autocompile-setting-changed", { value: newValue }
|
2017-09-05 07:21:23 -04:00
|
|
|
|
2018-01-17 10:04:24 -05:00
|
|
|
if $scope.autocompile_enabled
|
2017-09-05 08:57:11 -04:00
|
|
|
toggleAutoCompile(true)
|
2017-09-04 06:41:52 -04:00
|
|
|
|
2016-08-24 11:05:22 -04:00
|
|
|
# abort compile if syntax checks fail
|
2016-09-06 06:19:14 -04:00
|
|
|
$scope.stop_on_validation_error = localStorage("stop_on_validation_error:#{$scope.project_id}")
|
|
|
|
$scope.stop_on_validation_error ?= true # turn on for all users by default
|
2016-08-24 11:05:22 -04:00
|
|
|
$scope.$watch "stop_on_validation_error", (new_value, old_value) ->
|
|
|
|
if new_value? and old_value != new_value
|
|
|
|
localStorage("stop_on_validation_error:#{$scope.project_id}", new_value)
|
|
|
|
|
2016-02-02 09:50:48 -05:00
|
|
|
$scope.draft = localStorage("draft:#{$scope.project_id}") or false
|
|
|
|
$scope.$watch "draft", (new_value, old_value) ->
|
|
|
|
if new_value? and old_value != new_value
|
|
|
|
localStorage("draft:#{$scope.project_id}", new_value)
|
2015-01-12 11:46:17 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
sendCompileRequest = (options = {}) ->
|
|
|
|
url = "/project/#{$scope.project_id}/compile"
|
2016-05-31 11:20:46 -04:00
|
|
|
params = {}
|
2017-10-09 10:18:55 -04:00
|
|
|
if options.isAutoCompileOnLoad or options.isAutoCompileOnChange
|
2016-05-31 11:20:46 -04:00
|
|
|
params["auto_compile"]=true
|
2016-08-25 10:52:37 -04:00
|
|
|
# if the previous run was a check, clear the error logs
|
|
|
|
$scope.pdf.logEntries = [] if $scope.check
|
2016-08-24 11:05:22 -04:00
|
|
|
# keep track of whether this is a compile or check
|
|
|
|
$scope.check = if options.check then true else false
|
2016-08-26 10:54:01 -04:00
|
|
|
event_tracking.sendMB "syntax-check-request" if options.check
|
2016-08-24 11:05:22 -04:00
|
|
|
# send appropriate check type to clsi
|
|
|
|
checkType = switch
|
|
|
|
when $scope.check then "validate" # validate only
|
2016-08-25 10:52:37 -04:00
|
|
|
when options.try then "silent" # allow use to try compile once
|
2016-08-24 11:05:22 -04:00
|
|
|
when $scope.stop_on_validation_error then "error" # try to compile
|
|
|
|
else "silent" # ignore errors
|
2018-09-19 05:51:35 -04:00
|
|
|
# FIXME: Temporarily disable syntax checking as it is causing
|
|
|
|
# excessive support requests for projects migrated from v1
|
|
|
|
# https://github.com/overleaf/sharelatex/issues/911
|
|
|
|
if checkType == "error"
|
|
|
|
checkType = "silent"
|
2014-07-08 07:02:26 -04:00
|
|
|
return $http.post url, {
|
2014-11-28 09:26:21 -05:00
|
|
|
rootDoc_id: options.rootDocOverride_id or null
|
2016-02-02 09:50:48 -05:00
|
|
|
draft: $scope.draft
|
2016-08-24 11:05:22 -04:00
|
|
|
check: checkType
|
2017-10-13 03:23:16 -04:00
|
|
|
# use incremental compile for all users but revert to a full
|
2017-09-07 10:05:42 -04:00
|
|
|
# compile if there is a server error
|
2017-10-13 03:23:16 -04:00
|
|
|
incrementalCompilesEnabled: not $scope.pdf.error
|
2014-07-08 07:02:26 -04:00
|
|
|
_csrf: window.csrfToken
|
2016-05-31 11:20:46 -04:00
|
|
|
}, {params: params}
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2018-07-16 11:18:08 -04:00
|
|
|
buildPdfDownloadUrl = (pdfDownloadDomain, path)->
|
2018-08-21 04:24:48 -04:00
|
|
|
#we only download builds from compiles server for security reasons
|
2018-08-22 11:33:15 -04:00
|
|
|
if pdfDownloadDomain? and path? and path.indexOf("build") != -1
|
2018-07-16 11:18:08 -04:00
|
|
|
return "#{pdfDownloadDomain}#{path}"
|
|
|
|
else
|
|
|
|
return path
|
|
|
|
|
2016-10-13 08:47:05 -04:00
|
|
|
parseCompileResponse = (response) ->
|
2016-05-18 07:50:50 -04:00
|
|
|
|
2016-07-26 11:26:27 -04:00
|
|
|
# keep last url
|
|
|
|
last_pdf_url = $scope.pdf.url
|
2018-06-08 12:17:00 -04:00
|
|
|
pdfDownloadDomain = response.pdfDownloadDomain
|
2014-07-08 07:02:26 -04:00
|
|
|
# Reset everything
|
|
|
|
$scope.pdf.error = false
|
|
|
|
$scope.pdf.timedout = false
|
|
|
|
$scope.pdf.failure = false
|
|
|
|
$scope.pdf.url = null
|
2016-03-21 11:00:25 -04:00
|
|
|
$scope.pdf.clsiMaintenance = false
|
2016-03-21 11:16:17 -04:00
|
|
|
$scope.pdf.tooRecentlyCompiled = false
|
2016-04-25 07:42:03 -04:00
|
|
|
$scope.pdf.renderingError = false
|
2016-06-02 08:09:11 -04:00
|
|
|
$scope.pdf.projectTooLarge = false
|
2016-07-14 09:48:46 -04:00
|
|
|
$scope.pdf.compileTerminated = false
|
2016-08-24 11:48:45 -04:00
|
|
|
$scope.pdf.compileExited = false
|
2016-08-25 10:52:37 -04:00
|
|
|
$scope.pdf.failedCheck = false
|
2017-09-26 03:07:35 -04:00
|
|
|
$scope.pdf.compileInProgress = false
|
2017-10-09 10:21:01 -04:00
|
|
|
$scope.pdf.autoCompileDisabled = false
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2018-07-16 11:18:08 -04:00
|
|
|
|
2016-05-24 10:10:55 -04:00
|
|
|
# make a cache to look up files by name
|
|
|
|
fileByPath = {}
|
2016-06-06 09:56:34 -04:00
|
|
|
if response?.outputFiles?
|
|
|
|
for file in response?.outputFiles
|
|
|
|
fileByPath[file.path] = file
|
2016-05-24 10:10:55 -04:00
|
|
|
|
2016-07-20 04:58:34 -04:00
|
|
|
# prepare query string
|
|
|
|
qs = {}
|
|
|
|
# add a query string parameter for the compile group
|
|
|
|
if response.compileGroup?
|
|
|
|
ide.compileGroup = qs.compileGroup = response.compileGroup
|
|
|
|
# add a query string parameter for the clsi server id
|
|
|
|
if response.clsiServerId?
|
|
|
|
ide.clsiServerId = qs.clsiserverid = response.clsiServerId
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
if response.status == "timedout"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.timedout = true
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, {pdfDownloadDomain:pdfDownloadDomain})
|
2016-07-14 09:48:46 -04:00
|
|
|
else if response.status == "terminated"
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.compileTerminated = true
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, {pdfDownloadDomain:pdfDownloadDomain})
|
2016-07-27 11:53:22 -04:00
|
|
|
else if response.status in ["validation-fail", "validation-pass"]
|
|
|
|
$scope.pdf.view = 'pdf'
|
2018-07-16 11:18:08 -04:00
|
|
|
$scope.pdf.url = buildPdfDownloadUrl pdfDownloadDomain, last_pdf_url
|
2016-07-27 11:53:22 -04:00
|
|
|
$scope.shouldShowLogs = true
|
2016-08-25 10:52:37 -04:00
|
|
|
$scope.pdf.failedCheck = true if response.status is "validation-fail"
|
2016-08-26 10:54:01 -04:00
|
|
|
event_tracking.sendMB "syntax-check-#{response.status}"
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, { validation: true, pdfDownloadDomain:pdfDownloadDomain})
|
2016-07-26 11:26:27 -04:00
|
|
|
else if response.status == "exited"
|
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.pdf.compileExited = true
|
2018-07-16 11:18:08 -04:00
|
|
|
$scope.pdf.url = buildPdfDownloadUrl pdfDownloadDomain, last_pdf_url
|
2016-07-26 11:26:27 -04:00
|
|
|
$scope.shouldShowLogs = true
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, {pdfDownloadDomain:pdfDownloadDomain})
|
2014-07-08 07:02:26 -04:00
|
|
|
else if response.status == "autocompile-backoff"
|
2017-10-09 10:18:55 -04:00
|
|
|
if $scope.pdf.isAutoCompileOnLoad # initial autocompile
|
2017-10-03 11:23:49 -04:00
|
|
|
$scope.pdf.view = 'uncompiled'
|
|
|
|
else # background autocompile from typing
|
|
|
|
$scope.pdf.view = 'errors'
|
2017-10-09 10:21:01 -04:00
|
|
|
$scope.pdf.autoCompileDisabled = true
|
2017-10-03 11:23:49 -04:00
|
|
|
$scope.autocompile_enabled = false # disable any further autocompiles
|
|
|
|
event_tracking.sendMB "autocompile-rate-limited", {hasPremiumCompile: $scope.hasPremiumCompile}
|
2014-11-27 10:42:37 -05:00
|
|
|
else if response.status == "project-too-large"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2014-11-27 10:42:37 -05:00
|
|
|
$scope.pdf.projectTooLarge = true
|
2014-07-08 07:02:26 -04:00
|
|
|
else if response.status == "failure"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.failure = true
|
2016-03-22 12:59:40 -04:00
|
|
|
$scope.shouldShowLogs = true
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, {pdfDownloadDomain:pdfDownloadDomain})
|
2016-03-21 11:00:25 -04:00
|
|
|
else if response.status == 'clsi-maintenance'
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2016-03-21 11:00:25 -04:00
|
|
|
$scope.pdf.clsiMaintenance = true
|
2016-03-21 11:16:17 -04:00
|
|
|
else if response.status == "too-recently-compiled"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2016-03-21 11:16:17 -04:00
|
|
|
$scope.pdf.tooRecentlyCompiled = true
|
2016-06-02 08:09:11 -04:00
|
|
|
else if response.status == "validation-problems"
|
|
|
|
$scope.pdf.view = "validation-problems"
|
|
|
|
$scope.pdf.validation = response.validationProblems
|
2017-10-17 10:50:38 -04:00
|
|
|
$scope.shouldShowLogs = false
|
2017-09-26 03:07:35 -04:00
|
|
|
else if response.status == "compile-in-progress"
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.compileInProgress = true
|
2016-03-22 06:32:44 -04:00
|
|
|
else if response.status == "success"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.pdf.view = 'pdf'
|
2016-03-22 06:32:55 -04:00
|
|
|
$scope.shouldShowLogs = false
|
2016-05-19 08:28:20 -04:00
|
|
|
|
2016-05-13 06:45:09 -04:00
|
|
|
# define the base url. if the pdf file has a build number, pass it to the clsi in the url
|
2016-05-20 05:09:42 -04:00
|
|
|
if fileByPath['output.pdf']?.url?
|
2018-07-16 11:18:08 -04:00
|
|
|
$scope.pdf.url = buildPdfDownloadUrl pdfDownloadDomain, fileByPath['output.pdf'].url
|
2016-05-20 05:09:42 -04:00
|
|
|
else if fileByPath['output.pdf']?.build?
|
2015-02-25 12:06:27 -05:00
|
|
|
build = fileByPath['output.pdf'].build
|
2018-07-16 11:18:08 -04:00
|
|
|
$scope.pdf.url = buildPdfDownloadUrl pdfDownloadDomain, "/project/#{$scope.project_id}/build/#{build}/output/output.pdf"
|
2016-05-13 06:45:09 -04:00
|
|
|
else
|
2018-07-16 11:18:08 -04:00
|
|
|
$scope.pdf.url = buildPdfDownloadUrl pdfDownloadDomain, "/project/#{$scope.project_id}/output/output.pdf"
|
2016-05-20 05:09:42 -04:00
|
|
|
# check if we need to bust cache (build id is unique so don't need it in that case)
|
|
|
|
if not fileByPath['output.pdf']?.build?
|
2016-05-19 11:23:56 -04:00
|
|
|
qs.cache_bust = "#{Date.now()}"
|
2016-05-13 06:45:09 -04:00
|
|
|
# convert the qs hash into a query string and append it
|
2016-07-20 04:58:34 -04:00
|
|
|
$scope.pdf.url += createQueryString qs
|
2016-06-16 10:20:57 -04:00
|
|
|
# Save all downloads as files
|
|
|
|
qs.popupDownload = true
|
2016-06-16 09:05:21 -04:00
|
|
|
$scope.pdf.downloadUrl = "/project/#{$scope.project_id}/output/output.pdf" + createQueryString(qs)
|
2015-02-25 12:06:27 -05:00
|
|
|
|
2018-07-16 11:18:08 -04:00
|
|
|
fetchLogs(fileByPath, {pdfDownloadDomain:pdfDownloadDomain})
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
IGNORE_FILES = ["output.fls", "output.fdb_latexmk"]
|
|
|
|
$scope.pdf.outputFiles = []
|
2015-02-23 12:43:22 -05:00
|
|
|
|
|
|
|
if !response.outputFiles?
|
|
|
|
return
|
2016-07-12 09:35:43 -04:00
|
|
|
|
|
|
|
# prepare list of output files for download dropdown
|
|
|
|
qs = {}
|
|
|
|
if response.clsiServerId?
|
|
|
|
qs.clsiserverid = response.clsiServerId
|
2014-07-08 07:02:26 -04:00
|
|
|
for file in response.outputFiles
|
|
|
|
if IGNORE_FILES.indexOf(file.path) == -1
|
2018-08-27 14:25:01 -04:00
|
|
|
isOutputFile = /^output\./.test(file.path)
|
2016-07-12 09:35:43 -04:00
|
|
|
$scope.pdf.outputFiles.push {
|
|
|
|
# Turn 'output.blg' into 'blg file'.
|
2016-08-15 11:45:33 -04:00
|
|
|
name: if isOutputFile then "#{file.path.replace(/^output\./, "")} file" else file.path
|
2016-07-12 09:35:43 -04:00
|
|
|
url: "/project/#{project_id}/output/#{file.path}" + createQueryString qs
|
2016-08-15 11:45:33 -04:00
|
|
|
main: if isOutputFile then true else false
|
2016-07-12 09:35:43 -04:00
|
|
|
}
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2016-08-15 11:45:33 -04:00
|
|
|
# sort the output files into order, main files first, then others
|
|
|
|
$scope.pdf.outputFiles.sort (a,b) -> (b.main - a.main) || a.name.localeCompare(b.name)
|
|
|
|
|
2016-05-19 11:26:54 -04:00
|
|
|
|
2016-07-28 11:19:10 -04:00
|
|
|
fetchLogs = (fileByPath, options) ->
|
2016-07-26 11:26:27 -04:00
|
|
|
|
2016-07-28 11:19:10 -04:00
|
|
|
if options?.validation
|
|
|
|
chktexFile = fileByPath['output.chktex']
|
|
|
|
else
|
|
|
|
logFile = fileByPath['output.log']
|
|
|
|
blgFile = fileByPath['output.blg']
|
2016-05-18 11:17:38 -04:00
|
|
|
|
|
|
|
getFile = (name, file) ->
|
2016-05-19 11:26:54 -04:00
|
|
|
opts =
|
|
|
|
method:"GET"
|
|
|
|
params:
|
2016-07-20 04:58:34 -04:00
|
|
|
compileGroup:ide.compileGroup
|
2016-05-19 11:26:54 -04:00
|
|
|
clsiserverid:ide.clsiServerId
|
2016-06-25 08:56:45 -04:00
|
|
|
if file?.url? # FIXME clean this up when we have file.urls out consistently
|
2016-05-20 07:28:06 -04:00
|
|
|
opts.url = file.url
|
2016-05-20 05:09:42 -04:00
|
|
|
else if file?.build?
|
2016-05-19 11:26:54 -04:00
|
|
|
opts.url = "/project/#{$scope.project_id}/build/#{file.build}/output/#{name}"
|
2016-05-18 11:17:38 -04:00
|
|
|
else
|
2016-05-19 11:26:54 -04:00
|
|
|
opts.url = "/project/#{$scope.project_id}/output/#{name}"
|
2016-07-20 04:54:19 -04:00
|
|
|
# check if we need to bust cache (build id is unique so don't need it in that case)
|
|
|
|
if not file?.build?
|
|
|
|
opts.params.cache_bust = "#{Date.now()}"
|
2018-08-21 04:24:48 -04:00
|
|
|
opts.url = buildPdfDownloadUrl options.pdfDownloadDomain, opts.url
|
2016-05-19 11:26:54 -04:00
|
|
|
return $http(opts)
|
2016-05-18 11:17:38 -04:00
|
|
|
|
|
|
|
# accumulate the log entries
|
|
|
|
logEntries =
|
|
|
|
all: []
|
|
|
|
errors: []
|
|
|
|
warnings: []
|
|
|
|
|
|
|
|
accumulateResults = (newEntries) ->
|
|
|
|
for key in ['all', 'errors', 'warnings']
|
2016-07-26 11:26:27 -04:00
|
|
|
if newEntries.type?
|
|
|
|
entry.type = newEntries.type for entry in newEntries[key]
|
2016-05-18 11:17:38 -04:00
|
|
|
logEntries[key] = logEntries[key].concat newEntries[key]
|
2016-06-27 06:34:24 -04:00
|
|
|
|
2016-05-18 11:17:38 -04:00
|
|
|
# use the parsers for each file type
|
|
|
|
processLog = (log) ->
|
|
|
|
$scope.pdf.rawLog = log
|
2016-06-16 06:14:45 -04:00
|
|
|
{errors, warnings, typesetting} = HumanReadableLogs.parse(log, ignoreDuplicates: true)
|
2016-05-18 11:17:38 -04:00
|
|
|
all = [].concat errors, warnings, typesetting
|
|
|
|
accumulateResults {all, errors, warnings}
|
|
|
|
|
2016-07-26 11:26:27 -04:00
|
|
|
processChkTex = (log) ->
|
|
|
|
errors = []
|
|
|
|
warnings = []
|
|
|
|
for line in log.split("\n")
|
|
|
|
if m = line.match /^(\S+):(\d+):(\d+): (Error|Warning): (.*)/
|
|
|
|
result = { file:m[1], line:m[2], column:m[3], level:m[4].toLowerCase(), message: "#{m[4]}: #{m[5]}"}
|
|
|
|
if result.level is 'error'
|
|
|
|
errors.push result
|
|
|
|
else
|
|
|
|
warnings.push result
|
|
|
|
all = [].concat errors, warnings
|
2016-08-25 11:55:49 -04:00
|
|
|
logHints = HumanReadableLogs.parse {type: "Syntax", all, errors, warnings}
|
2016-08-26 10:54:01 -04:00
|
|
|
event_tracking.sendMB "syntax-check-return-count", {errors:errors.length, warnings:warnings.length}
|
2016-07-27 11:53:22 -04:00
|
|
|
accumulateResults logHints
|
2016-07-26 11:26:27 -04:00
|
|
|
|
2016-05-18 11:17:38 -04:00
|
|
|
processBiber = (log) ->
|
|
|
|
{errors, warnings} = BibLogParser.parse(log, {})
|
|
|
|
all = [].concat errors, warnings
|
2016-07-26 11:26:27 -04:00
|
|
|
accumulateResults {type: "BibTeX", all, errors, warnings}
|
2016-05-18 11:17:38 -04:00
|
|
|
|
|
|
|
# output the results
|
|
|
|
handleError = () ->
|
|
|
|
$scope.pdf.logEntries = []
|
|
|
|
$scope.pdf.rawLog = ""
|
|
|
|
|
|
|
|
annotateFiles = () ->
|
|
|
|
$scope.pdf.logEntries = logEntries
|
|
|
|
$scope.pdf.logEntryAnnotations = {}
|
|
|
|
for entry in logEntries.all
|
|
|
|
if entry.file?
|
|
|
|
entry.file = normalizeFilePath(entry.file)
|
|
|
|
entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
|
|
|
if entity?
|
|
|
|
$scope.pdf.logEntryAnnotations[entity.id] ||= []
|
|
|
|
$scope.pdf.logEntryAnnotations[entity.id].push {
|
|
|
|
row: entry.line - 1
|
|
|
|
type: if entry.level == "error" then "error" else "warning"
|
|
|
|
text: entry.message
|
|
|
|
}
|
|
|
|
|
|
|
|
# retrieve the logfile and process it
|
2016-07-26 11:26:27 -04:00
|
|
|
if logFile?
|
|
|
|
response = getFile('output.log', logFile)
|
|
|
|
.then (response) -> processLog(response.data)
|
|
|
|
|
|
|
|
if blgFile? # retrieve the blg file if present
|
|
|
|
response = response.then () ->
|
|
|
|
getFile('output.blg', blgFile)
|
|
|
|
.then(
|
|
|
|
(response) -> processBiber(response.data),
|
|
|
|
() -> true # ignore errors in biber file
|
|
|
|
)
|
|
|
|
|
|
|
|
if response?
|
|
|
|
response.catch handleError
|
|
|
|
else
|
|
|
|
handleError()
|
|
|
|
|
|
|
|
if chktexFile?
|
|
|
|
getChkTex = () ->
|
|
|
|
getFile('output.chktex', chktexFile)
|
|
|
|
.then (response) -> processChkTex(response.data)
|
|
|
|
# always retrieve the chktex file if present
|
|
|
|
if response?
|
|
|
|
response = response.then getChkTex, getChkTex
|
|
|
|
else
|
|
|
|
response = getChkTex()
|
|
|
|
|
|
|
|
# display the combined result
|
2017-05-16 04:20:12 -04:00
|
|
|
if response?
|
|
|
|
response.finally annotateFiles
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
getRootDocOverride_id = () ->
|
|
|
|
doc = ide.editorManager.getCurrentDocValue()
|
|
|
|
return null if !doc?
|
|
|
|
for line in doc.split("\n")
|
2018-08-27 14:25:01 -04:00
|
|
|
if /^[^%]*\\documentclass/.test(line)
|
2014-07-08 07:02:26 -04:00
|
|
|
return ide.editorManager.getCurrentDocId()
|
|
|
|
return null
|
|
|
|
|
|
|
|
normalizeFilePath = (path) ->
|
2016-06-29 09:19:16 -04:00
|
|
|
path = path.replace(/^(.*)\/compiles\/[0-9a-f]{24}(-[0-9a-f]{24})?\/(\.\/)?/, "")
|
2014-07-08 07:02:26 -04:00
|
|
|
path = path.replace(/^\/compile\//, "")
|
|
|
|
|
|
|
|
rootDocDirname = ide.fileTreeManager.getRootDocDirname()
|
|
|
|
if rootDocDirname?
|
|
|
|
path = path.replace(/^\.\//, rootDocDirname + "/")
|
|
|
|
|
|
|
|
return path
|
|
|
|
|
|
|
|
$scope.recompile = (options = {}) ->
|
|
|
|
return if $scope.pdf.compiling
|
2016-07-05 11:02:46 -04:00
|
|
|
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBSampled "editor-recompile-sampled", options
|
2016-07-08 05:07:45 -04:00
|
|
|
|
2018-02-08 08:32:15 -05:00
|
|
|
$scope.lastStartedCompileAt = Date.now()
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.compiling = true
|
2017-10-09 10:18:55 -04:00
|
|
|
$scope.pdf.isAutoCompileOnLoad = options?.isAutoCompileOnLoad # initial autocompile
|
2016-03-08 08:20:23 -05:00
|
|
|
|
2016-08-24 11:05:22 -04:00
|
|
|
if options?.force
|
2016-08-26 10:54:01 -04:00
|
|
|
# for forced compile, turn off validation check and ignore errors
|
2016-08-24 11:05:22 -04:00
|
|
|
$scope.stop_on_validation_error = false
|
|
|
|
$scope.shouldShowLogs = false # hide the logs while compiling
|
2016-08-26 10:54:01 -04:00
|
|
|
event_tracking.sendMB "syntax-check-turn-off-checking"
|
2016-08-24 11:05:22 -04:00
|
|
|
|
2016-08-25 10:52:37 -04:00
|
|
|
if options?.try
|
|
|
|
$scope.shouldShowLogs = false # hide the logs while compiling
|
2016-08-26 10:54:01 -04:00
|
|
|
event_tracking.sendMB "syntax-check-try-compile-anyway"
|
2016-08-25 10:52:37 -04:00
|
|
|
|
2015-04-17 06:22:26 -04:00
|
|
|
ide.$scope.$broadcast("flush-changes")
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
options.rootDocOverride_id = getRootDocOverride_id()
|
|
|
|
|
|
|
|
sendCompileRequest(options)
|
2017-06-20 11:04:06 -04:00
|
|
|
.then (response) ->
|
|
|
|
{ data } = response
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.view = "pdf"
|
|
|
|
$scope.pdf.compiling = false
|
|
|
|
parseCompileResponse(data)
|
2017-06-20 11:04:06 -04:00
|
|
|
.catch (response) ->
|
|
|
|
{ data, status } = response
|
2017-04-24 11:16:02 -04:00
|
|
|
if status == 429
|
2017-04-24 10:56:09 -04:00
|
|
|
$scope.pdf.rateLimited = true
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.compiling = false
|
2016-04-25 07:42:03 -04:00
|
|
|
$scope.pdf.renderingError = false
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.pdf.error = true
|
2016-03-22 11:51:05 -04:00
|
|
|
$scope.pdf.view = 'errors'
|
2017-09-08 05:42:54 -04:00
|
|
|
.finally () ->
|
2018-02-08 08:32:15 -05:00
|
|
|
$scope.lastFinishedCompileAt = Date.now()
|
2016-03-08 08:20:23 -05:00
|
|
|
|
2014-07-21 10:39:15 -04:00
|
|
|
# This needs to be public.
|
|
|
|
ide.$scope.recompile = $scope.recompile
|
2016-07-05 11:02:46 -04:00
|
|
|
# This method is a simply wrapper and exists only for tracking purposes.
|
|
|
|
ide.$scope.recompileViaKey = () ->
|
|
|
|
$scope.recompile { keyShortcut: true }
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2016-07-14 09:48:46 -04:00
|
|
|
$scope.stop = () ->
|
|
|
|
return if !$scope.pdf.compiling
|
|
|
|
|
|
|
|
$http {
|
|
|
|
url: "/project/#{$scope.project_id}/compile/stop"
|
|
|
|
method: "POST"
|
|
|
|
params:
|
|
|
|
clsiserverid:ide.clsiServerId
|
|
|
|
headers:
|
|
|
|
"X-Csrf-Token": window.csrfToken
|
|
|
|
}
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.clearCache = () ->
|
|
|
|
$http {
|
|
|
|
url: "/project/#{$scope.project_id}/output"
|
|
|
|
method: "DELETE"
|
2016-05-18 07:50:50 -04:00
|
|
|
params:
|
|
|
|
clsiserverid:ide.clsiServerId
|
2014-07-08 07:02:26 -04:00
|
|
|
headers:
|
|
|
|
"X-Csrf-Token": window.csrfToken
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.toggleLogs = () ->
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.shouldShowLogs = !$scope.shouldShowLogs
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBOnce "ide-open-logs-once" if $scope.shouldShowLogs
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.showPdf = () ->
|
|
|
|
$scope.pdf.view = "pdf"
|
2016-03-22 05:39:33 -04:00
|
|
|
$scope.shouldShowLogs = false
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.toggleRawLog = () ->
|
|
|
|
$scope.pdf.showRawLog = !$scope.pdf.showRawLog
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMB "logs-view-raw" if $scope.pdf.showRawLog
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.openClearCacheModal = () ->
|
|
|
|
modalInstance = $modal.open(
|
|
|
|
templateUrl: "clearCacheModalTemplate"
|
|
|
|
controller: "ClearCacheModalController"
|
|
|
|
scope: $scope
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.syncToCode = (position) ->
|
|
|
|
synctex
|
|
|
|
.syncToCode(position)
|
|
|
|
.then (data) ->
|
|
|
|
{doc, line} = data
|
|
|
|
ide.editorManager.openDoc(doc, gotoLine: line)
|
2016-03-08 08:20:23 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
App.factory "synctex", ["ide", "$http", "$q", (ide, $http, $q) ->
|
2016-06-28 03:40:30 -04:00
|
|
|
# enable per-user containers by default
|
|
|
|
perUserCompile = true
|
2016-06-14 03:40:15 -04:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
synctex =
|
|
|
|
syncToPdf: (cursorPosition) ->
|
|
|
|
deferred = $q.defer()
|
|
|
|
|
|
|
|
doc_id = ide.editorManager.getCurrentDocId()
|
|
|
|
if !doc_id?
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
doc = ide.fileTreeManager.findEntityById(doc_id)
|
|
|
|
if !doc?
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
path = ide.fileTreeManager.getEntityPath(doc)
|
|
|
|
if !path?
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
2016-03-08 08:20:23 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
# If the root file is folder/main.tex, then synctex sees the
|
|
|
|
# path as folder/./main.tex
|
|
|
|
rootDocDirname = ide.fileTreeManager.getRootDocDirname()
|
|
|
|
if rootDocDirname? and rootDocDirname != ""
|
|
|
|
path = path.replace(RegExp("^#{rootDocDirname}"), "#{rootDocDirname}/.")
|
|
|
|
|
|
|
|
{row, column} = cursorPosition
|
|
|
|
|
|
|
|
$http({
|
2016-03-08 08:20:23 -05:00
|
|
|
url: "/project/#{ide.project_id}/sync/code",
|
2014-07-08 07:02:26 -04:00
|
|
|
method: "GET",
|
|
|
|
params: {
|
|
|
|
file: path
|
|
|
|
line: row + 1
|
|
|
|
column: column
|
2016-05-18 07:50:50 -04:00
|
|
|
clsiserverid:ide.clsiServerId
|
2014-07-08 07:02:26 -04:00
|
|
|
}
|
|
|
|
})
|
2017-06-20 11:04:06 -04:00
|
|
|
.then (response) ->
|
|
|
|
{ data } = response
|
2014-07-08 07:02:26 -04:00
|
|
|
deferred.resolve(data.pdf or [])
|
2017-06-20 11:04:06 -04:00
|
|
|
.catch (response) ->
|
|
|
|
error = response.data
|
2014-07-08 07:02:26 -04:00
|
|
|
deferred.reject(error)
|
|
|
|
|
|
|
|
return deferred.promise
|
|
|
|
|
|
|
|
syncToCode: (position, options = {}) ->
|
|
|
|
deferred = $q.defer()
|
|
|
|
if !position?
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
|
2016-06-14 07:32:54 -04:00
|
|
|
# FIXME: this actually works better if it's halfway across the
|
|
|
|
# page (or the visible part of the page). Synctex doesn't
|
|
|
|
# always find the right place in the file when the point is at
|
|
|
|
# the edge of the page, it sometimes returns the start of the
|
|
|
|
# next paragraph instead.
|
|
|
|
h = position.offset.left
|
|
|
|
|
|
|
|
# Compute the vertical position to pass to synctex, which
|
|
|
|
# works with coordinates increasing from the top of the page
|
|
|
|
# down. This matches the browser's DOM coordinate of the
|
|
|
|
# click point, but the pdf position is measured from the
|
|
|
|
# bottom of the page so we need to invert it.
|
|
|
|
if options.fromPdfPosition and position.pageSize?.height?
|
|
|
|
v = (position.pageSize.height - position.offset.top) or 0 # measure from pdf point (inverted)
|
|
|
|
else
|
|
|
|
v = position.offset.top or 0 # measure from html click position
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
# It's not clear exactly where we should sync to if it wasn't directly
|
|
|
|
# clicked on, but a little bit down from the very top seems best.
|
|
|
|
if options.includeVisualOffset
|
2016-06-14 07:32:54 -04:00
|
|
|
v += 72 # use the same value as in pdfViewer highlighting visual offset
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$http({
|
2016-03-08 08:20:23 -05:00
|
|
|
url: "/project/#{ide.project_id}/sync/pdf",
|
2014-07-08 07:02:26 -04:00
|
|
|
method: "GET",
|
|
|
|
params: {
|
|
|
|
page: position.page + 1
|
2016-06-14 07:32:54 -04:00
|
|
|
h: h.toFixed(2)
|
|
|
|
v: v.toFixed(2)
|
2016-05-18 07:50:50 -04:00
|
|
|
clsiserverid:ide.clsiServerId
|
2014-07-08 07:02:26 -04:00
|
|
|
}
|
|
|
|
})
|
2017-06-20 11:04:06 -04:00
|
|
|
.then (response) ->
|
|
|
|
{ data } = response
|
2014-07-08 07:02:26 -04:00
|
|
|
if data.code? and data.code.length > 0
|
|
|
|
doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
|
|
|
|
return if !doc?
|
|
|
|
deferred.resolve({doc: doc, line: data.code[0].line})
|
2017-06-20 11:04:06 -04:00
|
|
|
.catch (response) ->
|
|
|
|
error = response.data
|
2014-07-08 07:02:26 -04:00
|
|
|
deferred.reject(error)
|
|
|
|
|
|
|
|
return deferred.promise
|
|
|
|
|
|
|
|
return synctex
|
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "PdfSynctexController", ["$scope", "synctex", "ide", ($scope, synctex, ide) ->
|
2014-07-10 09:36:04 -04:00
|
|
|
@cursorPosition = null
|
|
|
|
ide.$scope.$on "cursor:editor:update", (event, @cursorPosition) =>
|
|
|
|
|
|
|
|
$scope.syncToPdf = () =>
|
|
|
|
return if !@cursorPosition?
|
2014-07-08 07:02:26 -04:00
|
|
|
synctex
|
2014-07-10 09:36:04 -04:00
|
|
|
.syncToPdf(@cursorPosition)
|
2014-07-08 07:02:26 -04:00
|
|
|
.then (highlights) ->
|
|
|
|
$scope.pdf.highlights = highlights
|
|
|
|
|
2018-07-13 04:18:23 -04:00
|
|
|
ide.$scope.$on "cursor:editor:syncToPdf", $scope.syncToPdf
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.syncToCode = () ->
|
|
|
|
synctex
|
2016-06-14 07:32:54 -04:00
|
|
|
.syncToCode($scope.pdf.position, includeVisualOffset: true, fromPdfPosition: true)
|
2014-07-08 07:02:26 -04:00
|
|
|
.then (data) ->
|
|
|
|
{doc, line} = data
|
|
|
|
ide.editorManager.openDoc(doc, gotoLine: line)
|
|
|
|
]
|
|
|
|
|
2016-07-05 11:27:14 -04:00
|
|
|
App.controller "PdfLogEntryController", ["$scope", "ide", "event_tracking", ($scope, ide, event_tracking) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.openInEditor = (entry) ->
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBOnce "logs-jump-to-location-once"
|
2014-07-08 07:02:26 -04:00
|
|
|
entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
|
|
|
return if !entity? or entity.type != "doc"
|
|
|
|
if entry.line?
|
|
|
|
line = entry.line
|
2016-07-28 11:18:36 -04:00
|
|
|
if entry.column?
|
|
|
|
column = entry.column
|
|
|
|
ide.editorManager.openDoc(entity, gotoLine: line, gotoColumn: column)
|
2014-07-08 07:02:26 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
App.controller 'ClearCacheModalController', ["$scope", "$modalInstance", ($scope, $modalInstance) ->
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
|
|
|
|
|
|
|
$scope.clear = () ->
|
|
|
|
$scope.state.inflight = true
|
|
|
|
$scope
|
|
|
|
.clearCache()
|
|
|
|
.then () ->
|
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
2016-03-08 08:20:23 -05:00
|
|
|
]
|