Refactor ReferencesSearch* to just References*.

This commit is contained in:
Shane Kilkelly 2016-02-08 17:04:27 +00:00
parent b978171e0c
commit 326d9e59f8
8 changed files with 42 additions and 47 deletions

View file

@ -16,8 +16,6 @@ SecurityManager = require("../../managers/SecurityManager")
fs = require "fs"
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
ProjectUpdateHandler = require("./ProjectUpdateHandler")
ReferencesSearchHandler = require("../ReferencesSearch/ReferencesSearchHandler")
module.exports = ProjectController =
@ -218,9 +216,6 @@ module.exports = ProjectController =
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
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"
res.render 'project/editor',
title: project.name

View file

@ -1,9 +1,9 @@
logger = require('logger-sharelatex')
ReferencesSearchHandler = require('./ReferencesSearchHandler')
ReferencesHandler = require('./ReferencesHandler')
settings = require('settings-sharelatex')
EditorRealTimeController = require("../Editor/EditorRealTimeController")
module.exports = ReferencesSearchController =
module.exports = ReferencesController =
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'"
return res.send 400
logger.log {projectId, docIds: docIds}, "index references for project"
ReferencesSearchHandler.index projectId, docIds, (err, data) ->
ReferencesHandler.index projectId, docIds, (err, data) ->
if err
logger.err {err, projectId}, "error indexing all references"
return res.send 500
ReferencesSearchController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
indexAll: (req, res) ->
projectId = req.params.Project_id
shouldBroadcast = req.body.shouldBroadcast
logger.log {projectId}, "index all references for project"
ReferencesSearchHandler.indexAll projectId, (err, data) ->
ReferencesHandler.indexAll projectId, (err, data) ->
if err
logger.err {err, projectId}, "error indexing all references"
return res.send 500
ReferencesSearchController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data)
_handleIndexResponse: (req, res, projectId, shouldBroadcast, data) ->
if shouldBroadcast

View file

