Release v2.18.0: template default content
This commit is contained in:
1 parent
48e8f3eb4b
commit
24f1603b43
54 files changed
+1421
-151
No files matched your search
@@ -9,12 +9,13 @@ const { fetchAppSettings } = require('#src/data/app-settings');
|
||||
|
||||
async function getDataSourceUsageMaps(pool, common) {
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const [templateRegions] = await pool.query('SELECT default_content_json FROM c_template_regions WHERE default_content_json IS NOT NULL');
|
||||
const rssFeedIds = new Set();
|
||||
|
||||
for (let index = 0; index < slides.length; index += 1) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(slides[index].content_json) : null;
|
||||
function collectUsage(json) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(json) : null;
|
||||
if (!content || typeof content !== 'object') {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
(function walk(value) {
|
||||
@@ -40,6 +41,9 @@ async function getDataSourceUsageMaps(pool, common) {
|
||||
})(content);
|
||||
}
|
||||
|
||||
slides.forEach(function (slide) { collectUsage(slide.content_json); });
|
||||
templateRegions.forEach(function (region) { collectUsage(region.default_content_json); });
|
||||
|
||||
return rssFeedIds;
|
||||
}
|
||||
|
||||
@@ -119,32 +123,8 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
return res.status(404).send('RSS feed not found');
|
||||
}
|
||||
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const inUse = (slides || []).some(function (row) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(row.content_json) : null;
|
||||
if (!content || typeof content !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const stack = [content];
|
||||
while (stack.length) {
|
||||
const value = stack.pop();
|
||||
if (!value || typeof value !== 'object') {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (item) { stack.push(item); });
|
||||
continue;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(value, 'feed_id') && Number(value.feed_id) === Number(rssFeed.id)) {
|
||||
return true;
|
||||
}
|
||||
Object.keys(value).forEach(function (key) {
|
||||
stack.push(value[key]);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
const usageIds = await getDataSourceUsageMaps(pool, common);
|
||||
const inUse = usageIds.has(Number(rssFeed.id));
|
||||
|
||||
const pulledItems = typeof common.fetchRssFeedItemsByFeedId === 'function'
|
||||
? await common.fetchRssFeedItemsByFeedId(pool, rssFeed.id)
|
||||
@@ -317,7 +297,7 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
}
|
||||
|
||||
if (await isRssFeedInUse(pool, common, rssFeed.id)) {
|
||||
return res.redirect('/data-sources/rss-feeds?message=' + encodeURIComponent('This RSS feed is still used by one or more slides.'));
|
||||
return res.redirect('/data-sources/rss-feeds?message=' + encodeURIComponent('This RSS feed is still used by slides or template defaults.'));
|
||||
}
|
||||
|
||||
const connection = await pool.getConnection();
|
||||
@@ -337,4 +317,6 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.getDataSourceUsageMaps = getDataSourceUsageMaps;
|
||||
@@ -8,12 +8,13 @@ const { buildDuplicateTimetableGroupName, buildDuplicateTimetableGroup, buildDup
|
||||
|
||||
async function getDataSourceUsageMaps(pool, common) {
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const [templateRegions] = await pool.query('SELECT default_content_json FROM c_template_regions WHERE default_content_json IS NOT NULL');
|
||||
const timetableGroupIds = new Set();
|
||||
|
||||
for (let index = 0; index < slides.length; index += 1) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(slides[index].content_json) : null;
|
||||
function collectUsage(json) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(json) : null;
|
||||
if (!content || typeof content !== 'object') {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
(function walk(value) {
|
||||
@@ -39,6 +40,9 @@ async function getDataSourceUsageMaps(pool, common) {
|
||||
})(content);
|
||||
}
|
||||
|
||||
slides.forEach(function (slide) { collectUsage(slide.content_json); });
|
||||
templateRegions.forEach(function (region) { collectUsage(region.default_content_json); });
|
||||
|
||||
return timetableGroupIds;
|
||||
}
|
||||
|
||||
@@ -324,7 +328,7 @@ module.exports = function registerTimetableRoutes(app, deps) {
|
||||
|
||||
const usageIds = await getDataSourceUsageMaps(pool, common);
|
||||
if (usageIds.has(Number(timetableGroup.id))) {
|
||||
return res.redirect('/data-sources/timetables?message=' + encodeURIComponent('This timetable group is still used by one or more slides.'));
|
||||
return res.redirect('/data-sources/timetables?message=' + encodeURIComponent('This timetable group is still used by slides or template defaults.'));
|
||||
}
|
||||
|
||||
const connection = await pool.getConnection();
|
||||
@@ -343,4 +347,6 @@ module.exports = function registerTimetableRoutes(app, deps) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.getDataSourceUsageMaps = getDataSourceUsageMaps;
|
||||
@@ -10,9 +10,10 @@ const { buildAuditChanges } = require('#src/data/audit-log');
|
||||
|
||||
async function getWeatherLocationUsageIds(pool, common) {
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const [templateRegions] = await pool.query('SELECT default_content_json FROM c_template_regions WHERE default_content_json IS NOT NULL');
|
||||
const weatherLocationIds = new Set();
|
||||
slides.forEach(function (slide) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(slide.content_json) : null;
|
||||
function collectUsage(json) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(json) : null;
|
||||
if (!content || typeof content !== 'object') return;
|
||||
(function walk(value) {
|
||||
if (!value || typeof value !== 'object') return;
|
||||
@@ -26,7 +27,9 @@ async function getWeatherLocationUsageIds(pool, common) {
|
||||
}
|
||||
Object.keys(value).forEach(function (key) { walk(value[key]); });
|
||||
}(content));
|
||||
});
|
||||
}
|
||||
slides.forEach(function (slide) { collectUsage(slide.content_json); });
|
||||
templateRegions.forEach(function (region) { collectUsage(region.default_content_json); });
|
||||
return weatherLocationIds;
|
||||
}
|
||||
|
||||
@@ -189,7 +192,7 @@ module.exports = function registerWeatherRoutes(app, deps) {
|
||||
const location = await common.fetchWeatherLocationById(pool, Number(req.params.id));
|
||||
if (!location) return res.status(404).send('Weather location not found');
|
||||
if (await isWeatherLocationInUse(pool, common, location.id)) {
|
||||
return res.redirect('/data-sources/weather?message=' + encodeURIComponent('This weather location is still used by one or more slides.'));
|
||||
return res.redirect('/data-sources/weather?message=' + encodeURIComponent('This weather location is still used by slides or template defaults.'));
|
||||
}
|
||||
await pool.query('DELETE FROM i_weather_locations WHERE id = ?', [location.id]);
|
||||
dataSourceTasks.removeRecurringRefresh('weather-location', location.id);
|
||||
@@ -197,4 +200,6 @@ module.exports = function registerWeatherRoutes(app, deps) {
|
||||
res.redirect('/data-sources/weather?message=' + encodeURIComponent('Weather location deleted.'));
|
||||
} catch (error) { next(error); }
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.getWeatherLocationUsageIds = getWeatherLocationUsageIds;
|
||||
Reference in new issue
Block a user