mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-16 08:44:40 +00:00
LiveSync: Ajaxify & improve agent management
This commit is contained in:
parent
149154f920
commit
8d871d1dd3
@ -18,16 +18,16 @@ from __future__ import unicode_literals
|
||||
|
||||
from flask import request, redirect, flash
|
||||
from flask_pluginengine import render_plugin_template, current_plugin
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from indico.core.db import db
|
||||
from indico.modules.admin import RHAdminBase
|
||||
from indico.web.flask.util import url_for
|
||||
from indico.web.forms.base import FormDefaults
|
||||
from indico.web.util import jsonify_data
|
||||
from indico.web.util import jsonify_data, jsonify_template
|
||||
|
||||
from indico_livesync import _
|
||||
from indico_livesync.models.agents import LiveSyncAgent
|
||||
from indico_livesync.views import WPLiveSync
|
||||
|
||||
|
||||
def extend_plugin_details():
|
||||
@ -52,7 +52,10 @@ class RHAddAgent(RHAdminBase):
|
||||
|
||||
def _checkParams(self):
|
||||
self.backend_name = request.view_args['backend']
|
||||
self.backend = current_plugin.backend_classes[self.backend_name]
|
||||
try:
|
||||
self.backend = current_plugin.backend_classes[self.backend_name]
|
||||
except KeyError:
|
||||
raise NotFound
|
||||
|
||||
def _process(self):
|
||||
form = self.backend.form(obj=FormDefaults(name=self.backend.title))
|
||||
@ -63,9 +66,9 @@ class RHAddAgent(RHAdminBase):
|
||||
db.session.add(agent)
|
||||
flash(_('Agent added'), 'success')
|
||||
flash(_("Don't forget to run the initial export!"), 'highlight')
|
||||
return redirect(url_for('plugins.details', plugin='livesync'))
|
||||
return jsonify_data(flash=False)
|
||||
|
||||
return WPLiveSync.render_template('edit_agent.html', form=form, backend=self.backend)
|
||||
return jsonify_template('edit_agent.html', render_plugin_template, form=form, backend=self.backend, edit=False)
|
||||
|
||||
|
||||
class RHEditAgent(RHAdminBase):
|
||||
@ -78,12 +81,13 @@ class RHEditAgent(RHAdminBase):
|
||||
return redirect(url_for('plugins.details', plugin='livesync'))
|
||||
|
||||
def _process(self):
|
||||
form = self.agent.backend.form(obj=FormDefaults(self.agent, {'name'}, **self.agent.settings))
|
||||
form = self.agent.backend.form(obj=FormDefaults(name=self.agent.name, **self.agent.settings))
|
||||
if form.validate_on_submit():
|
||||
data = form.data
|
||||
self.agent.name = data.pop('name')
|
||||
self.agent.settings = data
|
||||
flash(_('Agent updated'), 'success')
|
||||
return redirect(url_for('plugins.details', plugin='livesync'))
|
||||
return jsonify_data(flash=False)
|
||||
|
||||
return WPLiveSync.render_template('edit_agent.html', form=form, backend=self.agent.backend, agent=self.agent)
|
||||
return jsonify_template('edit_agent.html', render_plugin_template, form=form, backend=self.agent.backend,
|
||||
edit=True)
|
||||
|
||||
@ -1,27 +1,10 @@
|
||||
{% extends 'layout/base.html' %}
|
||||
{% from 'forms/_form.html' import form_header, form_row, form_footer %}
|
||||
|
||||
{% block title %}LiveSync{% endblock %}
|
||||
|
||||
{% block subtitle %}
|
||||
{%- if agent -%}
|
||||
{% trans %}Edit Agent{% endtrans %}
|
||||
{%- else -%}
|
||||
{% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %}
|
||||
{%- endif -%}
|
||||
{% endblock %}
|
||||
{% extends 'layout/dialog_base.html' %}
|
||||
{% from 'forms/_form.html' import simple_form %}
|
||||
|
||||
{% block description %}
|
||||
{{ backend.description }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ form_header(form) }}
|
||||
{% for field in form.visible_fields %}
|
||||
{{ form_row(field) }}
|
||||
{% endfor %}
|
||||
{% call form_footer(form) %}
|
||||
<input class="i-button big highlight" type="submit" value="{% trans %}Save{% endtrans %}" {% if agent %}data-disabled-until-change{% endif %}>
|
||||
<a href="{{ url_for('plugins.details', plugin='livesync') }}" class="i-button big">{% trans %}Cancel{% endtrans %}</a>
|
||||
{% endcall %}
|
||||
{{ simple_form(form, back=_('Cancel'), disabled_until_change=edit) }}
|
||||
{% endblock %}
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
{% from 'message_box.html' import message_box %}
|
||||
|
||||
{% macro add_agent_link(name, backend, standalone=false) %}
|
||||
<a href="#"
|
||||
class="{{ 'i-button icon-plus' if standalone }}"
|
||||
data-href="{{ url_for_plugin('livesync.add_agent', backend=name) }}"
|
||||
data-title="{% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %}"
|
||||
data-reload-after
|
||||
data-ajax-dialog>
|
||||
{% if standalone %}
|
||||
{% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %}
|
||||
{% else %}
|
||||
{{ backend.title }}
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endmacro %}
|
||||
|
||||
<h2>{% trans %}LiveSync Agents{% endtrans %}</h2>
|
||||
|
||||
<div class="i-form">
|
||||
@ -50,7 +67,11 @@
|
||||
data-reload-after
|
||||
data-ajax></a>
|
||||
{%- if agent.backend -%}
|
||||
<a class="action-icon icon-edit" href="{{ url_for_plugin('livesync.edit_agent', agent) }}"></a>
|
||||
<a href="#" class="action-icon icon-edit"
|
||||
data-href="{{ url_for_plugin('livesync.edit_agent', agent) }}"
|
||||
data-title="{% trans %}Edit LiveSync agent{% endtrans %}"
|
||||
data-reload-after
|
||||
data-ajax-dialog></a>
|
||||
{%- endif -%}
|
||||
</td>
|
||||
</tr>
|
||||
@ -58,14 +79,28 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="info-message-box">
|
||||
<div class="message-text">{% trans %}No agents have been added yet.{% endtrans %}</div>
|
||||
</div>
|
||||
{% call message_box('info') %}
|
||||
{% trans %}No agents have been added yet.{% endtrans %}
|
||||
{% endcall %}
|
||||
{% endif %}
|
||||
|
||||
{% for name, backend in backends.items() | sort(attribute='1.title') %}
|
||||
<a class="i-button icon-plus" href="{{ url_for_plugin('livesync.add_agent', backend=name) }}">{% trans backend=backend.title %}Add {{ backend }} agent{% endtrans %}</a>
|
||||
{% endfor %}
|
||||
<div class="toolbar space-before">
|
||||
{% if backends|length == 1 %}
|
||||
{% set name, backend = backends.viewitems()|first %}
|
||||
{{ add_agent_link(name, backend, standalone=true) }}
|
||||
{% else %}
|
||||
<a class="i-button icon-plus {{ 'disabled' if not backends else 'arrow js-dropdown' }}"
|
||||
data-toggle="dropdown"
|
||||
title="{% if not backends %}{% trans %}No backend plugins enabled{% endtrans %}{% endif %}">
|
||||
{% trans %}Add{% endtrans %}
|
||||
</a>
|
||||
<ul class="dropdown">
|
||||
{% for name, backend in backends.viewitems() | sort(attribute='1.title') %}
|
||||
<li>{{ add_agent_link(name, backend) }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% set missing_initial_export = agents|rejectattr('initial_data_exported')|list %}
|
||||
{% if missing_initial_export %}
|
||||
@ -76,10 +111,11 @@
|
||||
{%- endtrans %}
|
||||
</p>
|
||||
<pre class="code"><code>
|
||||
{#- Don't "fix" the indentation of these lines! -#}
|
||||
{%- for agent in missing_initial_export -%}
|
||||
indico livesync initial_export {{ agent.id }}
|
||||
{% endfor -%}
|
||||
{%- filter dedent %}
|
||||
{%- for agent in missing_initial_export -%}
|
||||
indico livesync initial_export {{ agent.id }}
|
||||
{% endfor -%}
|
||||
{% endfilter -%}
|
||||
</code></pre>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
# This file is part of Indico.
|
||||
# Copyright (C) 2002 - 2017 European Organization for Nuclear Research (CERN).
|
||||
#
|
||||
# Indico is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# Indico is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from indico.core.plugins import WPJinjaMixinPlugin
|
||||
from indico.core.plugins.views import WPPlugins
|
||||
|
||||
|
||||
class WPLiveSync(WPJinjaMixinPlugin, WPPlugins):
|
||||
pass
|
||||
Loading…
x
Reference in New Issue
Block a user