Skip to content

Commit

Permalink
Improve configurations management
Browse files Browse the repository at this point in the history
  • Loading branch information
ToX82 committed Jul 13, 2024
1 parent 7e4974c commit 0da66ef
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
2 changes: 1 addition & 1 deletion logics/Configurations.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getAvailableParsers()
*/
public function checkFileExists($filename)
{
return file_exists($filename);
return file_exists($filename) && is_file($filename);
}

/**
Expand Down
55 changes: 19 additions & 36 deletions views/configurations/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,48 @@
<div class="col-8 offset-2">
<div class="add_configurations card border-secondary-subtle">
<div class="card-header">
New log configuration
<span class="iconify-preview iconify" data-width="24" data-icon="mdi:error" data-inline="false"></span>
<span class="title-preview">New Log Configuration</span>
</div>

<form method="post" action="save_configurations" class="needs-validation mt-3 ms-2 d-flex flex-column me-3"
novalidate>

<form method="post" action="save_configurations" class="needs-validation mt-3 ms-2 d-flex flex-column me-3" novalidate>
<div class="ms-2 d-flex flex-column mt-1 mb-3 align-items-start">
<h6><label for="icon" class="form-label">Select a new icon</label></h6>
<h6><label for="input-icon" class="form-label">Select the icon and color for this configuration</label></h6>
<div class="d-flex flex-row align-items-center">
<button type="button" class="iconify-open-dialog px-2 btn btn-primary"
data-icon-input="iconify-select" data-color-input="iconify-color">Find icon</button>
<input type="text" value="mdi:error" placeholder="Iconify code, eg. mdi:error"
class="iconify-select form-control ms-2" size="20"
id="input-icon" name="input-icon" required>
<input type="color" class="iconify-color ms-2"
id="input-color" name="input-color" value="#000000">
<input type="color" class="iconify-color form-control form-control-color me-2" id="input-color" name="input-color" value="#000000">
<input type="text" value="mdi:error" placeholder="Iconify code, eg. mdi:error" class="iconify-select form-control me-2" size="20" id="input-icon" name="input-icon" required>
<button type="button" class="iconify-open-dialog btn btn-primary" data-icon-input="iconify-select" data-color-input="iconify-color">Cambia</button>
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="title" class="form-label">Icon preview</label></h6>
<div class="iconify-preview">
<span class="iconify iconify-preview" data-height="32" data-width="32" data-icon="mdi:error" data-inline="false"></span>
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="title" class="form-label">Title</label></h6>
<input type="text" class="form-control" id="input-title" name="input-title"
placeholder="title" required>
<div class="invalid-feedback">
Title is missing.
</div>
<h6><label for="input-title" class="form-label">Name</label></h6>
<input type="text" class="form-control" id="input-title" name="input-title" placeholder="Enter a name for this configuration (eg. 'My app error.log')" required>
<div class="invalid-feedback">The config name is missing.</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="file" class="form-label">File</label></h6>
<input type="text" class="form-control" id="input-file" name="input-file"
placeholder="file-path" required>
<h6><label for="input-file" class="form-label">Log file path</label></h6>
<input type="text" class="form-control" id="input-file" name="input-file" placeholder="Enter the path to the log file (eg. '/var/www/myapp/error.log')" required>
<div class="invalid-feedback">
File is missing or does not exist.
The log file path is missing or does not exist.
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="parser" class="form-label">Parser</label></h6>
<h6><label for="input-parser" class="form-label">Parser</label></h6>
<select class="form-control" id="input-parser" name="input-parser">
<?php foreach ($parsers as $parser) { ?>
<option><?= $parser ?></option>
<?php } ?>
<?php foreach ($parsers as $parser) { ?>
<option><?= $parser ?></option>
<?php } ?>
</select>
</div>

<div class="d-flex align-items-center justify-content-between m-3 me-0">
<div class="d-flex align-items-start">
<h6><label for="state" class="form-label">State</label></h6>
<h6><label for="input-disabled" class="form-label">Active</label></h6>
<div class="form-check form-switch ms-3">
<input type="checkbox" class="form-check-input" id="input-disabled" name="input-disabled"
role="switch" checked>
<input type="checkbox" class="form-check-input" id="input-disabled" name="input-disabled" role="switch" checked>
</div>
</div>
<input type="submit" name="btn-save-config" value="Add" class="btn btn-primary">
Expand Down
62 changes: 22 additions & 40 deletions views/configurations/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,52 @@
<div class="col-8 offset-2">
<div class="card border-secondary-subtle">
<div class="card-header">
<?= $config->title ?>
<span class="iconify-preview iconify" data-height="24" data-width="24" color="<?=$config->color?>" data-icon="<?=$config->icon?>" data-inline="false"></span>
<span class="title-preview"><?= $config->title ?></span>
</div>

<form method="post" action="save_configurations" class="needs-validation mt-3 ms-2 d-flex flex-column me-3"
novalidate>
<input class="form-control" type="text" id="input-name" name="input-name"
placeholder="configuration-name" value="<?= $configName ?>" hidden>
<form method="post" action="save_configurations" class="needs-validation mt-3 ms-2 d-flex flex-column me-3" novalidate>
<input class="form-control" type="text" id="input-name" name="input-name" placeholder="configuration-name" value="<?= $configName ?>" hidden>

<div class="ms-2 d-flex flex-column mt-1 mb-3 align-items-start">
<h6><label for="icon" class="form-label">Icon</label></h6>
<h6><label for="input-icon" class="form-label">Select the icon and color for this configuration</label></h6>
<div class="d-flex flex-row align-items-center">
<i></i>
<button type="button" class="iconify-open-dialog px-2 btn btn-primary"
data-icon-input="iconify-select" data-color-input="iconify-color">Search icon</button>
<p class="mt-3 ms-2">or insert it manually</p>
<input type="text" placeholder="Iconify code" class="iconify-select ms-2" size="20"
id="input-icon" name="input-icon" value="<?=$config->icon?>">
<input type="color" class="iconify-color ms-2"
id="input-color" name="input-color" value="<?=$config->color?>">
<input type="color" class="iconify-color form-control form-control-color me-2" id="input-color" name="input-color" value="<?=$config->color?>">
<input type="text" value="<?=$config->icon?>" placeholder="Iconify code, eg. mdi:error" class="iconify-select form-control me-2" size="20" id="input-icon" name="input-icon" required>
<button type="button" class="iconify-open-dialog btn btn-primary" data-icon-input="iconify-select" data-color-input="iconify-color">Cambia</button>
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="title" class="form-label">Icon preview</label></h6>
<div class="iconify-preview">
<span class="iconify iconify-preview" data-height="32" data-width="32" data-icon="mdi:error" data-inline="false"></span>
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="title" class="form-label">Title</label></h6>
<input type="text" class="form-control" id="input-title" name="input-title"
value="<?=$config->title?>" required>
<div class="invalid-feedback">
Title is missing.
</div>
<h6><label for="title" class="form-label">Name</label></h6>
<input type="text" class="form-control" id="input-title" name="input-title" value="<?=$config->title?>" required>
<div class="invalid-feedback">The config name is missing.</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="file" class="form-label">File</label></h6>
<input type="text" class="form-control" id="input-file" name="input-file"
value="<?=$config->file?>" required>
<h6><label for="input-file" class="form-label">Log file path</label></h6>
<input type="text" class="form-control" id="input-file" name="input-file" value="<?=$config->file ?>" placeholder="Enter the path to the log file (eg. '/var/www/myapp/error.log')" required>
<div class="invalid-feedback">
File is missing or does not exist.
The log file path is missing or does not exist.
</div>
</div>

<div class="ms-2 d-flex flex-column mb-3 align-items-start">
<h6><label for="parser" class="form-label">Parser</label></h6>
<h6><label for="input-parser" class="form-label">Parser</label></h6>
<select class="form-control" id="input-parser" name="input-parser">
<?php foreach ($parsers as $parser) { ?>
<option <?= $config->parser == $parser ? 'selected' : '' ?>>
<?= $parser ?></option>
<?php } ?>
<?php foreach ($parsers as $parser) { ?>
<option <?= $config->parser == $parser ? 'selected' : '' ?>>
<?= $parser ?>
</option>
<?php } ?>
</select>
</div>

<div class="d-flex align-items-center justify-content-between m-3 me-0">
<div class="d-flex align-items-start">
<h6><label for="state" class="form-label">State</label></h6>
<h6><label for="input-disabled" class="form-label">Active</label></h6>
<div class="form-check form-switch ms-3">
<input type="checkbox" class="form-check-input" id="input-disabled" name="input-disabled"
role="switch" <?= $config->disabled ? '' : 'checked'; ?>
>
<input type="checkbox" class="form-check-input" id="input-disabled" name="input-disabled" role="switch" <?= $config->disabled ? '' : 'checked'; ?>>
</div>
</div>
<input type="submit" name="btn-save-config" value="Save" class="btn btn-primary">
Expand Down
6 changes: 5 additions & 1 deletion views/layouts/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
<div class="row my-4">
<div class="col-12 log-container">
<?php foreach ($views as $view) { ?>
<?php include($view); ?>
<?php if (is_file($view)) { ?>
<?php include($view); ?>
<?php } else { ?>
<p class="w-100 text-center">The template <?= $view ?> does not exist.</p>
<?php } ?>
<?php } ?>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions webroot/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $(document).ready(function () {
});

// Input file change event
$('#input-file').on('change blur', function () {
$('#input-file').on('keyup change', function () {
const $input = $(this);
const filename = $input.val();

Expand All @@ -48,6 +48,10 @@ $(document).ready(function () {
});
});

$('#input-title').on('keyup', function () {
$('.title-preview').html($(this).val());
});

// Icon preview updater
if ($('#input-icon').length > 0) {
setInterval(function () {
Expand All @@ -57,7 +61,7 @@ $(document).ready(function () {
const color = $('#input-color').val();

if (icon !== currentIcon || color !== currentColor) {
$('.iconify-preview').html(`<i class="iconify" data-width="32" data-icon="${icon}" color="${color}"></i>`);
$('.iconify-preview').html(`<i class="iconify" data-inline="false" data-width="24" data-icon="${icon}" color="${color}"></i>`);
}
}, 300);
}
Expand Down

0 comments on commit 0da66ef

Please sign in to comment.