mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Switched listen to watch (would have been confusing with eye-con, and listenTo function in Backbone). Added watch button and patch badge to level editor.
This commit is contained in:
parent
522dc6fb7d
commit
58b1019934
8 changed files with 55 additions and 22 deletions
|
@ -15,6 +15,8 @@
|
|||
fork: "Fork"
|
||||
play: "Play"
|
||||
retry: "Retry"
|
||||
watch: "Watch"
|
||||
unwatch: "Unwatch"
|
||||
|
||||
units:
|
||||
second: "second"
|
||||
|
|
|
@ -225,5 +225,11 @@ class CocoModel extends Backbone.Model
|
|||
@acceptedPatches ?= []
|
||||
@acceptedPatches.push patch
|
||||
@acceptedPatches = _.uniq(@acceptedPatches, false, (p) -> p.id)
|
||||
|
||||
watch: (doWatch=true) ->
|
||||
$.ajax("#{@urlRoot}/#{@id}/watch", {type:'PUT', data:{on:doWatch}})
|
||||
|
||||
watching: ->
|
||||
return me.id in @get('watchers') or []
|
||||
|
||||
module.exports = CocoModel
|
||||
|
|
|
@ -63,7 +63,7 @@ patchableProps = ->
|
|||
status: { enum: ['pending', 'accepted', 'rejected', 'cancelled']}
|
||||
})
|
||||
allowPatches: { type: 'boolean' }
|
||||
listeners: me.array({title:'Listeners'},
|
||||
watchers: me.array({title:'Watchers'},
|
||||
me.objectId(links: [{rel: 'extra', href: "/db/user/{($)}"}]))
|
||||
|
||||
me.extendPatchableProperties = (schema) ->
|
||||
|
|
|
@ -265,3 +265,8 @@ body[lang='ja']
|
|||
font-family: 'Glyphicons Halflings'
|
||||
src: url("/fonts/glyphicons-halflings-regular.eot")
|
||||
src: url("/fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"), url("/fonts/glyphicons-halflings-regular.woff") format("woff"), url("/fonts/glyphicons-halflings-regular.ttf") format("truetype"), url("/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular") format("svg")
|
||||
|
||||
.spr:after
|
||||
content: " "
|
||||
.spl:before
|
||||
content: " "
|
|
@ -27,10 +27,21 @@ block outer_content
|
|||
li
|
||||
a(href="#editor-level-systems-tab-view", data-toggle="tab", data-i18n="editor.level_tab_systems") Systems
|
||||
li
|
||||
a(href="#editor-level-patches", data-toggle="tab", data-i18n="resources.patches")#patches-tab Patches
|
||||
|
||||
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
|
||||
|
||||
ul.nav.navbar-nav.navbar-right
|
||||
li#watch-button.btn.btn-primary.navbar-btn
|
||||
span.watch
|
||||
span.spr Watch
|
||||
span.glyphicon.glyphicon-eye-open
|
||||
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
|
||||
if authorized
|
||||
li(data-i18n="common.save").btn.btn-primary.navbar-btn#commit-level-start-button Save
|
||||
|
|
|
@ -30,6 +30,7 @@ module.exports = class EditorLevelView extends View
|
|||
'click #history-button': 'showVersionHistory'
|
||||
'click #patches-tab': -> @patchesView.load()
|
||||
'click #commit-level-patch-button': 'startPatchingLevel'
|
||||
'click #watch-button': 'toggleWatchLevel'
|
||||
|
||||
constructor: (options, @levelID) ->
|
||||
super options
|
||||
|
@ -125,3 +126,8 @@ module.exports = class EditorLevelView extends View
|
|||
versionHistoryView = new VersionHistoryView level:@level, @levelID
|
||||
@openModalView versionHistoryView
|
||||
Backbone.Mediator.publish 'level:view-switched', e
|
||||
|
||||
toggleWatchLevel: ->
|
||||
button = @$el.find('#watch-button')
|
||||
@level.watch(button.find('.watch').is(':visible'))
|
||||
button.find('> span').toggleClass('secret')
|
|
@ -95,7 +95,7 @@ module.exports = class Handler
|
|||
# this handler should be overwritten by subclasses
|
||||
if @modelClass.schema.is_patchable
|
||||
return @getPatchesFor(req, res, args[0]) if req.route.method is 'get' and args[1] is 'patches'
|
||||
return @setListening(req, res, args[0]) if req.route.method is 'put' and args[1] is 'listen'
|
||||
return @setWatching(req, res, args[0]) if req.route.method is 'put' and args[1] is 'watch'
|
||||
return @sendNotFoundError(res)
|
||||
|
||||
getPatchesFor: (req, res, id) ->
|
||||
|
@ -105,16 +105,19 @@ module.exports = class Handler
|
|||
patches = (patch.toObject() for patch in patches)
|
||||
@sendSuccess(res, patches)
|
||||
|
||||
setListening: (req, res, id) ->
|
||||
setWatching: (req, res, id) ->
|
||||
@getDocumentForIdOrSlug id, (err, document) =>
|
||||
return @sendUnauthorizedError(res) unless @hasAccessToDocument(req, document, 'get')
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless document?
|
||||
listeners = document.get('listeners') or []
|
||||
watchers = document.get('watchers') or []
|
||||
me = req.user.get('_id')
|
||||
listeners = (l for l in listeners when not l.equals(me))
|
||||
listeners.push me if req.body.on
|
||||
document.set 'listeners', listeners
|
||||
console.log 'watchers?', me, watchers
|
||||
watchers = (l for l in watchers when not l.equals(me))
|
||||
console.log 'new watchers is', watchers, req.body.on, req.body
|
||||
watchers.push me if req.body.on and req.body.on isnt 'false'
|
||||
console.log 'watchers is actually now', watchers
|
||||
document.set 'watchers', watchers
|
||||
document.save (err, document) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendSuccess(res, @formatEntity(req, document))
|
||||
|
|
|
@ -53,27 +53,27 @@ describe '/db/patch', ->
|
|||
expect(body.length).toBe(1)
|
||||
done()
|
||||
|
||||
it 'allows you to set yourself as listening', (done) ->
|
||||
listeningURL = getURL("/db/article/#{articles[0]._id}/listen")
|
||||
request.put {uri: listeningURL, json: {on:true}}, (err, res, body) ->
|
||||
expect(body.listeners[0]).toBeDefined()
|
||||
it 'allows you to set yourself as watching', (done) ->
|
||||
watchingURL = getURL("/db/article/#{articles[0]._id}/watch")
|
||||
request.put {uri: watchingURL, json: {on:true}}, (err, res, body) ->
|
||||
expect(body.watchers[0]).toBeDefined()
|
||||
done()
|
||||
|
||||
it 'added the listener to the target document', (done) ->
|
||||
it 'added the watcher to the target document', (done) ->
|
||||
Article.findOne({}).exec (err, article) ->
|
||||
expect(article.toObject().listeners[0]).toBeDefined()
|
||||
expect(article.toObject().watchers[0]).toBeDefined()
|
||||
done()
|
||||
|
||||
it 'does not add duplicate listeners', (done) ->
|
||||
listeningURL = getURL("/db/article/#{articles[0]._id}/listen")
|
||||
request.put {uri: listeningURL, json: {on:true}}, (err, res, body) ->
|
||||
expect(body.listeners.length).toBe(1)
|
||||
it 'does not add duplicate watchers', (done) ->
|
||||
watchingURL = getURL("/db/article/#{articles[0]._id}/watch")
|
||||
request.put {uri: watchingURL, json: {on:true}}, (err, res, body) ->
|
||||
expect(body.watchers.length).toBe(1)
|
||||
done()
|
||||
|
||||
it 'allows removing yourself', (done) ->
|
||||
listeningURL = getURL("/db/article/#{articles[0]._id}/listen")
|
||||
request.put {uri: listeningURL, json: {on:false}}, (err, res, body) ->
|
||||
expect(body.listeners.length).toBe(0)
|
||||
watchingURL = getURL("/db/article/#{articles[0]._id}/watch")
|
||||
request.put {uri: watchingURL, json: {on:false}}, (err, res, body) ->
|
||||
expect(body.watchers.length).toBe(0)
|
||||
done()
|
||||
|
||||
it 'allows the submitter to withdraw the pull request', (done) ->
|
||||
|
|
Loading…
Reference in a new issue