mirror of
https://github.com/Casvt/MIND.git
synced 2026-04-03 03:00:22 -04:00
Added support for args in URL Builder (#3)
This commit is contained in:
@@ -88,13 +88,13 @@ def get_apprise_services() -> List[Dict[str, Union[str, Dict[str, list]]]]:
|
||||
'required': v['required'],
|
||||
'type': v['type'].split(':')[0],
|
||||
**({
|
||||
'options': v.get('values'),
|
||||
'default': v.get('default')
|
||||
} if v['type'].startswith('choice') else {
|
||||
'prefix': v.get('prefix'),
|
||||
'min': v.get('min'),
|
||||
'max': v.get('max'),
|
||||
'regex': v.get('regex')
|
||||
} if not v['type'].startswith('choice') else {
|
||||
'options': v.get('values'),
|
||||
'default': v.get('default')
|
||||
})
|
||||
}
|
||||
for k, v in
|
||||
@@ -106,6 +106,37 @@ def get_apprise_services() -> List[Dict[str, Union[str, Dict[str, list]]]]:
|
||||
|
||||
result['details']['tokens'].sort(key=_sort_tokens)
|
||||
|
||||
result['details']['args'] += [
|
||||
{
|
||||
'name': v.get('name', k),
|
||||
'map_to': k,
|
||||
'required': v.get('required', False),
|
||||
'type': v['type'].split(':')[0],
|
||||
**({
|
||||
'delim': v['delim'][0],
|
||||
'content': []
|
||||
} if v['type'].startswith('list') else {
|
||||
'options': v['values'],
|
||||
'default': v.get('default')
|
||||
} if v['type'].startswith('choice') else {
|
||||
'default': v['default']
|
||||
} if v['type'] == 'bool' else {
|
||||
'min': v.get('min'),
|
||||
'max': v.get('max'),
|
||||
'regex': v.get('regex')
|
||||
})
|
||||
}
|
||||
for k, v in
|
||||
filter(
|
||||
lambda a: (
|
||||
a[1].get('alias_of') is None
|
||||
and not a[0] in ('cto', 'format', 'overflow', 'rto', 'verify')
|
||||
),
|
||||
entry['details']['args'].items()
|
||||
)
|
||||
]
|
||||
result['details']['args'].sort(key=_sort_tokens)
|
||||
|
||||
apprise_services.append(result)
|
||||
|
||||
apprise_services.sort(key=lambda s: s['name'].lower())
|
||||
|
||||
@@ -158,7 +158,23 @@
|
||||
}
|
||||
|
||||
#add-service-window > p {
|
||||
margin-top: -.8rem;
|
||||
margin-bottom: calc((1rem + 2px) * -1);
|
||||
|
||||
border: 2px solid var(--color-gray);
|
||||
border-top-left-radius: 4px;
|
||||
border-top-right-radius: 4px;
|
||||
padding: .75rem 1rem;
|
||||
color: var(--color-gray);
|
||||
|
||||
text-align: left;
|
||||
|
||||
box-shadow: var(--default-shadow);
|
||||
}
|
||||
|
||||
#add-service-window > button {
|
||||
border-radius: 4px;
|
||||
border: 2px solid var(--color-gray);
|
||||
padding: .75rem;
|
||||
}
|
||||
|
||||
#add-service-window > a,
|
||||
|
||||
@@ -263,6 +263,23 @@ function createInt(token) {
|
||||
return int_input;
|
||||
};
|
||||
|
||||
function createBool(token) {
|
||||
const bool_input = document.createElement('select');
|
||||
bool_input.dataset.map = token.map_to || '';
|
||||
bool_input.dataset.prefix = '';
|
||||
bool_input.placeholder = token.name;
|
||||
bool_input.required = token.required;
|
||||
[['Yes', 'true'], ['No', 'false']].forEach(option => {
|
||||
const entry = document.createElement('option');
|
||||
entry.value = option[1];
|
||||
entry.innerText = option[0];
|
||||
bool_input.appendChild(entry);
|
||||
});
|
||||
bool_input.querySelector(`option[value="${token.default}"]`).setAttribute('selected', '');
|
||||
|
||||
return bool_input;
|
||||
};
|
||||
|
||||
function createEntriesList(token) {
|
||||
const entries_list = document.createElement('div');
|
||||
entries_list.classList.add('entries-list');
|
||||
@@ -345,33 +362,65 @@ function showAddServiceWindow(index) {
|
||||
|
||||
window.appendChild(createTitle());
|
||||
|
||||
data.details.tokens.forEach(token => {
|
||||
if (token.type === 'choice')
|
||||
window.appendChild(createChoice(token));
|
||||
[[data.details.tokens, 'tokens'], [data.details.args, 'args']].forEach(vars => {
|
||||
if (vars[1] === 'args' && vars[0].length > 0) {
|
||||
// The args are hidden behind a "Show Advanced Settings" button
|
||||
const show_args = document.createElement('button');
|
||||
show_args.type = 'button';
|
||||
show_args.innerText = 'Show Advanced Settings';
|
||||
show_args.addEventListener('click', e => {
|
||||
window.querySelectorAll('[data-is_arg="true"]').forEach(el => el.classList.toggle('hidden'));
|
||||
show_args.innerText = show_args.innerText === 'Show Advanced Settings' ? 'Hide Advanced Settings' : 'Show Advanced Settings';
|
||||
});
|
||||
window.appendChild(show_args);
|
||||
};
|
||||
|
||||
else if (token.type === 'list') {
|
||||
const joint_list = document.createElement('div');
|
||||
joint_list.dataset.map = token.map_to;
|
||||
joint_list.dataset.delim = token.delim;
|
||||
vars[0].forEach(token => {
|
||||
let result = null;
|
||||
if (token.type === 'choice') {
|
||||
const desc = document.createElement('p');
|
||||
desc.innerText = `${token.name}${!token.required ? ' (Optional)' : ''}`;
|
||||
desc.dataset.is_arg = vars[1] === 'args';
|
||||
window.appendChild(desc);
|
||||
result = createChoice(token);
|
||||
|
||||
} else if (token.type === 'list') {
|
||||
const joint_list = document.createElement('div');
|
||||
joint_list.dataset.map = token.map_to;
|
||||
joint_list.dataset.delim = token.delim;
|
||||
|
||||
const desc = document.createElement('p');
|
||||
desc.innerText = `${token.name}${!token.required ? ' (Optional)' : ''}`;
|
||||
joint_list.appendChild(desc);
|
||||
|
||||
if (token.content.length === 0)
|
||||
joint_list.appendChild(createEntriesList(token));
|
||||
else
|
||||
token.content.forEach(content =>
|
||||
joint_list.appendChild(createEntriesList(content))
|
||||
);
|
||||
|
||||
result = joint_list;
|
||||
|
||||
} else if (token.type === 'string')
|
||||
result = createString(token);
|
||||
else if (token.type === 'int')
|
||||
result = createInt(token);
|
||||
else if (token.type === 'bool') {
|
||||
const desc = document.createElement('p');
|
||||
desc.innerText = `${token.name}${!token.required ? ' (Optional)' : ''}`;
|
||||
desc.dataset.is_arg = vars[1] === 'args';
|
||||
window.appendChild(desc);
|
||||
result = createBool(token);
|
||||
};
|
||||
|
||||
const desc = document.createElement('p');
|
||||
desc.innerText = `${token.name}${!token.required ? ' (Optional)' : ''}`;
|
||||
joint_list.appendChild(desc);
|
||||
result.dataset.is_arg = vars[1] === 'args';
|
||||
window.appendChild(result);
|
||||
});
|
||||
|
||||
if (token.content.length === 0)
|
||||
joint_list.appendChild(createEntriesList(token));
|
||||
else
|
||||
token.content.forEach(content =>
|
||||
joint_list.appendChild(createEntriesList(content))
|
||||
);
|
||||
|
||||
window.appendChild(joint_list);
|
||||
|
||||
} else if (token.type === 'string')
|
||||
window.appendChild(createString(token));
|
||||
else if (token.type === 'int')
|
||||
window.appendChild(createInt(token));
|
||||
});
|
||||
if (vars[1] === 'args' && vars[0].length > 0)
|
||||
window.querySelectorAll('[data-is_arg="true"]').forEach(el => el.classList.toggle('hidden'));
|
||||
})
|
||||
|
||||
// Bottom options
|
||||
const options = document.createElement('div');
|
||||
@@ -396,7 +445,7 @@ function hideAddServiceWindow() {
|
||||
|
||||
function buildAppriseURL() {
|
||||
const data = notification_services[document.querySelector('#add-service-window').dataset.index];
|
||||
const inputs = document.querySelectorAll('#add-service-window > [data-map]');
|
||||
const inputs = document.querySelectorAll('#add-service-window > [data-map][data-is_arg="false"]');
|
||||
const values = {};
|
||||
|
||||
// Gather all values and format
|
||||
@@ -436,6 +485,32 @@ function buildAppriseURL() {
|
||||
for (const [key, value] of Object.entries(values))
|
||||
template = template.replace(`{${key}}`, value);
|
||||
|
||||
// Add args
|
||||
const args = [...document.querySelectorAll('#add-service-window > [data-map][data-is_arg="true"]')]
|
||||
.map(el => {
|
||||
if (['INPUT', 'SELECT'].includes(el.nodeName) && el.value)
|
||||
return `${el.dataset.map}=${el.value}`;
|
||||
else if (el.nodeName == 'DIV') {
|
||||
let value =
|
||||
[...el.querySelectorAll('.entries-list')]
|
||||
.map(l =>
|
||||
[...l.querySelectorAll('.input-entries > div')]
|
||||
.map(e => `${l.dataset.prefix || ''}${e.innerText}`)
|
||||
)
|
||||
.flat()
|
||||
.join(el.dataset.delim)
|
||||
|
||||
if (value)
|
||||
return `${el.dataset.map}=${value}`;
|
||||
};
|
||||
|
||||
return null;
|
||||
})
|
||||
.filter(el => el !== null)
|
||||
.join('&')
|
||||
template += (template.includes('?') ? '&' : '?') + args;
|
||||
template = template.replaceAll(' ', '%20');
|
||||
|
||||
console.debug(matching_templates);
|
||||
console.debug(template);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user