Backup
This commit is contained in:
parent
05a7f719dd
commit
beba8beac1
@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
]);
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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')
|
||||
]);
|
||||
}
|
||||
}
|
||||
18
app/Model/DB.php
Normal file
18
app/Model/DB.php
Normal 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
46
app/View/AddProject.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Components;
|
||||
namespace App\View;
|
||||
|
||||
use App\Components\MainLayout;
|
||||
use PHPNative\UI\BaseView;
|
||||
use PHPNative\UI\Collection\Views;
|
||||
use PHPNative\UI\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()
|
||||
public function __construct(private MainLayout $mainLayout)
|
||||
{
|
||||
$this->mainLayout = new MainLayout();
|
||||
}
|
||||
|
||||
public function getViews(): ?Views
|
||||
25
app/Windows/AddProject.php
Normal file
25
app/Windows/AddProject.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user