added rename project to list page

This commit is contained in:
Henry Oswald 2014-04-28 17:47:47 +01:00
parent 3655e83ff9
commit bf2c60f84d
6 changed files with 88 additions and 2 deletions

View file

@ -3,6 +3,7 @@ logger = require("logger-sharelatex")
projectDeleter = require("./ProjectDeleter")
projectDuplicator = require("./ProjectDuplicator")
projectCreationHandler = require("./ProjectCreationHandler")
editorController = require("../Editor/EditorController")
metrics = require('../../infrastructure/Metrics')
sanitize = require('sanitizer')
Project = require('../../models/Project').Project
@ -58,6 +59,16 @@ module.exports =
res.send {project_id:project._id}
renameProject: (req, res)->
project_id = req.params.Project_id
newName = req.body.newProjectName
editorController.renameProject project_id, newName, (err)->
if err?
logger.err err:err, project_id:project_id, newName:newName, "problem renaming project"
res.send 500
else
res.send 200
projectListPage: (req, res, next)->
timer = new metrics.Timer("project-list")
user_id = req.session.user._id

View file

@ -96,6 +96,7 @@ module.exports = class Router
app.get '/project', AuthenticationController.requireLogin(), ProjectController.projectListPage
app.post '/project/new', AuthenticationController.requireLogin(), ProjectController.newProject
app.get '/project/new/template', TemplatesMiddlewear.saveTemplateDataInSession, AuthenticationController.requireLogin(), TemplatesController.createProjectFromZipTemplate
app.get '/Project/:Project_id', SecurityManager.requestCanAccessProject, ProjectController.loadEditor
@ -118,6 +119,8 @@ module.exports = class Router
app.del '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject
app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, ProjectController.cloneProject
app.post '/project/:Project_id/rename', SecurityManager.requestIsOwner, ProjectController.renameProject
app.post '/Project/:Project_id/snapshot', SecurityManager.requestCanModifyProject, versioningController.takeSnapshot
app.get '/Project/:Project_id/version', SecurityManager.requestCanAccessProject, versioningController.listVersions
app.get '/Project/:Project_id/version/:Version_id', SecurityManager.requestCanAccessProject, versioningController.getVersion

View file

@ -10,6 +10,17 @@
button.btn.btn-danger.confirm Delete Forever
button.btn.cancel No
#renameProjectModal(style='display: none')
.modal
.modal-header
h3 Rename Project
.modal-body
form.form-horizontal(onkeydown="if (event.keyCode == 13){event.preventDefault(); document.getElementById('confirmRename').click()}")
input.inputmodal#projectNewName(placeholder='name')
.modal-footer
button.btn.btn-primary#confirmRename Rename
button.btn.cancel Cancel
#leaveProjectModal(style='display: none')
.modal
.modal-header

View file

@ -30,6 +30,8 @@ block content
-if (project.accessLevel == "owner")
li
a(href='/project/'+project_id, data-name=project.name, data-id=project_id, data-csrf=csrfToken).deleteProject Delete Project
li
a(href='/project/'+project_id+'/rename', data-name=project.name, data-id=project_id, data-csrf=csrfToken).renameProject Rename Project
-else
li
a(href='/project/'+project_id+'/leave', data-name=project.name, data-id=project_id, data-csrf=csrfToken).leaveProject Leave Project

View file

@ -58,7 +58,7 @@ require [
name = $(@).data("name")
id = $(@).data("id")
nameEl = $modal.find(".name").text(name)
$modal.find(".name").text(name)
href = this.href
self = @
@ -79,6 +79,40 @@ require [
$modal.find('.cancel').click (e)->
$modal.modal('hide')
$('.renameProject').click (event)->
event.preventDefault()
$modal = $('#renameProjectModal')
$confirm = $modal.find('#confirmRename')
$modal.modal({backdrop:true, show:true, keyboard:true})
name = $(@).data("name")
nameEl = $modal.find("#projectNewName").val(name)
nameEl.select()
href = this.href
self = @
window.r = @
$confirm.on 'click', (e) =>
newProjectName = nameEl.val()
$.ajax
url: href
type:'POST'
data:
_csrf: $(@).data("csrf")
newProjectName:newProjectName
success: (data)->
$modal.modal('hide')
if data.message
new Message data
else
$(self.parentNode.parentNode.parentNode.parentNode).find(".projectName").text(newProjectName)
$(self.parentNode.parentNode).find("li a").each ()->
$(this).data('name', newProjectName)
$modal.on 'hide', ->
$confirm.off 'click'
$modal.find('.cancel').click (e)->
$modal.modal('hide')
$(".leaveProject").click (event) ->
event.preventDefault()
$modal = $('#leaveProjectModal')

View file

@ -35,12 +35,17 @@ describe "ProjectController", ->
findById: sinon.stub()
@SecurityManager =
userCanAccessProject:sinon.stub()
@EditorController =
renameProject:sinon.stub()
@ProjectController = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"logger-sharelatex":
log:->
err:->
"./ProjectDeleter": @ProjectDeleter
"./ProjectDuplicator": @ProjectDuplicator
"./ProjectCreationHandler": @ProjectCreationHandler
"../Editor/EditorController": @EditorController
"../Subscription/SubscriptionLocator": @SubscriptionLocator
"../Tags/TagsHandler":@TagsHandler
'../../models/Project': Project:@ProjectModel
@ -130,6 +135,26 @@ describe "ProjectController", ->
done()
@ProjectController.projectListPage @req, @res
describe "renameProject", ->
beforeEach ->
@newProjectName = "my supper great new project"
@req.body.newProjectName = @newProjectName
it "should call the editor controller", (done)->
@EditorController.renameProject.callsArgWith(2)
@res.send = (code)=>
code.should.equal 200
@EditorController.renameProject.calledWith(@project_id, @newProjectName).should.equal true
done()
@ProjectController.renameProject @req, @res
it "should send a 500 if there is a problem", (done)->
@EditorController.renameProject.callsArgWith(2, "problem")
@res.send = (code)=>
code.should.equal 500
@EditorController.renameProject.calledWith(@project_id, @newProjectName).should.equal true
done()
@ProjectController.renameProject @req, @res
describe "loadEditor", ->
beforeEach ->