Fix
This commit is contained in:
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\DeckFlow\AppInfo;
|
|
||||||
|
|
||||||
use OCP\AppFramework\App;
|
|
||||||
use OCP\BackgroundJob\IJobList;
|
|
||||||
use OCA\DeckFlow\BackgroundJobs\CheckOverdueCards;
|
|
||||||
|
|
||||||
class Application extends App {
|
|
||||||
public function __construct(array $urlParams = []) {
|
|
||||||
parent::__construct('deckflow', $urlParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register() {
|
|
||||||
$container = $this->getContainer();
|
|
||||||
$jobList = $container->query(IJobList::class);
|
|
||||||
$jobList->add(CheckOverdueCards::class);
|
|
||||||
}
|
|
||||||
}
|
|
9
appinfo/cron.php
Normal file
9
appinfo/cron.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
// lib/cron.php
|
||||||
|
|
||||||
|
/** @var \OCP\IContainer $container */
|
||||||
|
$container = require __DIR__ . '/../lib/container.php';
|
||||||
|
$job = $container->query('OCA\Deckflow\Cron\MoveOverdueCardsJob');
|
||||||
|
|
||||||
|
// Führe den Cronjob aus
|
||||||
|
$job->execute();
|
@ -1,9 +1,14 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<info>
|
<ocl:information xmlns:ocl="http://www.nextcloud.org/ns">
|
||||||
<id>deckflow</id>
|
<id>deckflow</id>
|
||||||
<name>Deck Flow</name>
|
<name>Deckflow</name>
|
||||||
<description>Automatisches Verschieben von überfälligen Karten in Nextcloud Deck</description>
|
<summary>Automatisiere Deck-Karten mit Cronjobs und Workflows</summary>
|
||||||
<version>1.0.0</version>
|
<description>Diese App automatisiert die Bewegung von Karten basierend auf Workflows und Überprüfungen von überfälligen Karten.</description>
|
||||||
<namespace>OCA\DeckFlow</namespace>
|
<version>0.1.0</version>
|
||||||
<category>automation</category>
|
<namespace>deckflow</namespace>
|
||||||
</info>
|
<dependencies>
|
||||||
|
<nextcloud>21</nextcloud>
|
||||||
|
<app>workflow</app>
|
||||||
|
<app>deck</app>
|
||||||
|
</dependencies>
|
||||||
|
</ocl:information>
|
||||||
|
31
lib/AppInfo/Application.php
Normal file
31
lib/AppInfo/Application.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\Deckflow\AppInfo;
|
||||||
|
|
||||||
|
use OCP\AppFramework\App;
|
||||||
|
use OCA\Deckflow\Controller\SettingsController;
|
||||||
|
use OCA\Deckflow\Cron\MoveOverdueCardsJob;
|
||||||
|
use OCP\IContainer;
|
||||||
|
|
||||||
|
class Application extends App {
|
||||||
|
|
||||||
|
public function __construct(array $urlParams = []) {
|
||||||
|
parent::__construct('deckflow', $urlParams);
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
// Routen für das Backend
|
||||||
|
$container->registerService('SettingsController', function(IContainer $c) {
|
||||||
|
return new SettingsController(
|
||||||
|
$c->query('OCP\IRequest'),
|
||||||
|
$c->query('OCP\IUserSession'),
|
||||||
|
$c->query('OCA\Deckflow\Service\WorkflowService')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// CronJob registrieren
|
||||||
|
$container->registerService('MoveOverdueCardsJob', function(IContainer $c) {
|
||||||
|
return new MoveOverdueCardsJob(
|
||||||
|
$c->query('OCA\Deckflow\Service\WorkflowService')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
27
lib/Cron/MoveOverdueCardsJob.php
Normal file
27
lib/Cron/MoveOverdueCardsJob.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\Deckflow\Cron;
|
||||||
|
|
||||||
|
use OCP\BackgroundJob\TimedJob;
|
||||||
|
use OCA\Deckflow\Service\WorkflowService;
|
||||||
|
|
||||||
|
class MoveOverdueCardsJob extends TimedJob {
|
||||||
|
|
||||||
|
private $workflowService;
|
||||||
|
|
||||||
|
public function __construct(WorkflowService $workflowService) {
|
||||||
|
parent::__construct();
|
||||||
|
$this->workflowService = $workflowService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ausführen des Cronjobs
|
||||||
|
*/
|
||||||
|
protected function run($argument) {
|
||||||
|
try {
|
||||||
|
// Überfällige Karten verschieben
|
||||||
|
$this->workflowService->moveOverdueCards();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\OCP\Util::writeLog('deckflow', 'Fehler beim Ausführen des Cronjobs: ' . $e->getMessage(), \OCP\Util::ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
lib/Service/WorkflowService.php
Normal file
52
lib/Service/WorkflowService.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\Deckflow\Service;
|
||||||
|
|
||||||
|
use OCP\IUserSession;
|
||||||
|
use OCA\Deck\Service\DeckService;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
|
class WorkflowService {
|
||||||
|
|
||||||
|
private $userSession;
|
||||||
|
private $deckService;
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct(IUserSession $userSession, DeckService $deckService, ILogger $logger) {
|
||||||
|
$this->userSession = $userSession;
|
||||||
|
$this->deckService = $deckService;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function moveOverdueCards() {
|
||||||
|
$user = $this->userSession->getUser();
|
||||||
|
if ($user === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hole alle Decks für den User
|
||||||
|
$decks = $this->deckService->getDecksByUser($user->getUID());
|
||||||
|
|
||||||
|
foreach ($decks as $deck) {
|
||||||
|
// Hole die Quell- und Zielstapel
|
||||||
|
$sourceStack = $deck->getStackById('sourceStackId'); // Ersetze durch die Konfiguration
|
||||||
|
$targetStack = $deck->getStackById('targetStackId'); // Ersetze durch die Konfiguration
|
||||||
|
|
||||||
|
// Überprüfe alle Karten im Quellstapel auf Überfälligkeit
|
||||||
|
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);
|
||||||
|
$this->logger->info("Card moved to target stack.");
|
||||||
|
}
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\DeckFlow\BackgroundJobs;
|
|
||||||
|
|
||||||
use OCP\BackgroundJob\TimedJob;
|
|
||||||
use OCA\Deck\Service\CardService;
|
|
||||||
use OCP\IConfig;
|
|
||||||
use OCP\ILogger;
|
|
||||||
use OCP\IUserManager;
|
|
||||||
use DateTime;
|
|
||||||
use DateTimeZone;
|
|
||||||
|
|
||||||
class CheckOverdueCards extends TimedJob {
|
|
||||||
private CardService $cardService;
|
|
||||||
private IConfig $config;
|
|
||||||
private IUserManager $userManager;
|
|
||||||
private ILogger $logger;
|
|
||||||
|
|
||||||
public function __construct(CardService $cardService, IConfig $config, IUserManager $userManager, ILogger $logger) {
|
|
||||||
parent::__construct();
|
|
||||||
$this->cardService = $cardService;
|
|
||||||
$this->config = $config;
|
|
||||||
$this->userManager = $userManager;
|
|
||||||
$this->logger = $logger;
|
|
||||||
$this->setInterval(3600);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function run($argument) {
|
|
||||||
$users = $this->userManager->search('');
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$userId = $user->getUID();
|
|
||||||
$rules = json_decode($this->config->getUserValue($userId, 'deckflow', 'rules', '[]'), true);
|
|
||||||
foreach ($rules as $rule) {
|
|
||||||
$sourceStack = $rule['source_stack'];
|
|
||||||
$targetStack = $rule['target_stack'];
|
|
||||||
$cards = $this->cardService->findAllCardsInStack($sourceStack);
|
|
||||||
$now = new DateTime('now', new DateTimeZone('UTC'));
|
|
||||||
|
|
||||||
foreach ($cards as $card) {
|
|
||||||
if (isset($card['duedate']) && new DateTime($card['duedate'], new DateTimeZone('UTC')) < $now) {
|
|
||||||
$this->cardService->updateCard($card['id'], ['stackId' => $targetStack]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\DeckFlow\Settings;
|
|
||||||
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
|
||||||
use OCP\Settings\ISettings;
|
|
||||||
use OCP\IConfig;
|
|
||||||
use OCP\IUserSession;
|
|
||||||
use OCA\Deck\Service\BoardService;
|
|
||||||
use OCA\Deck\Service\StackService;
|
|
||||||
|
|
||||||
class Personal implements ISettings {
|
|
||||||
private IConfig $config;
|
|
||||||
private IUserSession $userSession;
|
|
||||||
private BoardService $boardService;
|
|
||||||
private StackService $stackService;
|
|
||||||
|
|
||||||
public function __construct(IConfig $config, IUserSession $userSession, BoardService $boardService, StackService $stackService) {
|
|
||||||
$this->config = $config;
|
|
||||||
$this->userSession = $userSession;
|
|
||||||
$this->boardService = $boardService;
|
|
||||||
$this->stackService = $stackService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getForm() {
|
|
||||||
$userId = $this->userSession->getUser()->getUID();
|
|
||||||
$rules = json_decode($this->config->getUserValue($userId, 'deckflow', 'rules', '[]'), true);
|
|
||||||
$boards = $this->boardService->findAllBoards();
|
|
||||||
$stacks = [];
|
|
||||||
|
|
||||||
foreach ($boards as $board) {
|
|
||||||
$stacks[$board['id']] = $this->stackService->findAllStacksInBoard($board['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TemplateResponse('deckflow', 'personal', [
|
|
||||||
'rules' => $rules,
|
|
||||||
'boards' => $boards,
|
|
||||||
'stacks' => $stacks
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSection() { return 'deckflow'; }
|
|
||||||
public function getPriority() { return 50; }
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
<form id="deckflow-settings">
|
|
||||||
<h2>Deck Flow Regeln</h2>
|
|
||||||
<label for="board">Board auswählen:</label>
|
|
||||||
<select id="board" onchange="updateStacks()">
|
|
||||||
<option value="">-- Wähle ein Board --</option>
|
|
||||||
<?php foreach ($_['boards'] as $board): ?>
|
|
||||||
<option value="<?php p($board['id']); ?>"><?php p($board['title']); ?></option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label for="source_stack">Quell-Stapel:</label>
|
|
||||||
<select id="source_stack"></select>
|
|
||||||
|
|
||||||
<label for="target_stack">Ziel-Stapel:</label>
|
|
||||||
<select id="target_stack"></select>
|
|
||||||
|
|
||||||
<button type="button" onclick="addRule()">➕ Hinzufügen</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let stacks = <?php echo json_encode($_['stacks']); ?>;
|
|
||||||
|
|
||||||
function updateStacks() {
|
|
||||||
let boardId = document.getElementById('board').value;
|
|
||||||
let sourceSelect = document.getElementById('source_stack');
|
|
||||||
let targetSelect = document.getElementById('target_stack');
|
|
||||||
sourceSelect.innerHTML = '';
|
|
||||||
targetSelect.innerHTML = '';
|
|
||||||
|
|
||||||
if (stacks[boardId]) {
|
|
||||||
stacks[boardId].forEach(stack => {
|
|
||||||
sourceSelect.add(new Option(stack.title, stack.id));
|
|
||||||
targetSelect.add(new Option(stack.title, stack.id));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addRule() {
|
|
||||||
let boardId = document.getElementById('board').value;
|
|
||||||
let sourceStack = document.getElementById('source_stack').value;
|
|
||||||
let targetStack = document.getElementById('target_stack').value;
|
|
||||||
|
|
||||||
fetch('/apps/deckflow/settings/addRule', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({ board_id: boardId, source_stack: sourceStack, target_stack: targetStack }),
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
}).then(() => location.reload());
|
|
||||||
}
|
|
||||||
</script>
|
|
19
templates/settings.php
Normal file
19
templates/settings.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<h1>Deckflow Settings</h1>
|
||||||
|
<form method="post" action="/settings/deckflow">
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<button type="submit">Speichern</button>
|
||||||
|
</form>
|
Reference in New Issue
Block a user