-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 429368a
Showing
19 changed files
with
1,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Api\Data; | ||
|
||
interface TodoInterface | ||
{ | ||
|
||
const TASK = 'task'; | ||
const TODO_ID = 'todo_id'; | ||
|
||
/** | ||
* Get todo_id | ||
* @return string|null | ||
*/ | ||
public function getTodoId(); | ||
|
||
/** | ||
* Set todo_id | ||
* @param string $todoId | ||
* @return \Jajuma\PotTodo\Todo\Api\Data\TodoInterface | ||
*/ | ||
public function setTodoId($todoId); | ||
|
||
/** | ||
* Get task | ||
* @return string|null | ||
*/ | ||
public function getTask(); | ||
|
||
/** | ||
* Set task | ||
* @param string $task | ||
* @return \Jajuma\PotTodo\Todo\Api\Data\TodoInterface | ||
*/ | ||
public function setTask($task); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Api\Data; | ||
|
||
interface TodoSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface | ||
{ | ||
|
||
/** | ||
* Get Todo list. | ||
* @return \Jajuma\PotTodo\Api\Data\TodoInterface[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* Set task list. | ||
* @param \Jajuma\PotTodo\Api\Data\TodoInterface[] $items | ||
* @return $this | ||
*/ | ||
public function setItems(array $items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Api; | ||
|
||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
|
||
interface TodoRepositoryInterface | ||
{ | ||
|
||
/** | ||
* Save Todo | ||
* @param \Jajuma\PotTodo\Api\Data\TodoInterface $todo | ||
* @return \Jajuma\PotTodo\Api\Data\TodoInterface | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function save( | ||
\Jajuma\PotTodo\Api\Data\TodoInterface $todo | ||
); | ||
|
||
/** | ||
* Retrieve Todo | ||
* @param string $todoId | ||
* @return \Jajuma\PotTodo\Api\Data\TodoInterface | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function get($todoId); | ||
|
||
/** | ||
* Retrieve Todo matching the specified criteria. | ||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
* @return \Jajuma\PotTodo\Api\Data\TodoSearchResultsInterface | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function getList( | ||
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
); | ||
|
||
/** | ||
* Delete Todo | ||
* @param \Jajuma\PotTodo\Api\Data\TodoInterface $todo | ||
* @return bool true on success | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function delete( | ||
\Jajuma\PotTodo\Api\Data\TodoInterface $todo | ||
); | ||
|
||
/** | ||
* Delete Todo by ID | ||
* @param string $todoId | ||
* @return bool true on success | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function deleteById($todoId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Block\PowerToys; | ||
|
||
use Jajuma\PowerToys\Block\PowerToys\QuickAction; | ||
|
||
class Todo extends QuickAction | ||
{ | ||
const XML_PATH_ENABLE = 'power_toys/pot_todo/is_enabled'; | ||
|
||
public function isEnable(): bool | ||
{ | ||
return $this->_scopeConfig->isSetFlag(self::XML_PATH_ENABLE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 JaJuMa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
namespace Jajuma\PotTodo\Magewire; | ||
|
||
use Magewirephp\Magewire\Component; | ||
use Magewirephp\Magewire\Model\Element\FlashMessage; | ||
use Jajuma\PotTodo\Model\TodoFactory; | ||
use Rakit\Validation\Validator; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Jajuma\PotTodo\Model\ResourceModel\Todo\CollectionFactory as TodoCollectionFactory; | ||
|
||
class Todo extends \Magewirephp\Magewire\Component\Form | ||
{ | ||
public $task = ''; | ||
|
||
public $tasks = []; | ||
|
||
public $messageTodo = ''; | ||
|
||
public $rules = [ | ||
'task' => 'required' | ||
]; | ||
|
||
protected $messages = [ | ||
'task:required' => 'The "Task" property can\'t be empty', | ||
]; | ||
|
||
protected $todoFactory; | ||
|
||
protected $resourceConnection; | ||
|
||
private $todoCollectionFactory; | ||
|
||
public function __construct( | ||
TodoFactory $todoFactory, | ||
ResourceConnection $resourceConnection, | ||
TodoCollectionFactory $todoCollectionFactory, | ||
Validator $validator | ||
) { | ||
$this->todoFactory = $todoFactory; | ||
$this->todoCollectionFactory = $todoCollectionFactory; | ||
$this->resourceConnection = $resourceConnection; | ||
parent::__construct($validator); | ||
} | ||
|
||
public function mount(): void | ||
{ | ||
$this->fetchTasks(); | ||
parent::mount(); | ||
} | ||
|
||
private function fetchTasks() | ||
{ | ||
$todoCollection = $this->getTaskCollection()->getItems(); | ||
$this->tasks = []; | ||
foreach ($todoCollection as $item) { | ||
$this->tasks[] = $item->getData(); | ||
} | ||
} | ||
|
||
public function saveTask(string $title = null) | ||
{ | ||
//validate data | ||
try { | ||
$this->validate(); | ||
} catch (\Magewirephp\Magewire\Exception\ValidationException $exception) { | ||
foreach ($this->getErrors() as $error) { | ||
$this->dispatchErrorMessage($error); | ||
} | ||
} | ||
$todoModel = $this->todoFactory->create(); | ||
$data = [ | ||
'task' => $this->task | ||
]; | ||
$todoModel->setData($data); | ||
$todoModel->save(); | ||
$this->messageTodo = 'Task has been saved successfully.'; | ||
// Always empty it's current input title. | ||
$this->task = ''; | ||
$this->fetchTasks(); | ||
} | ||
|
||
public function removeTask($taskId) | ||
{ | ||
$todoModel = $this->todoFactory->create(); | ||
$todoModel = $todoModel->load($taskId); | ||
$todoModel->delete(); | ||
$this->messageTodo = 'Task has been removed successfully.'; | ||
$this->fetchTasks(); | ||
} | ||
|
||
public function removeAllTask() | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$table = $connection->getTableName('jajuma_powertoys_todo'); | ||
$query = "DELETE FROM " . $table; | ||
$connection->query($query); | ||
$this->messageTodo = 'All task has been removed successfully.'; | ||
$this->tasks = []; | ||
} | ||
|
||
private function getTaskCollection() | ||
{ | ||
$todoCollectionFactory = $this->todoCollectionFactory->create(); | ||
return $todoCollectionFactory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Model\ResourceModel; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
class Todo extends AbstractDb | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init('jajuma_powertoys_todo', 'todo_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* @author JaJuMa GmbH <info@jajuma.de> | ||
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved. | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Jajuma\PotTodo\Model\ResourceModel\Todo; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; | ||
|
||
class Collection extends AbstractCollection | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected $_idFieldName = 'todo_id'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init( | ||
\Jajuma\PotTodo\Model\Todo::class, | ||
\Jajuma\PotTodo\Model\ResourceModel\Todo::class | ||
); | ||
} | ||
} |
Oops, something went wrong.