mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Support the new update format from the track changes api
This commit is contained in:
parent
da9fa28612
commit
be64b510e8
9 changed files with 56 additions and 32 deletions
|
@ -1,13 +1,21 @@
|
||||||
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) ->) ->
|
||||||
url = settings.apis.trackchanges.url + req.url
|
AuthenticationController.getLoggedInUserId req, (error, user_id) ->
|
||||||
logger.log url: url, "proxying to track-changes api"
|
return next(error) if error?
|
||||||
getReq = request(url: url, method: req.method)
|
url = settings.apis.trackchanges.url + req.url
|
||||||
getReq.pipe(res)
|
logger.log url: url, "proxying to track-changes api"
|
||||||
getReq.on "error", (error) ->
|
getReq = request(
|
||||||
logger.error err: error, "track-changes API error"
|
url: url
|
||||||
next(error)
|
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)
|
|
@ -439,14 +439,17 @@
|
||||||
input(type="radio",name="toVersion").change-selector-to
|
input(type="radio",name="toVersion").change-selector-to
|
||||||
|
|
||||||
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...
|
||||||
|
|
|
@ -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) ->
|
||||||
|
|
|
@ -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()
|
data = {
|
||||||
date: moment(parseInt(@model.get("end_ts"), 10)).calendar()
|
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)
|
@$el.html Mustache.to_html(@templates.item, data)
|
||||||
return modelView
|
return this
|
||||||
|
|
||||||
onClick: (e) ->
|
onClick: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
@ -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) ->
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue