Skip to content

Commit

Permalink
Admin 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 19, 2020
1 parent 82c5c69 commit 7b645ce
Show file tree
Hide file tree
Showing 21 changed files with 663 additions and 531 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.2.0"></a>
# [1.2.0](https://github.com/flextype-plugins/admin) (2020-08-19)

### Features

* **core** update code base for new Flextype 0.9.10

<a name="1.1.1"></a>
# [1.1.1](https://github.com/flextype-plugins/admin) (2020-08-xx)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![preview](https://github.com/flextype-plugins/admin/raw/dev/preview.png)

<p align="center">
<a href="https://github.com/flextype-plugins/admin/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/admin.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/admin"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/admin"><img src="https://img.shields.io/github/downloads/flextype-plugins/admin/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.9-green.svg?color=black" alt="Flextype"></a> <a href="https://crowdin.com/project/flextype-plugin-admin"><img src="https://d322cqt584bo4o.cloudfront.net/flextype-plugin-admin/localized.svg?color=black" alt="Crowdin"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/admin?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/admin.svg?branch=dev&color=black" alt="Quality Score"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&colorB=728ADA&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/admin/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/admin.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/admin"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/admin"><img src="https://img.shields.io/github/downloads/flextype-plugins/admin/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg?color=black" alt="Flextype"></a> <a href="https://crowdin.com/project/flextype-plugin-admin"><img src="https://d322cqt584bo4o.cloudfront.net/flextype-plugin-admin/localized.svg?color=black" alt="Crowdin"></a> <a href="https://scrutinizer-ci.com/g/flextype-plugins/admin?branch=dev&color=black"><img src="https://img.shields.io/scrutinizer/g/flextype-plugins/admin.svg?branch=dev&color=black" alt="Quality Score"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&colorB=728ADA&label=Discord%20Chat" alt="Discord"></a>
</p>

