Skip to content

Commit

Permalink
NC 18 Workflow integration #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Rello committed Jan 6, 2020
1 parent 9e34766 commit 4ce6d3d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
4 changes: 4 additions & 0 deletions js/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.OCA.WorkflowEngine.registerOperator({
id: 'OCA\\Analytics\\Flow\\Operation',
color: 'var(--color-success)',
});
17 changes: 15 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@

namespace OCA\Analytics\AppInfo;

use OCA\Analytics\Flow\Operation;
use OCA\Analytics\Notification\Notifier;
use OCP\AppFramework\App;
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\IEventDispatcher;


class Application extends App {
class Application extends App
{

public function __construct(array $urlParams = array()) {
public function __construct(array $urlParams = array())
{

parent::__construct('analytics', $urlParams);
$this->register();
Expand All @@ -27,6 +32,14 @@ public function register()
{
$this->registerNotificationNotifier();
//$this->registerCommentsEntity();

$server = $this->getContainer()->getServer();
/** @var IEventDispatcher $dispatcher */
try {
$dispatcher = $server->query(IEventDispatcher::class);
} catch (QueryException $e) {
}
Operation::register($dispatcher);
}

protected function registerNotificationNotifier()
Expand Down
84 changes: 84 additions & 0 deletions lib/Flow/Operation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
/**
* Data Analytics
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the LICENSE.md file.
*
* @author Marcel Scherello <audioplayer@scherello.de>
* @copyright 2019 Marcel Scherello
*/

namespace OCA\Analytics\Flow;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\Util;
use OCP\WorkflowEngine\EntityContext\IDisplayText;
use OCP\WorkflowEngine\EntityContext\IUrl;
use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IManager as FlowManager;
use OCP\WorkflowEngine\IOperation;
use OCP\WorkflowEngine\IRuleMatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use UnexpectedValueException;

class Operation implements IOperation
{

private $logger;

public function __construct(
ILogger $logger
)
{
$this->logger = $logger;
}

public static function register(IEventDispatcher $dispatcher): void
{
$dispatcher->addListener(FlowManager::EVENT_NAME_REG_OPERATION, function (GenericEvent $event) {
$operation = \OC::$server->query(Operation::class);
$event->getSubject()->registerOperation($operation);
Util::addScript('analytics', 'flow');
});
}

public function getDisplayName(): string
{
return $this->l->t('Write to Analytics');
}

public function getDescription(): string
{
return $this->l->t('Writes data to report');
}

public function getIcon(): string
{
return $this->urlGenerator->imagePath('analytics', 'app.svg');
}

public function isAvailableForScope(int $scope): bool
{
return true;
}

/**
* Validates whether a configured workflow rule is valid. If it is not,
* an `\UnexpectedValueException` is supposed to be thrown.
*
* @throws UnexpectedValueException
* @since 9.1
*/
public function validateOperation($name, array $checks, $operation): void
{
}

public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void
{
$this->logger->debug("Test Flow Operation");
}
}

0 comments on commit 4ce6d3d

Please sign in to comment.