breaking: #10077, store nav items in objects

isekai-main
Barış Soner Uşaklı 3 years ago
parent 3b0c42a591
commit 69c96078ea

@ -64,9 +64,6 @@
"iconClass": "fa-cogs", "iconClass": "fa-cogs",
"textClass": "visible-xs-inline", "textClass": "visible-xs-inline",
"text": "[[global:header.admin]]", "text": "[[global:header.admin]]",
"groups": ["administrators"], "groups": ["administrators"]
"properties": {
"targetBlank": false
}
} }
] ]

@ -99,12 +99,9 @@ define('admin/settings/navigation', [
const el = $('#enabled').children('[data-index="' + index + '"]'); const el = $('#enabled').children('[data-index="' + index + '"]');
const form = el.find('form').serializeArray(); const form = el.find('form').serializeArray();
const data = {}; const data = {};
const properties = {};
form.forEach(function (input) { form.forEach(function (input) {
if (input.name.slice(0, 9) === 'property:' && input.value === 'on') { if (data[input.name]) {
properties[input.name.slice(9)] = true;
} else if (data[input.name]) {
if (!Array.isArray(data[input.name])) { if (!Array.isArray(data[input.name])) {
data[input.name] = [ data[input.name] = [
data[input.name], data[input.name],
@ -116,14 +113,6 @@ define('admin/settings/navigation', [
} }
}); });
data.properties = {};
for (const prop in properties) {
if (properties.hasOwnProperty(prop)) {
data.properties[prop] = properties[prop];
}
}
nav.push(data); nav.push(data);
}); });

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

@ -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);
},
};

@ -84,7 +84,7 @@
<div class="checkbox"> <div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"> <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> <span class="mdl-switch__label"><strong>[[admin/settings/navigation:open-new-window]]</strong></span>
</label> </label>
</div> </div>

Loading…
Cancel
Save