PdfController.coffee 21 KB

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