From f88e0ac0abd0024e595154568c8060b3fb833138 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Wed, 16 Apr 2014 10:42:32 -0700 Subject: [PATCH] Set up patches for components. --- app/models/CocoModel.coffee | 11 ++++++----- app/models/Patch.coffee | 5 ++++- app/styles/editor/level/component/edit.sass | 7 +++++++ app/templates/editor/level/component/edit.jade | 6 +++++- app/templates/editor/level/edit.jade | 3 +-- app/views/editor/level/component/edit.coffee | 13 ++++++++++--- app/views/editor/level/save_view.coffee | 2 +- app/views/editor/level/thangs_tab_view.coffee | 2 +- app/views/modal/save_version_modal.coffee | 13 +++++++------ 9 files changed, 42 insertions(+), 20 deletions(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index a99f48fd4..838b30530 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -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}}) diff --git a/app/models/Patch.coffee b/app/models/Patch.coffee index 68b62eca9..c505c93c0 100644 --- a/app/models/Patch.coffee +++ b/app/models/Patch.coffee @@ -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}}) \ No newline at end of file + PatchModel.setStatus @id, status + + @setStatus: (id, status) -> + $.ajax("/db/patch/#{id}/status", {type:"PUT", data: {status:status}}) \ No newline at end of file diff --git a/app/styles/editor/level/component/edit.sass b/app/styles/editor/level/component/edit.sass index 5c9deda4c..2cd8e5d4f 100644 --- a/app/styles/editor/level/component/edit.sass +++ b/app/styles/editor/level/component/edit.sass @@ -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 diff --git a/app/templates/editor/level/component/edit.jade b/app/templates/editor/level/component/edit.jade index 23c24cf6c..1a6d74d38 100644 --- a/app/templates/editor/level/component/edit.jade +++ b/app/templates/editor/level/component/edit.jade @@ -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 \ No newline at end of file diff --git a/app/templates/editor/level/edit.jade b/app/templates/editor/level/edit.jade index 873d881b4..297d000f8 100644 --- a/app/templates/editor/level/edit.jade +++ b/app/templates/editor/level/edit.jade @@ -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 diff --git a/app/views/editor/level/component/edit.coffee b/app/views/editor/level/component/edit.coffee index 3f91f1467..caf2340e5 100644 --- a/app/views/editor/level/component/edit.coffee +++ b/app/views/editor/level/component/edit.coffee @@ -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 \ No newline at end of file diff --git a/app/views/editor/level/save_view.coffee b/app/views/editor/level/save_view.coffee index f47b07657..86ba7e96b 100644 --- a/app/views/editor/level/save_view.coffee +++ b/app/views/editor/level/save_view.coffee @@ -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 diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index 5c5ca8dbd..3e0ed6583 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -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') diff --git a/app/views/modal/save_version_modal.coffee b/app/views/modal/save_version_modal.coffee index fda6b3951..d06aef707 100644 --- a/app/views/modal/save_version_modal.coffee +++ b/app/views/modal/save_version_modal.coffee @@ -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: ->