also adds admin settings that pass entities as initial state Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>pull/16682/head
parent
9a6f7cc8cb
commit
804d4fe69f
@ -0,0 +1,68 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\WorkflowEngine\Entity; |
||||
|
||||
use OCP\Files\IRootFolder; |
||||
use OCP\IL10N; |
||||
use OCP\IURLGenerator; |
||||
use OCP\WorkflowEngine\IEntity; |
||||
|
||||
class File implements IEntity { |
||||
|
||||
/** @var IL10N */ |
||||
protected $l10n; |
||||
/** @var IURLGenerator */ |
||||
protected $urlGenerator; |
||||
|
||||
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) { |
||||
$this->l10n = $l10n; |
||||
$this->urlGenerator = $urlGenerator; |
||||
} |
||||
|
||||
public function getId(): string { |
||||
return 'WorkflowEngine_Entity_File'; |
||||
} |
||||
|
||||
public function getName(): string { |
||||
return $this->l10n->t('File'); |
||||
} |
||||
|
||||
public function getIcon(): string { |
||||
return $this->urlGenerator->imagePath('core', 'categories/files.svg'); |
||||
} |
||||
|
||||
public function getEvents(): array { |
||||
$emitterClass = IRootFolder::class; |
||||
$slot = '\OC\Files'; |
||||
return [ |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postCreate', $this->l10n->t('File created')), |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postWrite', $this->l10n->t('File updated')), |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postRename', $this->l10n->t('File renamed')), |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postDelete', $this->l10n->t('File deleted')), |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postTouch', $this->l10n->t('File accessed')), |
||||
new GenericEntityEmitterEvent($emitterClass, $slot, 'postCopy', $this->l10n->t('File copied')), |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\WorkflowEngine\Entity; |
||||
|
||||
class GenericEntityEmitterEvent implements IEntityEmitterEvent { |
||||
/** @var string */ |
||||
private $emitterClassName; |
||||
/** @var string */ |
||||
private $eventName; |
||||
/** @var string */ |
||||
private $displayName; |
||||
/** @var string */ |
||||
private $slot; |
||||
|
||||
public function __construct(string $emitterClassName, string $slot, string $eventName, string $displayName) { |
||||
$this->emitterClassName = $emitterClassName; |
||||
$this->eventName = $eventName; |
||||
$this->displayName = $displayName; |
||||
$this->slot = $slot; |
||||
} |
||||
|
||||
public function getEmitterClassName(): string { |
||||
return $this->emitterClassName; |
||||
} |
||||
|
||||
public function getSlot(): string { |
||||
return $this->slot; |
||||
} |
||||
|
||||
public function getDisplayName(): string { |
||||
return $this->displayName; |
||||
} |
||||
|
||||
public function getEventName(): string { |
||||
return $this->eventName; |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\WorkflowEngine\Entity; |
||||
|
||||
|
||||
use OCP\WorkflowEngine\IEntityEvent; |
||||
|
||||
interface IEntityEmitterEvent extends IEntityEvent { |
||||
public function getEmitterClassName(): string; |
||||
|
||||
public function getSlot(): string; |
||||
} |
||||
@ -0,0 +1,126 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\WorkflowEngine\Settings; |
||||
|
||||
use OCA\WorkflowEngine\AppInfo\Application; |
||||
use OCA\WorkflowEngine\Manager; |
||||
use OCP\AppFramework\Http\TemplateResponse; |
||||
use OCP\IInitialStateService; |
||||
use OCP\IL10N; |
||||
use OCP\Settings\ISettings; |
||||
use OCP\WorkflowEngine\IEntity; |
||||
use OCP\WorkflowEngine\IEntityEvent; |
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||||
|
||||
class Admin implements ISettings { |
||||
|
||||
/** @var IL10N */ |
||||
private $l10n; |
||||
|
||||
/** @var string */ |
||||
private $appName; |
||||
|
||||
/** @var EventDispatcherInterface */ |
||||
private $eventDispatcher; |
||||
|
||||
/** @var Manager */ |
||||
private $manager; |
||||
|
||||
/** @var IInitialStateService */ |
||||
private $initialStateService; |
||||
|
||||
/** |
||||
* @param string $appName |
||||
* @param IL10N $l |
||||
* @param EventDispatcherInterface $eventDispatcher |
||||
*/ |
||||
public function __construct( |
||||
$appName, |
||||
IL10N $l, |
||||
EventDispatcherInterface $eventDispatcher, |
||||
Manager $manager, |
||||
IInitialStateService $initialStateService |
||||
) { |
||||
$this->appName = $appName; |
||||
$this->l10n = $l; |
||||
$this->eventDispatcher = $eventDispatcher; |
||||
$this->manager = $manager; |
||||
$this->initialStateService = $initialStateService; |
||||
} |
||||
|
||||
/** |
||||
* @return TemplateResponse |
||||
*/ |
||||
public function getForm() { |
||||
$this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts'); |
||||
|
||||
$entities = $this->manager->getEntitiesList(); |
||||
|
||||
$this->initialStateService->provideInitialState( |
||||
Application::APP_ID, |
||||
'entities', |
||||
$this->entitiesToArray($entities) |
||||
); |
||||
|
||||
return new TemplateResponse(Application::APP_ID, 'admin', [], 'blank'); |
||||
} |
||||
|
||||
/** |
||||
* @return string the section ID, e.g. 'sharing' |
||||
*/ |
||||
public function getSection() { |
||||
return 'workflow'; |
||||
} |
||||
|
||||
/** |
||||
* @return int whether the form should be rather on the top or bottom of |
||||
* the admin section. The forms are arranged in ascending order of the |
||||
* priority values. It is required to return a value between 0 and 100. |
||||
* |
||||
* E.g.: 70 |
||||
*/ |
||||
public function getPriority() { |
||||
return 0; |
||||
} |
||||
|
||||
private function entitiesToArray(array $entities) { |
||||
return array_map(function (IEntity $entity) { |
||||
$events = array_map(function(IEntityEvent $entityEvent) { |
||||
return [ |
||||
'eventName' => $entityEvent->getEventName(), |
||||
'displayName' => $entityEvent->getDisplayName() |
||||
]; |
||||
}, $entity->getEvents()); |
||||
|
||||
return [ |
||||
'id' => $entity->getId(), |
||||
'icon' => $entity->getIcon(), |
||||
'name' => $entity->getName(), |
||||
'events' => $events, |
||||
]; |
||||
}, $entities); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,84 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCP\WorkflowEngine; |
||||
|
||||
/** |
||||
* Interface IEntity |
||||
* |
||||
* This interface represents an entity that supports events the workflow engine |
||||
* can listen to. For example a file with the create, update, etc. events. |
||||
* |
||||
* Ensure to listen to 'OCP/WorkflowEngine::loadEntities' for registering your |
||||
* entities. |
||||
* |
||||
* @package OCP\WorkflowEngine |
||||
* @since 18.0.0 |
||||
*/ |
||||
interface IEntity { |
||||
|
||||
/** |
||||
* returns a unique ID of the entity. |
||||
* |
||||
* It can be, but does not need to be the class name of the entitiy. Beware |
||||
* that it will be referenced in the database when rules are established, |
||||
* so it should not change over the course of the app life. |
||||
* |
||||
* Example 1: "OCA/MyApp/Entity/Cat" |
||||
* Example 2: "myapp_Cats" |
||||
* |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getId(): string; |
||||
|
||||
/** |
||||
* returns a translated name to be presented in the web interface. |
||||
* |
||||
* Example: "File" (en), "Dosiero" (eo) |
||||
* |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getName(): string; |
||||
|
||||
/** |
||||
* returns the URL to the icon of the entity for display in the web interface. |
||||
* |
||||
* Usually, the implementation would utilize the `imagePath()` method of the |
||||
* `\OCP\IURLGenerator` instance and simply return its result. |
||||
* |
||||
* Example implementation: return $this->urlGenerator->imagePath('myApp', 'cat.svg'); |
||||
* |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getIcon(): string; |
||||
|
||||
/** |
||||
* returns a list of supported events |
||||
* |
||||
* @return IEntityEvent[] |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getEvents(): array; |
||||
|
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
/** |
||||
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCP\WorkflowEngine; |
||||
|
||||
/** |
||||
* Interface IEntityEvent |
||||
* |
||||
* represents an entitiy event that is dispatched via EventDispatcher |
||||
* |
||||
* @package OCP\WorkflowEngine |
||||
*/ |
||||
interface IEntityEvent { |
||||
/** |
||||
* returns a translated name to be presented in the web interface. |
||||
* |
||||
* Example: "created" (en), "kreita" (eo) |
||||
* |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getDisplayName(): string; |
||||
|
||||
/** |
||||
* returns the event name that is emitted by the EventDispatcher, e.g.: |
||||
* |
||||
* Example: "OCA\MyApp\Factory\Cats::postCreated" |
||||
* |
||||
* @since 18.0.0 |
||||
*/ |
||||
public function getEventName(): string; |
||||
} |
||||
Loading…
Reference in new issue