From f0d12ec11790debb8982ea3a2804f2e2a38b1322 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 18 Jan 2020 20:26:40 -0500 Subject: [PATCH] display loaded config on welcome page --- apprise_api/api/templates/config.html | 163 ++++++++++++++++++------ apprise_api/api/tests/test_json_urls.py | 15 ++- apprise_api/api/views.py | 5 +- apprise_api/static/css/base.css | 8 ++ 4 files changed, 151 insertions(+), 40 deletions(-) diff --git a/apprise_api/api/templates/config.html b/apprise_api/api/templates/config.html index c03b368..88611d0 100644 --- a/apprise_api/api/templates/config.html +++ b/apprise_api/api/templates/config.html @@ -1,36 +1,70 @@ {% extends 'base.html' %} {% load i18n %} {% block body %} -

{% trans "Management for:" %} {{ key }}

+

{% trans "Management for:" %} {{ key }}

-

- {% blocktrans %} - Here is where you can store your configuration so that it can be accessed by Apprise. You can always refer to the - Apprise Wiki if you're having troubles - assembling your URL(s). - You have chosen to associate your configuration with the key {{key}}. If anything was previously - associated with this key, it will be replaced if you continue. - {% endblocktrans %} -

-

- {% blocktrans %} - In the future you can return to this configuration screen at any time by placing the following into your - browser:{% endblocktrans %} -
{{request.scheme}}://{{request.META.HTTP_HOST}}{{request.path}} -

- {% blocktrans %}For example, the following command would cause apprise to retrieve the configuration loaded and - send a test notification to all of your added services:{% endblocktrans %} -
apprise --body="Test Message" --tag=all \
-     --config={{request.scheme}}://{{request.META.HTTP_HOST}}{% url "get" key %}
+
{% trans "Getting Started" %}
+
    +
  1. + {% blocktrans %} + Here is where you can store your Apprise configuration associated with the key {{key}}. + {% endblocktrans %} +
  2. +
  3. + {% blocktrans %} + You can always refer to the + Apprise Wiki if you're having + troubles + assembling your URL(s). + {% endblocktrans %} +
  4. +
  5. + {% blocktrans %} + In the future you can return to this configuration screen at any time by placing the following into your + browser: + {% endblocktrans %} + {{request.scheme}}://{{request.META.HTTP_HOST}}{{request.path}} +
  6. +
+
+
+
+

+ {% blocktrans %}To get started, the first thing you want to do is define your configuration. Do this by + clicking + on the Configuration tab. + {% endblocktrans %} +

+
+
+
+
+
{% trans "Working With Your Configuration" %}
+ {% blocktrans %}The following command would cause apprise to retrieve the configuration loaded and + send a test notification to all of your added services:{% endblocktrans %} +
+
apprise --body="Test Message" --tag=all \
+     --config={{request.scheme}}://{{request.META.HTTP_HOST}}{% url "get" key %}
+
+
+
{% trans "Loaded Configuration" %}
+
+
+
+
+
@@ -38,8 +72,8 @@ {% blocktrans %}Define your configuration below:{% endblocktrans %}
{{ form_cfg }} -

