Skip to content

Commit

Permalink
Added type hints + moved interface to bootstrap 5
Browse files Browse the repository at this point in the history
  • Loading branch information
RoanB committed Oct 2, 2024
1 parent d9d62c5 commit 1d63d33
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 53 deletions.
23 changes: 12 additions & 11 deletions lib/Skeleton/Package/Api/Web/Module/Call.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* Module Index
*
Expand All @@ -9,8 +12,8 @@

namespace Skeleton\Package\Api\Web\Module;

use \Skeleton\Core\Application\Web\Module;
use \Skeleton\Package\Api\Config;
use Skeleton\Application\Web\Module;
use Skeleton\Package\Api\Config;

abstract class Call extends Module {

Expand All @@ -19,17 +22,15 @@ abstract class Call extends Module {
* Default = yes
*
* @access public
* @var bool $login_required
*/
public $login_required = false;
public bool $login_required = false;

/**
* Template to use
*
* @access public
* @var string $template
*/
public $template = false;
public ?String $template = null;

/**
* Display
Expand All @@ -38,7 +39,7 @@ abstract class Call extends Module {
*
* @access public
*/
public function display() {
public function display(): void {
if (!isset($_REQUEST['call'])) {
$this->display_404();
}
Expand Down Expand Up @@ -82,7 +83,7 @@ public function display() {
* @access private
* @return bool $authenticated
*/
private function authenticate() {
private function authenticate(): bool {
if (isset(Config::$api_keys) and Config::$api_keys === false) {
return true;
}
Expand All @@ -104,7 +105,7 @@ private function authenticate() {
* @access public
* @return array $calls
*/
public function get_calls() {
public function get_calls(): array {
$class = new \ReflectionClass($this);
$methods = $class->getMethods();
$result = [];
Expand All @@ -129,7 +130,7 @@ public function get_calls() {
*
* @access private
*/
private function display_404() {
private function display_404(): void {
header("HTTP/1.0 404 Not Found");
echo '404: not found';
exit;
Expand All @@ -140,7 +141,7 @@ private function display_404() {
*
* @access private
*/
private function display_403() {
private function display_403(): void {
header("HTTP/1.0 403 Forbidden");
echo '403: not allowed';
exit;
Expand Down
15 changes: 9 additions & 6 deletions lib/Skeleton/Package/Api/Web/Module/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* Module Index
*
Expand All @@ -9,7 +12,8 @@

namespace Skeleton\Package\Api\Web\Module;

use \Skeleton\Core\Application\Web\Module;
use Skeleton\Application\Web\Module;
use Skeleton\Application\Web\Template;

abstract class Index extends Module {

Expand All @@ -20,22 +24,21 @@ abstract class Index extends Module {
* @access public
* @var bool $login_required
*/
public $login_required = false;
public bool $login_required = false;

/**
* Template to use
*
* @access public
* @var string $template
*/
public $template = '@skeleton-package-api\index.twig';
public ?string $template = '@skeleton-package-api\index.twig';

/**
* Display method
*
* @access public
*/
public function display() {
public function display(): void {
$application = \Skeleton\Core\Application::get();
$module_path = $application->module_path;

Expand All @@ -62,7 +65,7 @@ public function display() {
}
}

$template = \Skeleton\Core\Web\Template::get();
$template = Template::get();
$template->assign('modules', $modules);
}

Expand Down
71 changes: 35 additions & 36 deletions template/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,42 @@
</head>



<body data-spy="scroll" data-target="#myScrollspy">
<div class="container">
<h1>{% trans "RESTful API" %}</h1>
<h1>RESTful API</h1>
<p class="lead">
<i>
Below you can find a list of API calls that are available for you.
</i>
</p>
<div class="row">
<div class="col-sm-3" id="myScrollspy">
<ul class="nav nav-tabs nav-stacked" data-offset-top="120" data-spy="affix">
<li class="active"><a href="#settings"><b>{% trans "Settings" %}</b></a></li>
<ul class="nav flex-column" data-offset-top="120" data-spy="affix">
<li class="nav-item active"><a href="#settings"><b>Settings</b></a></li>
{% for module in modules %}
<li><a href="#{{ module.get_name() }}">{{ module.get_module_path() }}</a></li>
<li class="nav-item"><a class="nav-link" href="#{{ module.get_name() }}">{{ module.get_module_path() }}</a></li>
{% endfor %}
</ul>
</div>
<div class="col-sm-9">
<div id="settings">
<h2>{% trans "Settings" %}</h2>
<h2>Settings</h2>

<div class="form-horizontal">
<div class="panel panel-default">
<div class="panel-heading">{% trans "Web client settings" %}</div>
<div class="panel-body">
<div class="card">
<div class="card-header">Web client settings</div>
<div class="card-body">
<p>{{ docblock.getDescription() }}</p>

{% block authentication %}
<div class="form-group">
<label class="col-xs-3 control-label">{% trans "API Key" %}</label>
<label class="col-xs-3 control-label">API Key</label>
<div class="col-xs-9"><input type="text" id="api_key" class="form-control param" value="{{ env.cookie.api_key }}"/></div>
</div>
{% endblock %}

<div class="form-group">
<label class="col-xs-3 control-label">{% trans "Output" %}</label>
<label class="col-xs-3 control-label">Output</label>
<div class="col-xs-9">
<select class="form-control param" id="api_output">
<option value="print_r" {% if env.cookie.api_output == 'print_r' %}selected{% endif %}>print_r</option>
Expand All @@ -70,8 +69,8 @@
</div>

<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button type="submit" class="btn btn-primary" onclick="save_settings()">{% trans "Save" %}</button>
<div class="col-xs-9 col-xs-offset-3 mt-2">
<button type="submit" class="btn btn-primary" onclick="save_settings()">Save</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -108,9 +107,9 @@

{% for call, docblock in module.get_calls() %}
<form class="form-horizontal" data-path="{{ module.get_module_path() }}" data-call="{{ call }}">
<div class="panel panel-default">
<div class="panel-heading">{{ module.get_module_path() }}?call=<b>{{ call }}</b></div>
<div class="panel-body">
<div class="card mt-3">
<div class="card-header">{{ module.get_module_path() }}?call=<b>{{ call }}</b></div>
<div class="card-body">
<blockquote>
{{ docblock.getDescription()|nl2br }}
</blockquote>
Expand All @@ -123,8 +122,8 @@
</div>
{% endfor %}
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button type="submit" class="btn btn-success">{% trans "Execute" %}</button>
<div class="col-xs-9 col-xs-offset-3 mt-2">
<button type="submit" class="btn btn-success">Execute</button>
</div>
</div>
</div>
Expand All @@ -138,26 +137,25 @@
</div>
</div>

<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<pre>Some text in the modal.</pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="myModal">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<pre>Some text in the modal.</pre>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-bs-target="#myModal" data-bs-toggle="modal" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>


<script type="text/javascript">
$('form').on('submit', function(event) {
path = $(this).data('path');
Expand All @@ -178,13 +176,14 @@
type: 'POST',
data: data,
success: function( data ) {
var myModal = new bootstrap.Modal(document.getElementById('myModal'));
$("#myModal .modal-body pre" ).html( data );
$('#myModal .modal-title').html( path );
$('#myModal').modal();
myModal.show();
},
error: function (xhr, ajaxOptions, thrownError) {
$( "#myModal .modal-body pre" ).html( xhr.responseText );
$('#myModal').modal();
$('#myModal').show();
}
});
Expand Down

0 comments on commit 1d63d33

Please sign in to comment.