Extended the save version modal to allow submitting patches.

This commit is contained in:
Scott Erickson 2014-04-10 13:09:44 -07:00
parent 3c832d3707
commit a3951b0fa7
10 changed files with 84 additions and 23 deletions

View file

@ -1,5 +1,6 @@
storage = require 'lib/storage'
deltasLib = require 'lib/deltas'
auth = require 'lib/auth'
class CocoSchema extends Backbone.Model
constructor: (path, args...) ->
@ -200,6 +201,8 @@ class CocoModel extends Backbone.Model
hasReadAccess: (actor) ->
# actor is a User object
actor ?= auth.me
return true if actor.isAdmin()
if @get('permissions')?
for permission in @get('permissions')
if permission.target is 'public' or actor.get('_id') is permission.target
@ -210,6 +213,8 @@ class CocoModel extends Backbone.Model
hasWriteAccess: (actor) ->
# actor is a User object
actor ?= auth.me
return true if actor.isAdmin()
if @get('permissions')?
for permission in @get('permissions')
if permission.target is 'public' or actor.get('_id') is permission.target

5
app/models/Patch.coffee Normal file
View file

@ -0,0 +1,5 @@
CocoModel = require('./CocoModel')
module.exports = class PatchModel extends CocoModel
@className: "Patch"
urlRoot: "/db/patch"

View file

@ -1,6 +1,11 @@
#save-version-modal
.modal-body
padding: 10px 50px 30px 20px
.modal-footer
text-align: left
.buttons
text-align: right
#cla-link
cursor: pointer

View file

@ -1,30 +1,46 @@
extends /templates/modal/modal_base
block modal-header-content
h3(data-i18n="versions.save_version_title") Save New Version
if isPatch
h3(data-i18n="versions.submit_patch_title") Submit Patch
else
h3(data-i18n="versions.save_version_title") Save New Version
block modal-body-content
.changes-stub
form.form-inline
.form-group.commit-message
input.form-control#commit-message(name="commitMessage", type="text", placeholder="Commit Message")
.checkbox
label
input#major-version(name="version-is-major", type="checkbox")
| Major Changes
if hasChanges
.changes-stub
form.form-inline
.form-group.commit-message
input.form-control#commit-message(name="commitMessage", type="text", placeholder="Commit Message")
if !isPatch
.checkbox
label
input#major-version(name="version-is-major", type="checkbox")
| Major Changes
else
.alert.alert-danger No changes
block modal-body-wait-content
h3(data-i18n="common.saving") Saving...
if hasChanges
if isPatch
h3(data-i18n="versions.submitting_patch") Submitting Patch...
else
h3(data-i18n="common.saving") Saving...
block modal-footer-content
if !noSaveButton
if hasChanges
#accept-cla-wrapper.alert.alert-info
span(data-i18n="versions.cla_prefix") To save changes, first you must agree to our
|
strong#cla-link(data-i18n="versions.cla_url") CLA
span(data-i18n="versions.cla_suffix") .
button.btn#agreement-button(data-i18n="versions.cla_agree") I AGREE
button.btn.btn-sm#agreement-button(data-i18n="versions.cla_agree") I AGREE
if isPatch
.alert.alert-info An owner will need to approve it before your changes will become visible.
button.btn(data-dismiss="modal", data-i18n="common.cancel") Cancel
if !noSaveButton
button.btn.btn-primary#save-version-button(data-i18n="common.save") Save
.buttons
button.btn(data-dismiss="modal", data-i18n="common.cancel") Cancel
if hasChanges && !isPatch
button.btn.btn-primary#save-version-button(data-i18n="common.save") Save
if hasChanges && isPatch
button.btn.btn-primary#submit-patch-button(data-i18n="versions.submit_patch") Submit Patch

View file

@ -38,8 +38,7 @@ module.exports = class UsersView extends View
@users.fetch()
@listenTo(@users, 'all', @render)
getRenderData: =>
getRenderData: ->
c = super()
c.users = (user.attributes for user in @users.models)
console.log('our render data', c)
c

