mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-26 12:50:31 -04:00
Added a patches view.
This commit is contained in:
parent
2c67df355c
commit
bbb9fb7a64
8 changed files with 123 additions and 3 deletions
app
collections
lib
styles/editor
templates/editor
views
10
app/collections/PatchesCollection.coffee
Normal file
10
app/collections/PatchesCollection.coffee
Normal file
|
@ -0,0 +1,10 @@
|
|||
PatchModel = require 'models/Patch'
|
||||
CocoCollection = require 'models/CocoCollection'
|
||||
|
||||
module.exports = class PatchesCollection extends CocoCollection
|
||||
model: PatchModel
|
||||
|
||||
initialize: (models, options, forModel, @status='pending') ->
|
||||
super(arguments...)
|
||||
@url = "#{forModel.urlRoot}/#{forModel.get('original')}/patches?status=#{@status}"
|
||||
|
17
app/lib/NameLoader.coffee
Normal file
17
app/lib/NameLoader.coffee
Normal file
|
@ -0,0 +1,17 @@
|
|||
CocoClass = require 'lib/CocoClass'
|
||||
|
||||
namesCache = {}
|
||||
|
||||
class NameLoader extends CocoClass
|
||||
loadNames: (ids) ->
|
||||
toLoad = (id for id in ids when not namesCache[id])
|
||||
return false unless toLoad.length
|
||||
jqxhr = $.ajax('/db/user/x/names', {type:'POST', data:{ids:toLoad}})
|
||||
jqxhr.done @loadedNames
|
||||
|
||||
loadedNames: (newNames) =>
|
||||
_.extend namesCache, newNames
|
||||
|
||||
getName: (id) -> namesCache[id]
|
||||
|
||||
module.exports = new NameLoader()
|
3
app/styles/editor/patches.sass
Normal file
3
app/styles/editor/patches.sass
Normal file
|
@ -0,0 +1,3 @@
|
|||
.patches-view
|
||||
.status-buttons
|
||||
margin: 10px 0
|
27
app/templates/editor/patches.jade
Normal file
27
app/templates/editor/patches.jade
Normal file
|
@ -0,0 +1,27 @@
|
|||
.btn-group(data-toggle="buttons").status-buttons
|
||||
label.btn.btn-default.pending
|
||||
input(type="radio", name="status", value="pending")
|
||||
| Pending
|
||||
label.btn.btn-default.accepted
|
||||
input(type="radio", name="status", value="accepted")
|
||||
| Accepted
|
||||
label.btn.btn-default.rejected
|
||||
input(type="radio", name="status", value="rejected")
|
||||
| Rejected
|
||||
label.btn.btn-default.withdrawn
|
||||
input(type="radio", name="status", value="withdrawn")
|
||||
| Withdrawn
|
||||
|
||||
if patches.loading
|
||||
p Loading
|
||||
else
|
||||
table.table.table-condensed.table-bordered
|
||||
tr
|
||||
th Submitter
|
||||
th Submitted
|
||||
th Commit Message
|
||||
for patch in patches
|
||||
tr
|
||||
td= patch.userName
|
||||
td= moment(patch.get('created')).format('llll')
|
||||
td= patch.get('commitMessage')
|
|
@ -27,6 +27,8 @@ block content
|
|||
a(href="#editor-thang-spritesheets-view", data-toggle="tab") Spritesheets
|
||||
li
|
||||
a(href="#editor-thang-colors-tab-view", data-toggle="tab")#color-tab Colors
|
||||
li
|
||||
a(href="#editor-thang-patches-view", data-toggle="tab")#patches-tab Patches
|
||||
|
||||
div.tab-content
|
||||
div.tab-pane#editor-thang-colors-tab-view
|
||||
|
@ -83,6 +85,10 @@ block content
|
|||
div.tab-pane#editor-thang-spritesheets-view
|
||||
|
||||
div#spritesheets
|
||||
|
||||
div.tab-pane#editor-thang-patches-view
|
||||
|
||||
div.patches-view
|
||||
|
||||
div#error-view
|
||||
|
||||
|
|
49
app/views/editor/patches_view.coffee
Normal file
49
app/views/editor/patches_view.coffee
Normal file
|
@ -0,0 +1,49 @@
|
|||
CocoView = require 'views/kinds/CocoView'
|
||||
template = require 'templates/editor/patches'
|
||||
PatchesCollection = require 'collections/PatchesCollection'
|
||||
nameLoader = require 'lib/NameLoader'
|
||||
|
||||
module.exports = class PatchesView extends CocoView
|
||||
template: template
|
||||
className: 'patches-view'
|
||||
status: 'pending'
|
||||
|
||||
events:
|
||||
'change .status-buttons': 'onStatusButtonsChanged'
|
||||
|
||||
constructor: (@model, options) ->
|
||||
super(options)
|
||||
@initPatches()
|
||||
|
||||
initPatches: ->
|
||||
@startedLoading = false
|
||||
@patches = new PatchesCollection([], {}, @model, @status)
|
||||
@listenToOnce @patches, 'sync', @gotPatches
|
||||
@addResourceToLoad @patches, 'patches'
|
||||
|
||||
gotPatches: ->
|
||||
ids = (p.get('creator') for p in @patches.models)
|
||||
jqxhr = nameLoader.loadNames ids
|
||||
if jqxhr then @addRequestToLoad(jqxhr, 'user_names', 'gotPatches') else @render()
|
||||
|
||||
load: ->
|
||||
return if @startedLoading
|
||||
@patches.fetch()
|
||||
@startedLoading = true
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
patch.userName = nameLoader.getName(patch.get('creator')) for patch in @patches.models
|
||||
c.patches = @patches.models
|
||||
c.status
|
||||
c
|
||||
|
||||
afterRender: ->
|
||||
@$el.find(".#{@status}").addClass 'active'
|
||||
|
||||
onStatusButtonsChanged: (e) ->
|
||||
@loaded = false
|
||||
@status = $(e.target).val()
|
||||
@initPatches()
|
||||
@load()
|
||||
@render()
|
|
@ -9,6 +9,7 @@ View = require 'views/kinds/RootView'
|
|||
ThangComponentEditView = require 'views/editor/components/main'
|
||||
VersionHistoryView = require './versions_view'
|
||||
ColorsTabView = require './colors_tab_view'
|
||||
PatchesView = require 'views/editor/patches_view'
|
||||
SaveVersionModal = require 'views/modal/save_version_modal'
|
||||
ErrorView = require '../../error_view'
|
||||
template = require 'templates/editor/thang/edit'
|
||||
|
@ -35,6 +36,7 @@ module.exports = class ThangTypeEditView extends View
|
|||
'click #end-button': 'endAnimation'
|
||||
'click #history-button': 'showVersionHistory'
|
||||
'click #save-button': 'openSaveModal'
|
||||
'click #patches-tab': -> @patchesView.load()
|
||||
|
||||
subscriptions:
|
||||
'save-new-version': 'saveNewThangType'
|
||||
|
@ -92,6 +94,7 @@ module.exports = class ThangTypeEditView extends View
|
|||
@initSliders()
|
||||
@initComponents()
|
||||
@insertSubView(new ColorsTabView(@thangType))
|
||||
@patchesView = @insertSubView(new PatchesView(@thangType), @$el.find('.patches-view'))
|
||||
@showReadOnly() unless me.isAdmin() or @thangType.hasWriteAccess(me)
|
||||
|
||||
initComponents: =>
|
||||
|
|
|
@ -101,6 +101,7 @@ module.exports = class CocoView extends Backbone.View
|
|||
context.fbRef = context.pathname.replace(/[^a-zA-Z0-9+/=\-.:_]/g, '').slice(0, 40) or 'home'
|
||||
context.isMobile = @isMobile()
|
||||
context.isIE = @isIE()
|
||||
context.moment = moment
|
||||
context
|
||||
|
||||
afterRender: ->
|
||||
|
@ -300,18 +301,22 @@ module.exports = class CocoView extends Backbone.View
|
|||
# Subviews
|
||||
|
||||
insertSubView: (view, elToReplace=null) ->
|
||||
@subviews[view.id].destroy() if view.id of @subviews
|
||||
key = view.id or (view.constructor.name+classCount++)
|
||||
key = _.string.underscored(key)
|
||||
@subviews[key].destroy() if key of @subviews
|
||||
elToReplace ?= @$el.find('#'+view.id)
|
||||
elToReplace.after(view.el).remove()
|
||||
view.parent = @
|
||||
view.render()
|
||||
view.afterInsert()
|
||||
@subviews[view.id] = view
|
||||
view.parentKey = key
|
||||
@subviews[key] = view
|
||||
view
|
||||
|
||||
removeSubView: (view) ->
|
||||
view.$el.empty()
|
||||
delete @subviews[view.parentKey]
|
||||
view.destroy()
|
||||
delete @subviews[view.id]
|
||||
|
||||
# Utilities
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue