Show spell palette for Thangs with apiProperties that aren't programmable.

This commit is contained in:
Nick Winter 2014-04-25 16:57:42 -07:00
parent d8d2a57c38
commit 834c27bbd7
6 changed files with 63 additions and 38 deletions

View file

@ -32,7 +32,7 @@ module.exports = class Simulator extends CocoClass
@simulateAnotherTaskAfterDelay()
handleNoGamesResponse: ->
@trigger 'statusUpdate', 'There were no games to simulate--nice. Retrying in 10 seconds.'
@trigger 'statusUpdate', 'There were no games to simulate--all simulations are done or in process. Retrying in 10 seconds.'
@simulateAnotherTaskAfterDelay()
simulateAnotherTaskAfterDelay: =>
@ -102,7 +102,7 @@ module.exports = class Simulator extends CocoClass
sendResultsBackToServer: (results) =>
@trigger 'statusUpdate', 'Simulation completed, sending results back to server!'
console.log "Sending result back to server!"
$.ajax
url: "/queue/scoring"
data: results
@ -279,9 +279,9 @@ class SimulationTask
getReceiptHandle: -> @rawData.receiptHandle
getSessions: -> @rawData.sessions
getSpellKeyToTeamMap: -> @spellKeyToTeamMap
getPlayerTeams: -> _.pluck @rawData.sessions, 'team'
generateSpellKeyToSourceMap: ->
@ -303,7 +303,7 @@ class SimulationTask
fullSpellName = [thangName,spellName].join '/'
if _.contains(teamSpells, fullSpellName)
teamCode[fullSpellName]=spell
_.merge spellKeyToSourceMap, teamCode
spellKeyToSourceMap

View file

@ -14,6 +14,8 @@ block content
i.icon-cog
span(data-i18n='account_profile.approved').approved Approved
span(data-i18n='account_profile.not_approved').not-approved Not Approved
if user.id != me.id
button.btn.edit-settings-button#enter-espionage-mode 007
if user.get('jobProfile')
- var profile = user.get('jobProfile');

View file

@ -11,6 +11,7 @@ module.exports = class ProfileView extends View
'click #toggle-job-profile-approved': 'toggleJobProfileApproved'
'keyup #job-profile-notes': 'onJobProfileNotesChanged'
'click #contact-candidate': 'onContactCandidate'
'click #enter-espionage-mode': 'enterEspionageMode'
constructor: (options, @userID) ->
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
@ -52,6 +53,17 @@ module.exports = class ProfileView extends View
@user.save()
@updateProfileApproval()
enterEspionageMode: ->
postData = emailLower: @user.get('email').toLowerCase(), usernameLower: @user.get('name').toLowerCase()
$.ajax
type: "POST",
url: "/auth/spy"
data: postData
success: @espionageSuccess
espionageSuccess: (model) ->
window.location.reload()
onJobProfileNotesChanged: (e) =>
notes = @$el.find("#job-profile-notes").val()
@user.set 'jobProfileNotes', notes

View file

@ -1,36 +1,31 @@
{backboneFailure, genericFailure} = require 'lib/errors'
View = require 'views/kinds/RootView'
template = require 'templates/admin'
storage = require 'lib/storage'
module.exports = class AdminView extends View
id: "admin-view"
template: template
events:
'click #enter-espionage-mode': 'enterEspionageMode'
enterEspionageMode: ->
userEmail = $("#user-email").val().toLowerCase()
username = $("#user-username").val().toLowerCase()
userIdentifier = userEmail || username
postData =
usernameLower: username
emailLower: userEmail
$.ajax
type: "POST",
url: "/auth/spy"
data: postData
success: @espionageSuccess
error: @espionageFailure
espionageSuccess: (model) ->
storage.save('whoami',model)
window.location.reload()
espionageFailure: (jqxhr, status,error)->
console.log "There was an error entering espionage mode: #{error}"

View file

@ -51,19 +51,24 @@ module.exports = class SpellPaletteView extends View
allDocs['__' + doc.name].push doc
if doc.type is 'snippet' then doc.owner = 'snippets'
propStorage =
'this': 'programmableProperties'
more: 'moreProgrammableProperties'
Math: 'programmableMathProperties'
Array: 'programmableArrayProperties'
Object: 'programmableObjectProperties'
String: 'programmableStringProperties'
Vector: 'programmableVectorProperties'
snippets: 'programmableSnippets'
if @options.programmable
propStorage =
'this': 'programmableProperties'
more: 'moreProgrammableProperties'
Math: 'programmableMathProperties'
Array: 'programmableArrayProperties'
Object: 'programmableObjectProperties'
String: 'programmableStringProperties'
Vector: 'programmableVectorProperties'
snippets: 'programmableSnippets'
else
propStorage =
'this': 'apiProperties'
count = 0
propGroups = {}
for owner, storage of propStorage
added = propGroups[owner] = _.sortBy(@thang[storage] ? []).slice()
props = _.reject @thang[storage] ? [], (prop) -> prop[0] is '_' # no private properties
added = propGroups[owner] = _.sortBy(props).slice()
count += added.length
shortenize = count > 6
@ -78,7 +83,7 @@ module.exports = class SpellPaletteView extends View
doc ?= prop
@entries.push @addEntry(doc, shortenize, tabbify, owner is 'snippets')
groupForEntry = (entry) ->
return 'more' if entry.doc.owner is 'this' and entry.doc.name in propGroups.more
return 'more' if entry.doc.owner is 'this' and entry.doc.name in (propGroups.more ? [])
entry.doc.owner
@entries = _.sortBy @entries, (entry) ->
order = ['this', 'more', 'Math', 'Vector', 'snippets']

View file

@ -178,14 +178,12 @@ module.exports = class TomeView extends View
thang = e.thang
spellName = e.spellName
@spellList?.$el.hide()
return @clearSpellView() unless thang?.isProgrammable
selectedThangSpells = (@spells[spellKey] for spellKey in @thangSpells[thang.id])
if spellName
spell = _.find selectedThangSpells, {name: spellName}
else
spell = @thangList.topSpellForThang thang
#spell = selectedThangSpells[0] # TODO: remember last selected spell for this thang
return @clearSpellView() unless spell?.canRead()
return @clearSpellView() unless thang
spell = @spellFor thang, spellName
unless spell?.canRead()
@clearSpellView()
@updateSpellPalette thang, spell
return
unless spell.view is @spellView
@clearSpellView()
@spellView = spell.view
@ -198,9 +196,22 @@ module.exports = class TomeView extends View
@spellList.setThangAndSpell thang, spell
@spellView?.setThang thang
@spellTabView?.setThang thang
if @spellPaletteView?.thang isnt thang
@spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled # TODO: know when palette should have been disabled but didn't exist
@updateSpellPalette thang, spell
updateSpellPalette: (thang, spell) ->
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
@spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel, programmable: spell?.canRead()
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled if spell # TODO: know when palette should have been disabled but didn't exist
spellFor: (thang, spellName) ->
return null unless thang?.isProgrammable
selectedThangSpells = (@spells[spellKey] for spellKey in @thangSpells[thang.id])
if spellName
spell = _.find selectedThangSpells, {name: spellName}
else
spell = @thangList.topSpellForThang thang
#spell = selectedThangSpells[0] # TODO: remember last selected spell for this thang
spell
reloadAllCode: ->
spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team or (spell.team in ["common", "neutral", null])