mirror of
https://github.com/digitalocean/nginxconfig.io.git
synced 2025-08-11 03:23:34 +08:00
Import domains from url query params on load
This commit is contained in:
@@ -10,10 +10,11 @@ export default (defaults, cat, isInteraction = true) => {
|
||||
// Save user interaction if value changed
|
||||
if (isInteraction
|
||||
&& this.$parent
|
||||
&& 'hasUserInteraction' in this.$parent.$data
|
||||
&& !this.$parent.$data.hasUserInteraction
|
||||
&& 'data' in this.$parent.$props
|
||||
&& 'hasUserInteraction' in this.$parent.$props.data
|
||||
&& !this.$parent.$props.data.hasUserInteraction
|
||||
&& this.$props.data[key].value !== value)
|
||||
this.$parent.$data.hasUserInteraction = true;
|
||||
this.$parent.$props.data.hasUserInteraction = true;
|
||||
|
||||
this.$props.data[key].value = value;
|
||||
this.$props.data[key].computed = value;
|
||||
|
@@ -3,6 +3,8 @@ const categoriesExport = (categories) => {
|
||||
|
||||
// Work through each category
|
||||
for (const category in categories) {
|
||||
// Ignore presets
|
||||
if (category === 'presets') continue;
|
||||
const categoryData = {};
|
||||
|
||||
// Go over each property in the category
|
||||
|
79
src/nginxconfig/util/import_data.js
Normal file
79
src/nginxconfig/util/import_data.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import qs from 'qs';
|
||||
import clone from 'clone';
|
||||
import Domain from '../templates/domain';
|
||||
import isObject from './is_object';
|
||||
|
||||
export default (query, domains, global, nextTick) => {
|
||||
const data = qs.parse(query, {
|
||||
ignoreQueryPrefix: true,
|
||||
allowDots: true,
|
||||
decoder(value) {
|
||||
// If it's a set of digits, parse it as a float
|
||||
if (/^(\d+|\d*\.\d+)$/.test(value)) {
|
||||
return parseFloat(value);
|
||||
}
|
||||
|
||||
// If it matches a keyword, convert it
|
||||
let keywords = {
|
||||
true: true,
|
||||
false: false,
|
||||
null: null,
|
||||
undefined: undefined,
|
||||
};
|
||||
if (value in keywords) {
|
||||
return keywords[value];
|
||||
}
|
||||
|
||||
// Otherwise, leave it as is
|
||||
return value;
|
||||
},
|
||||
});
|
||||
|
||||
// Handle domains
|
||||
if ('domains' in data) {
|
||||
// Check its an array or object
|
||||
if (Array.isArray(data.domains) || isObject(data.domains)) {
|
||||
// Ensure we're working with an array
|
||||
const values = isObject(data.domains) ? Object.values(data.domains) : data.domains;
|
||||
|
||||
// Work through each potential domain
|
||||
for (const domainData of values) {
|
||||
// Check this is an object
|
||||
if (!isObject(domainData)) continue;
|
||||
|
||||
// Create a new domain (assume it has had custom user settings)
|
||||
const domainImported = clone(Domain.delegated);
|
||||
domainImported.hasUserInteraction = true;
|
||||
domains.push(domainImported);
|
||||
|
||||
// Apply the initial values on the next Vue tick, once the watchers are ready
|
||||
nextTick(() => {
|
||||
// Work through each potential category
|
||||
for (const category in domainData) {
|
||||
// Ignore presets
|
||||
if (category === 'presets') continue;
|
||||
|
||||
// Check this is a real category
|
||||
if (!(category in domainImported)) continue;
|
||||
|
||||
// Check this is an object
|
||||
if (!isObject(domainData[category])) continue;
|
||||
|
||||
// Work through each potential setting in this category
|
||||
for (const key in domainData[category]) {
|
||||
// Check this is a real key
|
||||
if (!(key in domainImported[category])) continue;
|
||||
|
||||
// Apply the value
|
||||
domainImported[category][key].value = domainData[category][key];
|
||||
domainImported[category][key].computed = domainData[category][key];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle global settings
|
||||
// TODO
|
||||
};
|
1
src/nginxconfig/util/is_object.js
Normal file
1
src/nginxconfig/util/is_object.js
Normal file
@@ -0,0 +1 @@
|
||||
export default obj => Object.prototype.toString.call(obj) === '[object Object]';
|
Reference in New Issue
Block a user