Set up patches for components.

This commit is contained in:
Scott Erickson 2014-04-16 10:42:32 -07:00
parent c395a3414e
commit f88e0ac0ab
9 changed files with 42 additions and 20 deletions

View file

@ -68,7 +68,8 @@ class CocoModel extends Backbone.Model
@markToRevert()
@clearBackup()
@trigger "save", @
patch.setStatus 'accepted' for patch in @acceptedPatches or []
PatchModel = require 'models/Patch'
PatchModel.setStatus id, 'accepted' for id in @get('acceptedPatches') or []
return super attrs, options
fetch: ->
@ -95,7 +96,6 @@ class CocoModel extends Backbone.Model
cloneNewMinorVersion: ->
newData = $.extend(null, {}, @attributes)
clone = new @constructor(newData)
clone.acceptedPatches = @acceptedPatches
clone
cloneNewMajorVersion: ->
@ -222,9 +222,10 @@ class CocoModel extends Backbone.Model
deltasLib.expandDelta(delta, @_revertAttributes, @schema())
addPatchToAcceptOnSave: (patch) ->
@acceptedPatches ?= []
@acceptedPatches.push patch
@acceptedPatches = _.uniq(@acceptedPatches, false, (p) -> p.id)
acceptedPatches = @get('acceptedPatches') or [] # not actually stored on the db
acceptedPatches.push patch.id
acceptedPatches = _.uniq(acceptedPatches)
@set 'acceptedPatches', acceptedPatches
watch: (doWatch=true) ->
$.ajax("#{@urlRoot}/#{@id}/watch", {type:'PUT', data:{on:doWatch}})

View file

@ -5,4 +5,7 @@ module.exports = class PatchModel extends CocoModel
urlRoot: "/db/patch"
setStatus: (status) ->
$.ajax("/db/patch/#{@id}/status", {type:"PUT", data: {status:status}})
PatchModel.setStatus @id, status
@setStatus: (id, status) ->
$.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}})

View file

@ -1,4 +1,11 @@
#editor-level-component-edit-view
nav
margin-bottom: 0
#component-patches
padding: 0 10px 10px
background: white
.navbar-text
float: left

View file

@ -14,10 +14,12 @@ nav.navbar.navbar-default(role='navigation')
a(href="#component-config-schema" data-toggle="tab" data-i18n="editor.level_component_config_schema") Config Schema
li
a(href="#component-settings" data-toggle="tab" data-i18n="editor.level_component_settings") Settings
li
a(href="#component-patches" data-toggle="tab" data-i18n="resources.patches")#component-patches-tab Patches
ul.nav.navbar-nav.navbar-left
li(data-i18n="general.version_history").btn.btn-primary.navbar-btn#history-button Version History
ul.nav.navbar-nav.navbar-right
li(data-i18n="editor.level_component_btn_new").btn.btn-primary.navbar-btn#create-new-component-button Create New Component
li.btn.btn-primary.navbar-btn#patch-component-button Patch
.tab-content
.tab-pane.active#component-code
@ -26,3 +28,5 @@ nav.navbar.navbar-default(role='navigation')
#config-schema-treema
.tab-pane#component-settings
#edit-component-treema
.tab-pane#component-patches
.patches-view

View file

@ -30,7 +30,6 @@ block outer_content
a(href="#editor-level-patches", data-toggle="tab")#patches-tab
span(data-i18n="resources.patches").spr Patches
- var patches = level.get('patches')
- patches = [1,2,3,3,4,5,6]
if patches && patches.length
span.badge= patches.length
@ -42,7 +41,7 @@ block outer_content
span.unwatch.secret
span.spr Unwatch
span.glyphicon.glyphicon-eye-close
li(data-toggle="coco-modal", data-target="modal/revert", data-i18n="editor.revert", disabled=authorized === true ? undefined : "true").btn.btn-primary.navbar-btn#revert-button Revert
li(data-toggle="coco-modal", data-target="modal/revert", data-i18n="editor.revert", disabled=anonymous ? "true": undefined).btn.btn-primary.navbar-btn#revert-button Revert
if authorized
li(data-i18n="common.save").btn.btn-primary.navbar-btn#commit-level-start-button Save
else

View file

