This commit is contained in:
Patrick Niebeling
2025-03-12 11:19:44 +01:00
parent 7f683fcec1
commit 9538c99576
15 changed files with 122 additions and 242 deletions

9
appinfo.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<appinfo>
<id>deckflow</id>
<name>Deckflow</name>
<description>Automatische Workflows für Nextcloud Decks</description>
<version>1.0.0</version>
<author>Dein Name</author>
<license>GPL-3.0</license>
</appinfo>

View File

@ -1,22 +0,0 @@
<?php
namespace OCA\Deckflow\AppInfo;
use OCP\AppFramework\App;
use OCA\Deckflow\Controller\SettingsController;
class Application extends App {
public function __construct() {
parent::__construct('deckflow');
}
public function register() {
$this->getContainer()->registerService('SettingsController', function($c) {
return new SettingsController(
$c->query('OCP\IRequest'),
$c->query('OCP\IUserSession'),
$c->query('OCA\Deckflow\Service\WorkflowService')
);
});
}
}

View File

@ -1,20 +0,0 @@
<?php
use OCP\AppFramework\Router;
use OCP\IContainer;
$container->registerService('SettingsController', function(IContainer $c) {
return new \OCA\Deckflow\Controller\SettingsController(
$c->query('OCP\IRequest'),
$c->query('OCP\IUserSession'),
$c->query('OCA\Deckflow\Service\WorkflowService')
);
});
// Hier wird die Route für den Webhook definiert
$container->registerService('WebhookController', function(IContainer $c) {
return new \OCA\Deckflow\Controller\WebhookController(
$c->query('OCP\IRequest'),
$c->query('OCA\Deckflow\Service\WorkflowService')
);
});

View File

@ -1,24 +0,0 @@
document.getElementById('addWorkflow').addEventListener('click', function() {
let workflowContainer = document.getElementById('workflows');
let newWorkflow = document.createElement('div');
newWorkflow.classList.add('workflow');
newWorkflow.innerHTML = `
<label for="deckId">Wählen Sie das Deck:</label>
<select name="deckId[]" id="deckId">
<!-- Liste der Decks des Users -->
</select>
<label for="sourceStack">Wählen Sie den Quellstapel:</label>
<select name="sourceStack[]" id="sourceStack">
<!-- Quellstapel -->
</select>
<label for="targetStack">Wählen Sie den Zielstapel:</label>
<select name="targetStack[]" id="targetStack">
<!-- Zielstapel -->
</select>
`;
workflowContainer.appendChild(newWorkflow);
});

View File

