historyFileEntity.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 `${
  24. fileOperationI18nNames.renamed
  25. } <strong>${simplifiedOldPathname}</strong> &rarr; <strong>${simplifiedPathname}</strong>`
  26. }
  27. ctrl.getFileOperationName = () => {
  28. if (ctrl.fileEntity.operation === 'edited') {
  29. return fileOperationI18nNames.edited
  30. } else if (ctrl.fileEntity.operation === 'renamed') {
  31. return fileOperationI18nNames.renamed
  32. } else if (ctrl.fileEntity.operation === 'added') {
  33. return fileOperationI18nNames.created
  34. } else if (ctrl.fileEntity.operation === 'removed') {
  35. return fileOperationI18nNames.deleted
  36. } else {
  37. return ''
  38. }
  39. }
  40. const _getSimplifiedPaths = (path1, path2) => {
  41. let path1Parts = path1.split('/')
  42. let path2Parts = path2.split('/')
  43. let maxIterations = Math.min(path1Parts.length, path2Parts.length) - 1
  44. for (
  45. var commonPartIndex = 0;
  46. commonPartIndex < maxIterations;
  47. commonPartIndex++
  48. ) {
  49. if (path1Parts[commonPartIndex] !== path2Parts[commonPartIndex]) {
  50. break
  51. }
  52. }
  53. path1Parts.splice(0, commonPartIndex)
  54. path2Parts.splice(0, commonPartIndex)
  55. return [path1Parts.join('/'), path2Parts.join('/')]
  56. }
  57. const _handleFolderClick = function() {
  58. ctrl.isOpen = !ctrl.isOpen
  59. ctrl.entityTypeIconClass = _getFolderIcon()
  60. }
  61. const _handleFileClick = () =>
  62. ctrl.historyFileTreeController.handleEntityClick(ctrl.fileEntity)
  63. var _getFolderIcon = function() {
  64. if (ctrl.isOpen) {
  65. return 'fa-folder-open'
  66. } else {
  67. return 'fa-folder'
  68. }
  69. }
  70. ctrl.$onInit = function() {
  71. if (ctrl.fileEntity.type === 'folder') {
  72. ctrl.isOpen = true
  73. ctrl.entityTypeIconClass = _getFolderIcon()
  74. ctrl.handleClick = _handleFolderClick
  75. } else {
  76. if (ctrl.fileEntity.operation) {
  77. ctrl.hasOperation = true
  78. }
  79. ctrl.entityTypeIconClass = `fa-${iconTypeFromName(ctrl.fileEntity.name)}`
  80. ctrl.entityOpTextClass = ctrl.fileEntity.operation
  81. ? `history-file-entity-name-${ctrl.fileEntity.operation}`
  82. : null
  83. ctrl.handleClick = _handleFileClick
  84. $scope.$watch(
  85. () => ctrl.historyFileTreeController.selectedPathname,
  86. selectedPathname =>
  87. (ctrl.isSelected = ctrl.fileEntity.pathname === selectedPathname)
  88. )
  89. }
  90. }
  91. }
  92. export default App.component('historyFileEntity', {
  93. require: {
  94. historyFileTreeController: '^historyFileTree'
  95. },
  96. bindings: {
  97. fileEntity: '<'
  98. },
  99. controller: historyFileEntityController,
  100. templateUrl: 'historyFileEntityTpl'
  101. })