Allow submitting changes for item desc. to GitHub

This commit is contained in:
Andrew Miner
2015-05-08 16:16:17 -07:00
parent 1254183c2c
commit 8eb5cef71b
5 changed files with 154 additions and 13 deletions
@@ -145,14 +145,26 @@ module.exports = class ItemPageController extends PageController
if not @model.item?
return w.reject new Error 'must have an item'
@client.fetchFile file:GitHub.file.itemDescription modSlug:@_itemSlug.mod, itemSlug:@_itemSlug.item
.then (fileRecord)=>
@_editingFile = fileRecord
@model.item.parse fileRecord.content
@client.fetchFile path:GitHub.file.itemDescription modSlug:@_itemSlug.mod, itemSlug:@_itemSlug.item
.then (response)=>
@_editingFile = response.json.data
@model.item.parse @_editingFile.content
@_descriptionController.model = @model.item.description
_endEditingDescription: ->
return w(true).delay(1000)
oldDescription = @model.item.description
@model.item.description = @_descriptionController.model
args =
content: @model.item.unparse()
message: "User-submitted text for #{@model.item.name}"
path: GitHub.file.itemDescription modSlug:@_itemSlug.mod, itemSlug:@_itemSlug.item
sha: @_editingFile.sha
@client.updateFile args
.catch (e)=>
@model.item.description = oldDescription
throw e
_refreshByline: ->
mod = @model.item?.modVersion?.mod
@@ -79,7 +79,6 @@ module.exports = class MarkdownSectionController extends BaseController
onSaveClicked: (event)->
event.preventDefault()
nextState = State.viewing
@state = State.waiting
@_endEditing()
.then =>
@@ -87,10 +86,9 @@ module.exports = class MarkdownSectionController extends BaseController
.catch (e)=>
logger.error "failed to end editing: #{e}"
@state = State.appologizing
nextState = State.editing
.delay @confirmDuration
.then =>
@state = nextState
@state = State.viewing
onTextChanged: (event)->
event.preventDefault()
+5
View File
@@ -45,6 +45,11 @@ module.exports = class Item extends BaseModel
return if this.name < that.name then -1 else +1
return 0
unparse: ->
ItemParser = require './item_parser' # to avoid require cycles
@_parser ?= new ItemParser model:this
return @_parser.unparse()
# Property Methods #############################################################################
getIsCraftable: ->
@@ -17,17 +17,23 @@ module.exports = class ItemParserV1 extends CommandParserVersionBase
@_buildItem rawData, model
_unparseModel: (builder, model)->
builder.line 'schema: ', 1
builder.line()
@_unparseItem builder, model
# Command Methods ##############################################################################
_command_description: (textParts...)->
@_rawData.description ?= ''
if not @_rawData.description?
@_rawData.description = ''
else
@_rawData.description += '\n'
@_rawData.description += textParts.join ', '
_command_officialUrl: (officialUrl)->
if @_rawData.officialUrl? then throw new Error 'duplicate declaration of "officialUrl"'
if officialUrl.length is 0 then throw new Error 'officialUrl cannot be empty'
if not officialUrl? or (officialUrl.length is 0) then throw new Error 'officialUrl cannot be empty'
@_rawData.officialUrl = officialUrl
_command_video: (youTubeId, nameParts...)->
@@ -41,6 +47,26 @@ module.exports = class ItemParserV1 extends CommandParserVersionBase
# Object Building Methods ######################################################################
_buildItem: (rawData, model)->
model.description = rawData.description if rawData.description
model.officialUrl = rawData.officialUrl if rawData.officialUrl
model.videos = rawData.videos if rawData.videos
model.description = rawData.description if rawData.description?
model.officialUrl = rawData.officialUrl if rawData.officialUrl?
model.videos = rawData.videos if rawData.videos?
# Un-parsing Methods ###########################################################################
_unparseItem: (builder, model)->
if model.officialUrl?
builder.line 'officialUrl: ', model.officialUrl
builder.line()
if model.description?
if model.description.indexOf('\n') isnt -1
builder.line 'description: <<-END'
builder.line model.description
builder.line 'END'
else
builder.line 'description: ', model.description
builder.line()
for video in model.videos
builder.line 'video: ', video.youTubeId, ', ', video.name
builder.line()