This commit is contained in:
Thomas Peterson 2024-09-30 08:49:32 +02:00
parent 05a7f719dd
commit beba8beac1
11 changed files with 149 additions and 29 deletions

View File

@ -2,9 +2,24 @@
namespace App\Components; namespace App\Components;
use PHPNative\UI\Collection\Views;
use PHPNative\UI\Widget\Button; use PHPNative\UI\Widget\Button;
use PHPNative\UI\Widget\Icon;
use PHPNative\UI\Widget\Text;
class CreateButton extends Button class CreateButton extends Button
{ {
public string $style = "bg-green-200 hover:bg-white text-black hover:text-green-500 m-10 p-8 w-full border border-black hover:border-red-500";
public function __construct(public string $label, string $style = '')
{
parent::__construct( style: "px-3 py-2 bg-sky-500 hover:bg-blue-800 text-white hover:text-green-500 m-10 p-8 w-full rounded-xl");
}
public function getViews(): ?\PHPNative\UI\Collection\Views
{
return new Views([
new Icon(\PHPNative\Tailwind\Data\Icon::plus, style: 'text-white'),
new Text($this->label, 'text-xl text-white m-3'),
]);
}
} }

View File

@ -9,12 +9,10 @@ class MainLayout extends Container
{ {
public string $style = "flex w-full"; public string $style = "flex w-full";
public ProjectList $projectList;
public TaskList $taskList; public TaskList $taskList;
public function __construct() public function __construct(public ProjectList $projectList)
{ {
parent::__construct(); parent::__construct();
$this->projectList = new ProjectList();
$this->taskList = new TaskList(); $this->taskList = new TaskList();
} }

View File

@ -2,11 +2,16 @@
namespace App\Components; namespace App\Components;
use App\Model\DB;
use App\Model\Project; use App\Model\Project;
use App\Windows\AddProject;
use App\Windows\MainWindow;
use PHPNative\Framework\Lifecycle\Lifecycle;
use PHPNative\Framework\Parallel\Worker; use PHPNative\Framework\Parallel\Worker;
use PHPNative\Storage\Storage;
use PHPNative\UI\Collection\Views; use PHPNative\UI\Collection\Views;
use PHPNative\UI\Widget\Container; use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Label; use PHPNative\UI\Widget\Text;
class ProjectList extends Container class ProjectList extends Container
{ {
@ -16,16 +21,34 @@ class ProjectList extends Container
public ProjectListData $listData; public ProjectListData $listData;
public function __construct() public function __construct(private Lifecycle $lifecycle, private \PHPNative\Container\Container $container)
{ {
parent::__construct(); parent::__construct();
$this->style = 'border-r-4 border-slate-500 basis-2/6 h-full flex flex-col'; $this->style = 'border-r-4 border-slate-500 basis-2/6 h-full flex flex-col';
$this->createButton = new CreateButton(label: "New Project"); $this->createButton = new CreateButton("create Project");
$this->createButton->setOnClick(fn(Worker $worker) => $this->reloadProjects($worker)); $this->createButton->setOnClick(fn(Worker $worker) => $this->addProject($worker));
$this->listData = new ProjectListData(); $this->listData = new ProjectListData();
$this->loadProjects();
} }
private function reloadProjects(Worker $worker): void { private function loadProjects(): void
{
$this->listData->views->clear();
/** @var DB $db */
$db = $this->container->get(Storage::class)->loadModel(DB::class);
foreach($db->getProjects() as $project) {
$this->listData->views->add(new Text(text: $project->title, style: 'w-full p-2 text-xl pl-10 hover:bg-slate-300'));
}
}
private function addProject(Worker $worker): void
{
$this->lifecycle->show(window: $this->container->get(AddProject::class), onClose: function() {
$this->loadProjects();
});
}
/*private function reloadProjects(Worker $worker): void {
$worker->async(function() { $worker->async(function() {
sleep("1"); sleep("1");
return [ return [
@ -57,19 +80,19 @@ class ProjectList extends Container
]; ];
}, function($data) { }, function($data) {
$this->listData->views = new Views(); $this->listData->views = new Views();
*/
/** @var Project $row */ /** @var Project $row */
foreach($data as $row) { /* foreach($data as $row) {
$this->listData->views->add(new Label($row->title, style: 'w-full p-2 pl-10 hover:bg-slate-300')); $this->listData->views->add(new Label($row->title, style: 'w-full p-2 text-xl pl-10 hover:bg-slate-300'));
} }
}); });
} }
*/
public function getViews(): ?Views public function getViews(): ?Views
{ {
return new Views([ return new Views([
$this->createButton, $this->createButton,
new Label(label: 'Projects:', style: 'ml-10 w-full'), new Text(text: 'Projects:', style: 'ml-10 w-full text-xl'),
$this->listData $this->listData
]); ]);
} }

View File

@ -5,7 +5,7 @@ namespace App\Components;
use PHPNative\Framework\Parallel\Worker; use PHPNative\Framework\Parallel\Worker;
use PHPNative\UI\Collection\Views; use PHPNative\UI\Collection\Views;
use PHPNative\UI\Widget\Container; use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Label; use PHPNative\UI\Widget\Text;
class ProjectListData extends Container class ProjectListData extends Container
{ {

View File

@ -5,7 +5,7 @@ namespace App\Components;
use PHPNative\UI\Collection\Views; use PHPNative\UI\Collection\Views;
use PHPNative\UI\View; use PHPNative\UI\View;
use PHPNative\UI\Widget\Container; use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Label; use PHPNative\UI\Widget\Text;
class TaskList extends Container class TaskList extends Container
{ {
@ -17,7 +17,7 @@ class TaskList extends Container
public function getViews(): ?Views public function getViews(): ?Views
{ {
return new Views([ return new Views([
new Label(label: 'Issues', style: 'w-full p-30 m-40 bg-lime-400 text-black') new Text(text: 'Issues', style: 'w-full bg-lime-400 m-10 p-10 text-black')
]); ]);
} }
} }

18
app/Model/DB.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Model;
class DB
{
private array $projects = [];
public function addProject(Project $project): void
{
$this->projects[] = $project;
}
public function getProjects(): array
{
return $this->projects;
}
}

46
app/View/AddProject.php Normal file
View File

@ -0,0 +1,46 @@
<?php
namespace App\View;
use App\Model\DB;
use App\Model\Project;
use PHPNative\Storage\Storage;
use PHPNative\UI\BaseView;
use PHPNative\UI\Collection\Views;
use PHPNative\UI\View;
use PHPNative\UI\Widget\Button;
use PHPNative\UI\Widget\Text;
use PHPNative\UI\Widget\TextEdit;
class AddProject extends BaseView implements View
{
public string $style = "bg-white h-full w-full flex flex-col";
public Button $saveButton;
public TextEdit $editText;
public function __construct(private Storage $storage)
{
$this->saveButton = new Button(views: new Views([new Text(text: 'save project', style: 'p-10 text-white text-2xl w-full text-center')]), style: 'w-full bg-lime-700 m-10');
$this->saveButton->setOnClick(fn() => $this->saveProject());
$this->editText = new TextEdit(style: 'text-2xl text-black border border-black w-full m-10 p-10', placeholder: 'Please provide any name');
}
public function getViews(): ?Views
{
return new Views([
new Text(text: 'add Project', style: 'text-2xl text-black text-center bg-lime-200 w-full m-10 p-10'),
$this->editText,
$this->saveButton
]);
}
private function saveProject()
{
$db = $this->storage->loadModel(DB::class);
$db->addProject(new Project(uniqid(), $this->editText->value));
$this->storage->saveModel($db);
}
}

View File

@ -1,20 +1,18 @@
<?php <?php
namespace App\Components; namespace App\View;
use App\Components\MainLayout;
use PHPNative\UI\BaseView; use PHPNative\UI\BaseView;
use PHPNative\UI\Collection\Views; use PHPNative\UI\Collection\Views;
use PHPNative\UI\View; use PHPNative\UI\View;
class WindowView extends BaseView implements View class WindowView extends BaseView implements View
{ {
public string $style = "bg-white"; public string $style = "bg-white w-full h-full flex flex-col";
private MainLayout $mainLayout; public function __construct(private MainLayout $mainLayout)
public function __construct()
{ {
$this->mainLayout = new MainLayout();
} }
public function getViews(): ?Views public function getViews(): ?Views

View File

@ -0,0 +1,25 @@
<?php
namespace App\Windows;
use App\View\WindowView;
use PHPNative\Framework\Application\Window;
use PHPNative\UI\View;
class AddProject implements Window
{
public function __construct(public \App\View\AddProject $windowView)
{
}
public function getTitle(): string
{
return "Add Project";
}
public function getView(): ?View
{
return $this->windowView;
}
}

View File

@ -2,18 +2,15 @@
namespace App\Windows; namespace App\Windows;
use App\Components\WindowView; use App\View\WindowView;
use PHPNative\Framework\Application\Window; use PHPNative\Framework\Application\Window;
use PHPNative\UI\View; use PHPNative\UI\View;
class MainWindow implements Window class MainWindow implements Window
{ {
public WindowView $windowView; public function __construct(public WindowView $windowView)
public function __construct()
{ {
$this->windowView = new WindowView();
} }
public function getTitle(): string public function getTitle(): string

View File

@ -9,6 +9,6 @@ try {
require_once getcwd() . '/../autoload.php'; require_once getcwd() . '/../autoload.php';
} }
Gui::boot(__DIR__)->run(\App\Windows\MainWindow::class); Gui::boot(root: __DIR__, app: \App\App::class)->run();
exit; exit;