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"
|
||||
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)
|
|
@ -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...
|
||||
|
|
|
@ -143,7 +143,6 @@ define [
|
|||
@view.showLog()
|
||||
|
||||
if outputFiles?
|
||||
console.log "outputFiles", outputFiles
|
||||
@view.showOutputFileDownloadLinks(outputFiles)
|
||||
|
||||
fetchLogAndUpdateView: (pdfExists) ->
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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) ->
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
background-color: white;
|
||||
|
||||
.track-changes-header {
|
||||
background-color: black;
|
||||
background-color: #282828;
|
||||
h3 {
|
||||
color: white;
|
||||
padding-left: 8px;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue