Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fff0af063 | |||
| e1e4c36180 | |||
| 8648b67061 |
18
Asset/css/qualkard.css
Normal file
18
Asset/css/qualkard.css
Normal file
@@ -0,0 +1,18 @@
|
||||
/* QualKard mastery badge (under the card title on the board). */
|
||||
.qk-line {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.qk-badge {
|
||||
display: inline-block;
|
||||
padding: 0 6px;
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
font-size: 0.85em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.qk-new { background: #e6b800; } /* unread */
|
||||
.qk-low { background: #c0392b; } /* < 50% */
|
||||
.qk-mid { background: #27ae60; } /* 50-89% */
|
||||
.qk-high { background: #2980b9; } /* >= 90% */
|
||||
@@ -193,4 +193,18 @@ class QualKardHelper extends Base
|
||||
));
|
||||
$this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(array('date_due' => $due));
|
||||
}
|
||||
|
||||
/**
|
||||
* The mastery badge (label + CSS class) for a card, from its stored average.
|
||||
*
|
||||
* @param int $task_id
|
||||
* @return array
|
||||
*/
|
||||
public function cardBadge($task_id)
|
||||
{
|
||||
$raw = $this->taskMetadataModel->get($task_id, 'qualkard_avg', '');
|
||||
$avg = ($raw === '' || $raw === null) ? null : (float) $raw;
|
||||
|
||||
return self::badge($avg);
|
||||
}
|
||||
}
|
||||
|
||||
38
Plugin.php
38
Plugin.php
@@ -3,6 +3,7 @@
|
||||
namespace Kanboard\Plugin\QualKard;
|
||||
|
||||
use Kanboard\Core\Plugin\Base;
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* QualKard -- flashcard spaced repetition on Kanboard cards.
|
||||
@@ -17,10 +18,43 @@ class Plugin extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
$container = $this->container;
|
||||
|
||||
// Per-board setup/reset/disable on Settings -> Integrations.
|
||||
$this->template->hook->attach('template:project:integrations', 'qualKard:project/integration');
|
||||
|
||||
// (The grade handler and the badge are wired in later versions.)
|
||||
// New card on a QualKard board -> reset it (unread, armed inert, moved to Drafts).
|
||||
$this->hook->on('model:task:creation:aftersave', function ($task_id) use ($container) {
|
||||
$helper = new \Kanboard\Plugin\QualKard\Helper\QualKardHelper($container);
|
||||
$task = $container['taskFinderModel']->getById($task_id);
|
||||
if (! empty($task) && $helper->isEnabled($task['project_id'])) {
|
||||
$helper->resetCard($task_id, (int) $task['project_id']);
|
||||
}
|
||||
});
|
||||
|
||||
// Card dragged INTO a grade column -> grade it (RecoReco then handles the movement). The
|
||||
// plugin on() wrapper drops the event, so we subscribe on the dispatcher to get the TaskEvent.
|
||||
$this->dispatcher->addListener(TaskModel::EVENT_MOVE_COLUMN, function ($event) use ($container) {
|
||||
$task = $event['task'];
|
||||
$helper = new \Kanboard\Plugin\QualKard\Helper\QualKardHelper($container);
|
||||
if (! $helper->isEnabled($task['project_id'])) {
|
||||
return;
|
||||
}
|
||||
$dst = (int) $event['dst_column_id'];
|
||||
foreach (array('hairy', 'hard', 'medium', 'easy') as $role) {
|
||||
if ($dst === $helper->col($task['project_id'], $role)) {
|
||||
$helper->grade($task['id'], \Kanboard\Plugin\QualKard\Helper\QualKardHelper::SCORE[$role]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Mastery badge under the card title on the board, plus its stylesheet.
|
||||
$this->template->hook->attach('template:board:private:task:after-title', 'qualKard:board/badge');
|
||||
$this->template->hook->attach('template:board:public:task:after-title', 'qualKard:board/badge');
|
||||
$this->hook->on('template:layout:css', array(
|
||||
'template' => 'plugins/QualKard/Asset/css/qualkard.css',
|
||||
));
|
||||
}
|
||||
|
||||
public function getHelpers()
|
||||
@@ -47,7 +81,7 @@ class Plugin extends Base
|
||||
|
||||
public function getPluginVersion()
|
||||
{
|
||||
return '0.3.0';
|
||||
return '0.5.0';
|
||||
}
|
||||
|
||||
public function getPluginHomepage()
|
||||
|
||||
12
Template/board/badge.php
Normal file
12
Template/board/badge.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// Mastery badge under the card title on a QualKard board. Server-rendered (survives board refresh).
|
||||
// Yellow "new" for an unread card; otherwise a percent of 5, red (<50) / green (<90) / blue (>=90).
|
||||
if (empty($task['project_id']) || ! $this->QualKardHelper->isEnabled($task['project_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$b = $this->QualKardHelper->cardBadge($task['id']);
|
||||
?>
|
||||
<div class="qk-line">
|
||||
<span class="qk-badge <?= $b['class'] ?>"><?= $this->text->e($b['label']) ?></span>
|
||||
</div>
|
||||
@@ -1,10 +1,10 @@
|
||||
<h3><i class="fa fa-graduation-cap fa-fw" aria-hidden="true"></i> <?= t('QualKard') ?></h3>
|
||||
<div class="listing">
|
||||
<?php if (! $this->helper->QualKardHelper->hasRecoReco()): ?>
|
||||
<?php if (! $this->QualKardHelper->hasRecoReco()): ?>
|
||||
|
||||
<p class="form-help"><?= t('QualKard needs the RecoReco plugin (its move engine). Install RecoReco to use QualKard.') ?></p>
|
||||
|
||||
<?php elseif (! $this->helper->QualKardHelper->isEnabled($project['id'])): ?>
|
||||
<?php elseif (! $this->QualKardHelper->isEnabled($project['id'])): ?>
|
||||
|
||||
<p class="form-help"><?= t('Turn this project into a spaced-repetition study board. This restructures the columns to Drafts | Study | Hairy | Hard | Medium | Easy | Done and moves every card to Drafts.') ?></p>
|
||||
<form method="post" action="<?= $this->url->href('QualKardController', 'setup', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>" onsubmit="return confirm('<?= t('This restructures the board and moves all cards to Drafts. Continue?') ?>');">
|
||||
@@ -26,3 +26,4 @@
|
||||
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
Reference in New Issue
Block a user