make settings a 2-step process, to fix #27

This commit is contained in:
Kyle Mahan 2015-07-30 07:06:58 -07:00
parent 1956a59bb0
commit 9ca946809b
6 changed files with 161 additions and 143 deletions

View file

@ -1,8 +1,7 @@
{% set settings = current_user.settings or {} %}
{% set replyMethod = settings.get('reply-method') %}
{% if replyMethod == 'micropub' and current_user.micropub_endpoint %}
{% set reply_method = settings.get('reply-method') %}
{% if reply_method == 'micropub' and current_user.micropub_endpoint %}
<form class="micropub-form" action="{{ url_for('api.publish') }}" method="POST">
<input type="hidden" name="target" value="{{ entry.permalink }}"/>
<div>
@ -22,14 +21,13 @@
</form>
<div class="micropub-response">
</div>
{% elif replyMethod == 'indie-config' %}
{% elif reply_method == 'indie-config' %}
{% for action in settings.get('indie-config-actions', []) %}
<indie-action with="{{ entry.permalink }}" do="{{ action }}">
<a class="reply-link" href="#">{{ action | capitalize }}</a>
</indie-action>
{% endfor %}
{% elif replyMethod == 'action-urls' %}
{% elif reply_method == 'action-urls' %}
{% for action, url in settings.get('action-urls', []) %}
<a class="reply-link" href="{{ url | replace('{url}', entry.permalink) }}" target="_blank">{{ action | capitalize }}</a>
{% endfor %}

View file