View file

@ -25,7 +25,7 @@ module.exports = class LevelSaveView extends SaveVersionModal
context.levelNeedsSave = @level.hasLocalChanges()
context.modifiedComponents = _.filter @supermodel.getModels(LevelComponent), @shouldSaveEntity
context.modifiedSystems = _.filter @supermodel.getModels(LevelSystem), @shouldSaveEntity
context.noSaveButton = not (context.levelNeedsSave or context.modifiedComponents.length or context.modifiedSystems.length)
context.hasChanges = (context.levelNeedsSave or context.modifiedComponents.length or context.modifiedSystems.length)
@lastContext = context
context

View file

@ -1,6 +1,8 @@
ModalView = require 'views/kinds/ModalView'
template = require 'templates/modal/save_version'
DeltaView = require 'views/editor/delta'
Patch = require 'models/Patch'
forms = require 'lib/forms'
module.exports = class SaveVersionModal extends ModalView
id: 'save-version-modal'
@ -11,15 +13,23 @@ module.exports = class SaveVersionModal extends ModalView
'click #save-version-button': 'onClickSaveButton'
'click #cla-link': 'onClickCLALink'
'click #agreement-button': 'onAgreedToCLA'
'click #submit-patch-button': 'onClickPatchButton'
constructor: (options) ->
super options
@model = options.model
new Patch()
@isPatch = not @model.hasWriteAccess()
getRenderData: ->
c = super()
c.isPatch = @isPatch
c.hasChanges = @model.hasLocalChanges()
c
afterRender: ->
super()
@$el.find(if me.get('signedCLA') then '#accept-cla-wrapper' else '#save-version-button').hide()
return unless @model
changeEl = @$el.find('.changes-stub')
deltaView = new DeltaView({model:@model})
@insertSubView(deltaView, changeEl)
@ -30,6 +40,27 @@ module.exports = class SaveVersionModal extends ModalView
commitMessage: @$el.find('#commit-message').val()
}
onClickPatchButton: ->
forms.clearFormAlerts @$el
patch = new Patch()
patch.set 'delta', @model.getDelta()
patch.set 'commitMessage', @$el.find('#commit-message').val()
patch.set 'target', {
'collection': _.string.underscored @model.constructor.className
'id': @model.id
}
errors = patch.validate()
forms.applyErrorsToForm(@$el, errors) if errors
res = patch.save()
return unless res
@enableModalInProgress(@$el)
res.error =>
@disableModalInProgress(@$el)
res.success =>
@hide()
onClickCLALink: ->
window.open('/cla', 'cla', 'height=800,width=900')

View file

@ -7,7 +7,7 @@ mongoose = require('mongoose')
PatchHandler = class PatchHandler extends Handler
modelClass: Patch
editableProperties: []
postEditableProperties: ['delta', 'target']
postEditableProperties: ['delta', 'target', 'commitMessage']
jsonSchema: require './patch_schema'
makeNewInstance: (req) ->

View file

@ -2,10 +2,9 @@ c = require '../commons/schemas'
patchables = ['level', 'thang_type', 'level_system', 'level_component', 'article']
PatchSchema = c.object({title:'Patch', required:['target', 'delta']}, {
PatchSchema = c.object({title:'Patch', required:['target', 'delta', 'commitMessage']}, {
delta: { title: 'Delta', type:['array', 'object'] }
title: c.shortString()
description: c.shortString({maxLength: 500})
commitMessage: c.shortString({maxLength: 500, minLength: 1})
creator: c.objectId(links: [{rel: 'extra', href: "/db/user/{($)}"}])
created: c.date( { title: 'Created', readOnly: true })
status: { enum: ['pending', 'accepted', 'rejected', 'withdrawn']}

View file

@ -14,6 +14,7 @@ describe '/db/patch', ->
patchURL = getURL('/db/patch')
patches = {}
patch =
commitMessage: 'Accept this patch!'
delta: {name:['test']}
target:
id:null