Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d02f49e293 | |||
| 85432401ea | |||
| 873df71ed0 |
56
Asset/js/recoreco-modal.js
Normal file
56
Asset/js/recoreco-modal.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* RecoReco -- keep the "days before" field within one period of the selected frequency.
|
||||
*
|
||||
* The Recurring schedule modal is injected by AJAX, so we react to the frequency <select> both when
|
||||
* it appears (MutationObserver) and when it changes (delegated event). Daily -> field disabled (0);
|
||||
* weekly -> max 6; monthly -> max 27; yearly -> max 364. The server clamps too, so this is only the
|
||||
* UI guard.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var CAPS = { daily: 0, weekly: 6, monthly_day: 27, monthly_dow: 27, yearly: 364 };
|
||||
|
||||
function apply(select) {
|
||||
// "days before" ceiling / disable by frequency.
|
||||
var input = document.querySelector('input[name="recoreco_days_before"]');
|
||||
if (input) {
|
||||
var max = CAPS.hasOwnProperty(select.value) ? CAPS[select.value] : 27;
|
||||
|
||||
if (max === 0) {
|
||||
input.value = 0;
|
||||
input.setAttribute("max", "0");
|
||||
input.disabled = true;
|
||||
} else {
|
||||
input.disabled = false;
|
||||
input.setAttribute("max", String(max));
|
||||
if (parseInt(input.value, 10) > max) {
|
||||
input.value = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The last-day/weekday checkbox only means something for monthly and yearly.
|
||||
var lastday = document.querySelector(".recoreco-lastday");
|
||||
if (lastday) {
|
||||
var monthlyOrYearly = select.value === "monthly_day" || select.value === "monthly_dow" || select.value === "yearly";
|
||||
lastday.style.display = monthlyOrYearly ? "" : "none";
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("change", function (e) {
|
||||
if (e.target && e.target.name === "recoreco_frequency") {
|
||||
apply(e.target);
|
||||
}
|
||||
});
|
||||
|
||||
if (window.MutationObserver) {
|
||||
new MutationObserver(function () {
|
||||
var select = document.querySelector('select[name="recoreco_frequency"]:not([data-recoreco-init])');
|
||||
if (select) {
|
||||
select.setAttribute("data-recoreco-init", "1");
|
||||
apply(select);
|
||||
}
|
||||
}).observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
})();
|
||||
@@ -7,29 +7,35 @@ use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* The "Recurring schedule" modal: configure a card's calendar recurrence and store it in task
|
||||
* metadata. v0.2 is storage only -- no spawning (that is the CLI engine in later versions).
|
||||
* metadata. The CLI engine (RecoRecoModel) does the actual spawning.
|
||||
*
|
||||
* Gate: a card can only be enabled when it has a due date (the recurrence anchor) and is not
|
||||
* already a native-recurring card (RecoReco and native recurrence are mutually exclusive).
|
||||
* Gate: a card can only be enabled when it has a due date (the recurrence anchor), is not already a
|
||||
* native-recurring card (mutually exclusive), and the board has a column other than the card's own
|
||||
* (the copy must land elsewhere).
|
||||
*/
|
||||
class RecurrenceController extends BaseController
|
||||
{
|
||||
public function edit(array $values = array(), array $errors = array())
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$columns = $this->targetColumns($task);
|
||||
$meta = $this->taskMetadataModel->getAll($task['id']);
|
||||
|
||||
if (empty($values)) {
|
||||
$values = $this->getStoredValues($task);
|
||||
$values = $this->getStoredValues($meta, $task, $columns);
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('recoReco:recurrence/edit', array(
|
||||
'task' => $task,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'columns_list' => $this->columnModel->getList($task['project_id']),
|
||||
'columns_list' => $columns,
|
||||
'frequency_list' => $this->getFrequencyList(),
|
||||
'has_due_date' => ! empty($task['date_due']),
|
||||
'is_native' => $task['recurrence_status'] != TaskModel::RECURRING_STATUS_NONE,
|
||||
'has_target' => ! empty($columns),
|
||||
'is_clone' => isset($meta['recoreco_clone']) && $meta['recoreco_clone'] == 1,
|
||||
'source_id' => isset($meta['recoreco_source']) ? (int) $meta['recoreco_source'] : 0,
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -37,34 +43,44 @@ class RecurrenceController extends BaseController
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$input = $this->request->getValues();
|
||||
$columns = $this->targetColumns($task);
|
||||
|
||||
// Only a plain card (has a due date, not native-recurring) may be enabled.
|
||||
$can_recur = ! empty($task['date_due']) && $task['recurrence_status'] == TaskModel::RECURRING_STATUS_NONE;
|
||||
// A clone can never be made recurring (that would recurse). Guard even though the modal
|
||||
// hides the form for clones.
|
||||
$is_clone = (int) $this->taskMetadataModel->get($task['id'], 'recoreco_clone', 0) === 1;
|
||||
|
||||
// Only a plain card (a due date, not native-recurring, not a clone, a valid target) may enable.
|
||||
$can_recur = ! empty($task['date_due'])
|
||||
&& $task['recurrence_status'] == TaskModel::RECURRING_STATUS_NONE
|
||||
&& ! $is_clone
|
||||
&& ! empty($columns);
|
||||
$enabled = ($can_recur && isset($input['recoreco_enabled']) && $input['recoreco_enabled'] == 1) ? 1 : 0;
|
||||
|
||||
$frequency = isset($input['recoreco_frequency']) && array_key_exists($input['recoreco_frequency'], $this->getFrequencyList())
|
||||
? $input['recoreco_frequency']
|
||||
: 'monthly_day';
|
||||
|
||||
// Keep the lead time under one period (else a copy's fire time crosses the prior occurrence).
|
||||
$daysBefore = isset($input['recoreco_days_before']) && ctype_digit((string) $input['recoreco_days_before']) ? (int) $input['recoreco_days_before'] : 0;
|
||||
$daysBefore = min($daysBefore, $this->maxDaysBefore($frequency));
|
||||
|
||||
$values = array(
|
||||
'recoreco_enabled' => $enabled,
|
||||
'recoreco_target_column' => isset($input['recoreco_target_column']) ? (int) $input['recoreco_target_column'] : (int) $task['column_id'],
|
||||
'recoreco_target_column' => $this->resolveTarget(isset($input['recoreco_target_column']) ? $input['recoreco_target_column'] : 0, $columns),
|
||||
'recoreco_frequency' => $frequency,
|
||||
'recoreco_last_day' => isset($input['recoreco_last_day']) ? 1 : 0,
|
||||
'recoreco_days_before' => isset($input['recoreco_days_before']) && ctype_digit((string) $input['recoreco_days_before']) ? (int) $input['recoreco_days_before'] : 0,
|
||||
'recoreco_days_before' => $daysBefore,
|
||||
'recoreco_link_copies' => isset($input['recoreco_link_copies']) ? 1 : 0,
|
||||
);
|
||||
|
||||
// Capture the anchor (the due date at enable time) -- the drift-free pattern. The engine
|
||||
// (v0.3) reads it to compute occurrences.
|
||||
// Capture the anchor (the due date at enable time) -- the drift-free pattern.
|
||||
if ($enabled) {
|
||||
$values['recoreco_anchor'] = (int) $task['date_due'];
|
||||
}
|
||||
|
||||
$this->taskMetadataModel->save($task['id'], $values);
|
||||
|
||||
// Reconcile the template's duplicate links with the setting right away (removes existing
|
||||
// links to its RecoReco clones when the option is off).
|
||||
// Reconcile the template's duplicate links with the setting right away.
|
||||
$model = new \Kanboard\Plugin\RecoReco\Model\RecoRecoModel($this->container);
|
||||
$model->syncCloneLinks($task['id'], $values['recoreco_link_copies'] == 1);
|
||||
|
||||
@@ -73,13 +89,34 @@ class RecurrenceController extends BaseController
|
||||
return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'])), true);
|
||||
}
|
||||
|
||||
private function getStoredValues(array $task)
|
||||
// Columns the copy can land in: every column except the template's own (the copy must move).
|
||||
private function targetColumns(array $task)
|
||||
{
|
||||
$meta = $this->taskMetadataModel->getAll($task['id']);
|
||||
$columns = $this->columnModel->getList($task['project_id']);
|
||||
unset($columns[$task['column_id']]);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
// A stored/posted target, if still a valid non-current column; otherwise the first one (or 0).
|
||||
private function resolveTarget($candidate, array $columns)
|
||||
{
|
||||
$candidate = (int) $candidate;
|
||||
|
||||
if (array_key_exists($candidate, $columns)) {
|
||||
return $candidate;
|
||||
}
|
||||
|
||||
$keys = array_keys($columns);
|
||||
|
||||
return empty($keys) ? 0 : (int) $keys[0];
|
||||
}
|
||||
|
||||
private function getStoredValues(array $meta, array $task, array $columns)
|
||||
{
|
||||
return array(
|
||||
'recoreco_enabled' => isset($meta['recoreco_enabled']) ? (int) $meta['recoreco_enabled'] : 0,
|
||||
'recoreco_target_column' => isset($meta['recoreco_target_column']) ? (int) $meta['recoreco_target_column'] : (int) $task['column_id'],
|
||||
'recoreco_target_column' => $this->resolveTarget(isset($meta['recoreco_target_column']) ? $meta['recoreco_target_column'] : 0, $columns),
|
||||
'recoreco_frequency' => isset($meta['recoreco_frequency']) ? $meta['recoreco_frequency'] : 'monthly_day',
|
||||
'recoreco_last_day' => isset($meta['recoreco_last_day']) ? (int) $meta['recoreco_last_day'] : 0,
|
||||
'recoreco_days_before' => isset($meta['recoreco_days_before']) ? (int) $meta['recoreco_days_before'] : 0,
|
||||
@@ -97,4 +134,22 @@ class RecurrenceController extends BaseController
|
||||
'daily' => t('Daily'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The largest allowed "days before" for a frequency -- kept strictly under one period so a
|
||||
* copy's fire time never crosses the previous occurrence. Daily = 0 (disabled).
|
||||
*/
|
||||
private function maxDaysBefore($frequency)
|
||||
{
|
||||
switch ($frequency) {
|
||||
case 'daily':
|
||||
return 0;
|
||||
case 'weekly':
|
||||
return 6;
|
||||
case 'yearly':
|
||||
return 364;
|
||||
default: // monthly_day, monthly_dow
|
||||
return 27;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
Helper/RecoRecoHelper.php
Normal file
38
Helper/RecoRecoHelper.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Plugin\RecoReco\Helper;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* Board helper: which RecoReco icon a card should show.
|
||||
*
|
||||
* Single-icon rule -- RecoReco only renders when the card is NOT native-recurring
|
||||
* (recurrence_status == NONE), so native's icon and RecoReco's icon can never appear together.
|
||||
*/
|
||||
class RecoRecoHelper extends Base
|
||||
{
|
||||
/**
|
||||
* @param array $task A board task row (has recurrence_status and id).
|
||||
* @return string 'template', 'clone', or '' (no RecoReco icon).
|
||||
*/
|
||||
public function iconType(array $task)
|
||||
{
|
||||
if ((int) $task['recurrence_status'] !== TaskModel::RECURRING_STATUS_NONE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$meta = $this->taskMetadataModel->getAll($task['id']);
|
||||
|
||||
if (isset($meta['recoreco_enabled']) && $meta['recoreco_enabled'] == 1) {
|
||||
return 'template';
|
||||
}
|
||||
|
||||
if (isset($meta['recoreco_clone']) && $meta['recoreco_clone'] == 1) {
|
||||
return 'clone';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
17
Plugin.php
17
Plugin.php
@@ -12,6 +12,14 @@ class Plugin extends Base
|
||||
// (next to native "Edit recurrence"). Opens the RecoReco config modal.
|
||||
$this->template->hook->attach('template:task:sidebar:after-basic-actions', 'recoReco:task/sidebar_action');
|
||||
|
||||
// Modal JS: keep "days before" within one period of the selected frequency.
|
||||
$this->hook->on('template:layout:js', array(
|
||||
'template' => 'plugins/RecoReco/Asset/js/recoreco-modal.js',
|
||||
));
|
||||
|
||||
// Board card icon: black on a recurring template, white (inverse) on a generated copy.
|
||||
$this->template->hook->attach('template:board:task:icons', 'recoReco:board/task_icon');
|
||||
|
||||
// The scheduling engine runs from the CLI (cron). Registered CLI-only so web requests do
|
||||
// not build the console app.
|
||||
if (php_sapi_name() === 'cli') {
|
||||
@@ -19,6 +27,13 @@ class Plugin extends Base
|
||||
}
|
||||
}
|
||||
|
||||
public function getHelpers()
|
||||
{
|
||||
return array(
|
||||
'Plugin\RecoReco\Helper' => array('RecoRecoHelper'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getPluginName()
|
||||
{
|
||||
return 'RecoReco';
|
||||
@@ -36,7 +51,7 @@ class Plugin extends Base
|
||||
|
||||
public function getPluginVersion()
|
||||
{
|
||||
return '1.1.0';
|
||||
return '1.2.0';
|
||||
}
|
||||
|
||||
public function getPluginHomepage()
|
||||
|
||||
10
Template/board/task_icon.php
Normal file
10
Template/board/task_icon.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php $type = $this->RecoRecoHelper->iconType($task) ?>
|
||||
<?php if ($type === 'template'): ?>
|
||||
<span title="<?= t('RecoReco: recurring template') ?>">
|
||||
<i class="fa fa-refresh fa-rotate-90" role="img" aria-label="<?= t('RecoReco: recurring template') ?>"></i>
|
||||
</span>
|
||||
<?php elseif ($type === 'clone'): ?>
|
||||
<span title="<?= t('RecoReco: generated copy') ?>">
|
||||
<i class="fa fa-refresh fa-rotate-90 fa-inverse" role="img" aria-label="<?= t('RecoReco: generated copy') ?>"></i>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
@@ -1,16 +1,39 @@
|
||||
<div class="page-header">
|
||||
<h2><?= t('Recurring schedule') ?><?php if ($has_due_date): ?> <small>(<?= date('Y-m-d H:i', $task['date_due']) ?>)</small><?php endif ?></h2>
|
||||
<h2>
|
||||
<?= t('Recurring schedule') ?>
|
||||
<?php if ($has_due_date): ?>
|
||||
<small>(<?= $this->url->link(date('Y-m-d H:i', $task['date_due']), 'TaskModificationController', 'edit', array('task_id' => $task['id']), false, 'js-modal-large') ?>)</small>
|
||||
<?php else: ?>
|
||||
<small>-- <?= $this->url->link(t('set a due date'), 'TaskModificationController', 'edit', array('task_id' => $task['id']), false, 'js-modal-large') ?></small>
|
||||
<?php endif ?>
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<?php $can_recur = $has_due_date && ! $is_native ?>
|
||||
<?php if ($is_clone): ?>
|
||||
|
||||
<?php if (! $has_due_date): ?>
|
||||
<p class="alert alert-info">
|
||||
<?= t('This card is a copy generated by RecoReco, so it cannot itself be made recurring.') ?>
|
||||
<?php if ($source_id): ?>
|
||||
<?= $this->url->link(t('Open the recurring template'), 'TaskViewController', 'show', array('task_id' => $source_id)) ?>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<?php $can_recur = $has_due_date && ! $is_native && $has_target ?>
|
||||
|
||||
<?php if (! $has_due_date): ?>
|
||||
<p class="alert alert-info"><?= t('Please set a due date first. RecoReco uses the card due date as the recurrence anchor.') ?></p>
|
||||
<?php elseif ($is_native): ?>
|
||||
<p class="alert alert-info"><?= t('This card already uses Kanboard built-in recurrence. RecoReco and native recurrence cannot be used together.') ?></p>
|
||||
<?php endif ?>
|
||||
<?php elseif ($is_native): ?>
|
||||
<p class="alert alert-info">
|
||||
<?= t('This card uses Kanboard built-in recurrence.') ?>
|
||||
<?= $this->url->link(t('Edit built-in recurrence'), 'TaskRecurrenceController', 'edit', array('task_id' => $task['id']), false, 'js-modal-medium') ?>
|
||||
</p>
|
||||
<?php elseif (! $has_target): ?>
|
||||
<p class="alert alert-info"><?= t('Add a target column first.') ?></p>
|
||||
<?php endif ?>
|
||||
|
||||
<form method="post" action="<?= $this->url->href('RecurrenceController', 'save', array('plugin' => 'RecoReco', 'task_id' => $task['id'])) ?>" autocomplete="off">
|
||||
<form method="post" action="<?= $this->url->href('RecurrenceController', 'save', array('plugin' => 'RecoReco', 'task_id' => $task['id'])) ?>" autocomplete="off">
|
||||
<?= $this->form->csrf() ?>
|
||||
|
||||
<?= $this->form->label(t('Make recurring'), 'recoreco_enabled') ?>
|
||||
@@ -29,16 +52,17 @@
|
||||
<?= $this->form->label(t('Frequency'), 'recoreco_frequency') ?>
|
||||
<?= $this->form->select('recoreco_frequency', $frequency_list, $values) ?>
|
||||
|
||||
<?= $this->form->checkbox('recoreco_last_day', t('Last day of the month (honored only when the due date is the last day / last weekday of its month)'), 1, $values['recoreco_last_day'] == 1) ?>
|
||||
<div class="recoreco-lastday">
|
||||
<?= $this->form->checkbox('recoreco_last_day', t('Fires on last day/weekday of the month'), 1, $values['recoreco_last_day'] == 1) ?>
|
||||
</div>
|
||||
|
||||
<?= $this->form->label(t('Create the copy this many days before the due date'), 'recoreco_days_before') ?>
|
||||
<input type="number" name="recoreco_days_before" min="0" value="<?= $this->text->e($values['recoreco_days_before']) ?>">
|
||||
|
||||
<?= $this->form->checkbox('recoreco_link_copies', t('Link copies to the template'), 1, $values['recoreco_link_copies'] == 1) ?>
|
||||
<p class="form-help">
|
||||
<?= t('When on, the template keeps a link to each copy -- a running count and one-click navigation to every one. Off by default; best left off for frequent (daily/weekly) schedules to avoid piling up links.') ?>
|
||||
</p>
|
||||
|
||||
<p class="form-help"><?= t('Links each copy back to the template (a count and quick navigation). Off by default.') ?></p>
|
||||
|
||||
<?= $this->modal->submitButtons() ?>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
Reference in New Issue
Block a user