Add onboarding weather and template gradients
This commit is contained in:
@@ -4,6 +4,7 @@ const { buildPagination } = require('../../lib/pagination');
|
||||
const renderWeatherLocationsPage = require('./weather/list');
|
||||
const renderWeatherLocationAddPage = require('./weather/add');
|
||||
const renderWeatherLocationEditPage = require('./weather/edit');
|
||||
const { buildDuplicateWeatherLocationName, buildDuplicateWeatherLocation } = require('./weather/duplicate');
|
||||
const { fetchAppSettings } = require('../../../data/app-settings');
|
||||
|
||||
async function getWeatherLocationUsageIds(pool, common) {
|
||||
@@ -85,6 +86,26 @@ module.exports = function registerWeatherRoutes(app, deps) {
|
||||
} catch (error) { next(error); }
|
||||
});
|
||||
|
||||
app.get('/data-sources/weather/:id/duplicate', requirePermission('weather.read'), requirePermission('weather.create'), async function (req, res, next) {
|
||||
try {
|
||||
const location = await common.fetchWeatherLocationById(pool, Number(req.params.id));
|
||||
if (!location) return res.status(404).send('Weather location not found');
|
||||
|
||||
let duplicateName = buildDuplicateWeatherLocationName(location.name);
|
||||
let duplicateIndex = 2;
|
||||
while (await common.fetchDuplicateName(pool, 'i_weather_locations', duplicateName)) {
|
||||
duplicateName = buildDuplicateWeatherLocationName(location.name) + ' (' + duplicateIndex + ')';
|
||||
duplicateIndex += 1;
|
||||
}
|
||||
|
||||
res.send(renderWeatherLocationAddPage(buildDuplicateWeatherLocation(location, duplicateName), req.query.message ? String(req.query.message) : 'Review the copied values and save when ready.', req.currentUser, {
|
||||
providerAvailability: await getProviderAvailability(),
|
||||
messageVariant: 'info',
|
||||
showSaveSecondaryActions: true
|
||||
}));
|
||||
} catch (error) { next(error); }
|
||||
});
|
||||
|
||||
app.post('/data-sources/weather', requirePermission('weather.create'), async function (req, res, next) {
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Weather location duplication helpers.
|
||||
|
||||
function buildDuplicateWeatherLocationName(locationName) {
|
||||
return 'Copy of ' + String(locationName || '').trim();
|
||||
}
|
||||
|
||||
function buildDuplicateWeatherLocation(location, duplicateName) {
|
||||
return Object.assign({}, location, {
|
||||
id: null,
|
||||
name: duplicateName,
|
||||
last_pulled_at: null,
|
||||
last_pull_error: '',
|
||||
last_response_status: null,
|
||||
last_response_content_type: '',
|
||||
last_response_json: ''
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildDuplicateWeatherLocationName,
|
||||
buildDuplicateWeatherLocation
|
||||
};
|
||||
Reference in New Issue
Block a user