historyEntry.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* eslint-disable
  2. max-len,
  3. no-undef,
  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. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. define([
  14. 'base',
  15. 'ide/colors/ColorManager',
  16. 'ide/history/util/displayNameForUser'
  17. ], function(App, ColorManager, displayNameForUser) {
  18. const historyEntryController = function($scope, $element, $attrs, _) {
  19. const ctrl = this
  20. // This method (and maybe the one below) will be removed soon. User details data will be
  21. // injected into the history API responses, so we won't need to fetch user data from other
  22. // local data structures.
  23. const _getUserById = id =>
  24. _.find(ctrl.users, function(user) {
  25. const curUserId =
  26. (user != null ? user._id : undefined) ||
  27. (user != null ? user.id : undefined)
  28. return curUserId === id
  29. })
  30. ctrl.displayName = displayNameForUser
  31. ctrl.displayNameById = id => displayNameForUser(_getUserById(id))
  32. ctrl.getProjectOpDoc = function(projectOp) {
  33. if (projectOp.rename != null) {
  34. return `${projectOp.rename.pathname} → ${projectOp.rename.newPathname}`
  35. } else if (projectOp.add != null) {
  36. return `${projectOp.add.pathname}`
  37. } else if (projectOp.remove != null) {
  38. return `${projectOp.remove.pathname}`
  39. }
  40. }
  41. ctrl.getUserCSSStyle = function(user) {
  42. const curUserId =
  43. (user != null ? user._id : undefined) ||
  44. (user != null ? user.id : undefined)
  45. const hue = ColorManager.getHueForUserId(curUserId) || 100
  46. if (ctrl.isEntrySelected() || ctrl.isEntryHoverSelected()) {
  47. return { color: '#FFF' }
  48. } else {
  49. return { color: `hsl(${hue}, 70%, 50%)` }
  50. }
  51. }
  52. ctrl.isEntrySelected = function() {
  53. if (ctrl.rangeSelectionEnabled) {
  54. return (
  55. ctrl.entry.toV <= ctrl.selectedHistoryRange.toV &&
  56. ctrl.entry.fromV >= ctrl.selectedHistoryRange.fromV
  57. )
  58. } else {
  59. return ctrl.entry.toV === ctrl.selectedHistoryVersion
  60. }
  61. }
  62. ctrl.isEntryHoverSelected = function() {
  63. return (
  64. ctrl.rangeSelectionEnabled &&
  65. ctrl.entry.toV <= ctrl.hoveredHistoryRange.toV &&
  66. ctrl.entry.fromV >= ctrl.hoveredHistoryRange.fromV
  67. )
  68. }
  69. ctrl.onDraggingStart = () => {
  70. ctrl.historyEntriesList.onDraggingStart()
  71. }
  72. ctrl.onDraggingStop = (isValidDrop, boundary) =>
  73. ctrl.historyEntriesList.onDraggingStop(isValidDrop, boundary)
  74. ctrl.onDrop = boundary => {
  75. if (boundary === 'toV') {
  76. $scope.$applyAsync(() =>
  77. ctrl.historyEntriesList.setRangeToV(ctrl.entry.toV)
  78. )
  79. } else if (boundary === 'fromV') {
  80. $scope.$applyAsync(() =>
  81. ctrl.historyEntriesList.setRangeFromV(ctrl.entry.fromV)
  82. )
  83. }
  84. }
  85. ctrl.onOver = boundary => {
  86. if (boundary === 'toV') {
  87. $scope.$applyAsync(() =>
  88. ctrl.historyEntriesList.setHoveredRangeToV(ctrl.entry.toV)
  89. )
  90. } else if (boundary === 'fromV') {
  91. $scope.$applyAsync(() =>
  92. ctrl.historyEntriesList.setHoveredRangeFromV(ctrl.entry.fromV)
  93. )
  94. }
  95. }
  96. ctrl.$onInit = () => {
  97. ctrl.$entryEl = $element.find('> .history-entry')
  98. ctrl.$entryDetailsEl = $element.find('.history-entry-details')
  99. ctrl.$toVHandleEl = $element.find('.history-entry-toV-handle')
  100. ctrl.$fromVHandleEl = $element.find('.history-entry-fromV-handle')
  101. ctrl.historyEntriesList.onEntryLinked(ctrl.entry, ctrl.$entryEl)
  102. }
  103. }
  104. return App.component('historyEntry', {
  105. bindings: {
  106. entry: '<',
  107. currentUser: '<',
  108. users: '<',
  109. rangeSelectionEnabled: '<',
  110. isDragging: '<',
  111. selectedHistoryVersion: '<?',
  112. selectedHistoryRange: '<?',
  113. hoveredHistoryRange: '<?',
  114. onSelect: '&',
  115. onLabelDelete: '&'
  116. },
  117. require: {
  118. historyEntriesList: '^historyEntriesList'
  119. },
  120. controller: historyEntryController,
  121. templateUrl: 'historyEntryTpl'
  122. })
  123. })