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.

root.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div id="updatenotification" class="followupsection">
  3. <div class="update">
  4. <template v-if="isNewVersionAvailable">
  5. <p v-if="versionIsEol">
  6. <span class="warning">
  7. <span class="icon icon-error-white"></span>
  8. {{ t('updatenotification', 'The version you are running is not maintained anymore. Please make sure to update to a supported version as soon as possible.') }}
  9. </span>
  10. </p>
  11. <p>
  12. <span v-html="newVersionAvailableString"></span><br>
  13. <span v-if="!isListFetched" class="icon icon-loading-small"></span>
  14. <span v-html="statusText"></span>
  15. </p>
  16. <template v-if="missingAppUpdates.length">
  17. <h3 @click="toggleHideMissingUpdates">
  18. {{ t('updatenotification', 'Apps missing updates') }}
  19. <span v-if="!hideMissingUpdates" class="icon icon-triangle-n"></span>
  20. <span v-if="hideMissingUpdates" class="icon icon-triangle-s"></span>
  21. </h3>
  22. <ul class="applist" v-if="!hideMissingUpdates">
  23. <li v-for="app in missingAppUpdates"><a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{app.appName}} ↗</a></li>
  24. </ul>
  25. </template>
  26. <template v-if="availableAppUpdates.length">
  27. <h3 @click="toggleHideAvailableUpdates">
  28. {{ t('updatenotification', 'Apps with available updates') }}
  29. <span v-if="!hideAvailableUpdates" class="icon icon-triangle-n"></span>
  30. <span v-if="hideAvailableUpdates" class="icon icon-triangle-s"></span>
  31. </h3>
  32. <ul class="applist">
  33. <li v-for="app in availableAppUpdates" v-if="!hideAvailableUpdates"><a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{app.appName}} ↗</a></li>
  34. </ul>
  35. </template>
  36. <div>
  37. <a v-if="updaterEnabled" href="#" class="button primary" @click="clickUpdaterButton">{{ t('updatenotification', 'Open updater') }}</a>
  38. <a v-if="downloadLink" :href="downloadLink" class="button" :class="{ hidden: !updaterEnabled }">{{ t('updatenotification', 'Download now') }}</a>
  39. <div class="whatsNew" v-if="whatsNew">
  40. <div class="toggleWhatsNew">
  41. <a class="button" v-click-outside="hideMenu" @click="toggleMenu">{{ t('updatenotification', 'What\'s new?') }}</a>
  42. <div class="popovermenu" :class="{ 'menu-center': true, open: openedWhatsNew }">
  43. <popover-menu :menu="whatsNew" />
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <template v-else-if="!isUpdateChecked">{{ t('updatenotification', 'The update check is not yet finished. Please refresh the page.') }}</template>
  50. <template v-else>
  51. {{ t('updatenotification', 'Your version is up to date.') }}
  52. <span class="icon-info svg" v-tooltip.auto="lastCheckedOnString"></span>
  53. </template>
  54. <template v-if="!isDefaultUpdateServerURL">
  55. <p class="topMargin">
  56. <em>{{ t('updatenotification', 'A non-default update server is in use to be checked for updates:') }} <code>{{updateServerURL}}</code></em>
  57. </p>
  58. </template>
  59. </div>
  60. <h3 class="update-channel-selector">
  61. {{ t('updatenotification', 'Update channel:') }}
  62. <div class="update-menu">
  63. <span class="icon-update-menu" @click="toggleUpdateChannelMenu">
  64. {{ localizedChannelName }}
  65. <span class="icon-triangle-s"></span>
  66. </span>
  67. <div class="popovermenu menu menu-center" v-bind:class="{ 'show-menu': openedUpdateChannelMenu}">
  68. <popover-menu :menu="channelList" />
  69. </div>
  70. </div>
  71. </h3>
  72. <span id="channel_save_msg" class="msg"></span><br />
  73. <p>
  74. <em>{{ t('updatenotification', 'You can always update to a newer version. But you can never downgrade to a more stable version.') }}</em><br />
  75. <em>{{ t('updatenotification', 'Note that after a new release it can take some time before it shows up here. We roll out new versions spread out over time to our users and sometimes skip a version when issues are found.') }}</em>
  76. </p>
  77. <p id="oca_updatenotification_groups">
  78. {{ t('updatenotification', 'Notify members of the following groups about available updates:') }}
  79. <multiselect v-model="notifyGroups" :options="availableGroups" :multiple="true" label="label" track-by="value" :tag-width="75" /><br />
  80. <em v-if="currentChannel === 'daily' || currentChannel === 'git'">{{ t('updatenotification', 'Only notification for app updates are available.') }}</em>
  81. <em v-if="currentChannel === 'daily'">{{ t('updatenotification', 'The selected update channel makes dedicated notifications for the server obsolete.') }}</em>
  82. <em v-if="currentChannel === 'git'">{{ t('updatenotification', 'The selected update channel does not support updates of the server.') }}</em>
  83. </p>
  84. </div>
  85. </template>
  86. <script>
  87. import { PopoverMenu, Multiselect } from 'nextcloud-vue';
  88. import { VTooltip } from 'v-tooltip';
  89. import ClickOutside from 'vue-click-outside';
  90. export default {
  91. name: 'root',
  92. components: {
  93. Multiselect,
  94. PopoverMenu,
  95. },
  96. directives: {
  97. ClickOutside,
  98. tooltip: VTooltip
  99. },
  100. data: function () {
  101. return {
  102. newVersionString: '',
  103. lastCheckedDate: '',
  104. isUpdateChecked: false,
  105. updaterEnabled: true,
  106. versionIsEol: false,
  107. downloadLink: '',
  108. isNewVersionAvailable: false,
  109. hasValidSubscription: false,
  110. updateServerURL: '',
  111. changelogURL: '',
  112. whatsNewData: [],
  113. currentChannel: '',
  114. channels: [],
  115. notifyGroups: '',
  116. availableGroups: [],
  117. isDefaultUpdateServerURL: true,
  118. enableChangeWatcher: false,
  119. availableAppUpdates: [],
  120. missingAppUpdates: [],
  121. appStoreFailed: false,
  122. appStoreDisabled: false,
  123. isListFetched: false,
  124. hideMissingUpdates: false,
  125. hideAvailableUpdates: true,
  126. openedWhatsNew: false,
  127. openedUpdateChannelMenu: false,
  128. };
  129. },
  130. _$el: null,
  131. _$notifyGroups: null,
  132. watch: {
  133. notifyGroups: function(selectedOptions) {
  134. if (!this.enableChangeWatcher) {
  135. return;
  136. }
  137. var selectedGroups = [];
  138. _.each(selectedOptions, function(group) {
  139. selectedGroups.push(group.value);
  140. });
  141. OCP.AppConfig.setValue('updatenotification', 'notify_groups', JSON.stringify(selectedGroups));
  142. },
  143. isNewVersionAvailable: function() {
  144. if (!this.isNewVersionAvailable) {
  145. return;
  146. }
  147. $.ajax({
  148. url: OC.linkToOCS('apps/updatenotification/api/v1/applist', 2) + this.newVersion,
  149. type: 'GET',
  150. beforeSend: function (request) {
  151. request.setRequestHeader('Accept', 'application/json');
  152. },
  153. success: function(response) {
  154. this.availableAppUpdates = response.ocs.data.available;
  155. this.missingAppUpdates = response.ocs.data.missing;
  156. this.isListFetched = true;
  157. this.appStoreFailed = false;
  158. }.bind(this),
  159. error: function(xhr) {
  160. this.availableAppUpdates = [];
  161. this.missingAppUpdates = [];
  162. this.appStoreDisabled = xhr.responseJSON.ocs.data.appstore_disabled;
  163. this.isListFetched = true;
  164. this.appStoreFailed = true;
  165. }.bind(this)
  166. });
  167. }
  168. },
  169. computed: {
  170. newVersionAvailableString: function() {
  171. return t('updatenotification', 'A new version is available: <strong>{newVersionString}</strong>', {
  172. newVersionString: this.newVersionString
  173. });
  174. },
  175. lastCheckedOnString: function() {
  176. return t('updatenotification', 'Checked on {lastCheckedDate}', {
  177. lastCheckedDate: this.lastCheckedDate
  178. });
  179. },
  180. statusText: function() {
  181. if (!this.isListFetched) {
  182. return t('updatenotification', 'Checking apps for compatible updates');
  183. }
  184. if (this.appStoreDisabled) {
  185. return t('updatenotification', 'Please make sure your config.php does not set <samp>appstoreenabled</samp> to false.');
  186. }
  187. if (this.appStoreFailed) {
  188. return t('updatenotification', 'Could not connect to the appstore or the appstore returned no updates at all. Search manually for updates or make sure your server has access to the internet and can connect to the appstore.');
  189. }
  190. return this.missingAppUpdates.length === 0 ? t('updatenotification', '<strong>All</strong> apps have an update for this version available', this) : n('updatenotification',
  191. '<strong>%n</strong> app has no update for this version available',
  192. '<strong>%n</strong> apps have no update for this version available',
  193. this.missingAppUpdates.length);
  194. },
  195. whatsNew: function() {
  196. if(this.whatsNewData.length === 0) {
  197. return null;
  198. }
  199. var whatsNew = [];
  200. for (var i in this.whatsNewData) {
  201. whatsNew[i] = { icon: 'icon-checkmark', longtext: this.whatsNewData[i] };
  202. }
  203. if(this.changelogURL) {
  204. whatsNew.push({
  205. href: this.changelogURL,
  206. text: t('updatenotification', 'View changelog'),
  207. icon: 'icon-link',
  208. target: '_blank',
  209. action: ''
  210. });
  211. }
  212. return whatsNew;
  213. },
  214. channelList: function() {
  215. let channelList = [];
  216. channelList.push({
  217. text: t('updatenotification', 'Enterprise'),
  218. longtext: t('updatenotification', 'For enterprise use. Provides always the latest patch level, but will not update to the next major release immediately. That update happens once Nextcloud GmbH has done additional hardening and testing for large-scale and mission-critical deployments. This channel is only available to customers and provides the Nextcloud Enterprise package.'),
  219. icon: 'icon-star',
  220. active: this.currentChannel === 'enterprise',
  221. disabled: !this.hasValidSubscription,
  222. action: this.changeReleaseChannelToEnterprise
  223. });
  224. channelList.push({
  225. text: t('updatenotification', 'Stable'),
  226. longtext: t('updatenotification', 'The most recent stable version. It is suited for regular use and will always update to the latest major version.'),
  227. icon: 'icon-checkmark',
  228. active: this.currentChannel === 'stable',
  229. action: this.changeReleaseChannelToStable
  230. });
  231. channelList.push({
  232. text: t('updatenotification', 'Beta'),
  233. longtext: t('updatenotification', 'A pre-release version only for testing new features, not for production environments.'),
  234. icon: 'icon-category-customization',
  235. active: this.currentChannel === 'beta',
  236. action: this.changeReleaseChannelToBeta
  237. });
  238. if (this.isNonDefaultChannel) {
  239. channelList.push({
  240. text: this.currentChannel,
  241. icon: 'icon-rename',
  242. active: true
  243. });
  244. }
  245. return channelList;
  246. },
  247. isNonDefaultChannel: function() {
  248. return this.currentChannel !== 'enterprise' && this.currentChannel !== 'stable' && this.currentChannel !== 'beta';
  249. },
  250. localizedChannelName: function() {
  251. switch (this.currentChannel) {
  252. case 'enterprise':
  253. return t('updatenotification', 'Enterprise');
  254. break;
  255. case 'stable':
  256. return t('updatenotification', 'Stable');
  257. break;
  258. case 'beta':
  259. return t('updatenotification', 'Beta');
  260. break;
  261. default:
  262. return this.currentChannel;
  263. break;
  264. }
  265. }
  266. },
  267. methods: {
  268. /**
  269. * Creates a new authentication token and loads the updater URL
  270. */
  271. clickUpdaterButton: function() {
  272. $.ajax({
  273. url: OC.generateUrl('/apps/updatenotification/credentials')
  274. }).success(function(token) {
  275. // create a form to send a proper post request to the updater
  276. var form = document.createElement('form');
  277. form.setAttribute('method', 'post');
  278. form.setAttribute('action', OC.getRootPath() + '/updater/');
  279. var hiddenField = document.createElement('input');
  280. hiddenField.setAttribute('type', 'hidden');
  281. hiddenField.setAttribute('name', 'updater-secret-input');
  282. hiddenField.setAttribute('value', token);
  283. form.appendChild(hiddenField);
  284. document.body.appendChild(form);
  285. form.submit();
  286. }.bind(this));
  287. },
  288. changeReleaseChannelToEnterprise: function() {
  289. this.changeReleaseChannel('enterprise')
  290. },
  291. changeReleaseChannelToStable: function() {
  292. this.changeReleaseChannel('stable')
  293. },
  294. changeReleaseChannelToBeta: function() {
  295. this.changeReleaseChannel('beta')
  296. },
  297. changeReleaseChannel: function(channel) {
  298. this.currentChannel = channel;
  299. $.ajax({
  300. url: OC.generateUrl('/apps/updatenotification/channel'),
  301. type: 'POST',
  302. data: {
  303. 'channel': this.currentChannel
  304. },
  305. success: function (data) {
  306. OC.msg.finishedAction('#channel_save_msg', data);
  307. }
  308. });
  309. this.openedUpdateChannelMenu = false;
  310. },
  311. toggleUpdateChannelMenu: function() {
  312. this.openedUpdateChannelMenu = !this.openedUpdateChannelMenu;
  313. },
  314. toggleHideMissingUpdates: function() {
  315. this.hideMissingUpdates = !this.hideMissingUpdates;
  316. },
  317. toggleHideAvailableUpdates: function() {
  318. this.hideAvailableUpdates = !this.hideAvailableUpdates;
  319. },
  320. toggleMenu: function() {
  321. this.openedWhatsNew = !this.openedWhatsNew;
  322. },
  323. hideMenu: function() {
  324. this.openedWhatsNew = false;
  325. },
  326. },
  327. beforeMount: function() {
  328. // Parse server data
  329. var data = JSON.parse($('#updatenotification').attr('data-json'));
  330. this.newVersion = data.newVersion;
  331. this.newVersionString = data.newVersionString;
  332. this.lastCheckedDate = data.lastChecked;
  333. this.isUpdateChecked = data.isUpdateChecked;
  334. this.updaterEnabled = data.updaterEnabled;
  335. this.downloadLink = data.downloadLink;
  336. this.isNewVersionAvailable = data.isNewVersionAvailable;
  337. this.updateServerURL = data.updateServerURL;
  338. this.currentChannel = data.currentChannel;
  339. this.channels = data.channels;
  340. this.notifyGroups = data.notifyGroups;
  341. this.isDefaultUpdateServerURL = data.isDefaultUpdateServerURL;
  342. this.versionIsEol = data.versionIsEol;
  343. this.hasValidSubscription = data.hasValidSubscription;
  344. if(data.changes && data.changes.changelogURL) {
  345. this.changelogURL = data.changes.changelogURL;
  346. }
  347. if(data.changes && data.changes.whatsNew) {
  348. if(data.changes.whatsNew.admin) {
  349. this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.admin);
  350. }
  351. this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.regular);
  352. }
  353. },
  354. mounted: function () {
  355. this._$el = $(this.$el);
  356. this._$notifyGroups = this._$el.find('#oca_updatenotification_groups_list');
  357. this._$notifyGroups.on('change', function () {
  358. this.$emit('input');
  359. }.bind(this));
  360. $.ajax({
  361. url: OC.linkToOCS('cloud', 2)+ '/groups',
  362. dataType: 'json',
  363. success: function(data) {
  364. var results = [];
  365. $.each(data.ocs.data.groups, function(i, group) {
  366. results.push({value: group, label: group});
  367. });
  368. this.availableGroups = results;
  369. this.enableChangeWatcher = true;
  370. }.bind(this)
  371. });
  372. }
  373. }
  374. </script>
  375. <style lang="scss" scoped>
  376. #updatenotification {
  377. margin-top: -25px;
  378. margin-bottom: 200px;
  379. div.update,
  380. p:not(.inlineblock) {
  381. margin-bottom: 25px;
  382. }
  383. h2.inlineblock {
  384. margin-top: 25px;
  385. }
  386. h3 {
  387. cursor: pointer;
  388. .icon {
  389. cursor: pointer;
  390. }
  391. &:first-of-type {
  392. margin-top: 0;
  393. }
  394. &.update-channel-selector {
  395. display: inline-block;
  396. cursor: inherit;
  397. }
  398. }
  399. .icon {
  400. display: inline-block;
  401. margin-bottom: -3px;
  402. }
  403. .icon-triangle-s, .icon-triangle-n {
  404. opacity: 0.5;
  405. }
  406. .whatsNew {
  407. display: inline-block;
  408. }
  409. .toggleWhatsNew {
  410. position: relative;
  411. }
  412. .popovermenu {
  413. p {
  414. margin-bottom: 0;
  415. width: 100%;
  416. }
  417. margin-top: 5px;
  418. width: 300px;
  419. }
  420. .applist {
  421. margin-bottom: 25px;
  422. }
  423. .update-menu {
  424. position: relative;
  425. cursor: pointer;
  426. margin-left: 3px;
  427. display: inline-block;
  428. .icon-update-menu {
  429. cursor: inherit;
  430. .icon-triangle-s {
  431. display: inline-block;
  432. vertical-align: middle;
  433. cursor: inherit;
  434. opacity: 1;
  435. }
  436. }
  437. .popovermenu {
  438. display: none;
  439. top: 28px;
  440. &.show-menu {
  441. display: block;
  442. }
  443. }
  444. }
  445. }
  446. </style>
  447. <style lang="scss">
  448. /* override needed to make menu wider */
  449. #updatenotification .popovermenu {
  450. p {
  451. margin-top: 5px;
  452. width: 100%;
  453. }
  454. margin-top: 5px;
  455. width: 300px;
  456. }
  457. /* override needed to replace yellow hover state with a dark one */
  458. #updatenotification .update-menu .icon-star:hover,
  459. #updatenotification .update-menu .icon-star:focus {
  460. background-image: var(--icon-star-000);
  461. }
  462. #updatenotification .topMargin {
  463. margin-top: 15px;
  464. }
  465. </style>