Support the new update format from the track changes api

This commit is contained in:
James Allen 2014-03-11 18:01:14 +00:00
parent da9fa28612
commit be64b510e8
9 changed files with 56 additions and 32 deletions

View file

@ -1,12 +1,20 @@
logger = require "logger-sharelatex" logger = require "logger-sharelatex"
request = require "request" request = require "request"
settings = require "settings-sharelatex" settings = require "settings-sharelatex"
AuthenticationController = require "../Authentication/AuthenticationController"
module.exports = TrackChangesController = module.exports = TrackChangesController =
proxyToTrackChangesApi: (req, res, next = (error) ->) -> proxyToTrackChangesApi: (req, res, next = (error) ->) ->
AuthenticationController.getLoggedInUserId req, (error, user_id) ->
return next(error) if error?
url = settings.apis.trackchanges.url + req.url url = settings.apis.trackchanges.url + req.url
logger.log url: url, "proxying to track-changes api" logger.log url: url, "proxying to track-changes api"
getReq = request(url: url, method: req.method) getReq = request(
url: url
method: req.method
headers:
"X-User-Id": user_id
)
getReq.pipe(res) getReq.pipe(res)
getReq.on "error", (error) -> getReq.on "error", (error) ->
logger.error err: error, "track-changes API error" logger.error err: error, "track-changes API error"

View file

@ -440,13 +440,16 @@
div(class='change-description') div(class='change-description')
div(class='change-date') {{date}} div(class='change-date') {{date}}
div(class='change-name') div {{{users}}}
div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);")
span {{name}}
div(class='restore') div(class='restore')
a(href="#") Restore to here a(href="#") Restore to here
script(type='text/template')#changeListItemUserTemplate
div(class='change-name')
div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);")
span {{name}}
script(type='text/template')#changeListTemplate script(type='text/template')#changeListTemplate
ul.change-list.nav.nav-pills.nav-stacked ul.change-list.nav.nav-pills.nav-stacked
li.loading-changes Loading... li.loading-changes Loading...

View file

@ -143,7 +143,6 @@ define [
@view.showLog() @view.showLog()
if outputFiles? if outputFiles?
console.log "outputFiles", outputFiles
@view.showOutputFileDownloadLinks(outputFiles) @view.showOutputFileDownloadLinks(outputFiles)
fetchLogAndUpdateView: (pdfExists) -> fetchLogAndUpdateView: (pdfExists) ->

View file

@ -158,24 +158,26 @@ define [
"click .restore a": "onRestoreClick" "click .restore a": "onRestoreClick"
template : $("#changeListItemTemplate").html() templates:
item: $("#changeListItemTemplate").html()
user: $("#changeListItemUserTemplate").html()
initialize: -> initialize: ->
@render() @render()
render: -> render: ->
@$el.html Mustache.to_html(@template, @modelView()) userHtml = for user in @model.get("users")
return this Mustache.to_html @templates.user, {
hue: user.hue()
modelView: -> name: user.name()
modelView = {
hue: @model.get("user").hue()
date: moment(parseInt(@model.get("end_ts"), 10)).calendar()
name: @model.get("user").name()
} }
# modelView.start_ts = util.formatDate(modelView.start_ts) data = {
# modelView.end_ts = util.formatDate(modelView.end_ts) date: moment(parseInt(@model.get("end_ts"), 10)).calendar()
return modelView users: userHtml.join("")
}
@$el.html Mustache.to_html(@templates.item, data)
return this
onClick: (e) -> onClick: (e) ->
e.preventDefault() e.preventDefault()

View file

@ -37,8 +37,8 @@ define [
@diff = new Diff({ @diff = new Diff({
project_id: @project_id project_id: @project_id
doc_id: @doc_id doc_id: @doc_id
from: fromModel.get("version") from: fromModel.get("fromVersion")
to: toModel.get("version") to: toModel.get("toVersion")
}) })
@diffView = new DiffView( @diffView = new DiffView(
model: @diff model: @diff

View file

@ -7,10 +7,12 @@ define [
model = { model = {
start_ts: change.meta.start_ts start_ts: change.meta.start_ts
end_ts: change.meta.end_ts end_ts: change.meta.end_ts
version: change.v fromVersion: change.fromV
toVersion: change.toV
} }
if change.meta.user? model.users = []
model.user = User.findOrBuild(change.meta.user.id, change.meta.user) for user in change.meta.users or []
else model.users.push User.findOrBuild(user.id, user)
model.user = User.getAnonymousUser() if model.users.length == 0
model.users.push User.getAnonymousUser()
return model return model

View file

@ -12,7 +12,7 @@ define [
url = "/project/#{@options.project_id}/doc/#{@options.doc_id}/updates?limit=#{@batchSize}" url = "/project/#{@options.project_id}/doc/#{@options.doc_id}/updates?limit=#{@batchSize}"
if @models.length > 0 if @models.length > 0
last = @models[@models.length - 1] last = @models[@models.length - 1]
url += "&to=#{last.get("version") - 1}" url += "&to=#{last.get("fromVersion") - 1}"
return url return url
parse: (json) -> parse: (json) ->

View file

@ -28,7 +28,7 @@
background-color: white; background-color: white;
.track-changes-header { .track-changes-header {
background-color: black; background-color: #282828;
h3 { h3 {
color: white; color: white;
padding-left: 8px; padding-left: 8px;

View file

@ -10,12 +10,14 @@ describe "TrackChangesController", ->
"request" : @request = sinon.stub() "request" : @request = sinon.stub()
"settings-sharelatex": @settings = {} "settings-sharelatex": @settings = {}
"logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()} "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
"../Authentication/AuthenticationController": @AuthenticationController = {}
describe "proxyToTrackChangesApi", -> describe "proxyToTrackChangesApi", ->
beforeEach -> beforeEach ->
@req = { url: "/mock/url", method: "POST" } @req = { url: "/mock/url", method: "POST" }
@res = "mock-res" @res = "mock-res"
@next = sinon.stub() @next = sinon.stub()
@user_id = "user-id-123"
@settings.apis = @settings.apis =
trackchanges: trackchanges:
url: "http://trackchanges.example.com" url: "http://trackchanges.example.com"
@ -24,14 +26,22 @@ describe "TrackChangesController", ->
pipe: sinon.stub() pipe: sinon.stub()
on: (event, handler) -> @events[event] = handler on: (event, handler) -> @events[event] = handler
@request.returns @proxy @request.returns @proxy
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id)
@TrackChangesController.proxyToTrackChangesApi @req, @res, @next @TrackChangesController.proxyToTrackChangesApi @req, @res, @next
describe "successfully", -> describe "successfully", ->
it "should get the user id", ->
@AuthenticationController.getLoggedInUserId
.calledWith(@req)
.should.equal true
it "should call the track changes api", -> it "should call the track changes api", ->
@request @request
.calledWith({ .calledWith({
url: "#{@settings.apis.trackchanges.url}#{@req.url}" url: "#{@settings.apis.trackchanges.url}#{@req.url}"
method: @req.method method: @req.method
headers:
"X-User-Id": @user_id
}) })
.should.equal true .should.equal true