allow getting doc paths by project id

This commit is contained in:
Brian Gough
2018-09-24 16:04:23 +01:00
parent 5954e45016
commit 418bc10a18
3 changed files with 14 additions and 8 deletions

View File

@@ -65,6 +65,12 @@ module.exports = ProjectEntityHandler = self =
files.push({path: path.join(folderPath, file.name), file:file})
callback null, docs, files
getAllDocPathsFromProjectById: (project_id, callback) ->
ProjectGetter.getProjectWithoutDocLines project_id, (err, project) ->
return callback(err) if err?
return callback(Errors.NotFoundError("no project")) if !project?
self.getAllDocPathsFromProject project, callback
getAllDocPathsFromProject: (project, callback) ->
logger.log project:project, "getting all docs for project"
self._getAllFoldersFromProject project, (err, folders = {}) ->

View File

@@ -33,7 +33,7 @@ module.exports = ProjectRootDocManager =
callback()
setRootDocFromName: (project_id, rootDocName, callback = (error) ->) ->
ProjectEntityHandler.getAllDocPathsFromProject project_id, (error, docPaths) ->
ProjectEntityHandler.getAllDocPathsFromProjectById project_id, (error, docPaths) ->
return callback(error) if error?
# find the root doc from the filename
root_doc_id = null

View File

@@ -83,12 +83,12 @@ describe 'ProjectRootDocManager', ->
"doc-id-2": "/main.tex"
"doc-id-3": "/nested/chapter1a.tex"
"doc-id-4": "/nested/chapter1b.tex"
@ProjectEntityHandler.getAllDocPathsFromProject = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityHandler.getAllDocPathsFromProjectById = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
@ProjectRootDocManager.setRootDocFromName @project_id, '/main.tex', done
it "should check the docs of the project", ->
@ProjectEntityHandler.getAllDocPathsFromProject.calledWith(@project_id)
@ProjectEntityHandler.getAllDocPathsFromProjectById.calledWith(@project_id)
.should.equal true
it "should set the root doc to main.tex", ->
@@ -102,12 +102,12 @@ describe 'ProjectRootDocManager', ->
"doc-id-2": "/main.tex"
"doc-id-3": "/nested/chapter1a.tex"
"doc-id-4": "/nested/chapter1b.tex"
@ProjectEntityHandler.getAllDocPathsFromProject = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityHandler.getAllDocPathsFromProjectById = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
@ProjectRootDocManager.setRootDocFromName @project_id, 'main.tex', done
it "should check the docs of the project", ->
@ProjectEntityHandler.getAllDocPathsFromProject.calledWith(@project_id)
@ProjectEntityHandler.getAllDocPathsFromProjectById.calledWith(@project_id)
.should.equal true
it "should set the root doc to main.tex", ->
@@ -121,12 +121,12 @@ describe 'ProjectRootDocManager', ->
"doc-id-2": "/main.tex"
"doc-id-3": "/nested/chapter1a.tex"
"doc-id-4": "/nested/chapter1b.tex"
@ProjectEntityHandler.getAllDocPathsFromProject = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityHandler.getAllDocPathsFromProjectById = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
@ProjectRootDocManager.setRootDocFromName @project_id, 'chapter1a.tex', done
it "should check the docs of the project", ->
@ProjectEntityHandler.getAllDocPathsFromProject.calledWith(@project_id)
@ProjectEntityHandler.getAllDocPathsFromProjectById.calledWith(@project_id)
.should.equal true
it "should set the root doc using the basename", ->
@@ -140,7 +140,7 @@ describe 'ProjectRootDocManager', ->
"doc-id-2": "/main.tex"
"doc-id-3": "/nested/chapter1a.tex"
"doc-id-4": "/nested/chapter1b.tex"
@ProjectEntityHandler.getAllDocPathsFromProject = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityHandler.getAllDocPathsFromProjectById = sinon.stub().callsArgWith(1, null, @docPaths)
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
@ProjectRootDocManager.setRootDocFromName @project_id, "other.tex", done