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

View file

@ -439,14 +439,17 @@
input(type="radio",name="toVersion").change-selector-to
div(class='change-description')
div(class='change-date') {{date}}
div(class='change-name')
div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);")
span {{name}}
div(class='change-date') {{date}}
div {{{users}}}
div(class='restore')
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
ul.change-list.nav.nav-pills.nav-stacked
li.loading-changes Loading...

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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