ide.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS103: Rewrite code to no longer use __guard__
  13. * DS207: Consider shorter variations of null checks
  14. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  15. */
  16. define(['base'], function(App) {
  17. // We create and provide this as service so that we can access the global ide
  18. // from within other parts of the angular app.
  19. App.factory('ide', function(
  20. $http,
  21. queuedHttp,
  22. $modal,
  23. $q,
  24. $filter,
  25. $timeout
  26. ) {
  27. const ide = {}
  28. ide.$http = $http
  29. ide.queuedHttp = queuedHttp
  30. ide.$q = $q
  31. ide.$filter = $filter
  32. ide.$timeout = $timeout
  33. this.recentEvents = []
  34. ide.pushEvent = (type, meta) => {
  35. if (meta == null) {
  36. meta = {}
  37. }
  38. sl_console.log('event', type, meta)
  39. this.recentEvents.push({ type, meta, date: new Date() })
  40. if (this.recentEvents.length > 100) {
  41. return this.recentEvents.shift()
  42. }
  43. }
  44. ide.reportError = (error, meta) => {
  45. if (meta == null) {
  46. meta = {}
  47. }
  48. meta.user_id = window.user_id
  49. meta.project_id = window.project_id
  50. meta.client_id = __guard__(
  51. this.socket != null ? this.socket.socket : undefined,
  52. x => x.sessionid
  53. )
  54. meta.transport = __guard__(
  55. __guard__(
  56. this.socket != null ? this.socket.socket : undefined,
  57. x2 => x2.transport
  58. ),
  59. x1 => x1.name
  60. )
  61. meta.client_now = new Date()
  62. meta.recent_events = this.recentEvents
  63. const errorObj = {}
  64. if (typeof error === 'object') {
  65. for (let key of Array.from(Object.getOwnPropertyNames(error))) {
  66. errorObj[key] = error[key]
  67. }
  68. } else if (typeof error === 'string') {
  69. errorObj.message = error
  70. }
  71. return $http.post('/error/client', {
  72. error: errorObj,
  73. meta,
  74. _csrf: window.csrfToken
  75. })
  76. }
  77. ide.showGenericMessageModal = (title, message) =>
  78. $modal.open({
  79. templateUrl: 'genericMessageModalTemplate',
  80. controller: 'GenericMessageModalController',
  81. resolve: {
  82. title() {
  83. return title
  84. },
  85. message() {
  86. return message
  87. }
  88. }
  89. })
  90. ide.showLockEditorMessageModal = (title, message) =>
  91. // modal to block the editor when connection is down
  92. $modal.open({
  93. templateUrl: 'lockEditorModalTemplate',
  94. controller: 'GenericMessageModalController',
  95. backdrop: 'static', // prevent dismiss by click on background
  96. keyboard: false, // prevent dismiss via keyboard
  97. resolve: {
  98. title() {
  99. return title
  100. },
  101. message() {
  102. return message
  103. }
  104. },
  105. windowClass: 'lock-editor-modal'
  106. })
  107. return ide
  108. })
  109. return App.controller('GenericMessageModalController', function(
  110. $scope,
  111. $modalInstance,
  112. title,
  113. message
  114. ) {
  115. $scope.title = title
  116. $scope.message = message
  117. return ($scope.done = () => $modalInstance.close())
  118. })
  119. })
  120. function __guard__(value, transform) {
  121. return typeof value !== 'undefined' && value !== null
  122. ? transform(value)
  123. : undefined
  124. }