1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-17 02:24:05 +02:00

feat(admin-plugin): update for API's #349

This commit is contained in:
Awilum
2020-02-13 17:13:14 +03:00
parent a53e32bb8d
commit ffc21164ca
5 changed files with 115 additions and 74 deletions

View File

@@ -44,4 +44,4 @@
</div>
</div>
</form>
{% endblock %}
{% endblock %}

View File

@@ -4,16 +4,16 @@
<form method="post" id="form">
{{ csrf() }}
<input type="hidden" name="api" value="{{ api }}">
<input type="hidden" name="api_token" value="{{ api_token }}">
<input type="hidden" name="created_by" value="{{ api_token_data.created_by }}">
<input type="hidden" name="created_at" value="{{ api_token_data.created_at }}">
<input type="hidden" name="uuid" value="{{ api_token_data.uuid }}">
<input type="hidden" name="calls" value="{{ api_token_data.calls }}">
<input type="hidden" name="token" value="{{ token }}">
<input type="hidden" name="created_by" value="{{ token_data.created_by }}">
<input type="hidden" name="created_at" value="{{ token_data.created_at }}">
<input type="hidden" name="uuid" value="{{ token_data.uuid }}">
<input type="hidden" name="calls" value="{{ token_data.calls }}">
<div class="flex row">
<div class="col w-full lg:w-4/12">
<div class="form-group">
<label for="title" class="form-control-title">{{ tr('admin_title') }}</label>
<input type="text" id="title" name="title" value="{{ api_token_data.title }}" class="form-control" required="required" data-parsley-minlength="1" data-parsley-error-message="{{ tr('admin_error_title_empty_input') }}" data-parsley-required="true">
<input type="text" id="title" name="title" value="{{ token_data.title }}" class="form-control" required="required" data-parsley-minlength="1" data-parsley-error-message="{{ tr('admin_error_title_empty_input') }}" data-parsley-required="true">
<small>{{ tr('admin_help_text_for_tokens_label') }}</small>
</div>
<div class="form-group">
@@ -22,7 +22,7 @@
type="text"
id="limit"
name="limit_calls"
value="{{ api_token_data.limit_calls }}"
value="{{ token_data.limit_calls }}"
class="form-control"
required="required"
data-parsley-required="true"
@@ -33,14 +33,14 @@
</div>
<div class="form-group">
<label for="icon" class="form-control-title">{{ tr('admin_icon') }}</label>
<input type="text" id="fieldsetIcon" name="icon" value="{{ api_token_data.icon }}" class="form-control" required="required" data-parsley-required="true" data-parsley-minlength="1" data-parsley-error-message="{{ tr('admin_error_icon_empty_input') }}">
<input type="text" id="fieldsetIcon" name="icon" value="{{ token_data.icon }}" class="form-control" required="required" data-parsley-required="true" data-parsley-minlength="1" data-parsley-error-message="{{ tr('admin_error_icon_empty_input') }}">
<small>{{ tr('admin_help_text_for_api_token_icon', {':link': '<a href="https://fontawesome.com/icons?d=gallery&m=free" target="_blank">fontawesome</a>'})|raw }}</small>
</div>
<div class="form-group">
<label for="type" class="form-control-title">{{ tr('admin_state') }}</label>
<select class="form-control js-select" name="state">
<option value="enabled" {% if api_token_data.state == 'enabled' %} selected="selected" {% endif %}>{{ tr('admin_enabled') }}</option>
<option value="disabled" {% if api_token_data.state == 'disabled' %} selected="selected" {% endif %} ">{{ tr('admin_disabled') }}</option>
<option value="enabled" {% if token_data.state == 'enabled' %} selected="selected" {% endif %}>{{ tr('admin_enabled') }}</option>
<option value="disabled" {% if token_data.state == 'disabled' %} selected="selected" {% endif %} ">{{ tr('admin_disabled') }}</option>
</select>
</div>
<div class="button-group">

View File

