mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Integrate history file tree in the UI.
This commit is contained in:
parent
6701b4413b
commit
a716f9ccd3
2 changed files with 58 additions and 0 deletions
|
@ -0,0 +1,13 @@
|
|||
define [], () ->
|
||||
return iconTypeFromName = (name) ->
|
||||
ext = name.split(".").pop()?.toLowerCase()
|
||||
if ext in ["png", "pdf", "jpg", "jpeg", "gif"]
|
||||
return "image"
|
||||
else if ext in ["csv", "xls", "xlsx"]
|
||||
return "table"
|
||||
else if ext in ["py", "r"]
|
||||
return "file-text"
|
||||
else if ext in ['bib']
|
||||
return 'book'
|
||||
else
|
||||
return "file"
|
|
@ -0,0 +1,45 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
|
||||
App.controller "HistoryV2FileTreeController", ["$scope", "ide", "_", ($scope, ide, _) ->
|
||||
$scope.currentFileTree = []
|
||||
_selectedDefaultPathname = (files) ->
|
||||
# TODO: Improve heuristic to determine the default pathname to show.
|
||||
if files? and files.length > 0
|
||||
mainFile = files.find (file) -> /main\.tex$/.test file.pathname
|
||||
if mainFile?
|
||||
mainFile.pathname
|
||||
else
|
||||
files[0].pathname
|
||||
|
||||
$scope.handleFileSelection = (file) ->
|
||||
$scope.history.selection.pathname = file.pathname
|
||||
|
||||
$scope.$watch 'history.files', (files) ->
|
||||
$scope.currentFileTree = _.reduce files, reducePathsToTree, []
|
||||
$scope.history.selection.pathname = _selectedDefaultPathname(files)
|
||||
|
||||
reducePathsToTree = (currentFileTree, fileObject) ->
|
||||
filePathParts = fileObject.pathname.split "/"
|
||||
currentFileTreeLocation = currentFileTree
|
||||
for pathPart, index in filePathParts
|
||||
isFile = index == filePathParts.length - 1
|
||||
if isFile
|
||||
fileTreeEntity =
|
||||
name: pathPart
|
||||
pathname: fileObject.pathname
|
||||
type: "file"
|
||||
operation: fileObject.operation || "edited"
|
||||
currentFileTreeLocation.push fileTreeEntity
|
||||
else
|
||||
fileTreeEntity = _.find currentFileTreeLocation, (entity) => entity.name == pathPart
|
||||
if !fileTreeEntity?
|
||||
fileTreeEntity =
|
||||
name: pathPart
|
||||
type: "folder"
|
||||
children: []
|
||||
currentFileTreeLocation.push fileTreeEntity
|
||||
currentFileTreeLocation = fileTreeEntity.children
|
||||
return currentFileTree
|
||||
]
|
Loading…
Reference in a new issue