@ -1,131 +1,26 @@
{% extends "base.jinja2" %}
{% block body %}
<main>
{% set reply_method = settings.get('reply-method') %}
<form id="settings" name="settings" action="{{ url_for('.settings') }}"
method="POST" data-reply-method="{{reply_method}}">
<button type="submit">Save Changes</button>
<div id="reply-mechanism-settings">
<h2>Reply Mechanism</h2>
<p>
<input type="radio" id="reply-method-micropub"
name="reply-method" value="micropub"
{% if reply_method == 'micropub' %}checked{% endif %}/>
<label for="reply-method-micropub">Micropub.</label>
Each post will have a Like and Reply button that will post content to your site directly via micropub. See <a href="https://indiewebcamp.com/Micropub">Micropub</a> for details.
</p>
<p>
<input type="radio" id="reply-method-indie-config"
name="reply-method" value="indie-config"
{% if reply_method == 'indie-config' %}checked{% endif %}/>
<label for="reply-method-indie-config">Indie-config.</label>
Clicking Like or Reply will invoke your <code>web+action</code> handler if registered. See <a href="https://indiewebcamp.com/indie-config">indie-config</a> for details.
</p>
<p>
<input type="radio" id="reply-method-action-urls"
name="reply-method" value="action-urls"
{% if reply_method == 'action-urls' %}checked{% endif %}/>
<label for="reply-method-action-urls">Configurable action urls.</label>
Configure Woodwind with your preferred web action handlers. The placeholder <code>{url}</code> will be replaced with the permalink URL of each entry.
</p>
</div>
<!-- reply via micropub -->
<div id="micropub-settings">
<h2>Micropub</h2>
<p>
Configure micropub credentials.
</p>
{% if current_user.micropub_endpoint or current_user.access_token %}
<input type="text" value="{{ current_user.micropub_endpoint }}" readonly />
<input type="text" value="{{ current_user.access_token }}" readonly />
<p>
<a href="{{url_for('.authorize', next=request.path)}}">Reauthorize Micropub</a>
</p>
<p>
<a href="{{url_for('.deauthorize', next=request.path)}}">Revoke Credentials</a>
</p>
{% else %}
<p>
<a href="{{url_for('.authorize', next=request.path)}}">Authorize Micropub</a>
</p>
{% endif %}
</div>
<!-- reply via indie-config -->
<div id="indie-config-settings">
<h2>Indie-Config</h2>
<p>
Select indie-config actions.
</p>
{% set selectedActions = settings.get('indie-config-actions', []) %}
<p>
{% for action in ['like', 'favorite', 'reply', 'repost', 'bookmark'] %}
<label>
<input type="checkbox" name="indie-config-action" value="{{ action }}"
{% if action in selectedActions %}checked{% endif %} />
{{ action | capitalize }}
</label><br/>
{% endfor %}
</p>
</div>
<!-- configure endpoints manually -->
<div id="action-urls-settings">
<h2>Action URLs</h2>
<div id="action-urls-inputs">
{% set actionUrls = settings.get('action-urls', {}) %}
{% for action, url in actionUrls %}
<input type="text" name="action" class="input-25" value="{{action}}" />
<input type="text" name="action-url" class="input-75" value="{{url}}" />
{% endfor %}
<input type="text" id="action-1" name="action" class="input-25" placeholder="Like" />
<input type="text" id="action-url-1" name="action-url" class="input-75" placeholder="http://example.com/new/like?url={url}" />
</div>
<button id="add-action">Add</button>
</div>
<button type="submit">Save Changes</button>
<form method="POST">
{% set reply_method = settings.get('reply-method') %}
<h2>Reply Mechanism</h2>
<p>
<input type="radio" id="reply-method-micropub" name="reply-method" value="micropub" {% if reply_method == 'micropub' %}checked{% endif %}/>
<label for="reply-method-micropub">Micropub.</label>
Each post will have Like, Repost, and Reply buttons that will post content to your site directly via micropub. See <a href="https://indiewebcamp.com/Micropub">Micropub</a> for details.
</p>
<p>
<input type="radio" id="reply-method-indie-config" name="reply-method" value="indie-config" {% if reply_method == 'indie-config' %}checked{% endif %}/>
<label for="reply-method-indie-config">Indie-config.</label>
Clicking an indie-action link will invoke your <code>web+action</code> handler if registered. See <a href="https://indiewebcamp.com/indie-config">indie-config</a> for details.
</p>
<p>
<input type="radio" id="reply-method-action-urls" name="reply-method" value="action-urls" {% if reply_method == 'action-urls' %}checked{% endif %}/>
<label for="reply-method-action-urls">Configurable action urls.</label>
Manually configure your own web action handlers. The placeholder <code>{url}</code> will be replaced with the permalink URL of each entry.
</p>
<button type="submit">Next</button>
</form>
</main>
<script>
$('#add-action').click(function(evt) {
evt.preventDefault();
$('#action-1').clone().appendTo('#action-urls-inputs');
$('#action-url-1').clone().appendTo('#action-urls-inputs');
});
function showRelevantSection() {
var savedReplyMethod = $('form').data('reply-method')
var replyMethod = $('input[name=reply-method]:checked').val();
$('#micropub-settings').hide();
$('#indie-config-settings').hide();
$('#action-urls-settings').hide();
if (replyMethod == 'micropub' && savedReplyMethod == 'micropub') {
$('#micropub-settings').show();
} else if (replyMethod == 'indie-config') {
$('#indie-config-settings').show();
} else if (replyMethod == 'action-urls') {
$('#action-urls-settings').show();
}
}
$('input[name=reply-method]').change(showRelevantSection);
$(showRelevantSection);
</script>
{% endblock body %}

View file

@ -0,0 +1,36 @@
{% extends "base.jinja2" %}
{% block body %}
<main>
<form method="POST">
<!-- configure endpoints manually -->
<h2>Action URLs</h2>
<p>
Manually configure your own web action handlers. The placeholder <code>{url}</code> will be replaced with the permalink URL of each entry.
</p>
<div id="action-urls-inputs">
{% set actionUrls = settings.get('action-urls', {}) %}
{% for action, url in actionUrls %}
<input type="text" name="action" class="input-25" value="{{action}}" />
<input type="text" name="action-url" class="input-75" value="{{url}}" />
{% endfor %}
<input type="text" id="action-1" name="action" class="input-25" placeholder="Like" />
<input type="text" id="action-url-1" name="action-url" class="input-75" placeholder="http://example.com/new/like?url={url}" />
</div>
<div style="text-align: center">
<button style="" id="add-action">Add</button>
</div>
<div>
<button type="submit">Save Changes</button>
</div>
</p>
</form>
</main>
<script>
$('#add-action').click(function(evt) {
evt.preventDefault();
$('#action-1').clone().appendTo('#action-urls-inputs');
$('#action-url-1').clone().appendTo('#action-urls-inputs');
});
</script>
{% endblock body %}

