historyFileEntity.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import App from '../../../base'
  13. import iconTypeFromName from '../../file-tree/util/iconTypeFromName'
  14. import fileOperationI18nNames from '../../file-tree/util/fileOperationI18nNames'
  15. const historyFileEntityController = function($scope, $element, $attrs) {
  16. const ctrl = this
  17. ctrl.hasOperation = false
  18. ctrl.getRenameTooltip = i18nRenamedStr => {
  19. let [simplifiedOldPathname, simplifiedPathname] = _getSimplifiedPaths(
  20. ctrl.fileEntity.oldPathname,
  21. ctrl.fileEntity.pathname
  22. )
  23. return `${fileOperationI18nNames.renamed} <strong>${simplifiedOldPathname}</strong> &rarr; <strong>${simplifiedPathname}</strong>`
  24. }
  25. ctrl.getFileOperationName = () => {
  26. if (ctrl.fileEntity.operation === 'edited') {
  27. return fileOperationI18nNames.edited
  28. } else if (ctrl.fileEntity.operation === 'renamed') {
  29. return fileOperationI18nNames.renamed
  30. } else if (ctrl.fileEntity.operation === 'added') {
  31. return fileOperationI18nNames.created
  32. } else if (ctrl.fileEntity.operation === 'removed') {
  33. return fileOperationI18nNames.deleted
  34. } else {
  35. return ''
  36. }
  37. }
  38. const _getSimplifiedPaths = (path1, path2) => {
  39. let path1Parts = path1.split('/')
  40. let path2Parts = path2.split('/')
  41. let maxIterations = Math.min(path1Parts.length, path2Parts.length) - 1
  42. for (
  43. var commonPartIndex = 0;
  44. commonPartIndex < maxIterations;
  45. commonPartIndex++
  46. ) {
  47. if (path1Parts[commonPartIndex] !== path2Parts[commonPartIndex]) {
  48. break
  49. }
  50. }
  51. path1Parts.splice(0, commonPartIndex)
  52. path2Parts.splice(0, commonPartIndex)
  53. return [path1Parts.join('/'), path2Parts.join('/')]
  54. }
  55. const _handleFolderClick = function() {
  56. ctrl.isOpen = !ctrl.isOpen
  57. ctrl.entityTypeIconClass = _getFolderIcon()
  58. }
  59. const _handleFileClick = () =>
  60. ctrl.historyFileTreeController.handleEntityClick(ctrl.fileEntity)
  61. var _getFolderIcon = function() {
  62. if (ctrl.isOpen) {
  63. return 'fa-folder-open'
  64. } else {
  65. return 'fa-folder'
  66. }
  67. }
  68. ctrl.$onInit = function() {
  69. if (ctrl.fileEntity.type === 'folder') {
  70. ctrl.isOpen = true
  71. ctrl.entityTypeIconClass = _getFolderIcon()
  72. ctrl.handleClick = _handleFolderClick
  73. } else {
  74. if (ctrl.fileEntity.operation) {
  75. ctrl.hasOperation = true
  76. }
  77. ctrl.entityTypeIconClass = `fa-${iconTypeFromName(ctrl.fileEntity.name)}`
  78. ctrl.entityOpTextClass = ctrl.fileEntity.operation
  79. ? `history-file-entity-name-${ctrl.fileEntity.operation}`
  80. : null
  81. ctrl.handleClick = _handleFileClick
  82. $scope.$watch(
  83. () => ctrl.historyFileTreeController.selectedPathname,
  84. selectedPathname =>
  85. (ctrl.isSelected = ctrl.fileEntity.pathname === selectedPathname)
  86. )
  87. }
  88. }
  89. }
  90. export default App.component('historyFileEntity', {
  91. require: {
  92. historyFileTreeController: '^historyFileTree'
  93. },
  94. bindings: {
  95. fileEntity: '<'
  96. },
  97. controller: historyFileEntityController,
  98. templateUrl: 'historyFileEntityTpl'
  99. })