@@ -51,7 +85,7 @@ {% endblocktrans %}
{{ form_notify }} -
@@ -68,6 +102,18 @@ async function update() { document.querySelector('.config-overview li a[href="#notify"]') .parentNode.classList.add('disabled'); + // Disable any has-config entries + document.querySelector('.has-config') + .style.display = 'none'; + + // Ensure we show our progress loader and reset our url list + document.querySelector('#url-list').textContent = '' + document.querySelector('#url-list-progress').style.display = null; + + // Ensure no-config sections are visible + document.querySelector('.no-config') + .style.display = null; + // perform our status check let response = await fetch('{% url "get" key %}', { method: 'POST', @@ -92,10 +138,18 @@ async function update() { document.querySelector('#id_config').value = text; }); + // Ensure has-config sections are visible + document.querySelector('.has-config') + .style.display = null; + + // Disable any no-config entries + document.querySelector('.no-config') + .style.display = 'none'; + // perform a tag retrieval; start with 'all' let tags = ['all']; - let jsonResponse = fetch('{% url "json_urls" key %}', { + let jsonResponse = fetch('{% url "json_urls" key %}?privacy=1', { method: 'GET', }).then(function(jsonResponse) { return jsonResponse.json(); @@ -125,8 +179,41 @@ async function update() { } }); + // Now build our our loaded list of configuration for our welcome page + let urlList = document.createElement('ul'); + + // Create a list item for each url retrieved + data.urls.forEach(function (entry) { + let code = document.createElement('code'); + let li = document.createElement('li'); + code.textContent = entry.url; + li.setAttribute('class', 'card-panel'); + li.appendChild(code); + + // Get our tags associate with the URL + entry.tags.forEach(function (tag) { + let chip = document.createElement('div'); + chip.setAttribute('class', 'chip'); + chip.textContent = `🏷️ ${tag}`; + li.appendChild(chip); + }); + + urlList.appendChild(li); + }); + + // Store our new list + document.querySelector('#url-list-progress').style.display = 'none'; + document.querySelector('#url-list').textContent = '' + if(urlList.childNodes.length > 0) { + document.querySelector('#url-list').appendChild(urlList); + } else { + document.querySelector('#url-list').textContent = '{% trans "There are no Apprise URL(s) loaded." %}' + } + }).catch(function (err) { // There was an error + document.querySelector('#url-list-progress').style.display = 'none'; + document.querySelector('#url-list').textContent = '{% trans "An error occurred retrieving the list of loaded Apprise URL(s)" %}' }); return response; @@ -155,15 +242,15 @@ document.querySelector('#addconfig').onsubmit = function(event) { // user notification Swal.fire( - 'Save', - 'Successfully saved the specified URL(s).', + '{% trans "Save" %}', + '{% trans "Successfully saved the specified URL(s)." %}', 'success' ); } else { // user notification Swal.fire( - 'Save', - 'Failed to save the specified URL(s).', + '{% trans "Save" %}', + '{% trans "Failed to save the specified URL(s)." %}', 'error' ); } @@ -181,7 +268,7 @@ document.querySelector('#donotify').onsubmit = function(event) { const chipInput = document.querySelector('.chips > input'); if(chipInput.value) { // This code just handles text typed in the tag section that was - // not submitted. This forces any lingering un-commited text + // not submitted. This forces any lingering un-committed text // into a tag just prior to it's submission const ev = new KeyboardEvent('keydown', { altKey:false, @@ -223,8 +310,8 @@ document.querySelector('#donotify').onsubmit = function(event) { // perform our notification Swal.fire( - 'Notification', - 'Sending notification(s)...', + '{% trans "Notification" %}', + '{% trans "Sending notification(s)..." %}', ); Swal.showLoading() let response = fetch('{% url "notify" key %}', { @@ -235,15 +322,15 @@ document.querySelector('#donotify').onsubmit = function(event) { { // user notification Swal.fire( - 'Notification', - 'Successfully sent the notification(s).', + '{% trans "Notification" %}', + '{% trans "Successfully sent the notification(s)." %}', 'success' ); } else { // user notification Swal.fire( - 'Notification', - 'Failed to send the notification(s).', + '{% trans "Notification" %}', + '{% trans "Failed to send the notification(s)." %}', 'error' ); } diff --git a/apprise_api/api/tests/test_json_urls.py b/apprise_api/api/tests/test_json_urls.py index 21c7a12..5d27498 100644 --- a/apprise_api/api/tests/test_json_urls.py +++ b/apprise_api/api/tests/test_json_urls.py @@ -85,7 +85,20 @@ class JsonUrlsTests(SimpleTestCase): assert 'tags' in response.json() assert 'urls' in response.json() - # No errors occured, therefore no error entry + # No errors occurred, therefore no error entry + assert 'error' not in response.json() + + # No tags (but can be assumed "all") is always present + assert len(response.json()['tags']) == 0 + + # Same request as above but we set the privacy flag + response = self.client.get('/json/urls/{}?privacy=1'.format(key)) + assert response.status_code == 200 + assert response['Content-Type'].startswith('application/json') + assert 'tags' in response.json() + assert 'urls' in response.json() + + # No errors occurred, therefore no error entry assert 'error' not in response.json() # No tags (but can be assumed "all") is always present diff --git a/apprise_api/api/views.py b/apprise_api/api/views.py index b3b1a04..99dcbe9 100644 --- a/apprise_api/api/views.py +++ b/apprise_api/api/views.py @@ -532,6 +532,9 @@ class JsonUrlView(View): 'urls': [], } + # Privacy flag + privacy = bool(request.GET.get('privacy', False)) + config, format = ConfigCache.get(key) if config is None: # The returned value of config and format tell a rather cryptic @@ -583,7 +586,7 @@ class JsonUrlView(View): for notification in a_obj: # Set Notification response['urls'].append({ - 'url': notification.url(privacy=False), + 'url': notification.url(privacy=privacy), 'tags': notification.tags, }) diff --git a/apprise_api/static/css/base.css b/apprise_api/static/css/base.css index 4ac6867..ef7a167 100644 --- a/apprise_api/static/css/base.css +++ b/apprise_api/static/css/base.css @@ -66,4 +66,12 @@ textarea { .material-icons{ display: inline-flex; vertical-align: middle; +} +#url-list code { + display: block; + background-color: inherit; +} +#url-list .chip { + background-color: inherit; + border: 1px solid #e4e4e4; } \ No newline at end of file