You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

whatsnew.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  6. *
  7. * @license AGPL-3.0-or-later
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. import _ from 'underscore'
  24. import $ from 'jquery'
  25. import { generateOcsUrl } from '@nextcloud/router'
  26. /**
  27. * @param {any} options -
  28. */
  29. export function query(options) {
  30. options = options || {}
  31. const dismissOptions = options.dismiss || {}
  32. $.ajax({
  33. type: 'GET',
  34. url: options.url || generateOcsUrl('core/whatsnew?format=json'),
  35. success: options.success || function(data, statusText, xhr) {
  36. onQuerySuccess(data, statusText, xhr, dismissOptions)
  37. },
  38. error: options.error || onQueryError,
  39. })
  40. }
  41. /**
  42. * @param {any} version -
  43. * @param {any} options -
  44. */
  45. export function dismiss(version, options) {
  46. options = options || {}
  47. $.ajax({
  48. type: 'POST',
  49. url: options.url || generateOcsUrl('core/whatsnew'),
  50. data: { version: encodeURIComponent(version) },
  51. success: options.success || onDismissSuccess,
  52. error: options.error || onDismissError,
  53. })
  54. // remove element immediately
  55. $('.whatsNewPopover').remove()
  56. }
  57. /**
  58. * @param {any} data -
  59. * @param {any} statusText -
  60. * @param {any} xhr -
  61. * @param {any} dismissOptions -
  62. */
  63. function onQuerySuccess(data, statusText, xhr, dismissOptions) {
  64. console.debug('querying Whats New data was successful: ' + statusText)
  65. console.debug(data)
  66. if (xhr.status !== 200) {
  67. return
  68. }
  69. let item, menuItem, text, icon
  70. const div = document.createElement('div')
  71. div.classList.add('popovermenu', 'open', 'whatsNewPopover', 'menu-left')
  72. const list = document.createElement('ul')
  73. // header
  74. item = document.createElement('li')
  75. menuItem = document.createElement('span')
  76. menuItem.className = 'menuitem'
  77. text = document.createElement('span')
  78. text.innerText = t('core', 'New in') + ' ' + data.ocs.data.product
  79. text.className = 'caption'
  80. menuItem.appendChild(text)
  81. icon = document.createElement('span')
  82. icon.className = 'icon-close'
  83. icon.onclick = function() {
  84. dismiss(data.ocs.data.version, dismissOptions)
  85. }
  86. menuItem.appendChild(icon)
  87. item.appendChild(menuItem)
  88. list.appendChild(item)
  89. // Highlights
  90. for (const i in data.ocs.data.whatsNew.regular) {
  91. const whatsNewTextItem = data.ocs.data.whatsNew.regular[i]
  92. item = document.createElement('li')
  93. menuItem = document.createElement('span')
  94. menuItem.className = 'menuitem'
  95. icon = document.createElement('span')
  96. icon.className = 'icon-checkmark'
  97. menuItem.appendChild(icon)
  98. text = document.createElement('p')
  99. text.innerHTML = _.escape(whatsNewTextItem)
  100. menuItem.appendChild(text)
  101. item.appendChild(menuItem)
  102. list.appendChild(item)
  103. }
  104. // Changelog URL
  105. if (!_.isUndefined(data.ocs.data.changelogURL)) {
  106. item = document.createElement('li')
  107. menuItem = document.createElement('a')
  108. menuItem.href = data.ocs.data.changelogURL
  109. menuItem.rel = 'noreferrer noopener'
  110. menuItem.target = '_blank'
  111. icon = document.createElement('span')
  112. icon.className = 'icon-link'
  113. menuItem.appendChild(icon)
  114. text = document.createElement('span')
  115. text.innerText = t('core', 'View changelog')
  116. menuItem.appendChild(text)
  117. item.appendChild(menuItem)
  118. list.appendChild(item)
  119. }
  120. div.appendChild(list)
  121. document.body.appendChild(div)
  122. }
  123. /**
  124. * @param {any} x -
  125. * @param {any} t -
  126. * @param {any} e -
  127. */
  128. function onQueryError(x, t, e) {
  129. console.debug('querying Whats New Data resulted in an error: ' + t + e)
  130. console.debug(x)
  131. }
  132. /**
  133. * @param {any} data -
  134. */
  135. function onDismissSuccess(data) {
  136. // noop
  137. }
  138. /**
  139. * @param {any} data -
  140. */
  141. function onDismissError(data) {
  142. console.debug('dismissing Whats New data resulted in an error: ' + data)
  143. }