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" 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 =
@ -225,9 +223,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

View file

@ -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.sendStatus 400 return res.sendStatus 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.sendStatus 500 return res.sendStatus 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.sendStatus 500 return res.sendStatus 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

View file

@ -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"

View file

@ -38,7 +38,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")
@ -179,8 +179,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

View file

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

View file

@ -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: []

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 KiB

View file

@ -242,3 +242,81 @@
margin-top:10px; margin-top:10px;
margin-bottom:0px; 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() 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.sendStatus.calledWith(400).should.equal true @res.sendStatus.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.sendStatus.calledWith(400).should.equal true @res.sendStatus.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()

View file

@ -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'