This commit is contained in:
Thomas Peterson 2024-10-13 21:39:35 +02:00
parent beba8beac1
commit fbd61a05d0
17 changed files with 341 additions and 49 deletions

View File

@ -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;
}
}

View File

@ -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,
]);
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Components;
use PHPNative\Tailwind\Data\Icon;
use PHPNative\UI\Collection\Views;
use PHPNative\UI\Widget\Button;
use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Text;
use PHPNative\UI\Widget\TextEdit;
class CreateNewTask extends Container
{
public Button $saveButton;
public TextEdit $textEdit;
public function __construct()
{
$this->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,
]);
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Components;
use App\Model\Project;
use PHPNative\UI\Collection\Views;
use PHPNative\UI\View;
use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Text;
class NoProjectSelectedTaskList extends Container
{
private Text $headline;
public function __construct()
{
$this->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
]);
}
}

View File

@ -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
]);
}

View File

@ -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';
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Components;
use PHPNative\Framework\Parallel\Worker;
use PHPNative\UI\Collection\Views;
use PHPNative\UI\Widget\Container;
use PHPNative\UI\Widget\Text;
class TaskListData extends Container
{
public function __construct()
{
parent::__construct();
$this->style = 'flex flex-col overflow-auto p-5 m-10 bg-white';
$this->views = new Views();
}
public function getViews(): ?Views
{
return $this->views;
}
}

View File

@ -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;
});
}
}

10
app/Model/Task.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App\Model;
class Task
{
public function __construct(public string $uuid = "", public string $title = "", public string $project = "")
{
}
}

View File

@ -1,8 +1,6 @@
<?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;
@ -23,7 +21,6 @@ class AddProject extends BaseView implements View
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');
}
@ -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);
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace App\View;
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\Container;
use PHPNative\UI\Widget\Text;
use PHPNative\UI\Widget\TextEdit;
class TestLayoutView extends BaseView implements View
{
public string $style = "bg-lime-100 h-full p-10 m-20 border border-red-600 w-full flex flex-col";
public function __construct()
{
/*
$this->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'),
]);*/
}
}

View File

@ -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]);
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Windows;
use App\View\TestLayoutView;
use PHPNative\UI\View;
use PHPNative\UI\Window;
class TestLayoutWindow extends Window
{
public function __construct(public TestLayoutView $windowView)
{
}
public function getTitle(): string
{
return "Test LayoutWindow";
}
public function getView(): ?View
{
return $this->windowView;
}
}