historyFileEntity.js 3.3 KB

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