From fbd61a05d0c3d8cbb47d5b3c11e0091e1614c3e0 Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Sun, 13 Oct 2024 21:39:35 +0200 Subject: [PATCH] Fixes --- app/App.php | 3 +- app/Components/CreateButton.php | 11 ++- app/Components/CreateNewTask.php | 37 +++++++++ app/Components/MainLayout.php | 29 +++++-- app/Components/NoProjectSelectedTaskList.php | 27 +++++++ app/Components/ProjectList.php | 19 ++++- app/Components/ProjectListData.php | 8 +- app/Components/TaskList.php | 42 ++++++++++- app/Components/TaskListData.php | 23 ++++++ app/Model/DB.php | 17 +++++ app/Model/Task.php | 10 +++ app/View/AddProject.php | 10 --- app/View/TestLayoutView.php | 79 ++++++++++++++++++++ app/View/WindowView.php | 10 +-- app/Windows/AddProject.php | 21 +++++- app/Windows/MainWindow.php | 19 ++++- app/Windows/TestLayoutWindow.php | 25 +++++++ 17 files changed, 341 insertions(+), 49 deletions(-) create mode 100644 app/Components/CreateNewTask.php create mode 100644 app/Components/NoProjectSelectedTaskList.php create mode 100644 app/Components/TaskListData.php create mode 100644 app/Model/Task.php create mode 100644 app/View/TestLayoutView.php create mode 100644 app/Windows/TestLayoutWindow.php diff --git a/app/App.php b/app/App.php index 8b1fcac..f37aea9 100644 --- a/app/App.php +++ b/app/App.php @@ -3,6 +3,7 @@ namespace App; use App\Windows\MainWindow; +use App\Windows\TestLayoutWindow; class App implements \PHPNative\Framework\App { @@ -13,6 +14,6 @@ class App implements \PHPNative\Framework\App public function getStartWindow(): string { - return MainWindow::class; + return TestLayoutWindow::class; } } \ No newline at end of file diff --git a/app/Components/CreateButton.php b/app/Components/CreateButton.php index 7e5a9ad..0a6c1e8 100644 --- a/app/Components/CreateButton.php +++ b/app/Components/CreateButton.php @@ -10,16 +10,21 @@ use PHPNative\UI\Widget\Text; class CreateButton extends Button { + private Icon $icon; + private Text $text; + 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"); + 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 flex flex-row"); + $this->icon = new Icon(\PHPNative\Tailwind\Data\Icon::plus, style: 'text-white'); + $this->text = new Text($this->label, 'text-xl text-white m-3'); } 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'), + $this->icon, + $this->text, ]); } } \ No newline at end of file diff --git a/app/Components/CreateNewTask.php b/app/Components/CreateNewTask.php new file mode 100644 index 0000000..385cd96 --- /dev/null +++ b/app/Components/CreateNewTask.php @@ -0,0 +1,37 @@ +style = 'flex flex-row m-10 rounded w-full'; + + $this->saveButton = new Button(views: new Views([ + new \PHPNative\UI\Widget\Icon(icon: Icon::save, style: 'text-white'), + new Text(text: 'save Task', style: 'text-2xl text-white ml-30') + ]), style: 'flex-none w-150 bg-green-500 rounded-xl p-4 ml-10 hover:bg-green-700'); + + $this->textEdit = new TextEdit(style: 'flex-1 w-100 text-2xl bg-slate-200 px-10 rounded-xl text-black p-6', placeholder: 'Placeholder'); + } + + public function getViews(): ?Views + { + return new Views([ + $this->textEdit, + $this->saveButton, + ]); + } + +} \ No newline at end of file diff --git a/app/Components/MainLayout.php b/app/Components/MainLayout.php index 9a15826..4d868c4 100644 --- a/app/Components/MainLayout.php +++ b/app/Components/MainLayout.php @@ -7,21 +7,34 @@ use PHPNative\UI\Widget\Container; class MainLayout extends Container { - public string $style = "flex w-full"; - public TaskList $taskList; - public function __construct(public ProjectList $projectList) + public Views $noProjectSelectedViews; + public Views $projectSelectedViews; + + public function __construct(public ProjectList $projectList, public TaskList $taskList, private NoProjectSelectedTaskList $noProjectSelectedTaskList) { parent::__construct(); - $this->taskList = new TaskList(); + $this->style = "flex flex-row bg-slate-200"; + $this->noProjectSelectedViews = new Views([ + $this->projectList, + $this->noProjectSelectedTaskList + ]); + $this->projectSelectedViews = new Views([ + $this->projectList, + $this->taskList, + ]); + } public function getViews(): ?Views { - return new Views([ - $this->projectList, - $this->taskList, - ]); + if($this->projectList->selectedProject) { + $this->taskList->setProject($this->projectList->selectedProject); + return $this->projectSelectedViews; + }else{ + return $this->noProjectSelectedViews; + } + } } \ No newline at end of file diff --git a/app/Components/NoProjectSelectedTaskList.php b/app/Components/NoProjectSelectedTaskList.php new file mode 100644 index 0000000..ae69089 --- /dev/null +++ b/app/Components/NoProjectSelectedTaskList.php @@ -0,0 +1,27 @@ +style = "flex-1 bg-red-200"; + $this->headline = new Text(text: 'Please select Project', style: 'w-full text-4xl bg-lime-400 m-10 p-10 text-black'); + } + + public function getViews(): ?Views + { + return new Views([ + $this->headline + ]); + } +} \ No newline at end of file diff --git a/app/Components/ProjectList.php b/app/Components/ProjectList.php index ea033cd..11b4761 100644 --- a/app/Components/ProjectList.php +++ b/app/Components/ProjectList.php @@ -8,6 +8,7 @@ use App\Windows\AddProject; use App\Windows\MainWindow; use PHPNative\Framework\Lifecycle\Lifecycle; use PHPNative\Framework\Parallel\Worker; +use PHPNative\Renderer\Widgets\Button; use PHPNative\Storage\Storage; use PHPNative\UI\Collection\Views; use PHPNative\UI\Widget\Container; @@ -20,14 +21,18 @@ class ProjectList extends Container public ProjectListData $listData; + public ?Project $selectedProject = null; + private Text $headLine; + 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->style = 'flex-none w-100 bg-yellow-400 flex flex-col'; $this->createButton = new CreateButton("create Project"); $this->createButton->setOnClick(fn(Worker $worker) => $this->addProject($worker)); $this->listData = new ProjectListData(); + $this->headLine = new Text(text: 'Projects:', style: 'ml-10 mb-10 text-3xl'); $this->loadProjects(); } @@ -37,12 +42,18 @@ class ProjectList extends Container /** @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')); + $button = new \PHPNative\UI\Widget\Button(views: new Views([ + new Text(text: $project->title, style: 'w-full p-2 text-2xl pl-10 hover:bg-slate-300')] + )); + $button->setOnClick(function() use ($project) { + $this->selectedProject = $project; + }); + $this->listData->views->add($button); } } private function addProject(Worker $worker): void { - $this->lifecycle->show(window: $this->container->get(AddProject::class), onClose: function() { + $this->lifecycle->show(AddProject::class, onClose: function() { $this->loadProjects(); }); } @@ -92,7 +103,7 @@ class ProjectList extends Container { return new Views([ $this->createButton, - new Text(text: 'Projects:', style: 'ml-10 w-full text-xl'), + $this->headLine, $this->listData ]); } diff --git a/app/Components/ProjectListData.php b/app/Components/ProjectListData.php index 84e3291..0a8c05f 100644 --- a/app/Components/ProjectListData.php +++ b/app/Components/ProjectListData.php @@ -10,16 +10,10 @@ use PHPNative\UI\Widget\Text; class ProjectListData extends Container { - public Views $views; public function __construct() { parent::__construct(); - $this->style = 'flex flex-col overflow-auto'; $this->views = new Views(); - } - - public function getViews(): ?Views - { - return $this->views; + $this->style = 'flex flex-col overflow-auto'; } } \ No newline at end of file diff --git a/app/Components/TaskList.php b/app/Components/TaskList.php index c1a32f4..b528944 100644 --- a/app/Components/TaskList.php +++ b/app/Components/TaskList.php @@ -2,6 +2,10 @@ namespace App\Components; +use App\Model\DB; +use App\Model\Project; +use PHPNative\Framework\Lifecycle\Lifecycle; +use PHPNative\Storage\Storage; use PHPNative\UI\Collection\Views; use PHPNative\UI\View; use PHPNative\UI\Widget\Container; @@ -9,15 +13,49 @@ use PHPNative\UI\Widget\Text; class TaskList extends Container { - public function __construct() + private ?Project $project = null; + public CreateNewTask $createNewTask; + + public TaskListData $listData; + private Text $headline; + + public function __construct(private Lifecycle $lifecycle, private \PHPNative\Container\Container $container) { $this->style = "basis-4/6 h-full flex flex-col"; + $this->createNewTask = new CreateNewTask(); + $this->listData = new TaskListData(); + $this->headline = new Text(text:'', style: 'w-full bg-lime-200 text-4xl m-10 p-10 text-black'); } public function getViews(): ?Views { return new Views([ - new Text(text: 'Issues', style: 'w-full bg-lime-400 m-10 p-10 text-black') + $this->headline, + $this->createNewTask, + $this->listData ]); } + + public function setProject(?Project $project): void + { + if($this->project == null || $project->uuid != $this->project->uuid){ + $this->project = $project; + $this->headline->text = sprintf('Issues for Project "%s"', $this->project->title); + $this->loadTasks(); + } + } + + public function loadTasks() + { + $this->listData->views->clear(); + /** @var DB $db */ + $db = $this->container->get(Storage::class)->loadModel(DB::class); + foreach($db->getTasksForProject($this->project) as $task) { + $button = new \PHPNative\UI\Widget\Button(views: new Views([ + new Text(text: $task->title, style: 'w-full text-2xl')] + ), style: 'bg-slate-200 rounded-xl p-5 m-5'); + + $this->listData->views->add($button); + } + } } \ No newline at end of file diff --git a/app/Components/TaskListData.php b/app/Components/TaskListData.php new file mode 100644 index 0000000..93696fc --- /dev/null +++ b/app/Components/TaskListData.php @@ -0,0 +1,23 @@ +style = 'flex flex-col overflow-auto p-5 m-10 bg-white'; + $this->views = new Views(); + } + + public function getViews(): ?Views + { + return $this->views; + } +} \ No newline at end of file diff --git a/app/Model/DB.php b/app/Model/DB.php index 613a1dd..72bbedf 100644 --- a/app/Model/DB.php +++ b/app/Model/DB.php @@ -6,6 +6,8 @@ class DB { private array $projects = []; + private array $tasks = []; + public function addProject(Project $project): void { $this->projects[] = $project; @@ -15,4 +17,19 @@ class DB { return $this->projects; } + + public function addTask(Task $task): void + { + $this->tasks[] = $task; + } + + public function getTasksForProject(Project $project): array + { + return array_filter($this->tasks, function (Task $task) use ($project) { + if($task->project === $project->uuid) { + return true; + } + return false; + }); + } } \ No newline at end of file diff --git a/app/Model/Task.php b/app/Model/Task.php new file mode 100644 index 0000000..6be91ac --- /dev/null +++ b/app/Model/Task.php @@ -0,0 +1,10 @@ +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'); } @@ -36,11 +33,4 @@ class AddProject extends BaseView implements View ]); } - 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/View/TestLayoutView.php b/app/View/TestLayoutView.php new file mode 100644 index 0000000..1e351ee --- /dev/null +++ b/app/View/TestLayoutView.php @@ -0,0 +1,79 @@ +views = new Views([ + new Text(id: 'first', text: 'First', style: 'flex-none h-70 m-2 p-5 bg-green-200'), + new Container(id: 'vertical', style: 'flex-1 flex flex-col overflow-auto border border-black bg-sky-400', views: new Views([ + new Text(id:'third', text: 'third', style: 'p-10 bg-green-200'), + new Text(id:'four', text: 'four', style: 'p-10 border border-black bg-slate-200'), + new Text(id:'five', text: 'five', style: 'p-10 border border-black bg-slate-200'), + new Text(id:'six', text: 'six', style: 'p-10 border border-black bg-slate-200'), + new Text(id:'seven', text: 'seven', style: 'p-10 border border-black bg-slate-200'), + ])), + new Text(id: 'secound', text: 'Second', style: 'flex-none h-70 m-10 p-10 border border-black bg-slate-200'), + ]); +*/ + + $this->views = new Views([ + new Container(style: 'h-100 flex-none bg-slate-400 w-full'), + new Container(style: 'flex-1 bg-white w-full', views: new Views([ + new Container(style: 'flex-none w-100 bg-red-100 m-20'), + new Container(style: 'flex-1 bg-red-200 flex flex-col', views: new Views([ + new Text(id: 'first', text: 'First', style: 'm-2 p-5 bg-green-200'), + new Text(id: 'second', text: 'Second', style: 'm-10 p-10 border border-black bg-slate-200'), + new Container(id: 'vertical', style: 'flex flex-col overflow-auto border border-black', views: new Views([ + new Text(id:'third', text: 'third', style: 'p-5 bg-green-200'), + new Text(id:'four', text: 'four', style: 'p-10 border border-black bg-slate-200'), + new Text(id:'five', text: 'five', style: 'p-10 border border-black bg-slate-200'), + new Text(id:'six', text: 'six', style: 'm-10 p-10 border border-black bg-slate-200'), + new Text(id:'seven', text: 'seven', style: 'm-10 p-10 border border-black bg-slate-200'), + new Text(id:'eight', text: 'eight', style: 'm-10 p-10 border border-black bg-slate-200'), + ])) + ])), + new Container(style: 'flex-1 bg-red-300 flex flex-row'), + new Container(style: 'flex-none w-100 bg-red-400'), + ])), + new Container(style: 'flex-1 bg-sky-600 w-full m-5'), + new Container(style: 'h-50 flex-none bg-lime-400 w-full'), + ]); +/* + $this->views = new Views([ + new Container(style: 'flex flex-row bg-white w-full', views: new Views([ + new Container(style: 'flex-none w-100 bg-red-100 m-20'), + new Container(style: 'flex-1 bg-lime-200 flex-row', views: new Views([ + new Text(text: 'First', style: 'flex-none w-100 bg-green-200'), + new Text(text: 'Second', style: 'flex-1 border border-black bg-slate-200'), + ])), + new Container(style: 'flex-1 bg-red-300 flex flex-row', views: new Views([ + new Text(text: 'First', style: 'flex-none w-200 bg-green-200'), + new Text(text: 'Second', style: 'flex-1 m-10 border border-black bg-slate-200'), + ])), + new Container(style: 'flex-none w-100 bg-red-400'), + ])) + ]);*/ +/* + $this->views = new Views([ + new Container(style: 'h-100 flex-none bg-slate-400 w-full'), + new Container(style: 'flex-1 bg-sky-300 w-full'), + new Container(style: 'flex-1 bg-sky-600 w-full m-5'), + new Container(style: 'h-50 flex-none bg-lime-400 w-full'), + ]);*/ + } + +} \ No newline at end of file diff --git a/app/View/WindowView.php b/app/View/WindowView.php index 3e35574..574cea1 100644 --- a/app/View/WindowView.php +++ b/app/View/WindowView.php @@ -9,15 +9,11 @@ use PHPNative\UI\View; class WindowView extends BaseView implements View { - public string $style = "bg-white w-full h-full flex flex-col"; + public string $style = "bg-green-200 w-full h-full"; - public function __construct(private MainLayout $mainLayout) + public function __construct(public MainLayout $mainLayout) { - } - - public function getViews(): ?Views - { - return new Views([$this->mainLayout]); + $this->views = new Views([$this->mainLayout]); } } \ No newline at end of file diff --git a/app/Windows/AddProject.php b/app/Windows/AddProject.php index 356a368..3be9a31 100644 --- a/app/Windows/AddProject.php +++ b/app/Windows/AddProject.php @@ -2,15 +2,20 @@ namespace App\Windows; -use App\View\WindowView; -use PHPNative\Framework\Application\Window; +use App\Model\DB; +use App\Model\Project; +use PHPNative\Framework\Lifecycle\Lifecycle; +use PHPNative\Renderer\Thread; +use PHPNative\Storage\Storage; use PHPNative\UI\View; +use PHPNative\UI\Window; -class AddProject implements Window +class AddProject extends Window { - public function __construct(public \App\View\AddProject $windowView) + public function __construct(public Storage $storage, public \App\View\AddProject $windowView, private Lifecycle $lifecycle, private Thread $thread) { + $this->windowView->saveButton->setOnClick(fn() => $this->saveProject()); } public function getTitle(): string @@ -22,4 +27,12 @@ class AddProject implements Window { return $this->windowView; } + + private function saveProject() + { + $db = $this->storage->loadModel(DB::class); + $db->addProject(new Project(uniqid(), $this->windowView->editText->value)); + $this->storage->saveModel($db); + $this->lifecycle->closeWindow($this->thread->windowId); + } } \ No newline at end of file diff --git a/app/Windows/MainWindow.php b/app/Windows/MainWindow.php index 12be7e8..8a37e79 100644 --- a/app/Windows/MainWindow.php +++ b/app/Windows/MainWindow.php @@ -2,15 +2,20 @@ namespace App\Windows; +use App\Model\DB; +use App\Model\Project; +use App\Model\Task; use App\View\WindowView; -use PHPNative\Framework\Application\Window; +use PHPNative\Storage\Storage; use PHPNative\UI\View; +use PHPNative\UI\Window; -class MainWindow implements Window +class MainWindow extends Window { - public function __construct(public WindowView $windowView) + public function __construct(private Storage $storage, public WindowView $windowView) { + $this->windowView->mainLayout->taskList->createNewTask->saveButton->setOnClick(fn() => $this->saveTask()); } public function getTitle(): string @@ -22,4 +27,12 @@ class MainWindow implements Window { return $this->windowView; } + + public function saveTask(): void + { + $db = $this->storage->loadModel(DB::class); + $db->addTask(new Task(uniqid(), $this->windowView->mainLayout->taskList->createNewTask->textEdit->value, $this->windowView->mainLayout->projectList->selectedProject->uuid)); + $this->storage->saveModel($db); + $this->windowView->mainLayout->taskList->loadTasks(); + } } \ No newline at end of file diff --git a/app/Windows/TestLayoutWindow.php b/app/Windows/TestLayoutWindow.php new file mode 100644 index 0000000..931dddc --- /dev/null +++ b/app/Windows/TestLayoutWindow.php @@ -0,0 +1,25 @@ +windowView; + } +} \ No newline at end of file