View file

@ -0,0 +1,22 @@
{% extends "base.jinja2" %}
{% block body %}
<main>
<form method="POST">
<!-- reply via indie-config -->
<h2>Indie-Config</h2>
<p>
Clicking an indie-action link will invoke your <code>web+action</code> handler if registered. See <a href="https://indiewebcamp.com/indie-config">indie-config</a> for details.
</p>
{% set selectedActions = settings.get('indie-config-actions', []) %}
{% for action in ['like', 'favorite', 'reply', 'repost', 'bookmark'] %}
<label>
<input type="checkbox" name="indie-config-action" value="{{ action }}"
{% if action in selectedActions %}checked{% endif %} />
{{ action | capitalize }}
</label><br/>
{% endfor %}
<button type="submit">Save Changes</button>
</form>
</main>
{% endblock body %}

View file

@ -0,0 +1,27 @@
{% extends "base.jinja2" %}
{% block body %}
<main>
<!-- reply via micropub -->
<h2>Micropub</h2>
<p>
Each post will have Like, Repost, and Reply buttons that will post content to your site directly via micropub. See <a href="https://indiewebcamp.com/Micropub">Micropub</a> for details.
</p>
<p>
Configure micropub credentials.
</p>
{% if current_user.micropub_endpoint or current_user.access_token %}
<input type="text" value="{{ current_user.micropub_endpoint }}" readonly />
<input type="text" value="{{ current_user.access_token }}" readonly />
<p>
<a href="{{url_for('.authorize', next=request.path)}}">Reauthorize Micropub</a>
</p>
<p>
<a href="{{url_for('.deauthorize', next=request.path)}}">Revoke Credentials</a>
</p>
{% else %}
<p>
<a href="{{url_for('.authorize', next=request.path)}}">Authorize Micropub</a>
</p>
{% endif %}
</main>
{% endblock body %}

View file

@ -115,21 +115,61 @@ def settings():
settings = dict(settings)
reply_method = flask.request.form.get('reply-method')
settings['reply-method'] = reply_method
if reply_method == 'micropub':
pass
elif reply_method == 'indie-config':
settings['indie-config-actions'] = flask.request.form.getlist(
'indie-config-action')
elif reply_method == 'action-urls':
zipped = zip(
flask.request.form.getlist('action'),
flask.request.form.getlist('action-url'))
settings['action-urls'] = [[k, v] for k, v in zipped if k and v]
flask_login.current_user.settings = settings
db.session.commit()
return flask.render_template('settings.jinja2', settings=settings)
next_page = '.settings'
if reply_method == 'micropub':
next_page = '.settings_micropub'
elif reply_method == 'indie-config':
next_page = '.settings_indie_config'
elif reply_method == 'action-urls':
next_page = '.settings_action_urls'
return flask.redirect(flask.url_for(next_page))
@views.route('/settings/micropub')
@flask_login.login_required
def settings_micropub():
settings = flask_login.current_user.settings or {}
return flask.render_template('settings_micropub.jinja2', settings=settings)
@views.route('/settings/indie-config', methods=['GET', 'POST'])
@flask_login.login_required
def settings_indie_config():
settings = flask_login.current_user.settings or {}
if flask.request.method == 'GET':
return flask.render_template('settings_indie_config.jinja2',
settings=settings)
settings = dict(settings)
settings['indie-config-actions'] = flask.request.form.getlist(
'indie-config-action')
flask_login.current_user.settings = settings
print('new settings: ', settings)
db.session.commit()
return flask.redirect(flask.url_for('.index'))
@views.route('/settings/action-urls', methods=['GET', 'POST'])
@flask_login.login_required
def settings_action_urls():
settings = flask_login.current_user.settings or {}
if flask.request.method == 'GET':
return flask.render_template('settings_action_urls.jinja2',
settings=settings)
settings = dict(settings)
zipped = zip(
flask.request.form.getlist('action'),
flask.request.form.getlist('action-url'))
settings['action-urls'] = [[k, v] for k, v in zipped if k and v]
flask_login.current_user.settings = settings
db.session.commit()
return flask.redirect(flask.url_for('.index'))
@views.route('/update_feed', methods=['POST'])