From beba8beac175d4548947027a132dd4aeca593e31 Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Mon, 30 Sep 2024 08:49:32 +0200 Subject: [PATCH] Backup --- app/Components/CreateButton.php | 17 ++++++++- app/Components/MainLayout.php | 4 +-- app/Components/ProjectList.php | 43 +++++++++++++++++------ app/Components/ProjectListData.php | 2 +- app/Components/TaskList.php | 4 +-- app/Model/DB.php | 18 ++++++++++ app/View/AddProject.php | 46 +++++++++++++++++++++++++ app/{Components => View}/WindowView.php | 10 +++--- app/Windows/AddProject.php | 25 ++++++++++++++ app/Windows/MainWindow.php | 7 ++-- phpnative | 2 +- 11 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 app/Model/DB.php create mode 100644 app/View/AddProject.php rename app/{Components => View}/WindowView.php (58%) create mode 100644 app/Windows/AddProject.php diff --git a/app/Components/CreateButton.php b/app/Components/CreateButton.php index 1572c87..7e5a9ad 100644 --- a/app/Components/CreateButton.php +++ b/app/Components/CreateButton.php @@ -2,9 +2,24 @@ namespace App\Components; +use PHPNative\UI\Collection\Views; use PHPNative\UI\Widget\Button; +use PHPNative\UI\Widget\Icon; +use PHPNative\UI\Widget\Text; 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'), + ]); + } } \ No newline at end of file diff --git a/app/Components/MainLayout.php b/app/Components/MainLayout.php index 52131af..9a15826 100644 --- a/app/Components/MainLayout.php +++ b/app/Components/MainLayout.php @@ -9,12 +9,10 @@ class MainLayout extends Container { public string $style = "flex w-full"; - public ProjectList $projectList; public TaskList $taskList; - public function __construct() + public function __construct(public ProjectList $projectList) { parent::__construct(); - $this->projectList = new ProjectList(); $this->taskList = new TaskList(); } diff --git a/app/Components/ProjectList.php b/app/Components/ProjectList.php index 3dbeeb5..ea033cd 100644 --- a/app/Components/ProjectList.php +++ b/app/Components/ProjectList.php @@ -2,11 +2,16 @@ namespace App\Components; +use App\Model\DB; use App\Model\Project; +use App\Windows\AddProject; +use App\Windows\MainWindow; +use PHPNative\Framework\Lifecycle\Lifecycle; use PHPNative\Framework\Parallel\Worker; +use PHPNative\Storage\Storage; use PHPNative\UI\Collection\Views; use PHPNative\UI\Widget\Container; -use PHPNative\UI\Widget\Label; +use PHPNative\UI\Widget\Text; class ProjectList extends Container { @@ -16,16 +21,34 @@ class ProjectList extends Container public ProjectListData $listData; - public function __construct() + public function __construct(private Lifecycle $lifecycle, private \PHPNative\Container\Container $container) { parent::__construct(); $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->setOnClick(fn(Worker $worker) => $this->reloadProjects($worker)); + $this->createButton = new CreateButton("create Project"); + $this->createButton->setOnClick(fn(Worker $worker) => $this->addProject($worker)); $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() { sleep("1"); return [ @@ -57,19 +80,19 @@ class ProjectList extends Container ]; }, function($data) { $this->listData->views = new Views(); - +*/ /** @var Project $row */ - foreach($data as $row) { - $this->listData->views->add(new Label($row->title, style: 'w-full p-2 pl-10 hover:bg-slate-300')); + /* foreach($data as $row) { + $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 { return new Views([ $this->createButton, - new Label(label: 'Projects:', style: 'ml-10 w-full'), + new Text(text: 'Projects:', style: 'ml-10 w-full text-xl'), $this->listData ]); } diff --git a/app/Components/ProjectListData.php b/app/Components/ProjectListData.php index 66ac12f..84e3291 100644 --- a/app/Components/ProjectListData.php +++ b/app/Components/ProjectListData.php @@ -5,7 +5,7 @@ namespace App\Components; use PHPNative\Framework\Parallel\Worker; use PHPNative\UI\Collection\Views; use PHPNative\UI\Widget\Container; -use PHPNative\UI\Widget\Label; +use PHPNative\UI\Widget\Text; class ProjectListData extends Container { diff --git a/app/Components/TaskList.php b/app/Components/TaskList.php index cc3e868..c1a32f4 100644 --- a/app/Components/TaskList.php +++ b/app/Components/TaskList.php @@ -5,7 +5,7 @@ namespace App\Components; use PHPNative\UI\Collection\Views; use PHPNative\UI\View; use PHPNative\UI\Widget\Container; -use PHPNative\UI\Widget\Label; +use PHPNative\UI\Widget\Text; class TaskList extends Container { @@ -17,7 +17,7 @@ class TaskList extends Container public function getViews(): ?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') ]); } } \ No newline at end of file diff --git a/app/Model/DB.php b/app/Model/DB.php new file mode 100644 index 0000000..613a1dd --- /dev/null +++ b/app/Model/DB.php @@ -0,0 +1,18 @@ +projects[] = $project; + } + + public function getProjects(): array + { + return $this->projects; + } +} \ No newline at end of file diff --git a/app/View/AddProject.php b/app/View/AddProject.php new file mode 100644 index 0000000..ed88dd7 --- /dev/null +++ b/app/View/AddProject.php @@ -0,0 +1,46 @@ +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); + } + +} \ No newline at end of file diff --git a/app/Components/WindowView.php b/app/View/WindowView.php similarity index 58% rename from app/Components/WindowView.php rename to app/View/WindowView.php index f8d7281..3e35574 100644 --- a/app/Components/WindowView.php +++ b/app/View/WindowView.php @@ -1,20 +1,18 @@ mainLayout = new MainLayout(); } public function getViews(): ?Views diff --git a/app/Windows/AddProject.php b/app/Windows/AddProject.php new file mode 100644 index 0000000..356a368 --- /dev/null +++ b/app/Windows/AddProject.php @@ -0,0 +1,25 @@ +windowView; + } +} \ No newline at end of file diff --git a/app/Windows/MainWindow.php b/app/Windows/MainWindow.php index fd0ae1d..12be7e8 100644 --- a/app/Windows/MainWindow.php +++ b/app/Windows/MainWindow.php @@ -2,18 +2,15 @@ namespace App\Windows; -use App\Components\WindowView; +use App\View\WindowView; use PHPNative\Framework\Application\Window; use PHPNative\UI\View; class MainWindow implements Window { - public WindowView $windowView; - - public function __construct() + public function __construct(public WindowView $windowView) { - $this->windowView = new WindowView(); } public function getTitle(): string diff --git a/phpnative b/phpnative index 8cf9c74..487483a 100755 --- a/phpnative +++ b/phpnative @@ -9,6 +9,6 @@ try { require_once getcwd() . '/../autoload.php'; } -Gui::boot(__DIR__)->run(\App\Windows\MainWindow::class); +Gui::boot(root: __DIR__, app: \App\App::class)->run(); exit;