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() @simulateAnotherTaskAfterDelay()
handleNoGamesResponse: -> 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()
simulateAnotherTaskAfterDelay: => simulateAnotherTaskAfterDelay: =>
@ -102,7 +102,7 @@ module.exports = class Simulator extends CocoClass
sendResultsBackToServer: (results) => sendResultsBackToServer: (results) =>
@trigger 'statusUpdate', 'Simulation completed, sending results back to server!' @trigger 'statusUpdate', 'Simulation completed, sending results back to server!'
console.log "Sending result back to server!" console.log "Sending result back to server!"
$.ajax $.ajax
url: "/queue/scoring" url: "/queue/scoring"
data: results data: results
@ -279,9 +279,9 @@ class SimulationTask
getReceiptHandle: -> @rawData.receiptHandle getReceiptHandle: -> @rawData.receiptHandle
getSessions: -> @rawData.sessions getSessions: -> @rawData.sessions
getSpellKeyToTeamMap: -> @spellKeyToTeamMap getSpellKeyToTeamMap: -> @spellKeyToTeamMap
getPlayerTeams: -> _.pluck @rawData.sessions, 'team' getPlayerTeams: -> _.pluck @rawData.sessions, 'team'
generateSpellKeyToSourceMap: -> generateSpellKeyToSourceMap: ->
@ -303,7 +303,7 @@ class SimulationTask
fullSpellName = [thangName,spellName].join '/' fullSpellName = [thangName,spellName].join '/'
if _.contains(teamSpells, fullSpellName) if _.contains(teamSpells, fullSpellName)
teamCode[fullSpellName]=spell teamCode[fullSpellName]=spell
_.merge spellKeyToSourceMap, teamCode _.merge spellKeyToSourceMap, teamCode
spellKeyToSourceMap spellKeyToSourceMap

View file

@ -14,6 +14,8 @@ block content
i.icon-cog i.icon-cog
span(data-i18n='account_profile.approved').approved Approved span(data-i18n='account_profile.approved').approved Approved
span(data-i18n='account_profile.not_approved').not-approved Not 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') if user.get('jobProfile')
- var profile = 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' 'click #toggle-job-profile-approved': 'toggleJobProfileApproved'
'keyup #job-profile-notes': 'onJobProfileNotesChanged' 'keyup #job-profile-notes': 'onJobProfileNotesChanged'
'click #contact-candidate': 'onContactCandidate' 'click #contact-candidate': 'onContactCandidate'
'click #enter-espionage-mode': 'enterEspionageMode'
constructor: (options, @userID) -> constructor: (options, @userID) ->
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000 @onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
@ -52,6 +53,17 @@ module.exports = class ProfileView extends View
@user.save() @user.save()
@updateProfileApproval() @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) => onJobProfileNotesChanged: (e) =>
notes = @$el.find("#job-profile-notes").val() notes = @$el.find("#job-profile-notes").val()
@user.set 'jobProfileNotes', notes @user.set 'jobProfileNotes', notes

View file

@ -1,36 +1,31 @@
{backboneFailure, genericFailure} = require 'lib/errors' {backboneFailure, genericFailure} = require 'lib/errors'
View = require 'views/kinds/RootView' View = require 'views/kinds/RootView'
template = require 'templates/admin' template = require 'templates/admin'
storage = require 'lib/storage'
module.exports = class AdminView extends View module.exports = class AdminView extends View
id: "admin-view" id: "admin-view"
template: template template: template
events: events:
'click #enter-espionage-mode': 'enterEspionageMode' 'click #enter-espionage-mode': 'enterEspionageMode'
enterEspionageMode: -> enterEspionageMode: ->
userEmail = $("#user-email").val().toLowerCase() userEmail = $("#user-email").val().toLowerCase()
username = $("#user-username").val().toLowerCase() username = $("#user-username").val().toLowerCase()
userIdentifier = userEmail || username
postData = postData =
usernameLower: username usernameLower: username
emailLower: userEmail emailLower: userEmail
$.ajax $.ajax
type: "POST", type: "POST",
url: "/auth/spy" url: "/auth/spy"
data: postData data: postData
success: @espionageSuccess success: @espionageSuccess
error: @espionageFailure error: @espionageFailure
espionageSuccess: (model) -> espionageSuccess: (model) ->
storage.save('whoami',model)
window.location.reload() window.location.reload()
espionageFailure: (jqxhr, status,error)-> espionageFailure: (jqxhr, status,error)->
console.log "There was an error entering espionage mode: #{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 allDocs['__' + doc.name].push doc
if doc.type is 'snippet' then doc.owner = 'snippets' if doc.type is 'snippet' then doc.owner = 'snippets'
propStorage = if @options.programmable
'this': 'programmableProperties' propStorage =
more: 'moreProgrammableProperties' 'this': 'programmableProperties'
Math: 'programmableMathProperties' more: 'moreProgrammableProperties'
Array: 'programmableArrayProperties' Math: 'programmableMathProperties'
Object: 'programmableObjectProperties' Array: 'programmableArrayProperties'
String: 'programmableStringProperties' Object: 'programmableObjectProperties'
Vector: 'programmableVectorProperties' String: 'programmableStringProperties'
snippets: 'programmableSnippets' Vector: 'programmableVectorProperties'
snippets: 'programmableSnippets'
else
propStorage =
'this': 'apiProperties'
count = 0 count = 0
propGroups = {} propGroups = {}
for owner, storage of propStorage 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 count += added.length
shortenize = count > 6 shortenize = count > 6
@ -78,7 +83,7 @@ module.exports = class SpellPaletteView extends View
doc ?= prop doc ?= prop
@entries.push @addEntry(doc, shortenize, tabbify, owner is 'snippets') @entries.push @addEntry(doc, shortenize, tabbify, owner is 'snippets')
groupForEntry = (entry) -> 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 entry.doc.owner
@entries = _.sortBy @entries, (entry) -> @entries = _.sortBy @entries, (entry) ->
order = ['this', 'more', 'Math', 'Vector', 'snippets'] order = ['this', 'more', 'Math', 'Vector', 'snippets']

View file

@ -178,14 +178,12 @@ module.exports = class TomeView extends View
thang = e.thang thang = e.thang
spellName = e.spellName spellName = e.spellName
@spellList?.$el.hide() @spellList?.$el.hide()
return @clearSpellView() unless thang?.isProgrammable return @clearSpellView() unless thang
selectedThangSpells = (@spells[spellKey] for spellKey in @thangSpells[thang.id]) spell = @spellFor thang, spellName
if spellName unless spell?.canRead()
spell = _.find selectedThangSpells, {name: spellName} @clearSpellView()
else @updateSpellPalette thang, spell
spell = @thangList.topSpellForThang thang return
#spell = selectedThangSpells[0] # TODO: remember last selected spell for this thang
return @clearSpellView() unless spell?.canRead()
unless spell.view is @spellView unless spell.view is @spellView
@clearSpellView() @clearSpellView()
@spellView = spell.view @spellView = spell.view
@ -198,9 +196,22 @@ module.exports = class TomeView extends View
@spellList.setThangAndSpell thang, spell @spellList.setThangAndSpell thang, spell
@spellView?.setThang thang @spellView?.setThang thang
@spellTabView?.setThang thang @spellTabView?.setThang thang
if @spellPaletteView?.thang isnt thang @updateSpellPalette thang, spell
@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) ->
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: -> reloadAllCode: ->
spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team or (spell.team in ["common", "neutral", null]) spell.view.reloadCode false for spellKey, spell of @spells when spell.team is me.team or (spell.team in ["common", "neutral", null])