Admin Panel plugin for Flextype.
Expand All @@ -14,7 +14,7 @@ The following dependencies need to be installed for Form Admin Plugin.

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.9 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |
| [form](https://github.com/flextype-plugins/form) | >=1.0.0 | [download](https://github.com/flextype-plugins/form/releases) |
| [form-admin](https://github.com/flextype-plugins/form-admin) | >=1.0.0 | [download](https://github.com/flextype-plugins/form-admin/releases) |
Expand Down
73 changes: 43 additions & 30 deletions app/Controllers/ApiAccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@
use function Flextype\Component\I18n\__;
use function random_bytes;
use function time;
use Flextype\App\Foundation\Container;

class ApiAccessController extends Container

class ApiAccessController
{
/**
* Flextype Application
*/
protected $flextype;

/**
* __construct
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}

/**
* Access Index page
*
Expand All @@ -37,26 +50,26 @@ public function index(Request $request, Response $response) : Response
}
}

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/admin/templates/system/api/access/index.html',
[
'menu_item' => 'api',
'tokens' => $tokens,
'links' => [
'api' => [
'link' => $this->router->pathFor('admin.api.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api.index'),
'title' => __('admin_api'),
],
'api_Access' => [
'link' => $this->router->pathFor('admin.api_access.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.index'),
'title' => __('admin_access'),
'active' => true
],
],
'buttons' => [
'api_access_add' => [
'link' => $this->router->pathFor('admin.api_access.add'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.add'),
'title' => __('admin_create_new_token')
],
],
Expand All @@ -72,22 +85,22 @@ public function index(Request $request, Response $response) : Response
*/
public function add(Request $request, Response $response) : Response
{
return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/admin/templates/system/api/access/add.html',
[
'menu_item' => 'api',
'links' => [
'api' => [
'link' => $this->router->pathFor('admin.api.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api.index'),
'title' => __('admin_api'),
],
'api_access' => [
'link' => $this->router->pathFor('admin.api_access.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.index'),
'title' => __('admin_access')
],
'api_access_add' => [
'link' => $this->router->pathFor('admin.api_access.add'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.add'),
'title' => __('admin_create_new_token'),
'active' => true
],
Expand Down Expand Up @@ -121,12 +134,12 @@ public function addProcess(Request $request, Response $response) : Response
$uuid = Uuid::uuid4()->toString();

// Get time
$time = date($this->registry->get('flextype.settings.date_format'), time());
$time = date($this->flextype->container('registry')->get('flextype.settings.date_format'), time());

// Create API Token account
if (Filesystem::write(
$api_token_file_path,
$this->yaml->encode([
$this->flextype->container('yaml')->encode([
'title' => $post_data['title'],
'icon' => $post_data['icon'],
'limit_calls' => (int) $post_data['limit_calls'],
Expand All @@ -139,18 +152,18 @@ public function addProcess(Request $request, Response $response) : Response
'updated_at' => $time,
])
)) {
$this->flash->addMessage('success', __('admin_message_access_api_token_created'));
$this->flextype->container('flash')->addMessage('success', __('admin_message_access_api_token_created'));
} else {
$this->flash->addMessage('error', __('admin_message_access_api_token_was_not_created1'));
$this->flextype->container('flash')->addMessage('error', __('admin_message_access_api_token_was_not_created1'));
}
} else {
$this->flash->addMessage('error', __('admin_message_access_api_token_was_not_created2'));
$this->flextype->container('flash')->addMessage('error', __('admin_message_access_api_token_was_not_created2'));
}

if (isset($post_data['create-and-edit'])) {
return $response->withRedirect($this->router->pathFor('admin.api_access.edit') . '?token=' . $api_token);
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.api_access.edit') . '?token=' . $api_token);
} else {
return $response->withRedirect($this->router->pathFor('admin.api_access.index'));
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.api_access.index'));
}
}

Expand All @@ -163,9 +176,9 @@ public function addProcess(Request $request, Response $response) : Response
public function edit(Request $request, Response $response) : Response
{
$token = $request->getQueryParams()['token'];
$token_data = $this->yaml->decode(Filesystem::read(PATH['project'] . '/tokens' . '/access/' . $token . '/token.yaml'));
$token_data = $this->flextype->container('yaml')->decode(Filesystem::read(PATH['project'] . '/tokens' . '/access/' . $token . '/token.yaml'));

return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/admin/templates/system/api/access/edit.html',
[
Expand All @@ -174,15 +187,15 @@ public function edit(Request $request, Response $response) : Response
'token_data' => $token_data,
'links' => [
'api' => [
'link' => $this->router->pathFor('admin.api.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api.index'),
'title' => __('admin_api')
],
'api_access' => [
'link' => $this->router->pathFor('admin.api_access.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.index'),
'title' => __('admin_access')
],
'api_tokens_edit' => [
'link' => $this->router->pathFor('admin.api_access.edit'),
'link' => $this->flextype->container('router')->pathFor('admin.api_access.edit'),
'title' => __('admin_edit_token'),
'active' => true
],
Expand All @@ -209,7 +222,7 @@ public function editProcess(Request $request, Response $response) : Response
if (Filesystem::has($api_token_file_path)) {
if (Filesystem::write(
$api_token_file_path,
$this->yaml->encode([
$this->flextype->container('yaml')->encode([
'title' => $post_data['title'],
'icon' => $post_data['icon'],
'limit_calls' => (int) $post_data['limit_calls'],
Expand All @@ -219,16 +232,16 @@ public function editProcess(Request $request, Response $response) : Response
'created_by' => $post_data['created_by'],
'created_at' => $post_data['created_at'],
'updated_by' => Session::get('uuid'),
'updated_at' => date($this->registry->get('flextype.settings.date_format'), time()),
'updated_at' => date($this->flextype->container('registry')->get('flextype.settings.date_format'), time()),
])
)) {
$this->flash->addMessage('success', __('admin_message_access_api_token_updated'));
$this->flextype->container('flash')->addMessage('success', __('admin_message_access_api_token_updated'));
}
} else {
$this->flash->addMessage('error', __('admin_message_access_api_token_was_not_updated'));
$this->flextype->container('flash')->addMessage('error', __('admin_message_access_api_token_was_not_updated'));
}

return $response->withRedirect($this->router->pathFor('admin.api_access.index'));
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.api_access.index'));
}

/**
Expand All @@ -245,11 +258,11 @@ public function deleteProcess(Request $request, Response $response) : Response
$api_token_dir_path = PATH['project'] . '/tokens' . '/access/' . $post_data['token'];

if (Filesystem::deleteDir($api_token_dir_path)) {
$this->flash->addMessage('success', __('admin_message_access_api_token_deleted'));
$this->flextype->container('flash')->addMessage('success', __('admin_message_access_api_token_deleted'));
} else {
$this->flash->addMessage('error', __('admin_message_access_api_token_was_not_deleted'));
$this->flextype->container('flash')->addMessage('error', __('admin_message_access_api_token_was_not_deleted'));
}

return $response->withRedirect($this->router->pathFor('admin.api_access.index'));
return $response->withRedirect($this->flextype->container('router')->pathFor('admin.api_access.index'));
}
}
21 changes: 17 additions & 4 deletions app/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@
use function Flextype\Component\I18n\__;
use function random_bytes;
use function time;
use Flextype\App\Foundation\Container;

class ApiController extends Container

class ApiController
{
/**
* Flextype Application
*/
protected $flextype;

/**
* __construct
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}

/**
* Index page for API's
*
Expand All @@ -26,7 +39,7 @@ class ApiController extends Container
*/
public function index(Request $request, Response $response) : Response
{
return $this->twig->render(
return $this->flextype->container('twig')->render(
$response,
'plugins/admin/templates/system/api/index.html',
[
Expand Down Expand Up @@ -59,7 +72,7 @@ public function index(Request $request, Response $response) : Response
],
'links' => [
'api' => [
'link' => $this->router->pathFor('admin.api.index'),
'link' => $this->flextype->container('router')->pathFor('admin.api.index'),
'title' => __('admin_api'),
'active' => true,
],
Expand Down
Loading

0 comments on commit 7b645ce

Please sign in to comment.