@@ -0,0 +1,89 @@
{% extends "plugins/admin/templates/partials/base.html" %}
{% block content %}
{% if (tokens | length > 0) %}
<table class="table">
<thead>
<tr>
<th></th>
<th>
{{ tr('admin_title') }}
</th>
<th>
{{ tr('admin_token') }}
</th>
<th>
{{ tr('admin_calls') }}
</th>
</tr>
</thead>
<tbody>
{% for key, token in tokens %}
{% set token_file_path = PATH_TOKENS ~ '/delivery/entries/' ~ token.dirname ~ '/' ~ 'token.yaml' %}
{% if filesystem_has(token_file_path) %}
{% set token_data = parser_decode(filesystem_read(token_file_path), 'yaml') %}
{% endif %}
<tr>
<td class="w-1 text-center {% if token_data.state == 'disabled' %}opacity-50{% endif %}">
<i class="icon">{{ icon(token_data.icon) }}</i>
</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">
<a href="{{ path_for('admin.api_delivery_entries.edit') }}?token={{ token.dirname }}">{{ token_data.title }}</a>
</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">{{ token.dirname }}</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">{{ token_data.calls }}
/
{% if (token_data.limit_calls > 0) %}{{ token_data.limit_calls }}
{% else %}&infin;{% endif %}
</td>
<td class="text-right">
<button type="button" class="js-dropdown-btn" data-dropdown="dropdown-delivery-entries-{{ token.dirname }}">
<i class="icon">{{ icon('fas fa-ellipsis-h') }}</i>
</button>
<div id="dropdown-delivery-entries-{{ token.dirname }}" class="dropdown">
<a class="dropdown__item" href="{{ path_for('admin.api_delivery_entries.edit') }}?token={{ token.dirname }}">
<i class="icon icon--white mr-3">{{ icon('fas fa-edit') }}</i>
{{ tr('admin_edit') }}
</a>
<div class="dropdown__divider"></div>
<a class="dropdown__item" href="javascript:;" onclick="event.preventDefault(); deleteDeliveryEntriesToken('{{ token.dirname }}', {{ loop.index0 }});">
<i class="icon icon--white mr-3">{{ icon('fas fa-trash-alt') }}</i>
{{ tr('admin_delete') }}
</a>
<form id="delete-api-token-id-{{ token.dirname }}" action="{{ path_for('admin.api_delivery_entries.deleteProcess') }}" method="POST" style="display: none;">
{{ csrf() }}
<input type="hidden" name="token" value="{{ token.dirname }}">
</form>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div class="text-center flex justify-center items-center h-full">
<div>
<i class="icon icon--4xl">{{ icon('fas fa-database') }}</i>
<i class="icon icon--4xl mr-3 ml-3">{{ icon('fas angle-right') }}</i>
<i class="icon icon--4xl">{{ icon('fas fa-truck') }}</i>
<h3 class="text-2xl pt-5 pb-8">{{ tr('admin_you_have_not_created_any_delvery_entries_api_tokens_yet') }}</h3>
<a href="{{ path_for('admin.api_delivery_entries.add') }}" class="button">{{ tr('admin_create_new_delivery_entries_token') }}</a>
</div>
</div>
{% endif %}
{% endblock %}
{% block tail %}
<script>
function deleteDeliveryEntriesToken(id, row_num) {
dropdown[row_num].hide();
Swal.fire(
{title: "{{ tr('admin_confirmation_required') }}", text: "{{ tr('admin_confirmation_required_for_delivery_entries_token_delete') }}", showCancelButton: true, confirmButtonText: "{{ tr('admin_yes_iam_sure')|raw }}", cancelButtonText: "{{ tr('admin_cancel') }}"}
).then((result) => {
if (result.value) {
document.getElementById('delete-api-token-id-' + id).submit();
}
});
}
</script>
{% endblock %}

View File

