From aa31002b03229932c532f05045c9f8852245ffe1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Oct 2022 11:17:52 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=A7=AD=20Fix=20rebuilding=20the=20navigati?= =?utf8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Joas Schilling --- .../src/service/rebuild-navigation.js | 119 +----------------- core/src/components/AppMenu.vue | 6 + 2 files changed, 8 insertions(+), 117 deletions(-) diff --git a/apps/settings/src/service/rebuild-navigation.js b/apps/settings/src/service/rebuild-navigation.js index 57cb1e439bd..b252234df83 100644 --- a/apps/settings/src/service/rebuild-navigation.js +++ b/apps/settings/src/service/rebuild-navigation.js @@ -1,5 +1,6 @@ import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' +import { emit } from '@nextcloud/event-bus' export default () => { return axios.get(generateOcsUrl('core/navigation', 2) + '/apps?format=json') @@ -8,123 +9,7 @@ export default () => { return } - const addedApps = {} - const navEntries = data.ocs.data - const container = document.querySelector('#navigation #apps ul') - - // remove disabled apps - navEntries.forEach((entry) => { - if (!container.querySelector('li[data-id="' + entry.id + '"]')) { - addedApps[entry.id] = true - } - }) - - container.querySelectorAll('li[data-id]').forEach((el, index) => { - const id = el.dataset.id - // remove all apps that are not in the correct order - if (!navEntries[index] || (navEntries[index] && navEntries[index].id !== id)) { - el.remove() - document.querySelector(`#appmenu li[data-id=${id}]`).remove() - } - }) - - let previousEntry = {} - // add enabled apps to #navigation and #appmenu - navEntries.forEach((entry) => { - if (container.querySelector(`li[data-id="${entry.id}"]`) === null) { - const li = document.createElement('li') - li.dataset.id = entry.id - const img = ` - - - - - - - - - ` - - const imgElement = document.createElement('template') - imgElement.innerHTML = img - - const a = document.createElement('a') - a.setAttribute('href', entry.href) - - const filename = document.createElement('span') - filename.appendChild(document.createTextNode(entry.name)) - - const loading = document.createElement('div') - loading.setAttribute('class', 'unread-counter') - loading.style.display = 'none' - - // draw attention to the newly added app entry - // by flashing twice the more apps menu - if (addedApps[entry.id]) { - a.classList.add('animated') - } - - a.prepend(imgElement.content.firstChild, loading, filename) - li.append(a) - - // add app icon to the navigation - const previousElement = document.querySelector(`#navigation li[data-id=${previousEntry.id}]`) - if (previousElement) { - previousElement.insertAdjacentElement('afterend', li) - } else { - document.querySelector('#navigation #apps ul').prepend(li) - } - } - - if (document.getElementById('appmenu').querySelector(`li[data-id="${entry.id}"]`) === null) { - const li = document.createElement('li') - li.dataset.id = entry.id - // Generating svg embedded image (see layout.user.php) - let img - if (OCA.Theming && OCA.Theming.inverted) { - img = ` - - - - - ` - } else { - img = ` - - ` - } - const imgElement = document.createElement('template') - imgElement.innerHTML = img - - const a = document.createElement('a') - a.setAttribute('href', entry.href) - - const filename = document.createElement('span') - filename.appendChild(document.createTextNode(entry.name)) - - const loading = document.createElement('div') - loading.setAttribute('class', 'icon-loading-dark') - loading.style.display = 'none' - - // draw attention to the newly added app entry - // by flashing twice the more apps menu - if (addedApps[entry.id]) { - a.classList.add('animated') - } - - a.prepend(loading, filename, imgElement.content.firstChild) - li.append(a) - - // add app icon to the navigation - const previousElement = document.querySelector('#appmenu li[data-id=' + previousEntry.id + ']') - if (previousElement) { - previousElement.insertAdjacentElement('afterend', li) - } else { - document.queryElementById('appmenu').prepend(li) - } - } - previousEntry = entry - }) + emit('nextcloud:app-menu.refresh', { apps: data.ocs.data }) window.dispatchEvent(new Event('resize')) }) } diff --git a/core/src/components/AppMenu.vue b/core/src/components/AppMenu.vue index 0a337340ccb..2ee91c30f40 100644 --- a/core/src/components/AppMenu.vue +++ b/core/src/components/AppMenu.vue @@ -60,6 +60,7 @@