mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Move state management into LabelsMaster on the ide
This commit is contained in:
parent
965a46291b
commit
5443b92e7d
5 changed files with 53 additions and 51 deletions
|
@ -61,6 +61,7 @@ div.full-size(
|
||||||
track-changes= "editor.trackChanges",
|
track-changes= "editor.trackChanges",
|
||||||
doc-id="editor.open_doc_id"
|
doc-id="editor.open_doc_id"
|
||||||
renderer-data="reviewPanel.rendererData"
|
renderer-data="reviewPanel.rendererData"
|
||||||
|
labels-master="labelsMaster"
|
||||||
)
|
)
|
||||||
|
|
||||||
include ./review-panel
|
include ./review-panel
|
||||||
|
|
|
@ -9,6 +9,7 @@ define [
|
||||||
"ide/pdf/PdfManager"
|
"ide/pdf/PdfManager"
|
||||||
"ide/binary-files/BinaryFilesManager"
|
"ide/binary-files/BinaryFilesManager"
|
||||||
"ide/references/ReferencesManager"
|
"ide/references/ReferencesManager"
|
||||||
|
"ide/labels/LabelsMaster"
|
||||||
"ide/review-panel/ReviewPanelManager"
|
"ide/review-panel/ReviewPanelManager"
|
||||||
"ide/SafariScrollPatcher"
|
"ide/SafariScrollPatcher"
|
||||||
"ide/FeatureOnboardingController"
|
"ide/FeatureOnboardingController"
|
||||||
|
@ -45,6 +46,7 @@ define [
|
||||||
PdfManager
|
PdfManager
|
||||||
BinaryFilesManager
|
BinaryFilesManager
|
||||||
ReferencesManager
|
ReferencesManager
|
||||||
|
LabelsMaster
|
||||||
ReviewPanelManager
|
ReviewPanelManager
|
||||||
SafariScrollPatcher
|
SafariScrollPatcher
|
||||||
) ->
|
) ->
|
||||||
|
@ -117,6 +119,8 @@ define [
|
||||||
ide.project_id = $scope.project_id = window.project_id
|
ide.project_id = $scope.project_id = window.project_id
|
||||||
ide.$scope = $scope
|
ide.$scope = $scope
|
||||||
|
|
||||||
|
$scope.labelsMaster = ide.labelsMaster = new LabelsMaster(ide, $scope)
|
||||||
|
|
||||||
ide.referencesSearchManager = new ReferencesManager(ide, $scope)
|
ide.referencesSearchManager = new ReferencesManager(ide, $scope)
|
||||||
ide.connectionManager = new ConnectionManager(ide, $scope)
|
ide.connectionManager = new ConnectionManager(ide, $scope)
|
||||||
ide.fileTreeManager = new FileTreeManager(ide, $scope)
|
ide.fileTreeManager = new FileTreeManager(ide, $scope)
|
||||||
|
|
|
@ -37,6 +37,7 @@ define [
|
||||||
|
|
||||||
return {
|
return {
|
||||||
scope: {
|
scope: {
|
||||||
|
labelsMaster: '='
|
||||||
theme: "="
|
theme: "="
|
||||||
showPrintMargin: "="
|
showPrintMargin: "="
|
||||||
keybindings: "="
|
keybindings: "="
|
||||||
|
|
|
@ -11,30 +11,9 @@ define [
|
||||||
|
|
||||||
class LabelsManager
|
class LabelsManager
|
||||||
constructor: (@$scope, @editor, @element) ->
|
constructor: (@$scope, @editor, @element) ->
|
||||||
|
@labelsMaster = @$scope.labelsMaster
|
||||||
window.GET_LABELS = () =>
|
|
||||||
@loadProjectLabelsFromServer()
|
|
||||||
|
|
||||||
window.GET_DOC_LABELS = () =>
|
|
||||||
@loadCurrentDocLabelsFromServer()
|
|
||||||
|
|
||||||
@state =
|
|
||||||
documents: {} # map of DocId => List[Label]
|
|
||||||
|
|
||||||
@loadLabelsTimeout = null
|
@loadLabelsTimeout = null
|
||||||
|
|
||||||
@$scope.$on 'doc:labels:updated', (e, data) =>
|
|
||||||
if data.docId and data.labels
|
|
||||||
@state.documents[data.docId] = data.labels
|
|
||||||
|
|
||||||
@$scope.$on 'entity:deleted', (e, entity) =>
|
|
||||||
if entity.type == 'doc'
|
|
||||||
delete @state.documents[entity.id]
|
|
||||||
|
|
||||||
@$scope.$on 'file:upload:complete', (e, upload) =>
|
|
||||||
if upload.entity_type == 'doc'
|
|
||||||
@loadDocLabelsFromServer(upload.entity_id)
|
|
||||||
|
|
||||||
onChange = (change) =>
|
onChange = (change) =>
|
||||||
if change.remote
|
if change.remote
|
||||||
return
|
return
|
||||||
|
@ -49,41 +28,14 @@ define [
|
||||||
(commandFragment?.length > 2 and commandFragment.slice(0,7) == '\\label{'))
|
(commandFragment?.length > 2 and commandFragment.slice(0,7) == '\\label{'))
|
||||||
)
|
)
|
||||||
@scheduleLoadCurrentDocLabelsFromServer()
|
@scheduleLoadCurrentDocLabelsFromServer()
|
||||||
# @scheduleLoadLabelsFromOpenDoc()
|
|
||||||
|
|
||||||
@editor.on "changeSession", (e) =>
|
@editor.on "changeSession", (e) =>
|
||||||
e.oldSession.off "change", onChange
|
e.oldSession.off "change", onChange
|
||||||
e.session.on "change", onChange
|
e.session.on "change", onChange
|
||||||
# setTimeout(
|
|
||||||
# () =>
|
|
||||||
# # @scheduleLoadLabelsFromOpenDoc()
|
|
||||||
# @loadProjectLabelsFromServer()
|
|
||||||
# , 0
|
|
||||||
# )
|
|
||||||
|
|
||||||
# Load now
|
|
||||||
@loadProjectLabelsFromServer()
|
|
||||||
|
|
||||||
loadProjectLabelsFromServer: () ->
|
|
||||||
$.get(
|
|
||||||
"/project/#{window.project_id}/labels"
|
|
||||||
, (data) =>
|
|
||||||
if data.projectLabels
|
|
||||||
for docId, docLabels of data.projectLabels
|
|
||||||
@state.documents[docId] = docLabels
|
|
||||||
)
|
|
||||||
|
|
||||||
loadCurrentDocLabelsFromServer: () ->
|
loadCurrentDocLabelsFromServer: () ->
|
||||||
currentDocId = @$scope.docId
|
currentDocId = @$scope.docId
|
||||||
@loadDocLabelsFromServer(currentDocId)
|
@labelsMaster.loadDocLabelsFromServer(currentDocId)
|
||||||
|
|
||||||
loadDocLabelsFromServer: (docId) ->
|
|
||||||
$.get(
|
|
||||||
"/project/#{window.project_id}/#{docId}/labels"
|
|
||||||
, (data) =>
|
|
||||||
if data.docId and data.labels
|
|
||||||
@state.documents[data.docId] = data.labels
|
|
||||||
)
|
|
||||||
|
|
||||||
scheduleLoadCurrentDocLabelsFromServer: () ->
|
scheduleLoadCurrentDocLabelsFromServer: () ->
|
||||||
# De-bounce loading labels with a timeout
|
# De-bounce loading labels with a timeout
|
||||||
|
@ -97,4 +49,4 @@ define [
|
||||||
)
|
)
|
||||||
|
|
||||||
getAllLabels: () ->
|
getAllLabels: () ->
|
||||||
_.flatten(labels for docId, labels of @state.documents)
|
@labelsMaster.getAllLabels()
|
||||||
|
|
44
services/web/public/coffee/ide/labels/LabelsMaster.coffee
Normal file
44
services/web/public/coffee/ide/labels/LabelsMaster.coffee
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
define [
|
||||||
|
], () ->
|
||||||
|
class LabelsMaster
|
||||||
|
constructor: (@ide, @$scope) ->
|
||||||
|
|
||||||
|
@_state = {
|
||||||
|
documents: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@$scope.$on 'doc:labels:updated', (e, data) =>
|
||||||
|
if data.docId and data.labels
|
||||||
|
@_state.documents[data.docId] = data.labels
|
||||||
|
|
||||||
|
@$scope.$on 'entity:deleted', (e, entity) =>
|
||||||
|
if entity.type == 'doc'
|
||||||
|
delete @_state.documents[entity.id]
|
||||||
|
|
||||||
|
@$scope.$on 'file:upload:complete', (e, upload) =>
|
||||||
|
if upload.entity_type == 'doc'
|
||||||
|
@loadDocLabelsFromServer(upload.entity_id)
|
||||||
|
|
||||||
|
# load project labels now
|
||||||
|
@loadProjectLabelsFromServer()
|
||||||
|
|
||||||
|
getAllLabels: () ->
|
||||||
|
_.flatten(labels for docId, labels of @_state.documents)
|
||||||
|
|
||||||
|
## Loaders
|
||||||
|
loadProjectLabelsFromServer: () ->
|
||||||
|
$.get(
|
||||||
|
"/project/#{window.project_id}/labels"
|
||||||
|
, (data) =>
|
||||||
|
if data.projectLabels
|
||||||
|
for docId, docLabels of data.projectLabels
|
||||||
|
@_state.documents[docId] = docLabels
|
||||||
|
)
|
||||||
|
|
||||||
|
loadDocLabelsFromServer: (docId) ->
|
||||||
|
$.get(
|
||||||
|
"/project/#{window.project_id}/#{docId}/labels"
|
||||||
|
, (data) =>
|
||||||
|
if data.docId and data.labels
|
||||||
|
@_state.documents[data.docId] = data.labels
|
||||||
|
)
|
Loading…
Reference in a new issue