2020-01-29 06:50:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2020 OpenLP Developers #
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# This program 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. #
|
|
|
|
# #
|
|
|
|
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2020-04-26 21:37:35 +00:00
|
|
|
import logging
|
2020-01-27 22:57:58 +00:00
|
|
|
from openlp.core.api.lib import login_required
|
|
|
|
|
|
|
|
from flask import jsonify, request, abort, Blueprint
|
|
|
|
|
|
|
|
from openlp.core.common.registry import Registry
|
|
|
|
|
|
|
|
|
|
|
|
service_views = Blueprint('service', __name__)
|
2020-04-26 21:37:35 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2020-01-27 22:57:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
@service_views.route('/items')
|
|
|
|
def service_items():
|
|
|
|
live_controller = Registry().get('live_controller')
|
|
|
|
service_items = []
|
|
|
|
if live_controller.service_item:
|
|
|
|
current_unique_identifier = live_controller.service_item.unique_identifier
|
|
|
|
else:
|
|
|
|
current_unique_identifier = None
|
|
|
|
for item in Registry().get('service_manager').service_items:
|
|
|
|
service_item = item['service_item']
|
|
|
|
if 'ccli_number' in service_item.data_string:
|
|
|
|
ccli_number = service_item.data_string['ccli_number']
|
|
|
|
else:
|
|
|
|
ccli_number = ''
|
|
|
|
service_items.append({
|
|
|
|
'id': str(service_item.unique_identifier),
|
|
|
|
'title': str(service_item.get_display_title()),
|
|
|
|
'plugin': str(service_item.name),
|
|
|
|
'ccli_number': str(ccli_number),
|
|
|
|
'notes': str(service_item.notes),
|
2020-05-16 06:11:21 +00:00
|
|
|
'selected': (service_item.unique_identifier == current_unique_identifier),
|
|
|
|
'is_valid': str(service_item.is_valid)
|
2020-01-27 22:57:58 +00:00
|
|
|
})
|
|
|
|
return jsonify(service_items)
|
|
|
|
|
|
|
|
|
|
|
|
@service_views.route('/show', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def service_set():
|
|
|
|
data = request.json
|
|
|
|
if not data:
|
2020-04-26 21:37:35 +00:00
|
|
|
log.error('Missing request data')
|
2020-01-27 22:57:58 +00:00
|
|
|
abort(400)
|
|
|
|
try:
|
|
|
|
id = int(data.get('id', -1))
|
|
|
|
except ValueError:
|
2020-04-26 21:37:35 +00:00
|
|
|
log.error('Invalid data passed ' + data)
|
2020-01-27 22:57:58 +00:00
|
|
|
abort(400)
|
2020-04-09 21:55:27 +00:00
|
|
|
Registry().get('service_manager').servicemanager_set_item.emit(id)
|
2020-01-27 22:57:58 +00:00
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
2020-04-26 21:37:35 +00:00
|
|
|
@service_views.route('/show_id', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def service_set_by_uid():
|
|
|
|
data = request.json
|
|
|
|
if not data:
|
|
|
|
log.error('Missing request data')
|
|
|
|
abort(400)
|
|
|
|
try:
|
|
|
|
id = str(data.get('uid', ''))
|
|
|
|
except ValueError:
|
|
|
|
log.error('Invalid data passed ' + data)
|
|
|
|
abort(400)
|
|
|
|
Registry().get('service_manager').servicemanager_set_item_by_uuid.emit(id)
|
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
2020-01-27 22:57:58 +00:00
|
|
|
@service_views.route('/progress', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def service_direction():
|
|
|
|
ALLOWED_ACTIONS = ['next', 'previous']
|
|
|
|
data = request.json
|
|
|
|
if not data:
|
2020-04-26 21:37:35 +00:00
|
|
|
log.error('Missing request data')
|
2020-01-27 22:57:58 +00:00
|
|
|
abort(400)
|
|
|
|
action = data.get('action', '').lower()
|
|
|
|
if action not in ALLOWED_ACTIONS:
|
2020-04-26 21:37:35 +00:00
|
|
|
log.error('Invalid data passed ' + str(data))
|
2020-01-27 22:57:58 +00:00
|
|
|
abort(400)
|
|
|
|
getattr(Registry().get('service_manager'), 'servicemanager_{action}_item'.format(action=action)).emit()
|
|
|
|
return '', 204
|
2020-05-16 06:11:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@service_views.route('/new', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def new_service():
|
|
|
|
getattr(Registry().get('service_manager'), 'servicemanager_new_file').emit()
|
|
|
|
return '', 204
|