@ -2,6 +2,8 @@ View = require 'views/kinds/CocoView'
VersionHistoryView = require 'views/editor/component/versions_view'
template = require 'templates/editor/level/component/edit'
LevelComponent = require 'models/LevelComponent'
PatchesView = require 'views/editor/patches_view'
SaveVersionModal = require 'views/modal/save_version_modal'
module.exports = class LevelComponentEditView extends View
id: "editor-level-component-edit-view"
@ -12,6 +14,8 @@ module.exports = class LevelComponentEditView extends View
'click #done-editing-component-button': 'endEditing'
'click #history-button': 'showVersionHistory'
'click .nav a': (e) -> $(e.target).tab('show')
'click #component-patches-tab': -> @patchesView.load()
'click #patch-component-button': 'startPatchingComponent'
constructor: (options) ->
super options
@ -21,6 +25,7 @@ module.exports = class LevelComponentEditView extends View
getRenderData: (context={}) ->
context = super(context)
context.editTitle = "#{@levelComponent.get('system')}.#{@levelComponent.get('name')}"
context.component = @levelComponent
context
afterRender: ->
@ -28,6 +33,7 @@ module.exports = class LevelComponentEditView extends View
@buildSettingsTreema()
@buildConfigSchemaTreema()
@buildCodeEditor()
@patchesView = @insertSubView(new PatchesView(@levelComponent), @$el.find('.patches-view'))
buildSettingsTreema: ->
data = _.pick @levelComponent.attributes, (value, key) => key in @editableSettings
@ -40,7 +46,6 @@ module.exports = class LevelComponentEditView extends View
schema: schema
data: data
callbacks: {change: @onComponentSettingsEdited}
treemaOptions.readOnly = true unless me.isAdmin()
@componentSettingsTreema = @$el.find('#edit-component-treema').treema treemaOptions
@componentSettingsTreema.build()
@componentSettingsTreema.open()
@ -58,7 +63,6 @@ module.exports = class LevelComponentEditView extends View
schema: LevelComponent.schema.properties.configSchema
data: @levelComponent.get 'configSchema'
callbacks: {change: @onConfigSchemaEdited}
treemaOptions.readOnly = true unless me.isAdmin()
@configSchemaTreema = @$el.find('#config-schema-treema').treema treemaOptions
@configSchemaTreema.build()
@configSchemaTreema.open()
@ -73,7 +77,6 @@ module.exports = class LevelComponentEditView extends View
editorEl = @$el.find '#component-code-editor'
editorEl.text @levelComponent.get('code')
@editor = ace.edit(editorEl[0])
@editor.setReadOnly(not me.isAdmin())
session = @editor.getSession()
session.setMode 'ace/mode/coffee'
session.setTabSize 2
@ -97,4 +100,8 @@ module.exports = class LevelComponentEditView extends View
showVersionHistory: (e) ->
versionHistoryView = new VersionHistoryView component:@levelComponent, @levelComponent.id
@openModalView versionHistoryView
Backbone.Mediator.publish 'level:view-switched', e
startPatchingComponent: (e) ->
@openModalView new SaveVersionModal({model:@levelComponent})
Backbone.Mediator.publish 'level:view-switched', e

View file

@ -30,7 +30,7 @@ module.exports = class LevelSaveView extends SaveVersionModal
context
afterRender: ->
super()
super(false)
changeEls = @$el.find('.changes-stub')
models = if @lastContext.levelNeedsSave then [@level] else []
models = models.concat @lastContext.modifiedComponents

View file

@ -255,7 +255,7 @@ module.exports = class ThangsTabView extends View
# @thangsTreema.deselectAll()
selectAddThang: (e) =>
return unless $(e.target).closest('.editor-level-thangs-tab-view').length
return unless (not e) or $(e.target).closest('.editor-level-thangs-tab-view').length
if e then target = $(e.target) else target = @$el.find('.add-thangs-palette') # pretend to click on background if no event
return true if target.attr('id') is 'surface'
target = target.closest('.add-thang-palette-icon')

View file

@ -27,15 +27,16 @@ module.exports = class SaveVersionModal extends ModalView
c.hasChanges = @model.hasLocalChanges()
c
afterRender: ->
afterRender: (insertDeltaView=true) ->
super()
@$el.find(if me.get('signedCLA') then '#accept-cla-wrapper' else '#save-version-button').hide()
changeEl = @$el.find('.changes-stub')
try
deltaView = new DeltaView({model:@model})
@insertSubView(deltaView, changeEl)
catch e
console.error "Couldn't create delta view:", e
if insertDeltaView
try
deltaView = new DeltaView({model:@model})
@insertSubView(deltaView, changeEl)
catch e
console.error "Couldn't create delta view:", e
@$el.find('.commit-message input').attr('placeholder', $.i18n.t('general.commit_msg'))
onClickSaveButton: ->