Integrate history file tree in the UI.

This commit is contained in:
Paulo Reis 2018-05-21 15:12:47 +01:00
parent 6701b4413b
commit a716f9ccd3
2 changed files with 58 additions and 0 deletions

View file

@ -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"

View 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
]