Get diffs showing in client

This commit is contained in:
James Allen 2017-12-07 10:13:46 +00:00
parent a1615e6d84
commit 4691a6e85c
3 changed files with 64 additions and 67 deletions

View file

@ -197,6 +197,7 @@ module.exports = class Router
webRouter.get "/project/:Project_id/updates", AuthorizationMiddlewear.ensureUserCanReadProject, HistoryController.selectHistoryApi, HistoryController.proxyToHistoryApi
webRouter.get "/project/:Project_id/doc/:doc_id/diff", AuthorizationMiddlewear.ensureUserCanReadProject, HistoryController.selectHistoryApi, HistoryController.proxyToHistoryApi
webRouter.get "/project/:Project_id/diff", AuthorizationMiddlewear.ensureUserCanReadProject, HistoryController.selectHistoryApi, HistoryController.proxyToHistoryApi
webRouter.post "/project/:Project_id/doc/:doc_id/version/:version_id/restore", AuthorizationMiddlewear.ensureUserCanReadProject, HistoryController.selectHistoryApi, HistoryController.proxyToHistoryApi
webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject

View file

@ -134,10 +134,11 @@ div#history(ng-show="ui.view == 'history'")
div.description(ng-click="select()")
div.time {{ update.meta.end_ts | formatDate:'h:mm a' }}
div.docs(ng-repeat="(doc_path, doc) in update.docs", ng-if="update.docs")
span.doc {{ doc_path }}
div.docs(ng-repeat="rename in update.renames", ng-if="update.renames")
span Renamed {{ rename.pathname }} to {{ rename.newPathname }}
div.docs(ng-repeat="pathname in update.docs", ng-if="update.docs")
span.doc {{ pathname }}
div.docs(ng-repeat="project_op in update.project_ops", ng-if="update.project_ops")
span(ng-if="project_op.rename")
| Renamed {{ project_op.rename.pathname }} to {{ project_op.rename.newPathname }}
div.users
div.user(ng-repeat="update_user in update.meta.users")
.color-square(ng-if="update_user != null", ng-style="{'background-color': 'hsl({{ update_user.hue }}, 70%, 50%)'}")

View file

