mirror of
https://github.com/claradex/nativegallery.git
synced 2024-12-22 08:30:56 +03:00
load models
This commit is contained in:
parent
6f725d0d70
commit
0f6feb123a
5 changed files with 77 additions and 84 deletions
26
app/Controllers/Api/Admin/GetVehicleInputs.php
Normal file
26
app/Controllers/Api/Admin/GetVehicleInputs.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers\Api\Admin;
|
||||
|
||||
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
||||
use App\Models\{User, Vote, Photo};
|
||||
|
||||
|
||||
class GetVehicleInputs
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$id = explode('/', $_SERVER['REQUEST_URI'])[4];
|
||||
$vehicle = DB::query('SELECT * FROM entities WHERE id=:id', array(':id'=>$id))[0];
|
||||
$data = json_decode($vehicle['sampledata'], true);
|
||||
foreach ($data as $d) {
|
||||
echo '
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">'.$d['name'].'</label>
|
||||
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро">
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ use \App\Controllers\Api\Users\LoadUser as UserLoad;
|
|||
use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility;
|
||||
use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews;
|
||||
use \App\Controllers\Api\Admin\LoadNews as AdminLoadNews;
|
||||
use \App\Controllers\Api\Admin\GetVehicleInputs as AdminGetVehicleInputs;
|
||||
class ApiController
|
||||
{
|
||||
|
||||
|
@ -83,6 +84,9 @@ class ApiController
|
|||
public static function adminloadnews() {
|
||||
return new AdminLoadNews();
|
||||
}
|
||||
public static function admingetvehicleinputs() {
|
||||
return new AdminGetVehicleInputs();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -65,6 +65,7 @@ class Routes
|
|||
Router::any('/api/admin/images/setvisibility', 'ApiController@adminsetvis');
|
||||
Router::any('/api/admin/createnews', 'ApiController@admincreatenews');
|
||||
Router::any('/api/admin/loadnews', 'ApiController@adminloadnews');
|
||||
Router::any('/api/admin/getvehicleinputs/$id', 'ApiController@admingetvehicleinputs');
|
||||
}
|
||||
Router::get('/logout', 'MainController@logout');
|
||||
Router::get('/404', 'ExceptionRegister@notfound');
|
||||
|
|
|
@ -38,10 +38,11 @@ if (isset($_POST['create'])) {
|
|||
<label for="exampleFormControlInput1" class="form-label">Название</label>
|
||||
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Цвет</label>
|
||||
<input type="text" name="color" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="exampleColorInput" class="form-label">Цвет</label>
|
||||
<input name="color" type="color" class="form-control form-control-color" id="exampleColorInput" value="#563d7c" title="Choose your color">
|
||||
</div>
|
||||
|
||||
<p>Вводимые переменные</p>
|
||||
<div class="alert alert-dark" role="alert">
|
||||
Добавляйте и регулируйте поля ввода, которые будут являться шаблонной формой для создания моделей к сущности.
|
||||
|
|
|
@ -4,6 +4,7 @@ use \App\Services\{Auth, DB};
|
|||
use \App\Models\{User, Vehicle};
|
||||
|
||||
|
||||
$vehicle = DB::query('SELECT * FROM entities WHERE id=:id', array(':id' => $_GET['id']))[0];
|
||||
|
||||
if (isset($_POST['create'])) {
|
||||
$postData = $_POST;
|
||||
|
@ -33,92 +34,52 @@ if (isset($_POST['create'])) {
|
|||
header('Location: /admin?type=Entities');
|
||||
}
|
||||
?>
|
||||
<h1><b>Создание сущности</b></h1>
|
||||
<form action="/admin?type=EntityCreate" method="post" name="form" id="form" enctype="multipart/form-data" style="display:inline-block; min-width:500px;">
|
||||
<h1><b>Создание модели</b></h1>
|
||||
<label>Сущность</label>
|
||||
<select id="entitySelect" class="form-select" aria-label="Default select example">
|
||||
<option selected disabled>Выберите сущность</option>
|
||||
<?php
|
||||
$datad = DB::query('SELECT * FROM entities');
|
||||
foreach ($datad as $d) {
|
||||
echo '<option value="'.$d['id'].'" style="background-color: '.$d['color'].'">'.$d['title'].'</option>';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Название</label>
|
||||
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Цвет</label>
|
||||
<input type="text" name="color" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
|
||||
</div>
|
||||
<p>Вводимые переменные</p>
|
||||
<div class="alert alert-dark" role="alert">
|
||||
Добавляйте и регулируйте поля ввода, которые будут являться шаблонной формой для создания моделей к сущности.
|
||||
</div>
|
||||
<div class="row" id="entityform">
|
||||
<div class="col-md-3">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Название переменной</label>
|
||||
<input name="variablename_1" type="text" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">ID</label>
|
||||
<input name="variableid_1" type="text" class="form-control" id="exampleFormControlInput1" placeholder="blablabla">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Тип</label>
|
||||
<select name="variabletype_1" class="form-select" aria-label="Default select example">
|
||||
<option value="1">Строка</option>
|
||||
<option value="2">Число</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">Обязателен?</label>
|
||||
<select name="variableimportant_1" class="form-select" aria-label="Default select example">
|
||||
<option value="1">Да</option>
|
||||
<option value="2">Нет</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button id="addButton" type="button" class="btn btn-outline-primary">Добавить ещё</button>
|
||||
<button id="addButton" type="submit" name="create" class="btn btn-primary">Создать сущность</button>
|
||||
</div>
|
||||
|
||||
</select>
|
||||
<form action="/admin?type=EntityCreate" method="post" name="form" id="form" enctype="multipart/form-data" style="display:inline-block; min-width:500px;">
|
||||
|
||||
|
||||
|
||||
<button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
<script>
|
||||
let count = 1; // Начальное значение для номера переменной
|
||||
document.getElementById('entitySelect').addEventListener('change', function() {
|
||||
const selectedValue = this.value;
|
||||
|
||||
document.getElementById('addButton').addEventListener('click', function() {
|
||||
count++; // Увеличиваем номер переменной
|
||||
if (selectedValue) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', "/api/admin/getvehicleinputs/"+selectedValue, true);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
if (xhr.status === 200) {
|
||||
document.getElementById('form').innerHTML = '';
|
||||
document.getElementById('form').innerHTML = '<button id="addButton" type="submit" name="create" class="btn btn-primary mt-5">Добавить модель</button>';
|
||||
|
||||
// Создаем новый элемент
|
||||
const newElement =
|
||||
`<div class="col-md-3">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput${count}" class="form-label">Название переменной</label>
|
||||
<input name="variablename_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="#FFFFFF">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput${count}" class="form-label">ID</label>
|
||||
<input name="variableid_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="blablabla">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label for="exampleFormControlInput${count}" class="form-label">Тип</label>
|
||||
<select name="variabletype_${count}" class="form-select" aria-label="Default select example">
|
||||
<option value="1">Строка</option>
|
||||
<option value="2">Число</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label for="exampleFormControlInput${count}" class="form-label">Обязателен?</label>
|
||||
<select name="variableimportant_${count}" class="form-select" aria-label="Default select example">
|
||||
<option value="1">Да</option>
|
||||
<option value="2">Нет</option>
|
||||
</select>
|
||||
</div>`;
|
||||
|
||||
// Добавляем новый элемент в #entityform
|
||||
document.getElementById('entityform').insertAdjacentHTML('beforeend', newElement);
|
||||
});
|
||||
document.getElementById('form').insertAdjacentHTML('afterbegin', xhr.responseText);
|
||||
|
||||
} else {
|
||||
console.error('Ошибка при загрузке данных:', xhr.statusText);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
</script>
|
Loading…
Reference in a new issue