First commit
This commit is contained in:
19
appinfo/app.php
Normal file
19
appinfo/app.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?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/info.xml
Normal file
9
appinfo/info.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<info>
|
||||
<id>deckflow</id>
|
||||
<name>Deck Flow</name>
|
||||
<description>Automatisches Verschieben von überfälligen Karten in Nextcloud Deck</description>
|
||||
<version>1.0.0</version>
|
||||
<namespace>OCA\DeckFlow</namespace>
|
||||
<category>automation</category>
|
||||
</info>
|
47
lib/Settings/BackgroundJobs/CheckOverdueCards.php
Normal file
47
lib/Settings/BackgroundJobs/CheckOverdueCards.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
lib/Settings/Personal.php
Normal file
44
lib/Settings/Personal.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?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; }
|
||||
}
|
49
templates/personal.php
Normal file
49
templates/personal.php
Normal file
@ -0,0 +1,49 @@
|
||||
<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>
|
Reference in New Issue
Block a user