many small fixes

This commit is contained in:
Dennis Eichhorn 2023-02-10 18:20:57 +01:00
parent 7d72ca7800
commit 8e010c0ab0
10 changed files with 168 additions and 19 deletions

View File

@ -0,0 +1,34 @@
{
"triggers": [
],
"actions": {
"1008000001": {
"name": "Check resources",
"description": {
"en": "Check resources",
"de": "Ueberpruefe Ressourcen"
},
"function_type": "API",
"function": "apiResourceCheck",
"inputs": [
"unit",
"{*}"
],
"outputs": [
"resources[]",
"{*}"
],
"settings": {
"unit": {
"type": "input",
"subtype": "number",
"default": null,
"title": {
"en": "Unit",
"de": "Unit"
}
}
}
}
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\OnlineResourceWatcher\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\OnlineResourceWatcher\Admin\Install;
use phpOMS\Application\ApplicationAbstract;
/**
* Workflow class.
*
* @package Modules\OnlineResourceWatcher\Admin\Install
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class Workflow
{
/**
* Install workflow providing
*
* @param ApplicationAbstract $app Application
* @param string $path Module path
*
* @return void
*
* @since 1.0.0
*/
public static function install(ApplicationAbstract $app, string $path) : void
{
\Modules\Workflow\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Workflow.install.json']);
}
}

View File

@ -18,7 +18,7 @@ use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/orw/resource.*$' => [
'^.*/orw/resource(\?.*|$)' => [
[
'dest' => '\Modules\OnlineResourceWatcher\Controller\ApiController:apiResourceCreate',
'verb' => RouteVerb::PUT,
@ -56,4 +56,16 @@ return [
],
],
],
'^.*/orw/resource/render.*$' => [
[
'dest' => '\Modules\OnlineResourceWatcher\Controller\ApiController:apiResourceRender',
'verb' => RouteVerb::GET,
'permission' => [
'module' => ApiController::NAME,
'type' => PermissionType::READ,
'state' => PermissionCategory::RESOURCE,
],
],
],
];

View File

@ -21,6 +21,7 @@ use Modules\OnlineResourceWatcher\Models\ReportStatus;
use Modules\OnlineResourceWatcher\Models\Resource;
use Modules\OnlineResourceWatcher\Models\ResourceMapper;
use Modules\OnlineResourceWatcher\Models\ResourceStatus;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
@ -41,6 +42,50 @@ use phpOMS\Utils\StringUtils;
*/
final class ApiController extends Controller
{
/**
* Api method to create resource
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiResourceRender(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
/** @var \Modules\OnlineResourceWatcher\Models\Resource $resource */
$resource = ResourceMapper::get()
->where('id', (int) $request->getData('id'))
->execute();
$path = '';
if (\is_dir($basePath = __DIR__ . '/' . $resource->path . '/' . $resource->lastVersionPath)) {
if (\is_file($basePath . '/index.htm')) {
$path = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $resource->lastVersionPath . '/index.htm';
} elseif (\is_file($basePath . '/index.html')) {
$path = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $resource->lastVersionPath . '/index.html';
} else {
$files = \scandir($basePath);
foreach ($files as $file) {
if ($file === '.' || $files === '..') {
continue;
}
$path = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $resource->lastVersionPath . '/' . $file;
}
}
}
$internalRequest = new HttpRequest();
$internalRequest->header->account = $request->header->account;
$internalRequest->setData('path', $path);
$this->app->moduleManager->get('Media')->apiMediaExport($internalRequest, $response, ['guard' => __DIR__ . '/../Files']);
}
/**
* Validate resource create request
*
@ -170,6 +215,7 @@ final class ApiController extends Controller
// Check downloaded resources
// @todo: this may not work correctly because the download runs async.
$totalCount = \count($toCheck);
$maxLoops = (int) \min(60 * 10, $totalCount * 10 / 4);
// @todo: the following code is INSANE, simplify!!!
$baseLen = \strlen($basePath . '/temp');
@ -179,7 +225,7 @@ final class ApiController extends Controller
$resource = $check['resource'];
// too many tries
if ($check['loop'] > 60 * 10) {
if ($check['loop'] > $maxLoops) {
$report = new Report();
$report->resource = $resource->getId();
$report->versionPath = (string) $check['timestamp'];
@ -205,7 +251,7 @@ final class ApiController extends Controller
$id = (int) \substr($path, $baseLen + 1, $end - $baseLen - 1);
// new resource
if ($check['loop'] === 60 * 10 && !\is_dir($basePath . '/' . $id)) {
if ($check['loop'] === $maxLoops && !\is_dir($basePath . '/' . $id)) {
$filesNew = \scandir($path);
if ($filesNew === false) {
$filesNew = [];

View File

@ -132,6 +132,7 @@ final class BackendController extends Controller
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/OnlineResourceWatcher/Theme/Backend/resource-single');
/** @var \Modules\OnlineResourceWatcher\Models\Resource $resource */
$resource = ResourceMapper::get()
->where('id', (int) $request->getData('id'))
->execute();

View File

@ -12,7 +12,7 @@
*/
declare(strict_types=1);
return [[
return ['OnlineResourceWatcher' => [
'Action' => 'Action',
'Add' => 'Add',
'Admin' => 'Admin',

View File

@ -12,7 +12,7 @@
*/
declare(strict_types=1);
return [[
return ['OnlineResourceWatcher' => [
'Action' => 'Action',
'Add' => 'Add',
'Admin' => 'Admin',
@ -83,4 +83,8 @@ return [[
'Element' => 'Element',
'Exit' => 'Exit',
'Url' => 'Url',
'Preview' => 'Preview',
'XPath' => 'XPath',
'Comparison' => 'Comparison',
'History' => 'History',
]];

View File

@ -76,7 +76,7 @@ use phpOMS\Uri\UriFactory;
<td><?= $this->getHtml('User', '0', '0'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td><?= $this->getHtml('Email', '0', '0'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<?php $c = 0; foreach ([] as $key => $value) : ++$c; $url = UriFactory::build('{/lang}/{/app}/{/prefix}admin/account/settings?{?}&id=' . $value->getId()); ?>
<?php $c = 0; foreach ([] as $key => $value) : ++$c; $url = UriFactory::build('{/lang}/{/app}/admin/account/settings?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td>
<td>

View File

@ -78,12 +78,12 @@ $next = $tableView->getNextLink(
<tbody>
<?php $count = 0;
foreach ($resources as $key => $resource) : ++$count;
$url = UriFactory::build('{/lang}/{/app}/{/prefix}orw/resource?id=' . $resource->getId()); ?>
$url = UriFactory::build('{/lang}/{/app}/orw/resource?id=' . $resource->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td><?= $resource->getId(); ?>
<td><?= $this->printHtml($resource->title); ?>
<td><?= $this->printHtml((string) $resource->getStatus()); ?>
<td>
<td><?= $this->printHtml($resource->checkedAt->format('Y-m-d H:i')); ?>
<td><?= $this->printHtml($resource->createdAt->format('Y-m-d')); ?>
<?php endforeach; ?>
<?php if ($count === 0) : ?>

View File

@ -14,7 +14,8 @@ declare(strict_types=1);
use phpOMS\Uri\UriFactory;
$resource = $this->getData('resource');
/** @var \Modules\OnlineResourceWatcher\Models\Resource */
$resource = $this->getData('resource') ?? new \Modules\OnlineResourceWatcher\Models\NullResource();
?>
<div class="row">
<div class="col-xs-8">
@ -37,12 +38,12 @@ $resource = $this->getData('resource');
<div class="form-group">
<label for="iUrl"><?= $this->getHtml('Url'); ?></label>
<input id="iUrl" name="uri" type="text" required>
<input id="iUrl" name="uri" type="text" value="<?= $this->printHtml($resource->uri); ?>" required>
</div>
<div class="form-group">
<label for="iXPath"><?= $this->getHtml('XPath'); ?></label>
<input id="iXPath" name="xpath" type="text">
<input id="iXPath" name="xpath" type="text" value="<?= $this->printHtml($resource->xpath); ?>">
</div>
</div>
<div class="portlet-foot">
@ -61,19 +62,27 @@ $resource = $this->getData('resource');
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-body">
<div id="resource" class="tabview tab-2 m-editor wf-100">
<div class="row col-simple">
<div class="col-xs-12 col-simple">
<div class="portlet col-simple">
<div class="portlet-body col-simple">
<div id="resource" class="tabview tab-2 m-editor col-simple">
<ul class="tab-links">
<li><label tabindex="0" for="resource-c-tab-1"><?= $this->getHtml('Preview'); ?></label>
<li><label tabindex="1" for="resource-c-tab-2"><?= $this->getHtml('Comparison'); ?></label>
</ul>
<div class="tab-content">
<div class="tab-content col-simple">
<input type="radio" id="resource-c-tab-1" name="tabular-1" checked>
<div class="tab">
<div class="tab col-simple">
<div class="col-simple">
<div class="col-xs-12 col-simple">
<section id="mediaFile" class="portlet col-simple">
<div class="portlet-body col-simple">
<iframe class="col-simple" id="iRenderFrame" src="<?= UriFactory::build('{/api}/orw/resource/render?id=' . $resource->getId()); ?>" loading="lazy" allowfullscreen></iframe>
</div>
</section>
</div>
</div>
</div>
<input type="radio" id="resource-c-tab-2" name="tabular-1">