@@ -1,61 +1,29 @@
{% extends "plugins/admin/templates/partials/base.html" %}
{% block content %}
{% if (tokens | length > 0) %}
{% if (api_list | length > 0) %}
<table class="table">
<thead>
<tr>
<th></th>
<th>
{{ tr('admin_title') }}
</th>
<th>
{{ tr('admin_token') }}
</th>
<th>
{{ tr('admin_calls') }}
{{ tr('admin_name') }}
</th>
</tr>
</thead>
<tbody>
{% for key, token in tokens %}
{% set token_file_path = PATH_TOKENS ~ '/' ~ api ~ '/' ~ token.dirname ~ '/' ~ 'token.yaml' %}
{% if filesystem_has(token_file_path) %}
{% set token_data = parser_decode(filesystem_read(token_file_path), 'yaml') %}
{% endif %}
{% for key, api in api_list %}
<tr>
<td class="w-1 text-center {% if token_data.state == 'disabled' %}opacity-50{% endif %}">
<i class="icon">{{ icon(token_data.icon) }}</i>
<td class="w-1 text-center">
{% if key == 'entries' %}
<i class="icon">{{ icon('fas fa-database') }}</i>
{% endif %}
{% if key == 'images' %}
<i class="icon">{{ icon('far fa-images') }}</i>
{% endif %}
</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">
<a href="{{ path_for('admin.api_tokens.edit') }}?api={{ api }}&api_token={{ token.dirname }}">{{ token_data.title }}</a>
</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">{{ token.dirname }}</td>
<td class="{% if token_data.state == 'disabled' %}opacity-50{% endif %}">{{ token_data.calls }}
/
{% if (token_data.limit_calls > 0) %}{{ token_data.limit_calls }}
{% else %}&infin;{% endif %}
</td>
<td class="text-right">
<button type="button" class="js-dropdown-btn" data-dropdown="dropdown-{{ api }}-{{ token.dirname }}">
<i class="icon">{{ icon('fas fa-ellipsis-h') }}</i>
</button>
<div id="dropdown-{{ api }}-{{ token.dirname }}" class="dropdown">
<a class="dropdown__item" href="{{ path_for('admin.api_tokens.edit') }}?api={{ api }}&api_token={{ token.dirname }}">
<i class="icon icon--white mr-3">{{ icon('fas fa-edit') }}</i>
{{ tr('admin_edit') }}
</a>
<div class="dropdown__divider"></div>
<a class="dropdown__item" href="javascript:;" onclick="event.preventDefault(); deleteDeliveryToken('{{ token.dirname }}', {{ loop.index0 }});">
<i class="icon icon--white mr-3">{{ icon('fas fa-trash-alt') }}</i>
{{ tr('admin_delete') }}
</a>
<form id="delete-api-token-id-{{ token.dirname }}" action="{{ path_for('admin.api_tokens.deleteProcess') }}" method="POST" style="display: none;">
{{ csrf() }}
<input type="hidden" name="api" value="{{ api }}">
<input type="hidden" name="api_token" value="{{ token.dirname }}">
</form>
</div>
<td>
<a href="{{ path_for('admin.api.index') }}/delivery/{{ key }}">{{ api }}</a>
</td>
</tr>
{% endfor %}
@@ -64,25 +32,9 @@
{% else %}
<div class="text-center flex justify-center items-center h-full">
<div>
<i class="icon icon--4xl">{{ icon('fas fa-truck') }}</i>
<h3 class="text-2xl pt-4 pb-8">{{ tr('admin_you_have_not_created_any_delvery_api_tokens_yet') }}</h3>
<a href="{{ path_for('admin.api_tokens.add') }}?api={{api}}" class="button">{{ tr('admin_create_new_delivery_token') }}</a>
<i class="icon icon--4xl">{{ icon('fas fa-network-wired') }}</i>
<h3 class="text-2xl pt-4 pb-8">{{ tr('admin_you_have_not_created_any_api_tokens_yet') }}</h3>
</div>
</div>
{% endif %}
{% endblock %}
{% block tail %}
<script>
function deleteDeliveryToken(id, row_num) {
dropdown[row_num].hide();
Swal.fire(
{title: "{{ tr('admin_confirmation_required') }}", text: "{{ tr('admin_confirmation_required_for_delivery_token_delete') }}", showCancelButton: true, confirmButtonText: "{{ tr('admin_yes_iam_sure')|raw }}", cancelButtonText: "{{ tr('admin_cancel') }}"}
).then((result) => {
if (result.value) {
document.getElementById('delete-api-token-id-' + id).submit();
}
});
}
</script>
{% endblock %}

View File

@@ -18,7 +18,7 @@
<i class="icon">{{ icon('fas fa-truck') }}</i>
</td>
<td>
<a href="{{ path_for('admin.api_tokens.index') }}?api={{ key }}">{{ api }}</a>
<a href="{{ path_for('admin.api.index') }}/{{ key }}">{{ api }}</a>
</td>
</tr>
{% endfor %}