PdfController.coffee 20 KB

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