From a716f9ccd3508dce1acd5fb1979c93cfc97bc9b1 Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Mon, 21 May 2018 15:12:47 +0100 Subject: [PATCH] Integrate history file tree in the UI. --- .../file-tree/util/iconTypeFromName.coffee | 13 ++++++ .../HistoryV2FileTreeController.coffee | 45 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 services/web/public/coffee/ide/file-tree/util/iconTypeFromName.coffee create mode 100644 services/web/public/coffee/ide/history/controllers/HistoryV2FileTreeController.coffee diff --git a/services/web/public/coffee/ide/file-tree/util/iconTypeFromName.coffee b/services/web/public/coffee/ide/file-tree/util/iconTypeFromName.coffee new file mode 100644 index 0000000000..01c11f395a --- /dev/null +++ b/services/web/public/coffee/ide/file-tree/util/iconTypeFromName.coffee @@ -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" \ No newline at end of file diff --git a/services/web/public/coffee/ide/history/controllers/HistoryV2FileTreeController.coffee b/services/web/public/coffee/ide/history/controllers/HistoryV2FileTreeController.coffee new file mode 100644 index 0000000000..fc9caaa6e4 --- /dev/null +++ b/services/web/public/coffee/ide/history/controllers/HistoryV2FileTreeController.coffee @@ -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 + ] \ No newline at end of file