Fix bug not letting add new instance + show mandatory fields with "*"
This commit is contained in:
parent
c59d25e93a
commit
addb800ec5
|
@ -13,6 +13,6 @@ if (isset($data['error']))
|
||||||
$software = trim($_GET['software']);
|
$software = trim($_GET['software']);
|
||||||
$instance = trim($_GET['instance']);
|
$instance = trim($_GET['instance']);
|
||||||
|
|
||||||
filedb_put("instances/$software/$instance/config");
|
filedb_put("instances/$software/$instance", 'config');
|
||||||
$uri = preg_replace('#api/v1/config/instances.*#', '', $_SERVER['REQUEST_URI']);
|
$uri = preg_replace('#api/v1/config/instances.*#', '', $_SERVER['REQUEST_URI']);
|
||||||
header('Location: '.$uri.'#home');
|
header('Location: '.$uri.'#home');
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
window.consts = {
|
window.consts = {
|
||||||
'instance_config': {
|
'instance_config': {
|
||||||
'mastodon': {
|
'mastodon': {
|
||||||
'musthave': ['instance_url','psql_host','psql_port','psql_db',
|
'fields': ['*instance_url','*psql_host','*psql_port','*psql_db',
|
||||||
'psql_username','psql_password','redis_host','redis_port','api_authkey'],
|
'*psql_username','*psql_password','redis_host','redis_port','*api_authkey'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<label for="software">Instance domain:</label>
|
<label for="software">Instance domain:</label>
|
||||||
<br class="sep"/>
|
<br class="sep"/>
|
||||||
<input type="text" name="instance"
|
<div class="flex">
|
||||||
class="w100" placeholder="example.org"/>
|
<input type="text" name="instance"
|
||||||
|
class="w100" placeholder="example.org"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<input class="btn green w100"
|
<input class="btn green w100"
|
||||||
|
|
|
@ -595,9 +595,12 @@ function load__instance(args) {
|
||||||
|
|
||||||
apcontrol_title(`Instance (${hargs['instance']})`);
|
apcontrol_title(`Instance (${hargs['instance']})`);
|
||||||
const config = parse_ini_config(window.vars['current_instance']['config']);
|
const config = parse_ini_config(window.vars['current_instance']['config']);
|
||||||
const musthave = window.consts['instance_config'][hargs['software']]['musthave'];
|
const fields = window.consts['instance_config'][hargs['software']]['fields'];
|
||||||
for (var i = 0; i < musthave.length; i++) {
|
for (var i = 0; i < fields.length; i++) {
|
||||||
if (config[musthave[i]] === undefined) {
|
if (!fields[i].startsWith('*'))
|
||||||
|
continue;
|
||||||
|
const f = fields[i].substr(1);
|
||||||
|
if (config[f] === undefined) {
|
||||||
window.view.instance.show_config();
|
window.view.instance.show_config();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div id="config-item">
|
<div id="config-item">
|
||||||
<label for="{field}">{placeholder}:</label>
|
<label for="{field}">{importantMark}{placeholder}:</label>
|
||||||
<input id="config_{field}" name="{field}" class="w100"
|
<input id="config_{field}" name="{field}" class="w100"
|
||||||
placeholder="{field}" type="text"/>
|
placeholder="{field}" type="text"/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,10 +25,11 @@ window.view.instance_config = {
|
||||||
mastodon: function(hargs, config) {
|
mastodon: function(hargs, config) {
|
||||||
E.element('#window-instance_config form').setAttribute('action',
|
E.element('#window-instance_config form').setAttribute('action',
|
||||||
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
|
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
|
||||||
const fields = window.consts['instance_config']['mastodon']['musthave'];
|
const fields = window.consts['instance_config']['mastodon']['fields'];
|
||||||
for (var i = 0; i < fields.length; i++) {
|
for (var i = 0; i < fields.length; i++) {
|
||||||
if (config[fields[i]] !== undefined)
|
const f = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
|
||||||
E.elemid(`config_${fields[i]}`).value = config[fields[i]];
|
if (config[f] !== undefined)
|
||||||
|
E.elemid(`config_${f}`).value = config[f];
|
||||||
}
|
}
|
||||||
if (config['instance_url'] === undefined) {
|
if (config['instance_url'] === undefined) {
|
||||||
http.get('api/v1/network/resolve-instance?hostname='+hargs['instance'],
|
http.get('api/v1/network/resolve-instance?hostname='+hargs['instance'],
|
||||||
|
@ -54,11 +55,14 @@ function load__instance_config(args) {
|
||||||
capitalize(hargs['software']) + ` (${hargs['instance']})`);
|
capitalize(hargs['software']) + ` (${hargs['instance']})`);
|
||||||
E.template('config', function(TPL) {
|
E.template('config', function(TPL) {
|
||||||
var html = '';
|
var html = '';
|
||||||
const fields = window.consts['instance_config'][hargs['software']]['musthave'];
|
const fields = window.consts['instance_config'][hargs['software']]['fields'];
|
||||||
for (var i = 0; i < fields.length; i++) {
|
for (var i = 0; i < fields.length; i++) {
|
||||||
|
const field = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
|
||||||
|
const important = fields[i].startsWith('*');
|
||||||
var tpl = TPL;
|
var tpl = TPL;
|
||||||
tpl = tpl.replaceAll('{field}', fields[i]);
|
tpl = tpl.replaceAll('{field}', field);
|
||||||
tpl = tpl.replaceAll('{placeholder}', human_field_name(fields[i]));
|
tpl = tpl.replaceAll('{placeholder}', human_field_name(field));
|
||||||
|
tpl = tpl.replaceAll('{importantMark}', important ? '*' : '');
|
||||||
html += tpl;
|
html += tpl;
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
|
|
Loading…
Reference in New Issue