From a3d61ca975f7f6f30643ad083b8205fe15365b12 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 28 Jan 2020 14:05:46 +0300 Subject: [PATCH] feat(admin-plugin): refactor api delivery #211 --- .../admin/app/Controllers/ApiController.php | 13 ++++++++++++- .../templates/system/api/delivery/index.html | 18 +++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/site/plugins/admin/app/Controllers/ApiController.php b/site/plugins/admin/app/Controllers/ApiController.php index 4a75eeb0..ed43955a 100644 --- a/site/plugins/admin/app/Controllers/ApiController.php +++ b/site/plugins/admin/app/Controllers/ApiController.php @@ -52,13 +52,24 @@ class ApiController extends Controller { $api = $request->getQueryParams()['api']; + $tokens = []; + $tokens_list = Filesystem::listContents(PATH['tokens'] . '/' . $api); + + if (count($tokens_list) > 0) { + foreach ($tokens_list as $token) { + if ($token['type'] == 'dir' && Filesystem::has(PATH['tokens'] . '/' . $api . '/' . $token['dirname'] . '/token.yaml')) { + $tokens[] = $token; + } + } + } + return $this->view->render( $response, 'plugins/admin/templates/system/api/delivery/index.html', [ 'menu_item' => 'api', 'api' => $api, - 'delivery_tokens_list' => Filesystem::listContents(PATH['tokens'] . '/delivery'), + 'tokens' => $tokens, 'links' => [ 'api' => [ 'link' => $this->router->pathFor('admin.api.index'), diff --git a/site/plugins/admin/templates/system/api/delivery/index.html b/site/plugins/admin/templates/system/api/delivery/index.html index e634b4c7..a27c65e7 100644 --- a/site/plugins/admin/templates/system/api/delivery/index.html +++ b/site/plugins/admin/templates/system/api/delivery/index.html @@ -1,7 +1,7 @@ {% extends "plugins/admin/templates/partials/base.html" %} {% block content %} - {% if (delivery_tokens_list | length > 0) %} + {% if (tokens | length > 0) %} @@ -18,8 +18,8 @@ - {% for key, delivery_token in delivery_tokens_list %} - {% set token_file_path = PATH_TOKENS ~ '/' ~ api ~ '/' ~ delivery_token.dirname ~ '/' ~ 'token.yaml' %} + {% 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 %} @@ -28,9 +28,9 @@ - +
- {{ token_data.title }} + {{ token_data.title }} {{ delivery_token.dirname }}{{ token.dirname }} {{ token_data.calls }} / {% if (token_data.limit_calls > 0) %}{{ token_data.limit_calls }} @@ -41,18 +41,18 @@