breaking: #10077, store nav items in objects

This commit is contained in:
Barış Soner Uşaklı
2021-12-13 16:00:22 -05:00
parent 3b0c42a591
commit 69c96078ea
5 changed files with 44 additions and 24 deletions

View File

@@ -15,15 +15,20 @@ pubsub.on('admin:navigation:save', () => {
admin.save = async function (data) {
const order = Object.keys(data);
const items = data.map((item, index) => {
const bulkSet = [];
data.forEach((item, index) => {
item.order = order[index];
return JSON.stringify(item);
if (item.hasOwnProperty('groups')) {
item.groups = JSON.stringify(item.groups);
}
bulkSet.push([`navigation:enabled:${item.order}`, item]);
});
cache = null;
pubsub.publish('admin:navigation:save');
await db.setObjectBulk(bulkSet);
await db.delete('navigation:enabled');
await db.sortedSetAdd('navigation:enabled', order, items);
await db.sortedSetAdd('navigation:enabled', order, order);
};
admin.getAdmin = async function () {
@@ -55,9 +60,12 @@ admin.get = async function () {
if (cache) {
return cache.map(item => ({ ...item }));
}
const data = await db.getSortedSetRange('navigation:enabled', 0, -1);
const ids = await db.getSortedSetRange('navigation:enabled', 0, -1);
const data = await db.getObjects(ids.map(id => `navigation:enabled:${id}`));
cache = data.map((item) => {
item = JSON.parse(item);
if (item.hasOwnProperty('groups')) {
item.groups = JSON.parse(item.groups);
}
item.groups = item.groups || [];
if (item.groups && !Array.isArray(item.groups)) {
item.groups = [item.groups];
@@ -73,8 +81,6 @@ async function getAvailable() {
const core = require('../../install/data/navigation.json').map((item) => {
item.core = true;
item.id = item.id || '';
item.properties = item.properties || { targetBlank: false };
return item;
});

View File

@@ -0,0 +1,28 @@
'use strict';
const db = require('../../database');
module.exports = {
name: 'Upgrade navigation items to hashes',
timestamp: Date.UTC(2021, 11, 13),
method: async function () {
const data = await db.getSortedSetRangeWithScores('navigation:enabled', 0, -1);
const order = [];
const bulkSet = [];
data.forEach((item) => {
const navItem = JSON.parse(item.value);
if (navItem.hasOwnProperty('properties') && navItem.properties) {
if (navItem.properties.hasOwnProperty('targetBlank')) {
navItem.targetBlank = navItem.properties.targetBlank;
}
delete navItem.properties;
}
bulkSet.push([`navigation:enabled:${item.score}`, navItem]);
order.push(item.score);
});
await db.setObjectBulk(bulkSet);
await db.delete('navigation:enabled');
await db.sortedSetAdd('navigation:enabled', order, order);
},
};

View File

@@ -84,7 +84,7 @@
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input class="mdl-switch__input" type="checkbox" name="property:targetBlank" <!-- IF enabled.properties.targetBlank -->checked<!-- ENDIF enabled.properties.targetBlank -->/>
<input class="mdl-switch__input" type="checkbox" name="targetBlank" <!-- IF enabled.targetBlank -->checked<!-- ENDIF enabled.targetBlank -->/>
<span class="mdl-switch__label"><strong>[[admin/settings/navigation:open-new-window]]</strong></span>
</label>
</div>