PdfController.coffee 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. define [
  2. "base"
  3. "ace/ace"
  4. "ide/human-readable-logs/HumanReadableLogs"
  5. "libs/bib-log-parser"
  6. "services/log-hints-feedback"
  7. ], (App, Ace, HumanReadableLogs, BibLogParser) ->
  8. App.controller "PdfController", ($scope, $http, ide, $modal, synctex, event_tracking, logHintsFeedback, localStorage) ->
  9. # enable per-user containers by default
  10. perUserCompile = true
  11. autoCompile = true
  12. # pdf.view = uncompiled | pdf | errors
  13. $scope.pdf.view = if $scope?.pdf?.url then 'pdf' else 'uncompiled'
  14. $scope.shouldShowLogs = false
  15. $scope.wikiEnabled = window.wikiEnabled;
  16. # view logic to check whether the files dropdown should "drop up" or "drop down"
  17. $scope.shouldDropUp = false
  18. logsContainerEl = document.querySelector ".pdf-logs"
  19. filesDropdownEl = logsContainerEl?.querySelector ".files-dropdown"
  20. # get the top coordinate of the files dropdown as a ratio (to the logs container height)
  21. # logs container supports scrollable content, so it's possible that ratio > 1.
  22. getFilesDropdownTopCoordAsRatio = () ->
  23. filesDropdownEl?.getBoundingClientRect().top / logsContainerEl?.getBoundingClientRect().height
  24. $scope.$watch "shouldShowLogs", (shouldShow) ->
  25. if shouldShow
  26. $scope.$applyAsync () ->
  27. $scope.shouldDropUp = getFilesDropdownTopCoordAsRatio() > 0.65
  28. # log hints tracking
  29. $scope.logHintsNegFeedbackValues = logHintsFeedback.feedbackOpts
  30. $scope.trackLogHintsLearnMore = () ->
  31. event_tracking.sendMB "logs-hints-learn-more"
  32. trackLogHintsFeedback = (isPositive, hintId) ->
  33. event_tracking.send "log-hints", (if isPositive then "feedback-positive" else "feedback-negative"), hintId
  34. event_tracking.sendMB (if isPositive then "log-hints-feedback-positive" else "log-hints-feedback-negative"), { hintId }
  35. $scope.trackLogHintsNegFeedbackDetails = (hintId, feedbackOpt, feedbackOtherVal) ->
  36. logHintsFeedback.submitFeedback hintId, feedbackOpt, feedbackOtherVal
  37. $scope.trackLogHintsPositiveFeedback = (hintId) -> trackLogHintsFeedback true, hintId
  38. $scope.trackLogHintsNegativeFeedback = (hintId) -> trackLogHintsFeedback false, hintId
  39. if ace.require("ace/lib/useragent").isMac
  40. $scope.modifierKey = "Cmd"
  41. else
  42. $scope.modifierKey = "Ctrl"
  43. # utility for making a query string from a hash, could use jquery $.param
  44. createQueryString = (args) ->
  45. qs_args = ("#{k}=#{v}" for k, v of args)
  46. if qs_args.length then "?" + qs_args.join("&") else ""
  47. $scope.stripHTMLFromString = (htmlStr) ->
  48. tmp = document.createElement("DIV")
  49. tmp.innerHTML = htmlStr
  50. return tmp.textContent || tmp.innerText || ""
  51. $scope.$on "project:joined", () ->
  52. return if !autoCompile
  53. autoCompile = false
  54. $scope.recompile(isAutoCompile: true)
  55. $scope.hasPremiumCompile = $scope.project.features.compileGroup == "priority"
  56. $scope.$on "pdf:error:display", () ->
  57. $scope.pdf.view = 'errors'
  58. $scope.pdf.renderingError = true
  59. # abort compile if syntax checks fail
  60. $scope.stop_on_validation_error = localStorage("stop_on_validation_error:#{$scope.project_id}")
  61. $scope.stop_on_validation_error ?= true # turn on for all users by default
  62. $scope.$watch "stop_on_validation_error", (new_value, old_value) ->
  63. if new_value? and old_value != new_value
  64. localStorage("stop_on_validation_error:#{$scope.project_id}", new_value)
  65. $scope.draft = localStorage("draft:#{$scope.project_id}") or false
  66. $scope.$watch "draft", (new_value, old_value) ->
  67. if new_value? and old_value != new_value
  68. localStorage("draft:#{$scope.project_id}", new_value)
  69. sendCompileRequest = (options = {}) ->
  70. url = "/project/#{$scope.project_id}/compile"
  71. params = {}
  72. if options.isAutoCompile
  73. params["auto_compile"]=true
  74. # if the previous run was a check, clear the error logs
  75. $scope.pdf.logEntries = [] if $scope.check
  76. # keep track of whether this is a compile or check
  77. $scope.check = if options.check then true else false
  78. event_tracking.sendMB "syntax-check-request" if options.check
  79. # send appropriate check type to clsi
  80. checkType = switch
  81. when $scope.check then "validate" # validate only
  82. when options.try then "silent" # allow use to try compile once
  83. when $scope.stop_on_validation_error then "error" # try to compile
  84. else "silent" # ignore errors
  85. return $http.post url, {
  86. rootDoc_id: options.rootDocOverride_id or null
  87. draft: $scope.draft
  88. check: checkType
  89. # use incremental compile for beta users but revert to a full
  90. # compile if there is a server error
  91. incrementalCompilesEnabled: window.user?.betaProgram and not $scope.pdf.error
  92. _csrf: window.csrfToken
  93. }, {params: params}
  94. parseCompileResponse = (response) ->
  95. # keep last url
  96. last_pdf_url = $scope.pdf.url
  97. # Reset everything
  98. $scope.pdf.error = false
  99. $scope.pdf.timedout = false
  100. $scope.pdf.failure = false
  101. $scope.pdf.url = null
  102. $scope.pdf.clsiMaintenance = false
  103. $scope.pdf.tooRecentlyCompiled = false
  104. $scope.pdf.renderingError = false
  105. $scope.pdf.projectTooLarge = false
  106. $scope.pdf.compileTerminated = false
  107. $scope.pdf.compileExited = false
  108. $scope.pdf.failedCheck = false
  109. # make a cache to look up files by name
  110. fileByPath = {}
  111. if response?.outputFiles?
  112. for file in response?.outputFiles
  113. fileByPath[file.path] = file
  114. # prepare query string
  115. qs = {}
  116. # add a query string parameter for the compile group
  117. if response.compileGroup?
  118. ide.compileGroup = qs.compileGroup = response.compileGroup
  119. # add a query string parameter for the clsi server id
  120. if response.clsiServerId?
  121. ide.clsiServerId = qs.clsiserverid = response.clsiServerId
  122. if response.status == "timedout"
  123. $scope.pdf.view = 'errors'
  124. $scope.pdf.timedout = true
  125. fetchLogs(fileByPath)
  126. else if response.status == "terminated"
  127. $scope.pdf.view = 'errors'
  128. $scope.pdf.compileTerminated = true
  129. fetchLogs(fileByPath)
  130. else if response.status in ["validation-fail", "validation-pass"]
  131. $scope.pdf.view = 'pdf'
  132. $scope.pdf.url = last_pdf_url
  133. $scope.shouldShowLogs = true
  134. $scope.pdf.failedCheck = true if response.status is "validation-fail"
  135. event_tracking.sendMB "syntax-check-#{response.status}"
  136. fetchLogs(fileByPath, { validation: true })
  137. else if response.status == "exited"
  138. $scope.pdf.view = 'pdf'
  139. $scope.pdf.compileExited = true
  140. $scope.pdf.url = last_pdf_url
  141. $scope.shouldShowLogs = true
  142. fetchLogs(fileByPath)
  143. else if response.status == "autocompile-backoff"
  144. $scope.pdf.view = 'uncompiled'
  145. else if response.status == "project-too-large"
  146. $scope.pdf.view = 'errors'
  147. $scope.pdf.projectTooLarge = true
  148. else if response.status == "failure"
  149. $scope.pdf.view = 'errors'
  150. $scope.pdf.failure = true
  151. $scope.shouldShowLogs = true
  152. fetchLogs(fileByPath)
  153. else if response.status == 'clsi-maintenance'
  154. $scope.pdf.view = 'errors'
  155. $scope.pdf.clsiMaintenance = true
  156. else if response.status == "too-recently-compiled"
  157. $scope.pdf.view = 'errors'
  158. $scope.pdf.tooRecentlyCompiled = true
  159. else if response.status == "validation-problems"
  160. $scope.pdf.view = "validation-problems"
  161. $scope.pdf.validation = response.validationProblems
  162. else if response.status == "success"
  163. $scope.pdf.view = 'pdf'
  164. $scope.shouldShowLogs = false
  165. # define the base url. if the pdf file has a build number, pass it to the clsi in the url
  166. if fileByPath['output.pdf']?.url?
  167. $scope.pdf.url = fileByPath['output.pdf'].url
  168. else if fileByPath['output.pdf']?.build?
  169. build = fileByPath['output.pdf'].build
  170. $scope.pdf.url = "/project/#{$scope.project_id}/build/#{build}/output/output.pdf"
  171. else
  172. $scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf"
  173. # check if we need to bust cache (build id is unique so don't need it in that case)
  174. if not fileByPath['output.pdf']?.build?
  175. qs.cache_bust = "#{Date.now()}"
  176. # convert the qs hash into a query string and append it
  177. $scope.pdf.url += createQueryString qs
  178. # Save all downloads as files
  179. qs.popupDownload = true
  180. $scope.pdf.downloadUrl = "/project/#{$scope.project_id}/output/output.pdf" + createQueryString(qs)
  181. fetchLogs(fileByPath)
  182. IGNORE_FILES = ["output.fls", "output.fdb_latexmk"]
  183. $scope.pdf.outputFiles = []
  184. if !response.outputFiles?
  185. return
  186. # prepare list of output files for download dropdown
  187. qs = {}
  188. if response.clsiServerId?
  189. qs.clsiserverid = response.clsiServerId
  190. for file in response.outputFiles
  191. if IGNORE_FILES.indexOf(file.path) == -1
  192. isOutputFile = file.path.match(/^output\./)
  193. $scope.pdf.outputFiles.push {
  194. # Turn 'output.blg' into 'blg file'.
  195. name: if isOutputFile then "#{file.path.replace(/^output\./, "")} file" else file.path
  196. url: "/project/#{project_id}/output/#{file.path}" + createQueryString qs
  197. main: if isOutputFile then true else false
  198. }
  199. # sort the output files into order, main files first, then others
  200. $scope.pdf.outputFiles.sort (a,b) -> (b.main - a.main) || a.name.localeCompare(b.name)
  201. fetchLogs = (fileByPath, options) ->
  202. if options?.validation
  203. chktexFile = fileByPath['output.chktex']
  204. else
  205. logFile = fileByPath['output.log']
  206. blgFile = fileByPath['output.blg']
  207. getFile = (name, file) ->
  208. opts =
  209. method:"GET"
  210. params:
  211. compileGroup:ide.compileGroup
  212. clsiserverid:ide.clsiServerId
  213. if file?.url? # FIXME clean this up when we have file.urls out consistently
  214. opts.url = file.url
  215. else if file?.build?
  216. opts.url = "/project/#{$scope.project_id}/build/#{file.build}/output/#{name}"
  217. else
  218. opts.url = "/project/#{$scope.project_id}/output/#{name}"
  219. # check if we need to bust cache (build id is unique so don't need it in that case)
  220. if not file?.build?
  221. opts.params.cache_bust = "#{Date.now()}"
  222. return $http(opts)
  223. # accumulate the log entries
  224. logEntries =
  225. all: []
  226. errors: []
  227. warnings: []
  228. accumulateResults = (newEntries) ->
  229. for key in ['all', 'errors', 'warnings']
  230. if newEntries.type?
  231. entry.type = newEntries.type for entry in newEntries[key]
  232. logEntries[key] = logEntries[key].concat newEntries[key]
  233. # use the parsers for each file type
  234. processLog = (log) ->
  235. $scope.pdf.rawLog = log
  236. {errors, warnings, typesetting} = HumanReadableLogs.parse(log, ignoreDuplicates: true)
  237. all = [].concat errors, warnings, typesetting
  238. accumulateResults {all, errors, warnings}
  239. processChkTex = (log) ->
  240. errors = []
  241. warnings = []
  242. for line in log.split("\n")
  243. if m = line.match /^(\S+):(\d+):(\d+): (Error|Warning): (.*)/
  244. result = { file:m[1], line:m[2], column:m[3], level:m[4].toLowerCase(), message: "#{m[4]}: #{m[5]}"}
  245. if result.level is 'error'
  246. errors.push result
  247. else
  248. warnings.push result
  249. all = [].concat errors, warnings
  250. logHints = HumanReadableLogs.parse {type: "Syntax", all, errors, warnings}
  251. event_tracking.sendMB "syntax-check-return-count", {errors:errors.length, warnings:warnings.length}
  252. accumulateResults logHints
  253. processBiber = (log) ->
  254. {errors, warnings} = BibLogParser.parse(log, {})
  255. all = [].concat errors, warnings
  256. accumulateResults {type: "BibTeX", all, errors, warnings}
  257. # output the results
  258. handleError = () ->
  259. $scope.pdf.logEntries = []
  260. $scope.pdf.rawLog = ""
  261. annotateFiles = () ->
  262. $scope.pdf.logEntries = logEntries
  263. $scope.pdf.logEntryAnnotations = {}
  264. for entry in logEntries.all
  265. if entry.file?
  266. entry.file = normalizeFilePath(entry.file)
  267. entity = ide.fileTreeManager.findEntityByPath(entry.file)
  268. if entity?
  269. $scope.pdf.logEntryAnnotations[entity.id] ||= []
  270. $scope.pdf.logEntryAnnotations[entity.id].push {
  271. row: entry.line - 1
  272. type: if entry.level == "error" then "error" else "warning"
  273. text: entry.message
  274. }
  275. # retrieve the logfile and process it
  276. if logFile?
  277. response = getFile('output.log', logFile)
  278. .then (response) -> processLog(response.data)
  279. if blgFile? # retrieve the blg file if present
  280. response = response.then () ->
  281. getFile('output.blg', blgFile)
  282. .then(
  283. (response) -> processBiber(response.data),
  284. () -> true # ignore errors in biber file
  285. )
  286. if response?
  287. response.catch handleError
  288. else
  289. handleError()
  290. if chktexFile?
  291. getChkTex = () ->
  292. getFile('output.chktex', chktexFile)
  293. .then (response) -> processChkTex(response.data)
  294. # always retrieve the chktex file if present
  295. if response?
  296. response = response.then getChkTex, getChkTex
  297. else
  298. response = getChkTex()
  299. # display the combined result
  300. if response?
  301. response.finally annotateFiles
  302. getRootDocOverride_id = () ->
  303. doc = ide.editorManager.getCurrentDocValue()
  304. return null if !doc?
  305. for line in doc.split("\n")
  306. match = line.match /^[^%]*\\documentclass/
  307. if match
  308. return ide.editorManager.getCurrentDocId()
  309. return null
  310. normalizeFilePath = (path) ->
  311. path = path.replace(/^(.*)\/compiles\/[0-9a-f]{24}(-[0-9a-f]{24})?\/(\.\/)?/, "")
  312. path = path.replace(/^\/compile\//, "")
  313. rootDocDirname = ide.fileTreeManager.getRootDocDirname()
  314. if rootDocDirname?
  315. path = path.replace(/^\.\//, rootDocDirname + "/")
  316. return path
  317. $scope.recompile = (options = {}) ->
  318. return if $scope.pdf.compiling
  319. event_tracking.sendMBSampled "editor-recompile-sampled", options
  320. $scope.pdf.compiling = true
  321. if options?.force
  322. # for forced compile, turn off validation check and ignore errors
  323. $scope.stop_on_validation_error = false
  324. $scope.shouldShowLogs = false # hide the logs while compiling
  325. event_tracking.sendMB "syntax-check-turn-off-checking"
  326. if options?.try
  327. $scope.shouldShowLogs = false # hide the logs while compiling
  328. event_tracking.sendMB "syntax-check-try-compile-anyway"
  329. ide.$scope.$broadcast("flush-changes")
  330. options.rootDocOverride_id = getRootDocOverride_id()
  331. sendCompileRequest(options)
  332. .then (response) ->
  333. { data } = response
  334. $scope.pdf.view = "pdf"
  335. $scope.pdf.compiling = false
  336. parseCompileResponse(data)
  337. .catch (response) ->
  338. { data, status } = response
  339. if status == 429
  340. $scope.pdf.rateLimited = true
  341. $scope.pdf.compiling = false
  342. $scope.pdf.renderingError = false
  343. $scope.pdf.error = true
  344. $scope.pdf.view = 'errors'
  345. # This needs to be public.
  346. ide.$scope.recompile = $scope.recompile
  347. # This method is a simply wrapper and exists only for tracking purposes.
  348. ide.$scope.recompileViaKey = () ->
  349. $scope.recompile { keyShortcut: true }
  350. $scope.stop = () ->
  351. return if !$scope.pdf.compiling
  352. $http {
  353. url: "/project/#{$scope.project_id}/compile/stop"
  354. method: "POST"
  355. params:
  356. clsiserverid:ide.clsiServerId
  357. headers:
  358. "X-Csrf-Token": window.csrfToken
  359. }
  360. $scope.clearCache = () ->
  361. $http {
  362. url: "/project/#{$scope.project_id}/output"
  363. method: "DELETE"
  364. params:
  365. clsiserverid:ide.clsiServerId
  366. headers:
  367. "X-Csrf-Token": window.csrfToken
  368. }
  369. $scope.toggleLogs = () ->
  370. $scope.shouldShowLogs = !$scope.shouldShowLogs
  371. event_tracking.sendMBOnce "ide-open-logs-once" if $scope.shouldShowLogs
  372. $scope.showPdf = () ->
  373. $scope.pdf.view = "pdf"
  374. $scope.shouldShowLogs = false
  375. $scope.toggleRawLog = () ->
  376. $scope.pdf.showRawLog = !$scope.pdf.showRawLog
  377. event_tracking.sendMB "logs-view-raw" if $scope.pdf.showRawLog
  378. $scope.openClearCacheModal = () ->
  379. modalInstance = $modal.open(
  380. templateUrl: "clearCacheModalTemplate"
  381. controller: "ClearCacheModalController"
  382. scope: $scope
  383. )
  384. $scope.syncToCode = (position) ->
  385. synctex
  386. .syncToCode(position)
  387. .then (data) ->
  388. {doc, line} = data
  389. ide.editorManager.openDoc(doc, gotoLine: line)
  390. $scope.switchToFlatLayout = () ->
  391. $scope.ui.pdfLayout = 'flat'
  392. $scope.ui.view = 'pdf'
  393. ide.localStorage "pdf.layout", "flat"
  394. $scope.switchToSideBySideLayout = () ->
  395. $scope.ui.pdfLayout = 'sideBySide'
  396. $scope.ui.view = 'editor'
  397. localStorage "pdf.layout", "split"
  398. if pdfLayout = localStorage("pdf.layout")
  399. $scope.switchToSideBySideLayout() if pdfLayout == "split"
  400. $scope.switchToFlatLayout() if pdfLayout == "flat"
  401. else
  402. $scope.switchToSideBySideLayout()
  403. $scope.startFreeTrial = (source) ->
  404. ga?('send', 'event', 'subscription-funnel', 'compile-timeout', source)
  405. event_tracking.sendMB "subscription-start-trial", { source }
  406. window.open("/user/subscription/new?planCode=#{$scope.startTrialPlanCode}")
  407. $scope.startedFreeTrial = true
  408. App.factory "synctex", ["ide", "$http", "$q", (ide, $http, $q) ->
  409. # enable per-user containers by default
  410. perUserCompile = true
  411. synctex =
  412. syncToPdf: (cursorPosition) ->
  413. deferred = $q.defer()
  414. doc_id = ide.editorManager.getCurrentDocId()
  415. if !doc_id?
  416. deferred.reject()
  417. return deferred.promise
  418. doc = ide.fileTreeManager.findEntityById(doc_id)
  419. if !doc?
  420. deferred.reject()
  421. return deferred.promise
  422. path = ide.fileTreeManager.getEntityPath(doc)
  423. if !path?
  424. deferred.reject()
  425. return deferred.promise
  426. # If the root file is folder/main.tex, then synctex sees the
  427. # path as folder/./main.tex
  428. rootDocDirname = ide.fileTreeManager.getRootDocDirname()
  429. if rootDocDirname? and rootDocDirname != ""
  430. path = path.replace(RegExp("^#{rootDocDirname}"), "#{rootDocDirname}/.")
  431. {row, column} = cursorPosition
  432. $http({
  433. url: "/project/#{ide.project_id}/sync/code",
  434. method: "GET",
  435. params: {
  436. file: path
  437. line: row + 1
  438. column: column
  439. clsiserverid:ide.clsiServerId
  440. }
  441. })
  442. .then (response) ->
  443. { data } = response
  444. deferred.resolve(data.pdf or [])
  445. .catch (response) ->
  446. error = response.data
  447. deferred.reject(error)
  448. return deferred.promise
  449. syncToCode: (position, options = {}) ->
  450. deferred = $q.defer()
  451. if !position?
  452. deferred.reject()
  453. return deferred.promise
  454. # FIXME: this actually works better if it's halfway across the
  455. # page (or the visible part of the page). Synctex doesn't
  456. # always find the right place in the file when the point is at
  457. # the edge of the page, it sometimes returns the start of the
  458. # next paragraph instead.
  459. h = position.offset.left
  460. # Compute the vertical position to pass to synctex, which
  461. # works with coordinates increasing from the top of the page
  462. # down. This matches the browser's DOM coordinate of the
  463. # click point, but the pdf position is measured from the
  464. # bottom of the page so we need to invert it.
  465. if options.fromPdfPosition and position.pageSize?.height?
  466. v = (position.pageSize.height - position.offset.top) or 0 # measure from pdf point (inverted)
  467. else
  468. v = position.offset.top or 0 # measure from html click position
  469. # It's not clear exactly where we should sync to if it wasn't directly
  470. # clicked on, but a little bit down from the very top seems best.
  471. if options.includeVisualOffset
  472. v += 72 # use the same value as in pdfViewer highlighting visual offset
  473. $http({
  474. url: "/project/#{ide.project_id}/sync/pdf",
  475. method: "GET",
  476. params: {
  477. page: position.page + 1
  478. h: h.toFixed(2)
  479. v: v.toFixed(2)
  480. clsiserverid:ide.clsiServerId
  481. }
  482. })
  483. .then (response) ->
  484. { data } = response
  485. if data.code? and data.code.length > 0
  486. doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
  487. return if !doc?
  488. deferred.resolve({doc: doc, line: data.code[0].line})
  489. .catch (response) ->
  490. error = response.data
  491. deferred.reject(error)
  492. return deferred.promise
  493. return synctex
  494. ]
  495. App.controller "PdfSynctexController", ["$scope", "synctex", "ide", ($scope, synctex, ide) ->
  496. @cursorPosition = null
  497. ide.$scope.$on "cursor:editor:update", (event, @cursorPosition) =>
  498. $scope.syncToPdf = () =>
  499. return if !@cursorPosition?
  500. synctex
  501. .syncToPdf(@cursorPosition)
  502. .then (highlights) ->
  503. $scope.pdf.highlights = highlights
  504. $scope.syncToCode = () ->
  505. synctex
  506. .syncToCode($scope.pdf.position, includeVisualOffset: true, fromPdfPosition: true)
  507. .then (data) ->
  508. {doc, line} = data
  509. ide.editorManager.openDoc(doc, gotoLine: line)
  510. ]
  511. App.controller "PdfLogEntryController", ["$scope", "ide", "event_tracking", ($scope, ide, event_tracking) ->
  512. $scope.openInEditor = (entry) ->
  513. event_tracking.sendMBOnce "logs-jump-to-location-once"
  514. entity = ide.fileTreeManager.findEntityByPath(entry.file)
  515. return if !entity? or entity.type != "doc"
  516. if entry.line?
  517. line = entry.line
  518. if entry.column?
  519. column = entry.column
  520. ide.editorManager.openDoc(entity, gotoLine: line, gotoColumn: column)
  521. ]
  522. App.controller 'ClearCacheModalController', ["$scope", "$modalInstance", ($scope, $modalInstance) ->
  523. $scope.state =
  524. inflight: false
  525. $scope.clear = () ->
  526. $scope.state.inflight = true
  527. $scope
  528. .clearCache()
  529. .then () ->
  530. $scope.state.inflight = false
  531. $modalInstance.close()
  532. $scope.cancel = () ->
  533. $modalInstance.dismiss('cancel')
  534. ]