@ -10,7 +10,7 @@ oneMinInMs = 60 * 1000
fiveMinsInMs = oneMinInMs * 5
module.exports = ReferencesSearchHandler =
module.exports = ReferencesHandler =
_buildDocUrl: (projectId, docId) ->
"#{settings.apis.docstore.url}/project/#{projectId}/doc/#{docId}/raw"
@ -40,18 +40,18 @@ module.exports = ReferencesSearchHandler =
logger.err {err, projectId}, "error finding project"
return callback(err)
logger.log {projectId}, "indexing all bib files in project"
docIds = ReferencesSearchHandler._findBibDocIds(project)
ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
docIds = ReferencesHandler._findBibDocIds(project)
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
index: (projectId, docIds, callback=(err, data)->) ->
Project.findPopulatedById projectId, (err, project) ->
if err
logger.err {err, projectId}, "error finding project"
return callback(err)
ReferencesSearchHandler._doIndexOperation(projectId, project, docIds, callback)
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
_doIndexOperation: (projectId, project, docIds, callback) ->
ReferencesSearchHandler._isFullIndex project, (err, isFullIndex) ->
ReferencesHandler._isFullIndex project, (err, isFullIndex) ->
if err
logger.err {err, projectId}, "error checking whether to do full index"
return callback(err)
@ -64,7 +64,7 @@ module.exports = ReferencesSearchHandler =
logger.err {err, projectId, docIds}, "error flushing docs to mongo"
return callback(err)
bibDocUrls = docIds.map (docId) ->
ReferencesSearchHandler._buildDocUrl projectId, docId
ReferencesHandler._buildDocUrl projectId, docId
logger.log {projectId, isFullIndex, docIds, bibDocUrls}, "sending request to references service"
request.post {
url: "#{settings.apis.references.url}/project/#{projectId}/index"

View file

@ -37,7 +37,7 @@ RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
ContactRouter = require("./Features/Contacts/ContactRouter")
ReferencesSearchController = require('./Features/ReferencesSearch/ReferencesSearchController')
ReferencesController = require('./Features/References/ReferencesController')
logger = require("logger-sharelatex")
_ = require("underscore")
@ -175,8 +175,8 @@ module.exports = class Router
webRouter.get /learn(\/.*)?/, WikiController.getPage
webRouter.post "/project/:Project_id/references/index", SecurityManager.requestCanAccessProject, ReferencesSearchController.index
webRouter.post "/project/:Project_id/references/indexAll", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexAll
webRouter.post "/project/:Project_id/references/index", SecurityManager.requestCanAccessProject, ReferencesController.index
webRouter.post "/project/:Project_id/references/indexAll", SecurityManager.requestCanAccessProject, ReferencesController.indexAll
#Admin Stuff
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index

View file

@ -8,7 +8,7 @@ define [
"ide/permissions/PermissionsManager"
"ide/pdf/PdfManager"
"ide/binary-files/BinaryFilesManager"
"ide/references-search/ReferencesSearchManager"
"ide/references/ReferencesManager"
"ide/settings/index"
"ide/share/index"
"ide/chat/index"
@ -38,7 +38,7 @@ define [
PermissionsManager
PdfManager
BinaryFilesManager
ReferencesSearchManager
ReferencesManager
) ->
App.controller "IdeController", ($scope, $timeout, ide, localStorage) ->
@ -74,7 +74,7 @@ define [
ide.project_id = $scope.project_id = window.project_id
ide.$scope = $scope
ide.referencesSearchManager = new ReferencesSearchManager(ide, $scope)
ide.referencesSearchManager = new ReferencesManager(ide, $scope)
ide.connectionManager = new ConnectionManager(ide, $scope)
ide.fileTreeManager = new FileTreeManager(ide, $scope)
ide.editorManager = new EditorManager(ide, $scope)

View file

@ -1,6 +1,6 @@
define [
], () ->
class ReferencesSearchManager
class ReferencesManager
constructor: (@ide, @$scope) ->
@$scope.$root._references = @state = keys: []

View file

@ -2,11 +2,11 @@ SandboxedModule = require('sandboxed-module')
should = require('chai').should()
sinon = require 'sinon'
assert = require("chai").assert
modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchController"
modulePath = "../../../../app/js/Features/References/ReferencesController"
MockRequest = require "../helpers/MockRequest"
MockResponse = require "../helpers/MockResponse"
describe "ReferencesSearchController", ->
describe "ReferencesController", ->
beforeEach ->
@projectId = '2222'
@ -18,7 +18,7 @@ describe "ReferencesSearchController", ->
'settings-sharelatex': @settings = {
apis: {web: {url: 'http://some.url'}}
},
'./ReferencesSearchHandler': @ReferencesSearchHandler = {
'./ReferencesHandler': @ReferencesHandler = {
index: sinon.stub()
indexAll: sinon.stub()
},
@ -41,7 +41,7 @@ describe "ReferencesSearchController", ->
beforeEach ->
@req.body = {shouldBroadcast: false}
@ReferencesSearchHandler.indexAll.callsArgWith(1, null, @fakeResponseData)
@ReferencesHandler.indexAll.callsArgWith(1, null, @fakeResponseData)
@call = (callback) =>
@controller.indexAll @req, @res
callback()
@ -59,16 +59,16 @@ describe "ReferencesSearchController", ->
@res.json.calledWith(@fakeResponseData).should.equal true
done()
it 'should call ReferencesSearchHandler.indexAll', (done) ->
it 'should call ReferencesHandler.indexAll', (done) ->
@call () =>
@ReferencesSearchHandler.indexAll.callCount.should.equal 1
@ReferencesSearchHandler.indexAll.calledWith(@projectId).should.equal true
@ReferencesHandler.indexAll.callCount.should.equal 1
@ReferencesHandler.indexAll.calledWith(@projectId).should.equal true
done()
describe 'when shouldBroadcast is true', ->
beforeEach ->
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
@req.body.shouldBroadcast = true
it 'should call EditorRealTimeController.emitToRoom', (done) ->
@ -92,7 +92,7 @@ describe "ReferencesSearchController", ->
describe 'when shouldBroadcast is false', ->
beforeEach ->
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
@req.body.shouldBroadcast = false
it 'should not call EditorRealTimeController.emitToRoom', (done) ->
@ -119,15 +119,15 @@ describe "ReferencesSearchController", ->
describe 'with docIds as an array and shouldBroadcast as false', ->
beforeEach ->
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
@call = (callback) =>
@controller.index @req, @res
callback()
it 'should call ReferencesSearchHandler.index', (done) ->
it 'should call ReferencesHandler.index', (done) ->
@call () =>
@ReferencesSearchHandler.index.callCount.should.equal 1
@ReferencesSearchHandler.index.calledWith(@projectId, @docIds).should.equal true
@ReferencesHandler.index.callCount.should.equal 1
@ReferencesHandler.index.calledWith(@projectId, @docIds).should.equal true
done()
it 'should return data', (done) ->
@ -148,10 +148,10 @@ describe "ReferencesSearchController", ->
@EditorRealTimeController.emitToRoom.callCount.should.equal 0
done()
describe 'when ReferencesSearchHandler.index produces an error', ->
describe 'when ReferencesHandler.index produces an error', ->
beforeEach ->
@ReferencesSearchHandler.index.callsArgWith(2, new Error('woops'), null)
@ReferencesHandler.index.callsArgWith(2, new Error('woops'), null)
it 'should produce an error response', (done) ->
@call () =>
@ -162,7 +162,7 @@ describe "ReferencesSearchController", ->
describe 'when shouldBroadcast is true', ->
beforeEach ->
@ReferencesSearchHandler.index.callsArgWith(2, null, @fakeResponseData)
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
@req.body.shouldBroadcast = true
it 'should call EditorRealTimeController.emitToRoom', (done) ->
@ -194,9 +194,9 @@ describe "ReferencesSearchController", ->
@res.send.calledWith(400).should.equal true
done()
it 'should not call ReferencesSearchHandler.index', (done) ->
it 'should not call ReferencesHandler.index', (done) ->
@call () =>
@ReferencesSearchHandler.index.callCount.should.equal 0
@ReferencesHandler.index.callCount.should.equal 0
done()
describe 'with invalid docIds', ->
@ -210,7 +210,7 @@ describe "ReferencesSearchController", ->
@res.send.calledWith(400).should.equal true
done()
it 'should not call ReferencesSearchHandler.index', (done) ->
it 'should not call ReferencesHandler.index', (done) ->
@call () =>
@ReferencesSearchHandler.index.callCount.should.equal 0
@ReferencesHandler.index.callCount.should.equal 0
done()

View file

@ -3,9 +3,9 @@ should = require('chai').should()
expect = require('chai').expect
sinon = require 'sinon'
assert = require("chai").assert
modulePath = "../../../../app/js/Features/ReferencesSearch/ReferencesSearchHandler"
modulePath = "../../../../app/js/Features/References/ReferencesHandler"
describe 'ReferencesSearchHandler', ->
describe 'ReferencesHandler', ->
beforeEach ->
@projectId = '222'