mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
breaking: #10077, store nav items in objects
This commit is contained in:
@@ -64,9 +64,6 @@
|
||||
"iconClass": "fa-cogs",
|
||||
"textClass": "visible-xs-inline",
|
||||
"text": "[[global:header.admin]]",
|
||||
"groups": ["administrators"],
|
||||
"properties": {
|
||||
"targetBlank": false
|
||||
}
|
||||
"groups": ["administrators"]
|
||||
}
|
||||
]
|
||||
@@ -99,12 +99,9 @@ define('admin/settings/navigation', [
|
||||
const el = $('#enabled').children('[data-index="' + index + '"]');
|
||||
const form = el.find('form').serializeArray();
|
||||
const data = {};
|
||||
const properties = {};
|
||||
|
||||
form.forEach(function (input) {
|
||||
if (input.name.slice(0, 9) === 'property:' && input.value === 'on') {
|
||||
properties[input.name.slice(9)] = true;
|
||||
} else if (data[input.name]) {
|
||||
if (data[input.name]) {
|
||||
if (!Array.isArray(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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
28
src/upgrades/1.19.0/navigation-enabled-hashes.js
Normal file
28
src/upgrades/1.19.0/navigation-enabled-hashes.js
Normal 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);
|
||||
},
|
||||
};
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user