Changed the versions history modal to show name and date.

This commit is contained in:
Scott Erickson 2014-06-24 16:41:55 -04:00
parent c5ff37eb9a
commit ee0b14eb61
5 changed files with 26 additions and 18 deletions

View file

@ -4,7 +4,7 @@ namesCache = {}
class NameLoader extends CocoClass
loadNames: (ids) ->
toLoad = (id for id in ids when not namesCache[id])
toLoad = _.uniq (id for id in ids when not namesCache[id])
return false unless toLoad.length
jqxhrOptions = {
url: '/db/user/x/names',

View file

@ -887,6 +887,7 @@
sprite_sheet: "Sprite Sheet"
candidate_sessions: "Candidate Sessions"
user_remark: "User Remark"
versions: "Versions"
delta:
added: "Added"

View file

@ -11,17 +11,17 @@ block modal-body-content
table.table.table-condensed
tr
th
th(data-i18n="general.name") Name
th(data-i18n="general.version") Version
th
th
th
th(data-i18n="general.commit_msg") Commit Message
for data in dataList
tr
td
input(type="checkbox", value=data._id).select
td
a(href="/editor/#{page}/#{data.slug || data._id}")
| #{data.name}
td #{data.version.major}.#{data.version.minor}
td= moment(data.created).format('l')
td= data.creator
td #{data.commitMessage}
div.delta-container

View file

@ -3,12 +3,15 @@ template = require 'templates/modal/versions'
tableTemplate = require 'templates/kinds/table'
DeltaView = require 'views/editor/delta'
PatchModal = require 'views/editor/patch_modal'
nameLoader = require 'lib/NameLoader'
CocoCollection = require 'collections/CocoCollection'
class VersionsViewCollection extends Backbone.Collection
class VersionsViewCollection extends CocoCollection
url: ""
model: null
initialize: (@url, @levelID, @model) ->
super()
@url = url + levelID + '/versions'
@model = model
@ -28,18 +31,19 @@ module.exports = class VersionsModalView extends ModalView
constructor: (options, @ID, @model) ->
super options
@view = new model(_id: @ID)
@view.fetch()
@listenToOnce(@view, 'sync', @onViewSync)
@original = new model(_id: @ID)
@original = @supermodel.loadModel(@original, 'document').model
@listenToOnce(@original, 'sync', @onViewSync)
onViewSync: ->
@collection = new VersionsViewCollection(@url, @view.attributes.original, @model)
@collection.fetch()
@listenTo(@collection, 'sync', @onVersionFetched)
@versions = new VersionsViewCollection(@url, @original.attributes.original, @model)
@versions = @supermodel.loadCollection(@versions, 'versions').model
@listenTo(@versions, 'sync', @onVersionsFetched)
onVersionFetched: ->
@startsLoading = false
@render()
onVersionsFetched: ->
ids = (p.get('creator') for p in @versions.models)
jqxhrOptions = nameLoader.loadNames ids
@supermodel.addRequestResource('user_names', jqxhrOptions).load() if jqxhrOptions
onSelectionChanged: ->
rows = @$el.find 'input.select:checked'
@ -56,5 +60,8 @@ module.exports = class VersionsModalView extends ModalView
getRenderData: (context={}) ->
context = super(context)
context.page = @page
context.dataList = (m.attributes for m in @collection.models) if @collection
if @versions
context.dataList = (m.attributes for m in @versions.models)
for version in context.dataList
version.creator = nameLoader.getName(version.creator)
context

View file

@ -205,7 +205,7 @@ module.exports = class Handler
# Keeping it simple for now and just allowing access to the first FETCH_LIMIT results.
query = {'original': mongoose.Types.ObjectId(id)}
sort = {'created': -1}
selectString = 'slug name version commitMessage created permissions'
selectString = 'slug name version commitMessage created creator permissions'
aggregate = $match: query
@modelClass.aggregate(aggregate).project(selectString).limit(FETCH_LIMIT).sort(sort).exec (err, results) =>
return @sendDatabaseError(res, err) if err