mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Refactor ReferencesSearch*
to just References*
.
This commit is contained in:
parent
b978171e0c
commit
326d9e59f8
8 changed files with 42 additions and 47 deletions
|
@ -16,8 +16,6 @@ SecurityManager = require("../../managers/SecurityManager")
|
||||||
fs = require "fs"
|
fs = require "fs"
|
||||||
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
|
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
|
||||||
ProjectUpdateHandler = require("./ProjectUpdateHandler")
|
ProjectUpdateHandler = require("./ProjectUpdateHandler")
|
||||||
ReferencesSearchHandler = require("../ReferencesSearch/ReferencesSearchHandler")
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = ProjectController =
|
module.exports = ProjectController =
|
||||||
|
|
||||||
|
@ -218,9 +216,6 @@ module.exports = ProjectController =
|
||||||
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
||||||
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
||||||
|
|
||||||
# HACK: don't do it for now
|
|
||||||
# ReferencesSearchHandler.indexProjectReferences project, -> # don't need to wait on this
|
|
||||||
|
|
||||||
logger.log project_id:project_id, "rendering editor page"
|
logger.log project_id:project_id, "rendering editor page"
|
||||||
res.render 'project/editor',
|
res.render 'project/editor',
|
||||||
title: project.name
|
title: project.name
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
logger = require('logger-sharelatex')
|
logger = require('logger-sharelatex')
|
||||||
ReferencesSearchHandler = require('./ReferencesSearchHandler')
|
ReferencesHandler = require('./ReferencesHandler')
|
||||||
settings = require('settings-sharelatex')
|
settings = require('settings-sharelatex')
|
||||||
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
||||||
|
|
||||||
module.exports = ReferencesSearchController =
|
module.exports = ReferencesController =
|
||||||
|
|
||||||
|
|
||||||
index: (req, res) ->
|
index: (req, res) ->
|
||||||
|
@ -14,21 +14,21 @@ module.exports = ReferencesSearchController =
|
||||||
logger.err {projectId, docIds}, "docIds is not valid, should be either Array or String 'ALL'"
|
logger.err {projectId, docIds}, "docIds is not valid, should be either Array or String 'ALL'"
|
||||||
return res.send 400
|
return res.send 400
|
||||||
logger.log {projectId, docIds: docIds}, "index references for project"
|
logger.log {projectId, docIds: docIds}, "index references for project"
|
||||||
ReferencesSearchHandler.index projectId, docIds, (err, data) ->
|
ReferencesHandler.index projectId, docIds, (err, data) ->
|
||||||
if err
|
if err
|
||||||
logger.err {err, projectId}, "error indexing all references"
|
logger.err {err, projectId}, "error indexing all references"
|
||||||
return res.send 500
|
return res.send 500
|
||||||
ReferencesSearchController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
||||||
|
|
||||||
indexAll: (req, res) ->
|
indexAll: (req, res) ->
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
shouldBroadcast = req.body.shouldBroadcast
|
shouldBroadcast = req.body.shouldBroadcast
|
||||||
logger.log {projectId}, "index all references for project"
|
logger.log {projectId}, "index all references for project"
|
||||||
ReferencesSearchHandler.indexAll projectId, (err, data) ->
|
ReferencesHandler.indexAll projectId, (err, data) ->
|
||||||
if err
|
if err
|
||||||
logger.err {err, projectId}, "error indexing all references"
|
logger.err {err, projectId}, "error indexing all references"
|
||||||
return res.send 500
|
return res.send 500
|
||||||
ReferencesSearchController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
|
||||||
|
|
||||||
_handleIndexResponse: (req, res, projectId, shouldBroadcast, data) ->
|
_handleIndexResponse: (req, res, projectId, shouldBroadcast, data) ->
|
||||||
if shouldBroadcast
|
if shouldBroadcast
|
|
@ -10,7 +10,7 @@ oneMinInMs = 60 * 1000
|
||||||
fiveMinsInMs = oneMinInMs * 5
|
fiveMinsInMs = oneMinInMs * 5
|
||||||
|
|
||||||
|
|
||||||
module.exports = ReferencesSearchHandler =
|
module.exports = ReferencesHandler =
|
||||||
|
|
||||||
_buildDocUrl: (projectId, docId) ->
|
_buildDocUrl: (projectId, docId) ->
|
||||||
"#{settings.apis.docstore.url}/project/#{projectId}/doc/#{docId}/raw"
|
"#{settings.apis.docstore.url}/project/#{projectId}/doc/#{docId}/raw"
|
||||||
|
@ -40,18 +40,18 @@ module.exports = ReferencesSearchHandler =
|
||||||
logger.err {err, projectId}, "error finding project"
|
logger.err {err, projectId}, "error finding project"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
logger.log {projectId}, "indexing all bib files in project"
|
logger.log {projectId}, "indexing all bib files in project"
|
||||||
docIds = ReferencesSearchHandler._findBibDocIds(project)
|
docIds = ReferencesHandler._findBibDocIds(project)
|
||||||
ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
|
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
|
||||||
|
|
||||||
index: (projectId, docIds, callback=(err, data)->) ->
|
index: (projectId, docIds, callback=(err, data)->) ->
|
||||||
Project.findPopulatedById projectId, (err, project) ->
|
Project.findPopulatedById projectId, (err, project) ->
|
||||||
if err
|
if err
|
||||||
logger.err {err, projectId}, "error finding project"
|
logger.err {err, projectId}, "error finding project"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
|
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
|
||||||
|
|
||||||
_doIndexOperation: (projectId, project, docIds, callback) ->
|
_doIndexOperation: (projectId, project, docIds, callback) ->
|
||||||
ReferencesSearchHandler._isFullIndex project, (err, isFullIndex) ->
|
ReferencesHandler._isFullIndex project, (err, isFullIndex) ->
|
||||||
if err
|
if err
|
||||||
logger.err {err, projectId}, "error checking whether to do full index"
|
logger.err {err, projectId}, "error checking whether to do full index"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
@ -64,7 +64,7 @@ module.exports = ReferencesSearchHandler =
|
||||||
logger.err {err, projectId, docIds}, "error flushing docs to mongo"
|
logger.err {err, projectId, docIds}, "error flushing docs to mongo"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
bibDocUrls = docIds.map (docId) ->
|
bibDocUrls = docIds.map (docId) ->
|
||||||
ReferencesSearchHandler._buildDocUrl projectId, docId
|
ReferencesHandler._buildDocUrl projectId, docId
|
||||||
logger.log {projectId, isFullIndex, docIds, bibDocUrls}, "sending request to references service"
|
logger.log {projectId, isFullIndex, docIds, bibDocUrls}, "sending request to references service"
|
||||||
request.post {
|
request.post {
|
||||||
url: "#{settings.apis.references.url}/project/#{projectId}/index"
|
url: "#{settings.apis.references.url}/project/#{projectId}/index"
|
|
@ -37,7 +37,7 @@ RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
|
||||||
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
|
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
|
||||||
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
|
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
|
||||||
ContactRouter = require("./Features/Contacts/ContactRouter")
|
ContactRouter = require("./Features/Contacts/ContactRouter")
|
||||||
ReferencesSearchController = require('./Features/ReferencesSearch/ReferencesSearchController')
|
ReferencesController = require('./Features/References/ReferencesController')
|
||||||
|
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
|
@ -175,8 +175,8 @@ module.exports = class Router
|
||||||
|
|
||||||
webRouter.get /learn(\/.*)?/, WikiController.getPage
|
webRouter.get /learn(\/.*)?/, WikiController.getPage
|
||||||
|
|
||||||
webRouter.post "/project/:Project_id/references/index", SecurityManager.requestCanAccessProject, ReferencesSearchController.index
|
webRouter.post "/project/:Project_id/references/index", SecurityManager.requestCanAccessProject, ReferencesController.index
|
||||||
webRouter.post "/project/:Project_id/references/indexAll", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexAll
|
webRouter.post "/project/:Project_id/references/indexAll", SecurityManager.requestCanAccessProject, ReferencesController.indexAll
|
||||||
|
|
||||||
#Admin Stuff
|
#Admin Stuff
|
||||||
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
|
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
|
||||||
|
|
|
@ -8,7 +8,7 @@ define [
|
||||||
"ide/permissions/PermissionsManager"
|
"ide/permissions/PermissionsManager"
|
||||||
"ide/pdf/PdfManager"
|
"ide/pdf/PdfManager"
|
||||||
"ide/binary-files/BinaryFilesManager"
|
"ide/binary-files/BinaryFilesManager"
|
||||||
"ide/references-search/ReferencesSearchManager"
|
"ide/references/ReferencesManager"
|
||||||
"ide/settings/index"
|
"ide/settings/index"
|
||||||
"ide/share/index"
|
"ide/share/index"
|
||||||
"ide/chat/index"
|
"ide/chat/index"
|
||||||
|
@ -38,7 +38,7 @@ define [
|
||||||
PermissionsManager
|
PermissionsManager
|
||||||
PdfManager
|
PdfManager
|
||||||
BinaryFilesManager
|
BinaryFilesManager
|
||||||
ReferencesSearchManager
|
ReferencesManager
|
||||||
) ->
|
) ->
|
||||||
|
|
||||||
App.controller "IdeController", ($scope, $timeout, ide, localStorage) ->
|
App.controller "IdeController", ($scope, $timeout, ide, localStorage) ->
|
||||||
|
@ -74,7 +74,7 @@ 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
|
||||||
|
|
||||||
ide.referencesSearchManager = new ReferencesSearchManager(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)
|
||||||
ide.editorManager = new EditorManager(ide, $scope)
|
ide.editorManager = new EditorManager(ide, $scope)
|
||||||
|
@ -94,7 +94,7 @@ define [
|
||||||
We don't want to delete your data on ShareLaTeX, so this project still contains your history and collaborators.
|
We don't want to delete your data on ShareLaTeX, so this project still contains your history and collaborators.
|
||||||
If the project has been renamed please look in your project list for a new project under the new name.
|
If the project has been renamed please look in your project list for a new project under the new name.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
DARK_THEMES = [
|
DARK_THEMES = [
|
||||||
"ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers",
|
"ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers",
|
||||||
"merbivore", "merbivore_soft", "mono_industrial", "monokai",
|
"merbivore", "merbivore_soft", "mono_industrial", "monokai",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
define [
|
define [
|
||||||
], () ->
|
], () ->
|
||||||
class ReferencesSearchManager
|
class ReferencesManager
|
||||||
constructor: (@ide, @$scope) ->
|
constructor: (@ide, @$scope) ->
|
||||||
|
|
||||||
@$scope.$root._references = @state = keys: []
|
@$scope.$root._references = @state = keys: []
|
|
@ -2,11 +2,11 @@ SandboxedModule = require('sandboxed-module')
|
||||||
should = require('chai').should()
|
should = require('chai').should()
|
||||||
sinon = require 'sinon'
|
sinon = require 'sinon'
|
||||||
assert = require("chai").assert
|
assert = require("chai").assert
|
||||||
modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchController"
|
modulePath = "../../../../app/js/Features/References/ReferencesController"
|
||||||
MockRequest = require "../helpers/MockRequest"
|
MockRequest = require "../helpers/MockRequest"
|
||||||
MockResponse = require "../helpers/MockResponse"
|
MockResponse = require "../helpers/MockResponse"
|
||||||
|
|
||||||
describe "ReferencesSearchController", ->
|
describe "ReferencesController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@projectId = '2222'
|
@projectId = '2222'
|
||||||
|
@ -18,7 +18,7 @@ describe "ReferencesSearchController", ->
|
||||||
'settings-sharelatex': @settings = {
|
'settings-sharelatex': @settings = {
|
||||||
apis: {web: {url: 'http://some.url'}}
|
apis: {web: {url: 'http://some.url'}}
|
||||||
},
|
},
|
||||||
'./ReferencesSearchHandler': @ReferencesSearchHandler = {
|
'./ReferencesHandler': @ReferencesHandler = {
|
||||||
index: sinon.stub()
|
index: sinon.stub()
|
||||||
indexAll: sinon.stub()
|
indexAll: sinon.stub()
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,7 @@ describe "ReferencesSearchController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.body = {shouldBroadcast: false}
|
@req.body = {shouldBroadcast: false}
|
||||||
@ReferencesSearchHandler.indexAll.callsArgWith(1, null, @fakeResponseData)
|
@ReferencesHandler.indexAll.callsArgWith(1, null, @fakeResponseData)
|
||||||
@call = (callback) =>
|
@call = (callback) =>
|
||||||
@controller.indexAll @req, @res
|
@controller.indexAll @req, @res
|
||||||
callback()
|
callback()
|
||||||
|
@ -59,16 +59,16 @@ describe "ReferencesSearchController", ->
|
||||||
@res.json.calledWith(@fakeResponseData).should.equal true
|
@res.json.calledWith(@fakeResponseData).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should call ReferencesSearchHandler.indexAll', (done) ->
|
it 'should call ReferencesHandler.indexAll', (done) ->
|
||||||
@call () =>
|
@call () =>
|
||||||
@ReferencesSearchHandler.indexAll.callCount.should.equal 1
|
@ReferencesHandler.indexAll.callCount.should.equal 1
|
||||||
@ReferencesSearchHandler.indexAll.calledWith(@projectId).should.equal true
|
@ReferencesHandler.indexAll.calledWith(@projectId).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'when shouldBroadcast is true', ->
|
describe 'when shouldBroadcast is true', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
|
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
|
||||||
@req.body.shouldBroadcast = true
|
@req.body.shouldBroadcast = true
|
||||||
|
|
||||||
it 'should call EditorRealTimeController.emitToRoom', (done) ->
|
it 'should call EditorRealTimeController.emitToRoom', (done) ->
|
||||||
|
@ -92,7 +92,7 @@ describe "ReferencesSearchController", ->
|
||||||
describe 'when shouldBroadcast is false', ->
|
describe 'when shouldBroadcast is false', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
|
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
|
||||||
@req.body.shouldBroadcast = false
|
@req.body.shouldBroadcast = false
|
||||||
|
|
||||||
it 'should not call EditorRealTimeController.emitToRoom', (done) ->
|
it 'should not call EditorRealTimeController.emitToRoom', (done) ->
|
||||||
|
@ -119,15 +119,15 @@ describe "ReferencesSearchController", ->
|
||||||
describe 'with docIds as an array and shouldBroadcast as false', ->
|
describe 'with docIds as an array and shouldBroadcast as false', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
|
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
|
||||||
@call = (callback) =>
|
@call = (callback) =>
|
||||||
@controller.index @req, @res
|
@controller.index @req, @res
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
it 'should call ReferencesSearchHandler.index', (done) ->
|
it 'should call ReferencesHandler.index', (done) ->
|
||||||
@call () =>
|
@call () =>
|
||||||
@ReferencesSearchHandler.index.callCount.should.equal 1
|
@ReferencesHandler.index.callCount.should.equal 1
|
||||||
@ReferencesSearchHandler.index.calledWith(@projectId, @docIds).should.equal true
|
@ReferencesHandler.index.calledWith(@projectId, @docIds).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should return data', (done) ->
|
it 'should return data', (done) ->
|
||||||
|
@ -148,10 +148,10 @@ describe "ReferencesSearchController", ->
|
||||||
@EditorRealTimeController.emitToRoom.callCount.should.equal 0
|
@EditorRealTimeController.emitToRoom.callCount.should.equal 0
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'when ReferencesSearchHandler.index produces an error', ->
|
describe 'when ReferencesHandler.index produces an error', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ReferencesSearchHandler.index.callsArgWith(2, new Error('woops'), null)
|
@ReferencesHandler.index.callsArgWith(2, new Error('woops'), null)
|
||||||
|
|
||||||
it 'should produce an error response', (done) ->
|
it 'should produce an error response', (done) ->
|
||||||
@call () =>
|
@call () =>
|
||||||
|
@ -162,7 +162,7 @@ describe "ReferencesSearchController", ->
|
||||||
describe 'when shouldBroadcast is true', ->
|
describe 'when shouldBroadcast is true', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
|
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
|
||||||
@req.body.shouldBroadcast = true
|
@req.body.shouldBroadcast = true
|
||||||
|
|
||||||
it 'should call EditorRealTimeController.emitToRoom', (done) ->
|
it 'should call EditorRealTimeController.emitToRoom', (done) ->
|
||||||
|
@ -194,9 +194,9 @@ describe "ReferencesSearchController", ->
|
||||||
@res.send.calledWith(400).should.equal true
|
@res.send.calledWith(400).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should not call ReferencesSearchHandler.index', (done) ->
|
it 'should not call ReferencesHandler.index', (done) ->
|
||||||
@call () =>
|
@call () =>
|
||||||
@ReferencesSearchHandler.index.callCount.should.equal 0
|
@ReferencesHandler.index.callCount.should.equal 0
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'with invalid docIds', ->
|
describe 'with invalid docIds', ->
|
||||||
|
@ -210,7 +210,7 @@ describe "ReferencesSearchController", ->
|
||||||
@res.send.calledWith(400).should.equal true
|
@res.send.calledWith(400).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should not call ReferencesSearchHandler.index', (done) ->
|
it 'should not call ReferencesHandler.index', (done) ->
|
||||||
@call () =>
|
@call () =>
|
||||||
@ReferencesSearchHandler.index.callCount.should.equal 0
|
@ReferencesHandler.index.callCount.should.equal 0
|
||||||
done()
|
done()
|
|
@ -3,9 +3,9 @@ should = require('chai').should()
|
||||||
expect = require('chai').expect
|
expect = require('chai').expect
|
||||||
sinon = require 'sinon'
|
sinon = require 'sinon'
|
||||||
assert = require("chai").assert
|
assert = require("chai").assert
|
||||||
modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchHandler"
|
modulePath = "../../../../app/js/Features/References/ReferencesHandler"
|
||||||
|
|
||||||
describe 'ReferencesSearchHandler', ->
|
describe 'ReferencesHandler', ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@projectId = '222'
|
@projectId = '222'
|
Loading…
Reference in a new issue