2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
import HumanReadableLogs from '../../human-readable-logs/HumanReadableLogs'
|
|
|
|
import BibLogParser from 'libs/bib-log-parser'
|
2020-09-28 06:51:15 -04:00
|
|
|
import PreviewPane from '../../../features/preview/components/preview-pane'
|
|
|
|
import { react2angular } from 'react2angular'
|
2021-01-14 10:16:54 -05:00
|
|
|
import { rootContext } from '../../../shared/context/root-context'
|
2020-05-19 05:02:56 -04:00
|
|
|
import 'ace/ace'
|
2021-02-17 08:52:32 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const AUTO_COMPILE_MAX_WAIT = 5000
|
|
|
|
// We add a 1 second debounce to sending user changes to server if they aren't
|
|
|
|
// collaborating with anyone. This needs to be higher than that, and allow for
|
|
|
|
// client to server latency, otherwise we compile before the op reaches the server
|
|
|
|
// and then again on ack.
|
|
|
|
const AUTO_COMPILE_DEBOUNCE = 2000
|
|
|
|
|
|
|
|
App.filter('trusted', $sce => url => $sce.trustAsResourceUrl(url))
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'PdfController',
|
|
|
|
function (
|
|
|
|
$scope,
|
|
|
|
$http,
|
|
|
|
ide,
|
|
|
|
$modal,
|
|
|
|
synctex,
|
|
|
|
eventTracking,
|
|
|
|
localStorage,
|
|
|
|
$q
|
|
|
|
) {
|
|
|
|
let autoCompile = true
|
|
|
|
|
|
|
|
// pdf.view = uncompiled | pdf | errors
|
|
|
|
$scope.pdf.view = $scope.pdf.url ? 'pdf' : 'uncompiled'
|
|
|
|
$scope.pdf.clearingCache = false
|
|
|
|
$scope.shouldShowLogs = false
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.logsUISubvariant = window.logsUISubvariant
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// view logic to check whether the files dropdown should "drop up" or "drop down"
|
|
|
|
$scope.shouldDropUp = false
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// Exposed methods for React layout handling
|
|
|
|
$scope.setPdfSplitLayout = function () {
|
|
|
|
$scope.$applyAsync(() => $scope.switchToSideBySideLayout('editor'))
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.setPdfFullLayout = function () {
|
|
|
|
$scope.$applyAsync(() => $scope.switchToFlatLayout('pdf'))
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const logsContainerEl = document.querySelector('.pdf-logs')
|
|
|
|
const filesDropdownEl =
|
|
|
|
logsContainerEl && logsContainerEl.querySelector('.files-dropdown')
|
|
|
|
|
|
|
|
// get the top coordinate of the files dropdown as a ratio (to the logs container height)
|
|
|
|
// logs container supports scrollable content, so it's possible that ratio > 1.
|
|
|
|
function getFilesDropdownTopCoordAsRatio() {
|
|
|
|
if (filesDropdownEl == null || logsContainerEl == null) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
filesDropdownEl.getBoundingClientRect().top /
|
|
|
|
logsContainerEl.getBoundingClientRect().height
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$watch('shouldShowLogs', shouldShow => {
|
|
|
|
if (shouldShow) {
|
|
|
|
$scope.$applyAsync(() => {
|
|
|
|
$scope.shouldDropUp = getFilesDropdownTopCoordAsRatio() > 0.65
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.trackLogHintsLearnMore = function () {
|
|
|
|
eventTracking.sendMB('logs-hints-learn-more')
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (ace.require('ace/lib/useragent').isMac) {
|
|
|
|
$scope.modifierKey = 'Cmd'
|
|
|
|
} else {
|
|
|
|
$scope.modifierKey = 'Ctrl'
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
|
|
|
|
// utility for making a query string from a hash, could use jquery $.param
|
|
|
|
function createQueryString(args) {
|
|
|
|
const qsArgs = []
|
|
|
|
for (const k in args) {
|
|
|
|
const v = args[k]
|
|
|
|
qsArgs.push(`${k}=${v}`)
|
|
|
|
}
|
|
|
|
if (qsArgs.length) {
|
|
|
|
return `?${qsArgs.join('&')}`
|
|
|
|
} else {
|
|
|
|
return ''
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$on('project:joined', () => {
|
|
|
|
if (!autoCompile) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
autoCompile = false
|
|
|
|
$scope.recompile({ isAutoCompileOnLoad: true })
|
|
|
|
$scope.hasPremiumCompile =
|
|
|
|
$scope.project.features.compileGroup === 'priority'
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$on('pdf:error:display', function () {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.renderingError = true
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
let autoCompileInterval = null
|
|
|
|
function autoCompileIfReady() {
|
|
|
|
if (
|
|
|
|
$scope.pdf.compiling ||
|
|
|
|
!$scope.autocompile_enabled ||
|
|
|
|
!$scope.pdf.uncompiled
|
|
|
|
) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// Only checking linting if syntaxValidation is on and visible to the user
|
|
|
|
const autoCompileLintingError =
|
|
|
|
ide.$scope.hasLintingError && ide.$scope.settings.syntaxValidation
|
|
|
|
if ($scope.autoCompileLintingError !== autoCompileLintingError) {
|
|
|
|
$scope.$apply(() => {
|
|
|
|
$scope.autoCompileLintingError = autoCompileLintingError
|
|
|
|
// We've likely been waiting a while until the user fixed the linting, but we
|
|
|
|
// don't want to compile as soon as it is fixed, so reset the timeout.
|
|
|
|
$scope.startedTryingAutoCompileAt = Date.now()
|
|
|
|
$scope.docLastChangedAt = Date.now()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (autoCompileLintingError && $scope.stop_on_validation_error) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// If there's a longish compile, don't compile immediately after if user is still typing
|
|
|
|
const startedTryingAt = Math.max(
|
|
|
|
$scope.startedTryingAutoCompileAt,
|
|
|
|
$scope.lastFinishedCompileAt || 0
|
|
|
|
)
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const timeSinceStartedTrying = Date.now() - startedTryingAt
|
|
|
|
const timeSinceLastChange = Date.now() - $scope.docLastChangedAt
|
|
|
|
|
|
|
|
let shouldCompile = false
|
|
|
|
if (timeSinceLastChange > AUTO_COMPILE_DEBOUNCE) {
|
|
|
|
// Don't compile in the middle of the user typing
|
|
|
|
shouldCompile = true
|
|
|
|
} else if (timeSinceStartedTrying > AUTO_COMPILE_MAX_WAIT) {
|
|
|
|
// Unless they type for a long time
|
|
|
|
shouldCompile = true
|
|
|
|
} else if (timeSinceStartedTrying < 0 || timeSinceLastChange < 0) {
|
|
|
|
// If time is non-monotonic, assume that the user's system clock has been
|
|
|
|
// changed and continue with compile
|
|
|
|
shouldCompile = true
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (shouldCompile) {
|
|
|
|
return triggerAutoCompile()
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function triggerAutoCompile() {
|
|
|
|
$scope.recompile({ isAutoCompileOnChange: true })
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function startTryingAutoCompile() {
|
|
|
|
if (autoCompileInterval != null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
$scope.startedTryingAutoCompileAt = Date.now()
|
|
|
|
autoCompileInterval = setInterval(autoCompileIfReady, 200)
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function stopTryingAutoCompile() {
|
|
|
|
clearInterval(autoCompileInterval)
|
|
|
|
autoCompileInterval = null
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.changesToAutoCompile = false
|
|
|
|
$scope.$watch('pdf.uncompiled', uncompiledChanges => {
|
|
|
|
// don't autocompile if disabled or the pdf is not visible
|
|
|
|
if (
|
|
|
|
$scope.pdf.uncompiled &&
|
|
|
|
$scope.autocompile_enabled &&
|
|
|
|
!$scope.ui.pdfHidden
|
|
|
|
) {
|
|
|
|
$scope.changesToAutoCompile = true
|
|
|
|
startTryingAutoCompile()
|
|
|
|
} else {
|
|
|
|
$scope.changesToAutoCompile = false
|
|
|
|
stopTryingAutoCompile()
|
|
|
|
}
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function recalculateUncompiledChanges() {
|
|
|
|
if ($scope.docLastChangedAt == null) {
|
|
|
|
$scope.pdf.uncompiled = false
|
|
|
|
} else if (
|
|
|
|
$scope.lastStartedCompileAt == null ||
|
|
|
|
$scope.docLastChangedAt > $scope.lastStartedCompileAt
|
|
|
|
) {
|
|
|
|
$scope.pdf.uncompiled = true
|
|
|
|
} else {
|
|
|
|
$scope.pdf.uncompiled = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function _updateDocLastChangedAt() {
|
|
|
|
$scope.docLastChangedAt = Date.now()
|
|
|
|
recalculateUncompiledChanges()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function onDocChanged() {
|
|
|
|
_updateDocLastChangedAt()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function onDocSaved() {
|
|
|
|
// We use the save as a trigger too, to account for the delay between the client
|
|
|
|
// and server. Otherwise, we might have compiled after the user made
|
|
|
|
// the change on the client, but before the server had it.
|
|
|
|
_updateDocLastChangedAt()
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function onCompilingStateChanged(compiling) {
|
|
|
|
recalculateUncompiledChanges()
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
ide.$scope.$on('doc:changed', onDocChanged)
|
|
|
|
ide.$scope.$on('doc:saved', onDocSaved)
|
|
|
|
$scope.$watch('pdf.compiling', onCompilingStateChanged)
|
|
|
|
|
|
|
|
$scope.autocompile_enabled =
|
|
|
|
localStorage(`autocompile_enabled:${$scope.project_id}`) || false
|
|
|
|
$scope.$watch('autocompile_enabled', (newValue, oldValue) => {
|
|
|
|
if (newValue != null && oldValue !== newValue) {
|
|
|
|
if (newValue === true) {
|
|
|
|
$scope.autoCompileLintingError = false
|
|
|
|
autoCompileIfReady()
|
|
|
|
}
|
|
|
|
localStorage(`autocompile_enabled:${$scope.project_id}`, newValue)
|
|
|
|
eventTracking.sendMB('autocompile-setting-changed', {
|
2021-04-27 03:52:58 -04:00
|
|
|
value: newValue,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// abort compile if syntax checks fail
|
|
|
|
$scope.stop_on_validation_error = localStorage(
|
|
|
|
`stop_on_validation_error:${$scope.project_id}`
|
|
|
|
)
|
|
|
|
if ($scope.stop_on_validation_error == null) {
|
|
|
|
$scope.stop_on_validation_error = true
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
// turn on for all users by default
|
|
|
|
$scope.$watch('stop_on_validation_error', (newValue, oldValue) => {
|
|
|
|
if (newValue != null && oldValue !== newValue) {
|
|
|
|
localStorage(`stop_on_validation_error:${$scope.project_id}`, newValue)
|
|
|
|
}
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.draft = localStorage(`draft:${$scope.project_id}`) || false
|
|
|
|
$scope.$watch('draft', (newValue, oldValue) => {
|
|
|
|
if (newValue != null && oldValue !== newValue) {
|
|
|
|
localStorage(`draft:${$scope.project_id}`, newValue)
|
|
|
|
}
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function sendCompileRequest(options) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {}
|
|
|
|
}
|
|
|
|
const url = `/project/${$scope.project_id}/compile`
|
|
|
|
const params = {}
|
|
|
|
if (options.isAutoCompileOnLoad || options.isAutoCompileOnChange) {
|
|
|
|
params.auto_compile = true
|
|
|
|
}
|
|
|
|
// if the previous run was a check, clear the error logs
|
|
|
|
if ($scope.check) {
|
|
|
|
$scope.pdf.logEntries = {}
|
|
|
|
}
|
|
|
|
// keep track of whether this is a compile or check
|
|
|
|
$scope.check = !!options.check
|
|
|
|
if (options.check) {
|
|
|
|
eventTracking.sendMB('syntax-check-request')
|
|
|
|
}
|
|
|
|
// send appropriate check type to clsi
|
|
|
|
let checkType
|
|
|
|
if ($scope.check) {
|
|
|
|
checkType = 'validate' // validate only
|
|
|
|
} else if (options.try) {
|
|
|
|
checkType = 'silent' // allow use to try compile once
|
|
|
|
} else if ($scope.stop_on_validation_error) {
|
|
|
|
checkType = 'error' // try to compile
|
|
|
|
} else {
|
|
|
|
checkType = 'silent' // ignore errors
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// FIXME: Temporarily disable syntax checking as it is causing
|
|
|
|
// excessive support requests for projects migrated from v1
|
|
|
|
// https://github.com/overleaf/sharelatex/issues/911
|
|
|
|
if (checkType === 'error') {
|
|
|
|
checkType = 'silent'
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return $http.post(
|
|
|
|
url,
|
|
|
|
{
|
|
|
|
rootDoc_id: options.rootDocOverride_id || null,
|
|
|
|
draft: $scope.draft,
|
|
|
|
check: checkType,
|
|
|
|
// use incremental compile for all users but revert to a full
|
|
|
|
// compile if there is a server error
|
|
|
|
incrementalCompilesEnabled: !$scope.pdf.error,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2021-04-14 09:17:21 -04:00
|
|
|
},
|
|
|
|
{ params }
|
|
|
|
)
|
2021-01-21 07:21:05 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function buildPdfDownloadUrl(pdfDownloadDomain, url) {
|
|
|
|
if (pdfDownloadDomain) {
|
|
|
|
return `${pdfDownloadDomain}${url}`
|
2019-10-28 10:05:23 -04:00
|
|
|
} else {
|
2021-04-14 09:17:21 -04:00
|
|
|
return url
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function parseCompileResponse(response) {
|
|
|
|
// keep last url
|
|
|
|
const lastPdfUrl = $scope.pdf.url
|
|
|
|
const { pdfDownloadDomain } = response
|
|
|
|
// Reset everything
|
|
|
|
$scope.pdf.error = false
|
|
|
|
$scope.pdf.timedout = false
|
|
|
|
$scope.pdf.failure = false
|
|
|
|
$scope.pdf.url = null
|
|
|
|
$scope.pdf.clsiMaintenance = false
|
|
|
|
$scope.pdf.tooRecentlyCompiled = false
|
|
|
|
$scope.pdf.renderingError = false
|
|
|
|
$scope.pdf.projectTooLarge = false
|
|
|
|
$scope.pdf.compileTerminated = false
|
|
|
|
$scope.pdf.compileExited = false
|
|
|
|
$scope.pdf.failedCheck = false
|
|
|
|
$scope.pdf.compileInProgress = false
|
|
|
|
$scope.pdf.autoCompileDisabled = false
|
|
|
|
if (window.showNewLogsUI) {
|
|
|
|
$scope.clsiErrors = {}
|
|
|
|
}
|
2020-11-26 04:58:42 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// make a cache to look up files by name
|
|
|
|
const fileByPath = {}
|
|
|
|
if (response.outputFiles != null) {
|
|
|
|
for (const file of response.outputFiles) {
|
|
|
|
fileByPath[file.path] = file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare query string
|
|
|
|
let qs = {}
|
|
|
|
// add a query string parameter for the compile group
|
|
|
|
if (response.compileGroup != null) {
|
|
|
|
ide.compileGroup = qs.compileGroup = response.compileGroup
|
|
|
|
}
|
|
|
|
// add a query string parameter for the clsi server id
|
|
|
|
if (response.clsiServerId != null) {
|
|
|
|
ide.clsiServerId = qs.clsiserverid = response.clsiServerId
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(das7pad): drop this hack once 2747f0d40af8729304 has landed in clsi
|
|
|
|
if (response.status === 'success' && !fileByPath['output.pdf']) {
|
|
|
|
response.status = 'failure'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.status === 'success') {
|
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.shouldShowLogs = false
|
|
|
|
$scope.pdf.lastCompileTimestamp = Date.now()
|
|
|
|
$scope.pdf.validation = {}
|
|
|
|
$scope.pdf.url = buildPdfDownloadUrl(
|
|
|
|
pdfDownloadDomain,
|
|
|
|
fileByPath['output.pdf'].url
|
|
|
|
)
|
|
|
|
// convert the qs hash into a query string and append it
|
|
|
|
$scope.pdf.url += createQueryString(qs)
|
|
|
|
|
|
|
|
// Save all downloads as files
|
|
|
|
qs.popupDownload = true
|
|
|
|
|
|
|
|
const { build: buildId } = fileByPath['output.pdf']
|
|
|
|
$scope.pdf.downloadUrl =
|
|
|
|
`/download/project/${$scope.project_id}/build/${buildId}/output/output.pdf` +
|
|
|
|
createQueryString(qs)
|
|
|
|
fetchLogs(fileByPath, { pdfDownloadDomain })
|
|
|
|
} else if (response.status === 'timedout') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.timedout = true
|
|
|
|
fetchLogs(fileByPath, { pdfDownloadDomain })
|
|
|
|
if (
|
|
|
|
!$scope.hasPremiumCompile &&
|
|
|
|
ide.$scope.project.owner._id === ide.$scope.user.id
|
|
|
|
) {
|
|
|
|
eventTracking.send(
|
|
|
|
'subscription-funnel',
|
|
|
|
'editor-click-feature',
|
|
|
|
'compile-timeout'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else if (response.status === 'terminated') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.compileTerminated = true
|
|
|
|
fetchLogs(fileByPath, { pdfDownloadDomain })
|
|
|
|
} else if (
|
|
|
|
['validation-fail', 'validation-pass'].includes(response.status)
|
2020-11-26 04:58:42 -05:00
|
|
|
) {
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.pdf.url = lastPdfUrl
|
2020-11-26 04:58:42 -05:00
|
|
|
$scope.shouldShowLogs = true
|
2021-04-14 09:17:21 -04:00
|
|
|
if (response.status === 'validation-fail') {
|
|
|
|
$scope.pdf.failedCheck = true
|
|
|
|
}
|
|
|
|
eventTracking.sendMB(`syntax-check-${response.status}`)
|
|
|
|
fetchLogs(fileByPath, { validation: true, pdfDownloadDomain })
|
|
|
|
} else if (response.status === 'exited') {
|
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.pdf.compileExited = true
|
|
|
|
$scope.pdf.url = lastPdfUrl
|
|
|
|
$scope.shouldShowLogs = true
|
|
|
|
fetchLogs(fileByPath, { pdfDownloadDomain })
|
|
|
|
} else if (response.status === 'autocompile-backoff') {
|
|
|
|
if ($scope.pdf.isAutoCompileOnLoad) {
|
|
|
|
// initial autocompile
|
|
|
|
$scope.pdf.view = 'uncompiled'
|
|
|
|
} else {
|
|
|
|
// background autocompile from typing
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.autoCompileDisabled = true
|
|
|
|
$scope.autocompile_enabled = false // disable any further autocompiles
|
|
|
|
eventTracking.sendMB('autocompile-rate-limited', {
|
2021-04-27 03:52:58 -04:00
|
|
|
hasPremiumCompile: $scope.hasPremiumCompile,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
} else if (response.status === 'project-too-large') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.projectTooLarge = true
|
|
|
|
} else if (response.status === 'failure') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.failure = true
|
|
|
|
$scope.shouldShowLogs = true
|
|
|
|
fetchLogs(fileByPath, { pdfDownloadDomain })
|
|
|
|
} else if (response.status === 'clsi-maintenance') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.clsiMaintenance = true
|
|
|
|
} else if (response.status === 'unavailable') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.clsiUnavailable = true
|
|
|
|
} else if (response.status === 'too-recently-compiled') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.tooRecentlyCompiled = true
|
|
|
|
} else if (response.status === 'validation-problems') {
|
|
|
|
$scope.pdf.view = 'validation-problems'
|
|
|
|
$scope.pdf.validation = response.validationProblems
|
|
|
|
$scope.shouldShowLogs = false
|
|
|
|
} else if (response.status === 'compile-in-progress') {
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.compileInProgress = true
|
|
|
|
} else {
|
|
|
|
// fall back to displaying an error
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
$scope.pdf.error = true
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (window.showNewLogsUI) {
|
|
|
|
$scope.pdf.compileFailed = false
|
|
|
|
// `$scope.clsiErrors` stores the error states nested within `$scope.pdf`
|
|
|
|
// for use with React's <PreviewPane errors={$scope.clsiErrors}/>
|
|
|
|
$scope.clsiErrors = Object.assign(
|
|
|
|
{},
|
|
|
|
$scope.pdf.error ? { error: true } : null,
|
|
|
|
$scope.pdf.renderingError ? { renderingError: true } : null,
|
|
|
|
$scope.pdf.clsiMaintenance ? { clsiMaintenance: true } : null,
|
|
|
|
$scope.pdf.clsiUnavailable ? { clsiUnavailable: true } : null,
|
|
|
|
$scope.pdf.tooRecentlyCompiled ? { tooRecentlyCompiled: true } : null,
|
|
|
|
$scope.pdf.compileTerminated ? { compileTerminated: true } : null,
|
|
|
|
$scope.pdf.rateLimited ? { rateLimited: true } : null,
|
|
|
|
$scope.pdf.compileInProgress ? { compileInProgress: true } : null,
|
|
|
|
$scope.pdf.timedout ? { timedout: true } : null,
|
|
|
|
$scope.pdf.autoCompileDisabled ? { autoCompileDisabled: true } : null
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (
|
|
|
|
$scope.pdf.view === 'errors' ||
|
|
|
|
$scope.pdf.view === 'validation-problems'
|
|
|
|
) {
|
|
|
|
$scope.shouldShowLogs = true
|
|
|
|
$scope.pdf.compileFailed = true
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const IGNORE_FILES = ['output.fls', 'output.fdb_latexmk']
|
|
|
|
$scope.pdf.outputFiles = []
|
|
|
|
|
|
|
|
if (response.outputFiles == null) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// prepare list of output files for download dropdown
|
|
|
|
qs = {}
|
|
|
|
if (response.clsiServerId != null) {
|
|
|
|
qs.clsiserverid = response.clsiServerId
|
|
|
|
}
|
|
|
|
for (const file of response.outputFiles) {
|
|
|
|
if (IGNORE_FILES.indexOf(file.path) === -1) {
|
|
|
|
const isOutputFile = /^output\./.test(file.path)
|
|
|
|
$scope.pdf.outputFiles.push({
|
|
|
|
// Turn 'output.blg' into 'blg file'.
|
|
|
|
name: isOutputFile
|
|
|
|
? `${file.path.replace(/^output\./, '')} file`
|
|
|
|
: file.path,
|
|
|
|
url: file.url + createQueryString(qs),
|
|
|
|
main: !!isOutputFile,
|
|
|
|
fileName: file.path,
|
2021-04-27 03:52:58 -04:00
|
|
|
type: file.type,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-11-16 05:01:01 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// sort the output files into order, main files first, then others
|
|
|
|
$scope.pdf.outputFiles.sort(
|
|
|
|
(a, b) => b.main - a.main || a.name.localeCompare(b.name)
|
|
|
|
)
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function fetchLogs(fileByPath, options) {
|
|
|
|
let blgFile, chktexFile, logFile
|
|
|
|
|
|
|
|
if (options != null ? options.validation : undefined) {
|
|
|
|
chktexFile = fileByPath['output.chktex']
|
|
|
|
} else {
|
|
|
|
logFile = fileByPath['output.log']
|
|
|
|
blgFile = fileByPath['output.blg']
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFile(name, file) {
|
|
|
|
const opts = {
|
|
|
|
method: 'GET',
|
|
|
|
url: buildPdfDownloadUrl(options.pdfDownloadDomain, file.url),
|
|
|
|
params: {
|
|
|
|
compileGroup: ide.compileGroup,
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiserverid: ide.clsiServerId,
|
|
|
|
},
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
return $http(opts)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// accumulate the log entries
|
|
|
|
const logEntries = {
|
|
|
|
all: [],
|
|
|
|
errors: [],
|
|
|
|
warnings: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
typesetting: [],
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function accumulateResults(newEntries) {
|
|
|
|
for (let key of ['all', 'errors', 'warnings', 'typesetting']) {
|
|
|
|
if (newEntries[key]) {
|
|
|
|
if (newEntries.type != null) {
|
|
|
|
for (let entry of newEntries[key]) {
|
|
|
|
entry.type = newEntries.type
|
|
|
|
}
|
2020-12-02 05:03:03 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
logEntries[key] = logEntries[key].concat(newEntries[key])
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// use the parsers for each file type
|
|
|
|
function processLog(log) {
|
|
|
|
$scope.pdf.rawLog = log
|
|
|
|
const { errors, warnings, typesetting } = HumanReadableLogs.parse(log, {
|
2021-04-27 03:52:58 -04:00
|
|
|
ignoreDuplicates: true,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
const all = [].concat(errors, warnings, typesetting)
|
|
|
|
accumulateResults({ all, errors, warnings, typesetting })
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function processChkTex(log) {
|
|
|
|
const errors = []
|
|
|
|
const warnings = []
|
|
|
|
for (let line of log.split('\n')) {
|
|
|
|
var m
|
|
|
|
if ((m = line.match(/^(\S+):(\d+):(\d+): (Error|Warning): (.*)/))) {
|
|
|
|
const result = {
|
|
|
|
file: m[1],
|
|
|
|
line: m[2],
|
|
|
|
column: m[3],
|
|
|
|
level: m[4].toLowerCase(),
|
2021-04-27 03:52:58 -04:00
|
|
|
message: `${m[4]}: ${m[5]}`,
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
if (result.level === 'error') {
|
|
|
|
errors.push(result)
|
|
|
|
} else {
|
|
|
|
warnings.push(result)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
const all = [].concat(errors, warnings)
|
|
|
|
const logHints = HumanReadableLogs.parse({
|
|
|
|
type: 'Syntax',
|
|
|
|
all,
|
|
|
|
errors,
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
eventTracking.sendMB('syntax-check-return-count', {
|
|
|
|
errors: errors.length,
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: warnings.length,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
accumulateResults(logHints)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function processBiber(log) {
|
|
|
|
const { errors, warnings } = BibLogParser.parse(log, {})
|
|
|
|
const all = [].concat(errors, warnings)
|
|
|
|
accumulateResults({ type: 'BibTeX:', all, errors, warnings })
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// output the results
|
|
|
|
function handleError() {
|
|
|
|
$scope.pdf.logEntries = {}
|
|
|
|
$scope.pdf.rawLog = ''
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function annotateFiles() {
|
|
|
|
$scope.pdf.logEntries = logEntries
|
|
|
|
$scope.pdf.logEntryAnnotations = {}
|
|
|
|
for (const entry of logEntries.all) {
|
|
|
|
if (entry.file != null) {
|
|
|
|
entry.file = normalizeFilePath(entry.file)
|
|
|
|
const entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
|
|
|
if (entity != null) {
|
|
|
|
if (!$scope.pdf.logEntryAnnotations[entity.id]) {
|
|
|
|
$scope.pdf.logEntryAnnotations[entity.id] = []
|
|
|
|
}
|
|
|
|
$scope.pdf.logEntryAnnotations[entity.id].push({
|
|
|
|
row: entry.line - 1,
|
|
|
|
type: entry.level === 'error' ? 'error' : 'warning',
|
2021-04-27 03:52:58 -04:00
|
|
|
text: entry.message,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// retrieve the logfile and process it
|
|
|
|
let response
|
|
|
|
if (logFile != null) {
|
|
|
|
response = getFile('output.log', logFile).then(response =>
|
|
|
|
processLog(response.data)
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (blgFile != null) {
|
|
|
|
// retrieve the blg file if present
|
|
|
|
response = response.then(() =>
|
|
|
|
getFile('output.blg', blgFile).then(
|
|
|
|
response => processBiber(response.data),
|
|
|
|
() => true
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
if (response != null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
response.catch(handleError)
|
2018-11-05 05:06:39 -05:00
|
|
|
} else {
|
2021-04-14 09:17:21 -04:00
|
|
|
handleError()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (chktexFile != null) {
|
|
|
|
const getChkTex = () =>
|
|
|
|
getFile('output.chktex', chktexFile).then(response =>
|
|
|
|
processChkTex(response.data)
|
|
|
|
)
|
|
|
|
// always retrieve the chktex file if present
|
|
|
|
if (response != null) {
|
|
|
|
response = response.then(getChkTex, getChkTex)
|
|
|
|
} else {
|
|
|
|
response = getChkTex()
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 08:52:32 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// display the combined result
|
|
|
|
if (response != null) {
|
|
|
|
response.finally(() => {
|
|
|
|
annotateFiles()
|
|
|
|
sendCompileMetrics()
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function sendCompileMetrics() {
|
|
|
|
const hasCompiled =
|
|
|
|
$scope.pdf.view !== 'errors' &&
|
|
|
|
$scope.pdf.view !== 'validation-problems'
|
|
|
|
|
|
|
|
if (hasCompiled && !window.user.alphaProgram) {
|
|
|
|
const metadata = {
|
|
|
|
errors: $scope.pdf.logEntries.errors.length,
|
|
|
|
warnings: $scope.pdf.logEntries.warnings.length,
|
|
|
|
typesetting: $scope.pdf.logEntries.typesetting.length,
|
|
|
|
newLogsUI: window.showNewLogsUI,
|
2021-04-27 03:52:58 -04:00
|
|
|
subvariant: window.showNewLogsUI ? window.logsUISubvariant : null,
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
eventTracking.sendMBSampled(
|
|
|
|
'compile-result',
|
|
|
|
JSON.stringify(metadata),
|
|
|
|
0.01
|
|
|
|
)
|
|
|
|
}
|
2021-03-18 04:39:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
|
|
|
|
function getRootDocOverrideId() {
|
|
|
|
const rootDocId = $scope.project.rootDoc_id
|
|
|
|
const currentDocId = ide.editorManager.getCurrentDocId()
|
|
|
|
if (currentDocId === rootDocId) {
|
|
|
|
return null // no need to override when in the root doc itself
|
|
|
|
}
|
|
|
|
const doc = ide.editorManager.getCurrentDocValue()
|
|
|
|
if (doc == null) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
for (let line of doc.split('\n')) {
|
|
|
|
if (/^[^%]*\\documentclass/.test(line)) {
|
|
|
|
return ide.editorManager.getCurrentDocId()
|
|
|
|
}
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
return null
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
|
|
|
|
function normalizeFilePath(path) {
|
|
|
|
path = path.replace(
|
|
|
|
/^(.*)\/compiles\/[0-9a-f]{24}(-[0-9a-f]{24})?\/(\.\/)?/,
|
|
|
|
''
|
|
|
|
)
|
|
|
|
path = path.replace(/^\/compile\//, '')
|
|
|
|
|
|
|
|
const rootDocDirname = ide.fileTreeManager.getRootDocDirname()
|
|
|
|
if (rootDocDirname != null) {
|
|
|
|
path = path.replace(/^\.\//, rootDocDirname + '/')
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
|
|
|
|
return path
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.recompile = function (options) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {}
|
|
|
|
}
|
|
|
|
if ($scope.pdf.compiling) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
eventTracking.sendMBSampled('editor-recompile-sampled', options)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.lastStartedCompileAt = Date.now()
|
|
|
|
$scope.pdf.compiling = true
|
|
|
|
$scope.pdf.isAutoCompileOnLoad =
|
|
|
|
options != null ? options.isAutoCompileOnLoad : undefined // initial autocompile
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (options != null ? options.force : undefined) {
|
|
|
|
// for forced compile, turn off validation check and ignore errors
|
|
|
|
$scope.stop_on_validation_error = false
|
|
|
|
$scope.shouldShowLogs = false // hide the logs while compiling
|
|
|
|
eventTracking.sendMB('syntax-check-turn-off-checking')
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (options != null ? options.try : undefined) {
|
|
|
|
$scope.shouldShowLogs = false // hide the logs while compiling
|
|
|
|
eventTracking.sendMB('syntax-check-try-compile-anyway')
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
ide.$scope.$broadcast('flush-changes')
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
options.rootDocOverride_id = getRootDocOverrideId()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
sendCompileRequest(options)
|
|
|
|
.then(function (response) {
|
|
|
|
const { data } = response
|
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.pdf.compiling = false
|
|
|
|
parseCompileResponse(data)
|
|
|
|
})
|
|
|
|
.catch(function (response) {
|
|
|
|
const { status } = response
|
|
|
|
if (status === 429) {
|
|
|
|
$scope.pdf.rateLimited = true
|
|
|
|
}
|
|
|
|
$scope.pdf.compiling = false
|
|
|
|
$scope.pdf.renderingError = false
|
|
|
|
$scope.pdf.error = true
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
if (window.showNewLogsUI) {
|
|
|
|
$scope.clsiErrors = { error: true }
|
|
|
|
$scope.shouldShowLogs = true
|
|
|
|
$scope.pdf.compileFailed = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
$scope.lastFinishedCompileAt = Date.now()
|
|
|
|
})
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// This needs to be public.
|
|
|
|
ide.$scope.recompile = $scope.recompile
|
|
|
|
// This method is a simply wrapper and exists only for tracking purposes.
|
|
|
|
ide.$scope.recompileViaKey = function () {
|
|
|
|
$scope.recompile({ keyShortcut: true })
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.stop = function () {
|
|
|
|
if (!$scope.pdf.compiling) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return $http({
|
|
|
|
url: `/project/${$scope.project_id}/compile/stop`,
|
|
|
|
method: 'POST',
|
|
|
|
params: {
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiserverid: ide.clsiServerId,
|
2021-04-14 09:17:21 -04:00
|
|
|
},
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-Csrf-Token': window.csrfToken,
|
|
|
|
},
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.clearCache = function () {
|
|
|
|
$scope.pdf.clearingCache = true
|
|
|
|
const deferred = $q.defer()
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// disable various download buttons
|
|
|
|
$scope.pdf.url = null
|
|
|
|
$scope.pdf.downloadUrl = null
|
|
|
|
$scope.pdf.outputFiles = []
|
|
|
|
|
|
|
|
$http({
|
|
|
|
url: `/project/${$scope.project_id}/output`,
|
|
|
|
method: 'DELETE',
|
|
|
|
params: {
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiserverid: ide.clsiServerId,
|
2021-04-14 09:17:21 -04:00
|
|
|
},
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-Csrf-Token': window.csrfToken,
|
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
.then(function (response) {
|
|
|
|
$scope.pdf.clearingCache = false
|
|
|
|
return deferred.resolve()
|
|
|
|
})
|
|
|
|
.catch(function (response) {
|
|
|
|
console.error(response)
|
|
|
|
const error = response.data
|
|
|
|
$scope.pdf.clearingCache = false
|
|
|
|
$scope.pdf.renderingError = false
|
|
|
|
$scope.pdf.error = true
|
|
|
|
$scope.pdf.view = 'errors'
|
|
|
|
return deferred.reject(error)
|
|
|
|
})
|
|
|
|
return deferred.promise
|
2019-10-28 10:05:23 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.recompileFromScratch = function () {
|
|
|
|
$scope.pdf.compiling = true
|
|
|
|
return $scope
|
|
|
|
.clearCache()
|
|
|
|
.then(() => {
|
|
|
|
$scope.pdf.compiling = false
|
|
|
|
$scope.recompile()
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error)
|
|
|
|
})
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.toggleLogs = function () {
|
|
|
|
$scope.$applyAsync(() => {
|
|
|
|
$scope.shouldShowLogs = !$scope.shouldShowLogs
|
|
|
|
if ($scope.shouldShowLogs) {
|
|
|
|
eventTracking.sendMBOnce('ide-open-logs-once')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-10-20 08:44:19 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.showPdf = function () {
|
|
|
|
$scope.pdf.view = 'pdf'
|
|
|
|
$scope.shouldShowLogs = false
|
|
|
|
}
|
2021-01-12 06:24:21 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.toggleRawLog = function () {
|
|
|
|
$scope.pdf.showRawLog = !$scope.pdf.showRawLog
|
|
|
|
if ($scope.pdf.showRawLog) {
|
|
|
|
eventTracking.sendMB('logs-view-raw')
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openClearCacheModal = function () {
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'clearCacheModalTemplate',
|
|
|
|
controller: 'ClearCacheModalController',
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2020-10-20 08:44:19 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.syncToCode = function (position) {
|
|
|
|
synctex.syncToCode(position).then(function (data) {
|
|
|
|
const { doc, line } = data
|
|
|
|
ide.editorManager.openDoc(doc, { gotoLine: line })
|
2020-10-20 08:44:19 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.setAutoCompile = function (isOn) {
|
|
|
|
$scope.$applyAsync(function () {
|
|
|
|
$scope.autocompile_enabled = isOn
|
2020-12-02 05:03:03 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
$scope.setDraftMode = function (isOn) {
|
|
|
|
$scope.$applyAsync(function () {
|
|
|
|
$scope.draft = isOn
|
2020-12-02 05:03:03 -05:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.setSyntaxCheck = function (isOn) {
|
|
|
|
$scope.$applyAsync(function () {
|
|
|
|
$scope.stop_on_validation_error = isOn
|
|
|
|
})
|
2020-11-05 05:22:05 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.runSyntaxCheckNow = function () {
|
|
|
|
$scope.$applyAsync(function () {
|
|
|
|
$scope.recompile({ check: true })
|
|
|
|
})
|
2020-11-05 05:22:05 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
|
|
|
|
$scope.openInEditor = function (entry) {
|
|
|
|
let column, line
|
|
|
|
eventTracking.sendMBOnce('logs-jump-to-location-once')
|
|
|
|
const entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
|
|
|
if (entity == null || entity.type !== 'doc') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (entry.line != null) {
|
|
|
|
line = entry.line
|
|
|
|
}
|
|
|
|
if (entry.column != null) {
|
|
|
|
column = entry.column
|
|
|
|
}
|
|
|
|
ide.editorManager.openDoc(entity, {
|
|
|
|
gotoLine: line,
|
2021-04-27 03:52:58 -04:00
|
|
|
gotoColumn: column,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
2020-11-05 05:22:05 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.factory('synctex', function (ide, $http, $q) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const synctex = {
|
2021-03-31 05:49:39 -04:00
|
|
|
syncToPdfInFlight: false,
|
|
|
|
syncToCodeInFlight: false,
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
syncToPdf(cursorPosition) {
|
|
|
|
const deferred = $q.defer()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const docId = ide.editorManager.getCurrentDocId()
|
|
|
|
if (docId == null) {
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
}
|
|
|
|
const doc = ide.fileTreeManager.findEntityById(docId)
|
|
|
|
if (doc == null) {
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
}
|
|
|
|
let path = ide.fileTreeManager.getEntityPath(doc)
|
|
|
|
if (path == null) {
|
|
|
|
deferred.reject()
|
|
|
|
return deferred.promise
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// If the root file is folder/main.tex, then synctex sees the
|
|
|
|
// path as folder/./main.tex
|
|
|
|
const rootDocDirname = ide.fileTreeManager.getRootDocDirname()
|
|
|
|
if (rootDocDirname != null && rootDocDirname !== '') {
|
|
|
|
path = path.replace(RegExp(`^${rootDocDirname}`), `${rootDocDirname}/.`)
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const { row, column } = cursorPosition
|
|
|
|
|
2021-03-31 05:49:39 -04:00
|
|
|
this.syncToPdfInFlight = true
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$http({
|
|
|
|
url: `/project/${ide.project_id}/sync/code`,
|
|
|
|
method: 'GET',
|
|
|
|
params: {
|
|
|
|
file: path,
|
|
|
|
line: row + 1,
|
|
|
|
column,
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiserverid: ide.clsiServerId,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-03-31 05:49:39 -04:00
|
|
|
.then(response => {
|
|
|
|
this.syncToPdfInFlight = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const { data } = response
|
|
|
|
return deferred.resolve(data.pdf || [])
|
|
|
|
})
|
2021-03-31 05:49:39 -04:00
|
|
|
.catch(response => {
|
|
|
|
this.syncToPdfInFlight = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const error = response.data
|
|
|
|
return deferred.reject(error)
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return deferred.promise
|
|
|
|
},
|
|
|
|
|
|
|
|
syncToCode(position, options) {
|
|
|
|
if (options == null) {
|
|
|
|
options = {}
|
|
|
|
}
|
|
|
|
const deferred = $q.defer()
|
|
|
|
if (position == null) {
|
|
|
|
deferred.reject()
|
2019-07-16 05:13:18 -04:00
|
|
|
return deferred.promise
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// FIXME: this actually works better if it's halfway across the
|
|
|
|
// page (or the visible part of the page). Synctex doesn't
|
|
|
|
// always find the right place in the file when the point is at
|
|
|
|
// the edge of the page, it sometimes returns the start of the
|
|
|
|
// next paragraph instead.
|
|
|
|
const h = position.offset.left
|
|
|
|
|
|
|
|
// Compute the vertical position to pass to synctex, which
|
|
|
|
// works with coordinates increasing from the top of the page
|
|
|
|
// down. This matches the browser's DOM coordinate of the
|
|
|
|
// click point, but the pdf position is measured from the
|
|
|
|
// bottom of the page so we need to invert it.
|
|
|
|
let v
|
|
|
|
if (
|
|
|
|
options.fromPdfPosition &&
|
|
|
|
(position.pageSize != null ? position.pageSize.height : undefined) !=
|
|
|
|
null
|
|
|
|
) {
|
|
|
|
v = position.pageSize.height - position.offset.top || 0 // measure from pdf point (inverted)
|
|
|
|
} else {
|
|
|
|
v = position.offset.top || 0 // measure from html click position
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// It's not clear exactly where we should sync to if it wasn't directly
|
|
|
|
// clicked on, but a little bit down from the very top seems best.
|
|
|
|
if (options.includeVisualOffset) {
|
|
|
|
v += 72 // use the same value as in pdfViewer highlighting visual offset
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-03-31 05:49:39 -04:00
|
|
|
this.syncToCodeInFlight = true
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$http({
|
|
|
|
url: `/project/${ide.project_id}/sync/pdf`,
|
|
|
|
method: 'GET',
|
|
|
|
params: {
|
|
|
|
page: position.page + 1,
|
|
|
|
h: h.toFixed(2),
|
|
|
|
v: v.toFixed(2),
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiserverid: ide.clsiServerId,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-03-31 05:49:39 -04:00
|
|
|
.then(response => {
|
|
|
|
this.syncToCodeInFlight = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const { data } = response
|
|
|
|
if (
|
|
|
|
data.code != null &&
|
|
|
|
data.code.length > 0 &&
|
|
|
|
data.code[0].file !== ''
|
|
|
|
) {
|
|
|
|
const doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
|
|
|
|
if (doc == null) {
|
2021-03-10 04:09:35 -05:00
|
|
|
deferred.reject()
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
return deferred.resolve({ doc, line: data.code[0].line })
|
|
|
|
} else if (data.code[0].file === '') {
|
|
|
|
ide.$scope.sync_tex_error = true
|
|
|
|
setTimeout(() => (ide.$scope.sync_tex_error = false), 4000)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
2021-03-31 05:49:39 -04:00
|
|
|
.catch(response => {
|
|
|
|
this.syncToCodeInFlight = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const error = response.data
|
|
|
|
return deferred.reject(error)
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return deferred.promise
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return synctex
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('PdfSynctexController', function ($scope, synctex, ide) {
|
2020-05-19 05:02:56 -04:00
|
|
|
this.cursorPosition = null
|
2021-03-31 05:49:39 -04:00
|
|
|
|
|
|
|
$scope.$watch(
|
|
|
|
() => synctex.syncToPdfInFlight,
|
|
|
|
value => ($scope.syncToPdfInFlight = value)
|
|
|
|
)
|
|
|
|
$scope.$watch(
|
|
|
|
() => synctex.syncToCodeInFlight,
|
|
|
|
value => ($scope.syncToCodeInFlight = value)
|
|
|
|
)
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
ide.$scope.$on('cursor:editor:update', (event, cursorPosition) => {
|
|
|
|
this.cursorPosition = cursorPosition
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.syncToPdf = () => {
|
|
|
|
if (this.cursorPosition == null) {
|
|
|
|
return
|
|
|
|
}
|
2021-03-31 05:49:39 -04:00
|
|
|
synctex.syncToPdf(this.cursorPosition).then(highlights => {
|
|
|
|
$scope.pdf.highlights = highlights
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
ide.$scope.$on('cursor:editor:syncToPdf', $scope.syncToPdf)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.syncToCode = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
synctex
|
|
|
|
.syncToCode($scope.pdf.position, {
|
|
|
|
includeVisualOffset: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
fromPdfPosition: true,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(function (data) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const { doc, line } = data
|
|
|
|
ide.editorManager.openDoc(doc, { gotoLine: line })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('ClearCacheModalController', function ($scope, $modalInstance) {
|
2020-10-20 08:44:19 -04:00
|
|
|
$scope.state = { error: false, inflight: false }
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.clear = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.state.inflight = true
|
2020-10-20 08:44:19 -04:00
|
|
|
$scope
|
|
|
|
.clearCache()
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(function () {
|
2020-10-20 08:44:19 -04:00
|
|
|
$scope.state.inflight = false
|
|
|
|
$modalInstance.close()
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.catch(function () {
|
2020-10-20 08:44:19 -04:00
|
|
|
$scope.state.error = true
|
|
|
|
$scope.state.inflight = false
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.cancel = () => $modalInstance.dismiss('cancel')
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2020-09-28 06:51:15 -04:00
|
|
|
// Wrap React component as Angular component. Only needed for "top-level" component
|
2021-01-14 10:16:54 -05:00
|
|
|
App.component(
|
|
|
|
'previewPane',
|
|
|
|
react2angular(
|
|
|
|
rootContext.use(PreviewPane),
|
|
|
|
Object.keys(PreviewPane.propTypes)
|
|
|
|
)
|
|
|
|
)
|