@ -22,7 +22,7 @@ define [
@$scope.$on "entity:selected", (event, entity) =>
if (@$scope.ui.view == "history") and (entity.type == "doc")
# TODO: Set selection.doc_path to entity path name
# TODO: Set selection.pathname to entity path name
# @$scope.history.selection.doc = entity
@reloadDiff()
@ -46,8 +46,6 @@ define [
range: {
fromV: null
toV: null
start_ts: null
end_ts: null
}
}
diff: null
@ -76,6 +74,7 @@ define [
.get(url)
.then (response) =>
{ data } = response
console.log "fetchNextBatchOfUpdates", data.updates
@_loadUpdates(data.updates)
@$scope.history.nextBeforeTimestamp = data.nextBeforeTimestamp
if !data.nextBeforeTimestamp?
@ -85,23 +84,21 @@ define [
reloadDiff: () ->
diff = @$scope.history.diff
{updates} = @$scope.history.selection
{fromV, toV, start_ts, end_ts, original_path} = @_calculateDiffDataFromSelection()
{fromV, toV, pathname} = @_calculateDiffDataFromSelection()
console.log "[reloadDiff] current diff", diff
console.log "[reloadDiff] new diff data", {fromV, toV, start_ts, end_ts, original_path}
console.log "[reloadDiff] new diff data", {fromV, toV, pathname}
return if !original_path?
return if !pathname?
return if diff? and
diff.doc_path == original_path and
diff.pathname == pathname and
diff.fromV == fromV and
diff.toV == toV
@$scope.history.diff = diff = {
fromV: fromV
toV: toV
start_ts: start_ts
end_ts: end_ts
doc_path: original_path
pathname: pathname
error: false
}
@ -109,8 +106,8 @@ define [
# with the new system!
if true # !doc.deleted
diff.loading = true
url = "/project/#{@$scope.project_id}/doc/by_path/diff"
query = ["path=#{encodeURIComponent(original_path)}"]
url = "/project/#{@$scope.project_id}/diff"
query = ["pathname=#{encodeURIComponent(pathname)}"]
if diff.fromV? and diff.toV?
query.push "from=#{diff.fromV}", "to=#{diff.toV}"
url += "?" + query.join("&")
@ -194,12 +191,12 @@ define [
return {text, highlights}
_loadUpdates: (updates = []) ->
console.log "FOO"
previousUpdate = @$scope.history.updates[@$scope.history.updates.length - 1]
console.log "BAR", updates
for update in updates
for doc_path, doc of update.docs or {}
doc.path = doc_path
doc.entity = @ide.fileTreeManager.findEntityByPath(doc_path, includeDeleted: true)
for update in updates or []
console.log "_loadUpdates, loading", update
for user in update.meta.users or []
if user?
@ -214,6 +211,7 @@ define [
previousUpdate = update
console.log("BAZ")
firstLoad = @$scope.history.updates.length == 0
@$scope.history.updates =
@ -223,59 +221,56 @@ define [
@autoSelectRecentUpdates() if firstLoad
_perDocSummaryOfUpdates: (updates) ->
current_paths = {}
current_pathnames = {}
docs_summary = {}
for update in updates # Updates are reverse chronologically ordered
console.log "[_perDocSummaryOfUpdates] update", update
if update.docs?
for doc_path, doc of update.docs
# doc_path may not be the latest doc path that this doc has had
if !current_paths[doc_path]?
current_paths[doc_path] = doc_path
current_path = current_paths[doc_path]
console.log "[_perDocSummaryOfUpdates] doc", doc, current_path
if !docs_summary[current_path]?
# todo start_ts and end_ts
docs_summary[current_path] = {
fromV: doc.fromV, toV: doc.toV,
original_path: doc_path
}
else
docs_summary[current_path] = {
fromV: Math.min(docs_summary[current_path].fromV, doc.fromV),
toV: Math.max(docs_summary[current_path].toV, doc.toV),
original_path: doc_path
}
else if update.renames?
for rename in update.renames
for pathname in update.docs or []
# current_pathname may not be the latest doc path that this doc has had
if !current_pathnames[pathname]?
current_pathnames[pathname] = pathname
current_pathname = current_pathnames[pathname]
if !docs_summary[current_pathname]?
docs_summary[current_pathname] = {
fromV: update.fromV, toV: update.toV,
pathname: pathname
}
console.log "[_perDocSummaryOfUpdates] creating summary", current_pathname, docs_summary[current_pathname]
else
console.log "[_perDocSummaryOfUpdates] updating summary", docs_summary[current_pathname], update
docs_summary[current_pathname] = {
fromV: Math.min(docs_summary[current_pathname].fromV, update.fromV),
toV: Math.max(docs_summary[current_pathname].toV, update.toV),
pathname: pathname
}
for project_op in update.project_ops or []
if project_op.rename?
rename = project_op.rename
console.log "[_perDocSummaryOfUpdates] rename", rename
if !current_paths[rename.newPathname]?
current_paths[rename.newPathname] = rename.newPathname
current_paths[rename.pathname] = current_paths[rename.newPathname]
delete current_paths[rename.newPathname]
if !current_pathnames[rename.newPathname]?
current_pathnames[rename.newPathname] = rename.newPathname
current_pathnames[rename.current_pathname] = current_pathnames[rename.newPathname]
delete current_pathnames[rename.newPathname]
console.log "[_perDocSummaryOfUpdates] docs_summary", docs_summary
console.log "[_perDocSummaryOfUpdates] current_paths", current_paths
console.log "[_perDocSummaryOfUpdates] current_pathnames", current_pathnames
return docs_summary
_calculateDiffDataFromSelection: () ->
fromV = toV = start_ts = end_ts = original_path = null
fromV = toV = pathname = null
selected_doc_path = @$scope.history.selection.doc_path
console.log "[_calculateDiffDataFromSelection] selected_doc_path", selected_doc_path
selected_pathname = @$scope.history.selection.pathname
console.log "[_calculateDiffDataFromSelection] selected_pathname", selected_pathname
for doc_path, doc of @_perDocSummaryOfUpdates(@$scope.history.selection.updates)
if doc_path == selected_doc_path
fromV = doc.fromV
toV = doc.toV
start_ts = doc.start_ts
end_ts = doc.end_ts
original_path = doc.original_path
for pathname, doc of @_perDocSummaryOfUpdates(@$scope.history.selection.updates)
console.log "[_calculateDiffDataFromSelection] pathname, doc", pathname, doc
if pathname == selected_pathname
{fromV, toV, pathname} = doc
break
return {fromV, toV, start_ts, end_ts, original_path}
return {fromV, toV, pathname}
# Set the track changes selected doc to one of the docs in the range
# of currently selected updates. If we already have a selected doc
@ -284,21 +279,21 @@ define [
affected_docs = @_perDocSummaryOfUpdates(@$scope.history.selection.updates)
console.log "[_selectDocFromUpdates] affected_docs", affected_docs
selected_doc_path = @$scope.history.selection.doc_path
console.log "[_selectDocFromUpdates] current selected_doc_path", selected_doc_path
if selected_doc_path? and affected_docs[selected_doc_path]
selected_pathname = @$scope.history.selection.pathname
console.log "[_selectDocFromUpdates] current selected_pathname", selected_pathname
if selected_pathname? and affected_docs[selected_pathname]
# Selected doc is already open
else
# Set to first possible candidate
for doc_path, doc of affected_docs
selected_doc_path = doc_path
for pathname, doc of affected_docs
selected_pathname = pathname
break
console.log "[_selectDocFromUpdates] new selected_doc_path", selected_doc_path
console.log "[_selectDocFromUpdates] new selected_pathname", selected_pathname
@$scope.history.selection.doc_path = selected_doc_path
if selected_doc_path?
entity = @ide.fileTreeManager.findEntityByPath(selected_doc_path)
@$scope.history.selection.pathname = selected_pathname
if selected_pathname?
entity = @ide.fileTreeManager.findEntityByPath(selected_pathname)
if entity?
@ide.fileTreeManager.selectEntity(entity)