PdfController.coffee 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. response.finally annotateFiles
  298. getRootDocOverride_id = () ->
  299. doc = ide.editorManager.getCurrentDocValue()
  300. return null if !doc?
  301. for line in doc.split("\n")
  302. match = line.match /^[^%]*\\documentclass/
  303. if match
  304. return ide.editorManager.getCurrentDocId()
  305. return null
  306. normalizeFilePath = (path) ->
  307. path = path.replace(/^(.*)\/compiles\/[0-9a-f]{24}(-[0-9a-f]{24})?\/(\.\/)?/, "")
  308. path = path.replace(/^\/compile\//, "")
  309. rootDocDirname = ide.fileTreeManager.getRootDocDirname()
  310. if rootDocDirname?
  311. path = path.replace(/^\.\//, rootDocDirname + "/")
  312. return path
  313. $scope.recompile = (options = {}) ->
  314. return if $scope.pdf.compiling
  315. event_tracking.sendMBSampled "editor-recompile-sampled", options
  316. $scope.pdf.compiling = true
  317. if options?.force
  318. # for forced compile, turn off validation check and ignore errors
  319. $scope.stop_on_validation_error = false
  320. $scope.shouldShowLogs = false # hide the logs while compiling
  321. event_tracking.sendMB "syntax-check-turn-off-checking"
  322. if options?.try
  323. $scope.shouldShowLogs = false # hide the logs while compiling
  324. event_tracking.sendMB "syntax-check-try-compile-anyway"
  325. ide.$scope.$broadcast("flush-changes")
  326. options.rootDocOverride_id = getRootDocOverride_id()
  327. sendCompileRequest(options)
  328. .success (data) ->
  329. $scope.pdf.view = "pdf"
  330. $scope.pdf.compiling = false
  331. parseCompileResponse(data)
  332. .error () ->
  333. $scope.pdf.compiling = false
  334. $scope.pdf.renderingError = false
  335. $scope.pdf.error = true
  336. $scope.pdf.view = 'errors'
  337. # This needs to be public.
  338. ide.$scope.recompile = $scope.recompile
  339. # This method is a simply wrapper and exists only for tracking purposes.
  340. ide.$scope.recompileViaKey = () ->
  341. $scope.recompile { keyShortcut: true }
  342. $scope.stop = () ->
  343. return if !$scope.pdf.compiling
  344. $http {
  345. url: "/project/#{$scope.project_id}/compile/stop"
  346. method: "POST"
  347. params:
  348. clsiserverid:ide.clsiServerId
  349. headers:
  350. "X-Csrf-Token": window.csrfToken
  351. }
  352. $scope.clearCache = () ->
  353. $http {
  354. url: "/project/#{$scope.project_id}/output"
  355. method: "DELETE"
  356. params:
  357. clsiserverid:ide.clsiServerId
  358. headers:
  359. "X-Csrf-Token": window.csrfToken
  360. }
  361. $scope.toggleLogs = () ->
  362. $scope.shouldShowLogs = !$scope.shouldShowLogs
  363. event_tracking.sendMBOnce "ide-open-logs-once" if $scope.shouldShowLogs
  364. $scope.showPdf = () ->
  365. $scope.pdf.view = "pdf"
  366. $scope.shouldShowLogs = false
  367. $scope.toggleRawLog = () ->
  368. $scope.pdf.showRawLog = !$scope.pdf.showRawLog
  369. event_tracking.sendMB "logs-view-raw" if $scope.pdf.showRawLog
  370. $scope.openClearCacheModal = () ->
  371. modalInstance = $modal.open(
  372. templateUrl: "clearCacheModalTemplate"
  373. controller: "ClearCacheModalController"
  374. scope: $scope
  375. )
  376. $scope.syncToCode = (position) ->
  377. synctex
  378. .syncToCode(position)
  379. .then (data) ->
  380. {doc, line} = data
  381. ide.editorManager.openDoc(doc, gotoLine: line)
  382. $scope.switchToFlatLayout = () ->
  383. $scope.ui.pdfLayout = 'flat'
  384. $scope.ui.view = 'pdf'
  385. ide.localStorage "pdf.layout", "flat"
  386. $scope.switchToSideBySideLayout = () ->
  387. $scope.ui.pdfLayout = 'sideBySide'
  388. $scope.ui.view = 'editor'
  389. localStorage "pdf.layout", "split"
  390. if pdfLayout = localStorage("pdf.layout")
  391. $scope.switchToSideBySideLayout() if pdfLayout == "split"
  392. $scope.switchToFlatLayout() if pdfLayout == "flat"
  393. else
  394. $scope.switchToSideBySideLayout()
  395. $scope.startFreeTrial = (source) ->
  396. ga?('send', 'event', 'subscription-funnel', 'compile-timeout', source)
  397. event_tracking.sendMB "subscription-start-trial", { source }
  398. window.open("/user/subscription/new?planCode=#{$scope.startTrialPlanCode}")
  399. $scope.startedFreeTrial = true
  400. App.factory "synctex", ["ide", "$http", "$q", (ide, $http, $q) ->
  401. # enable per-user containers by default
  402. perUserCompile = true
  403. synctex =
  404. syncToPdf: (cursorPosition) ->
  405. deferred = $q.defer()
  406. doc_id = ide.editorManager.getCurrentDocId()
  407. if !doc_id?
  408. deferred.reject()
  409. return deferred.promise
  410. doc = ide.fileTreeManager.findEntityById(doc_id)
  411. if !doc?
  412. deferred.reject()
  413. return deferred.promise
  414. path = ide.fileTreeManager.getEntityPath(doc)
  415. if !path?
  416. deferred.reject()
  417. return deferred.promise
  418. # If the root file is folder/main.tex, then synctex sees the
  419. # path as folder/./main.tex
  420. rootDocDirname = ide.fileTreeManager.getRootDocDirname()
  421. if rootDocDirname? and rootDocDirname != ""
  422. path = path.replace(RegExp("^#{rootDocDirname}"), "#{rootDocDirname}/.")
  423. {row, column} = cursorPosition
  424. $http({
  425. url: "/project/#{ide.project_id}/sync/code",
  426. method: "GET",
  427. params: {
  428. file: path
  429. line: row + 1
  430. column: column
  431. clsiserverid:ide.clsiServerId
  432. }
  433. })
  434. .success (data) ->
  435. deferred.resolve(data.pdf or [])
  436. .error (error) ->
  437. deferred.reject(error)
  438. return deferred.promise
  439. syncToCode: (position, options = {}) ->
  440. deferred = $q.defer()
  441. if !position?
  442. deferred.reject()
  443. return deferred.promise
  444. # FIXME: this actually works better if it's halfway across the
  445. # page (or the visible part of the page). Synctex doesn't
  446. # always find the right place in the file when the point is at
  447. # the edge of the page, it sometimes returns the start of the
  448. # next paragraph instead.
  449. h = position.offset.left
  450. # Compute the vertical position to pass to synctex, which
  451. # works with coordinates increasing from the top of the page
  452. # down. This matches the browser's DOM coordinate of the
  453. # click point, but the pdf position is measured from the
  454. # bottom of the page so we need to invert it.
  455. if options.fromPdfPosition and position.pageSize?.height?
  456. v = (position.pageSize.height - position.offset.top) or 0 # measure from pdf point (inverted)
  457. else
  458. v = position.offset.top or 0 # measure from html click position
  459. # It's not clear exactly where we should sync to if it wasn't directly
  460. # clicked on, but a little bit down from the very top seems best.
  461. if options.includeVisualOffset
  462. v += 72 # use the same value as in pdfViewer highlighting visual offset
  463. $http({
  464. url: "/project/#{ide.project_id}/sync/pdf",
  465. method: "GET",
  466. params: {
  467. page: position.page + 1
  468. h: h.toFixed(2)
  469. v: v.toFixed(2)
  470. clsiserverid:ide.clsiServerId
  471. }
  472. })
  473. .success (data) ->
  474. if data.code? and data.code.length > 0
  475. doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
  476. return if !doc?
  477. deferred.resolve({doc: doc, line: data.code[0].line})
  478. .error (error) ->
  479. deferred.reject(error)
  480. return deferred.promise
  481. return synctex
  482. ]
  483. App.controller "PdfSynctexController", ["$scope", "synctex", "ide", ($scope, synctex, ide) ->
  484. @cursorPosition = null
  485. ide.$scope.$on "cursor:editor:update", (event, @cursorPosition) =>
  486. $scope.syncToPdf = () =>
  487. return if !@cursorPosition?
  488. synctex
  489. .syncToPdf(@cursorPosition)
  490. .then (highlights) ->
  491. $scope.pdf.highlights = highlights
  492. $scope.syncToCode = () ->
  493. synctex
  494. .syncToCode($scope.pdf.position, includeVisualOffset: true, fromPdfPosition: true)
  495. .then (data) ->
  496. {doc, line} = data
  497. ide.editorManager.openDoc(doc, gotoLine: line)
  498. ]
  499. App.controller "PdfLogEntryController", ["$scope", "ide", "event_tracking", ($scope, ide, event_tracking) ->
  500. $scope.openInEditor = (entry) ->
  501. event_tracking.sendMBOnce "logs-jump-to-location-once"
  502. entity = ide.fileTreeManager.findEntityByPath(entry.file)
  503. return if !entity? or entity.type != "doc"
  504. if entry.line?
  505. line = entry.line
  506. if entry.column?
  507. column = entry.column
  508. ide.editorManager.openDoc(entity, gotoLine: line, gotoColumn: column)
  509. ]
  510. App.controller 'ClearCacheModalController', ["$scope", "$modalInstance", ($scope, $modalInstance) ->
  511. $scope.state =
  512. inflight: false
  513. $scope.clear = () ->
  514. $scope.state.inflight = true
  515. $scope
  516. .clearCache()
  517. .then () ->
  518. $scope.state.inflight = false
  519. $modalInstance.close()
  520. $scope.cancel = () ->
  521. $modalInstance.dismiss('cancel')
  522. ]