Merge branch 'sk-references-search'

Conflicts:
	app/coffee/Features/References/ReferencesController.coffee
This commit is contained in:
Shane Kilkelly 2016-02-19 11:30:55 +00:00
commit b505f0d455
10 changed files with 120 additions and 47 deletions

View file

@ -17,8 +17,6 @@ SecurityManager = require("../../managers/SecurityManager")
fs = require "fs"
InactiveProjectManager = require("../InactiveData/InactiveProjectManager")
ProjectUpdateHandler = require("./ProjectUpdateHandler")
ReferencesSearchHandler = require("../ReferencesSearch/ReferencesSearchHandler")
module.exports = ProjectController =
@ -225,9 +223,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.sendStatus 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.sendStatus 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.sendStatus 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

@ -38,7 +38,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")
@ -179,8 +179,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"
@ -39,7 +39,7 @@ define [
PermissionsManager
PdfManager
BinaryFilesManager
ReferencesSearchManager
ReferencesManager
) ->
App.controller "IdeController", ($scope, $timeout, ide, localStorage) ->
@ -75,7 +75,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: []

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 KiB

View file

@ -242,3 +242,81 @@
margin-top:10px;
margin-bottom:0px;
}
// -- References Search Modal --
.references-search-modal-backdrop {
// don't grey out the editor when the
// modal is active
background-color: transparent;
}
.references-search-modal {
// upgrade prompt
.references-search-upgrade-prompt {
padding: 24px;
padding-bottom: 48px;
.upgrade-prompt {
text-align: center;
width: 400px;
padding-top: 14px;
padding-bottom: 14px;
padding-left: 38px;
padding-right: 38px;
margin: auto;
background: white;
opacity: 0.95;
border-radius: 8px;
.message {
margin-top: 15px;
&.call-to-action {
font-weight: bold;
}
ul.list-unstyled {
text-align: left;
}
}
a.btn {
opacity: 1.0;
}
}
}
.search-form {
// position the spinner inside the input element
i.fa-spinner {
margin-top: -30px;
}
}
.alert-danger {
margin-top: 12px;
margin-bottom: 0px;
}
// search result items list
.search-results {
margin-top: 14px;
font-size: 12px;
.no-results-message {
font-size: 16px;
}
.search-result-hit {
&:hover {
cursor: pointer;
}
border-bottom: 1px solid #ddd;
padding: 8px;
&:last-child {
border-bottom: 1px solid transparent;
}
border-left: 4px solid transparent;
&.selected-search-result-hit {
background-color: @red;
color: white;
.hit-year.small {
color: white;
}
}
.hit-title {
font-size: 1.3em;
font-style: italic;
}
}
}
}

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.sendStatus.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.sendStatus.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'