@ -1,15 +1,22 @@
{
"name": "deckflow",
"description": "Automatisierung von Deck Workflows mit Flow",
"name": "deckflow/deckflow",
"description": "Automatische Workflows für Nextcloud Decks",
"type": "nextcloud-app",
"version": "1.0.0",
"license": "GPL-3.0",
"authors": [
{
"name": "Dein Name",
"email": "deine@email.de"
}
],
"require": {
"php": ">=7.2",
"nextcloud/server": "^23.0"
"php": "^7.2",
"nextcloud/app-framework": "^1.0"
},
"autoload": {
"psr-4": {
"OCA\\Deckflow\\": "lib/"
"Deckflow\\": "src/"
}
}
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace OCA\Deckflow\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\Deckflow\Service\WorkflowService;
class SettingsController extends Controller {
private $workflowService;
public function __construct(IRequest $request, IUserSession $userSession, WorkflowService $workflowService) {
parent::__construct('deckflow', $request);
$this->workflowService = $workflowService;
}
public function showSettingsForm() {
$workflows = $this->workflowService->getWorkflows();
return $this->render('settings.php', [
'workflows' => $workflows
]);
}
public function saveWorkflows() {
$deckId = $_POST['deckId'];
$sourceStackId = $_POST['sourceStack'];
$targetStackId = $_POST['targetStack'];
$this->workflowService->saveWorkflows($deckId, $sourceStackId, $targetStackId);
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace OCA\Deckflow\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCA\Deckflow\Service\WorkflowService;
class WebhookController extends Controller {
private $workflowService;
public function __construct(IRequest $request, WorkflowService $workflowService) {
parent::__construct('deckflow', $request);
$this->workflowService = $workflowService;
}
public function moveCards() {
$deckId = $_POST['deckId'];
$sourceStackId = $_POST['sourceStackId'];
$targetStackId = $_POST['targetStackId'];
$this->workflowService->moveOverdueCards($deckId, $sourceStackId, $targetStackId);
}
}

View File

@ -1,11 +0,0 @@
<?php
// Beispiel Cronjob zum Überprüfen der Workflows
require_once('path/to/autoload.php');
use OCA\Deckflow\Service\WorkflowService;
$workflowService = new WorkflowService($db, $userSession, $deckService);
$workflows = $workflowService->getWorkflows();
foreach ($workflows as $workflow) {
$workflowService->moveOverdueCards($workflow['deck_id'], $workflow['source_stack_id'], $workflow['target_stack_id']);
}

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://nextcloud.org/ns/nextcloud">
<table name="deckflow_workflows">
<column name="id" type="integer" unsigned="true" notnull="true" primarykey="true" autoincrement="true" />
<column name="user_id" type="string" length="255" notnull="true" />
<column name="deck_id" type="integer" unsigned="true" notnull="true" />
<column name="source_stack_id" type="integer" unsigned="true" notnull="true" />
<column name="target_stack_id" type="integer" unsigned="true" notnull="true" />
<column name="created_at" type="timestamp" notnull="true" default="CURRENT_TIMESTAMP" />
</table>
</schema>

View File

@ -1,61 +0,0 @@
<?php
namespace OCA\Deckflow\Service;
use OCP\IDBConnection;
use OCP\IUserSession;
use OCA\Deck\Service\DeckService;
class WorkflowService {
private $db;
private $userSession;
private $deckService;
public function __construct(IDBConnection $db, IUserSession $userSession, DeckService $deckService) {
$this->db = $db;
$this->userSession = $userSession;
$this->deckService = $deckService;
}
// Speichert die Workflows
public function saveWorkflows($deckId, $sourceStackId, $targetStackId) {
$userId = $this->userSession->getUser()->getUID();
$this->db->executeQuery("INSERT INTO *PREFIX*deckflow_workflows (user_id, deck_id, source_stack_id, target_stack_id)
VALUES (?, ?, ?, ?)", [
$userId,
$deckId,
$sourceStackId,
$targetStackId
]);
}
// Ruft alle Workflows für den aktuellen Benutzer ab
public function getWorkflows() {
$userId = $this->userSession->getUser()->getUID();
$result = $this->db->executeQuery("SELECT * FROM *PREFIX*deckflow_workflows WHERE user_id = ?", [$userId]);
return $result->fetchAll();
}
// Webhook zur Ausführung des Workflows, Karten zu verschieben
public function moveOverdueCards($deckId, $sourceStackId, $targetStackId) {
$deck = $this->deckService->getDeckById($deckId);
$sourceStack = $deck->getStackById($sourceStackId);
$targetStack = $deck->getStackById($targetStackId);
foreach ($sourceStack->getCards() as $card) {
if ($this->isCardOverdue($card)) {
$this->moveCardToTargetStack($card, $targetStack);
}
}
}
private function isCardOverdue($card) {
$dueDate = $card->getDueDate();
return $dueDate && $dueDate < time();
}
private function moveCardToTargetStack($card, $targetStack) {
$this->deckService->moveCardToStack($card, $targetStack);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Deckflow\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
class WorkflowJob extends TimedJob
{
private $workflowMapper;
public function __construct(ITimeFactory $timeFactory, WorkflowMapper $workflowMapper)
{
parent::__construct($timeFactory);
$this->workflowMapper = $workflowMapper;
}
protected function run($argument)
{
// Hier kommt die Logik für das Ausführen des Workflows hin
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Deckflow\Controller;
use OCP\IRequest;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
class DeckflowController extends Controller
{
private $request;
public function __construct(IRequest $request)
{
$this->request = $request;
}
public function index()
{
return new TemplateResponse('deckflow', 'index');
}
public function createWorkflow()
{
// Hier kommt die Logik für das Erstellen eines Workflows hin
}
public function editWorkflow()
{
// Hier kommt die Logik für das Bearbeiten eines Workflows hin
}
}

20
src/Db/WorkflowMapper.php Normal file
View File

@ -0,0 +1,20 @@
?php
namespace Deckflow\Db;
use OCP\AppFramework\Db\Mapper;
use Deckflow\Model\Workflow;
class WorkflowMapper extends Mapper
{
public function __construct(\OCP\IDBConnection $db)
{
parent::__construct($db, 'deckflow_workflows', Workflow::class);
}
public function findWorkflowsByUserId($userId)
{
$sql = 'SELECT * FROM deckflow_workflows WHERE user_id = ?';
return $this->findEntities($sql, [$userId]);
}
}

25
src/Model/Workflow.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace Deckflow\Model;
use OCP\AppFramework\Db\Entity;
class Workflow extends Entity
{
protected $id;
protected $userId;
protected $deckId;
protected $sourceStackId;
protected $targetStackId;
protected $createdAt;
public function __construct()
{
$this->addType('id', 'integer');
$this->addType('userId', 'string');
$this->addType('deckId', 'integer');
$this->addType('sourceStackId', 'integer');
$this->addType('targetStackId', 'integer');
$this->addType('createdAt', 'timestamp');
}
}

View File

@ -1,28 +0,0 @@
<h1>Deckflow Einstellungen</h1>
<form method="post" action="/settings/deckflow/save">
<div id="workflows">
<?php foreach ($workflows as $workflow): ?>
<div class="workflow">
<label for="deckId">Deck:</label>
<select name="deckId[]" id="deckId">
<!-- Hier Decks des Benutzers dynamisch laden -->
</select>
<label for="sourceStack">Quellstapel:</label>
<select name="sourceStack[]" id="sourceStack">
<!-- Quellstapel dynamisch laden -->
</select>
<label for="targetStack">Zielstapel:</label>
<select name="targetStack[]" id="targetStack">
<!-- Zielstapel dynamisch laden -->
</select>
</div>
<?php endforeach; ?>
</div>
<button type="button" id="addWorkflow">Weitere Kombination hinzufügen</button>
<button type="submit">Speichern</button>
</form>
<script src="/apps/deckflow/assets/js/addWorkflow.js"></script>