Skip to content

Commit

Permalink
Handle shareable levels when previewing them as a teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
sderickson committed Sep 29, 2016
1 parent 511881e commit bbadedb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/locale/en.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,8 @@
sharing:
game: "Game"
webpage: "Webpage"
your_students_preview: "Your students will click here to see their finished projects! Unavailable in teacher preview."
unavailable: "Link sharing not available in teacher preview."
share_game: "Share This Game"
share_web: "Share This Webpage"
victory_share_prefix: "Share this link to invite your friends & family to"
Expand Down
6 changes: 4 additions & 2 deletions app/models/CourseInstance.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ module.exports = class CourseInstance extends CocoModel
data: { userID: userID }
}
_.extend options, opts
@fetch options
jqxhr = @fetch options
if userID is me.id
unless me.get('courseInstances')
me.set('courseInstances', [])
me.get('courseInstances').push(@id)
return jqxhr

addMembers: (userIDs, opts) ->
options = {
Expand All @@ -42,8 +43,9 @@ module.exports = class CourseInstance extends CocoModel
data: { userID: userID }
}
_.extend options, opts
@fetch(options)
jqxhr = @fetch(options)
me.set('courseInstances', _.without(me.get('courseInstances'), @id)) if userID is me.id
return jqxhr

firstLevelURL: ->
"/play/level/dungeons-of-kithgard?course=#{@get('courseID')}&course-instance=#{@id}"
Expand Down
2 changes: 2 additions & 0 deletions app/models/LevelSession.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ module.exports = class LevelSession extends CocoModel
console.log "Couldn't transpile!\n#{source}\n", e
spellThang.aether.transpile ''
spells

isFake: -> @id is 'A Fake Session ID'
15 changes: 9 additions & 6 deletions app/templates/play/level/modal/progress-view.jade
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@
span(data-i18n='sharing.victory_course_share_web')
span= ' '
span(data-i18n='sharing.victory_course_share_suffix')
.row
.col-sm-9
input.text-h4.semibold.form-control.input-lg#share-level-input(value=view.shareURL)
.col-sm-3
button#share-level-btn.btn.btn-lg.btn-success.btn-illustrated
span(data-i18n='sharing.copy_url')
if view.session.isFake()
.alert.alert-warning(data-i18n="sharing.unavailable")
else
.row
.col-sm-9
input.text-h4.semibold.form-control.input-lg#share-level-input(value=view.shareURL)
.col-sm-3
button#share-level-btn.btn.btn-lg.btn-success.btn-illustrated
span(data-i18n='sharing.copy_url')

.row
.col-sm-5.col-sm-offset-2
Expand Down
20 changes: 13 additions & 7 deletions app/templates/play/level/tome/spell-top-bar-view.jade
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@
span(data-i18n='web_dev.image_gallery_title')

if view.options.level.get('shareable')
- var url = '/play/' + view.options.level.get('type') + '-level/' + view.options.level.get('slug') + '/' + view.options.session.id;
- if (view.options.courseID) url += '?course=' + view.options.courseID;
a.btn.btn-small.btn-illustrated(href=url)
if view.options.level.isType('game-dev')
span(data-i18n='sharing.game')
else
span(data-i18n='sharing.webpage')
- i18nName = view.options.level.isType('game-dev') ? 'sharing.game' : 'sharing.webpage'
if view.options.session.isFake()
button.btn.btn-small.btn-illustrated(
data-i18n=i18nName
data-toggle="popover"
data-placement="bottom"
data-content=translate('sharing.your_students_preview')
data-trigger="hover"
)
else
- var url = '/play/' + view.options.level.get('type') + '-level/' + view.options.level.get('slug') + '/' + view.options.session.id;
- if (view.options.courseID) url += '?course=' + view.options.courseID;
a.btn.btn-small.btn-illustrated(href=url, data-i18n=i18nName)

.clearfix
1 change: 1 addition & 0 deletions app/views/play/level/tome/SpellTopBarView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = class SpellTopBarView extends CocoView
afterRender: ->
super()
@attachTransitionEventListener()
@$('[data-toggle="popover"]').popover()

onDisableControls: (e) -> @toggleControls e, false
onEnableControls: (e) -> @toggleControls e, true
Expand Down
22 changes: 22 additions & 0 deletions test/app/models/CourseInstance.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CourseInstance = require 'models/CourseInstance'
factories = require 'test/app/factories'

describe 'CourseInstance', ->

beforeEach ->
@courseInstance = factories.makeCourseInstance()

describe 'addMember(userID, opts)', ->
it 'returns a jqxhr', ->
res = @courseInstance.addMember('1234')
expect(res.readyState).toBe(1)

describe 'addMembers(userIDs, opts)', ->
it 'returns a jqxhr', ->
res = @courseInstance.addMembers(['1234'])
expect(res.readyState).toBe(1)

describe 'removeMember(userID, opts)', ->
it 'returns a jqxhr', ->
res = @courseInstance.removeMember('1234')
expect(res.readyState).toBe(1)

0 comments on commit bbadedb

Please sign in to comment.