3 Commits
v0.4 ... v0.6

6 changed files with 92 additions and 21 deletions

18
Asset/css/qualkard.css Normal file
View 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% */

View File

@@ -120,6 +120,18 @@ class QualKardHelper extends Base
return (int) $this->projectMetadataModel->get($project_id, 'qualkard_col_'.$role, 0);
}
/**
* Is FinanceBuddy enabled on this board? QualKard refuses to convert a FinanceBuddy board (its
* restructure would wreck the finance columns).
*
* @param int $project_id
* @return bool
*/
public function fbEnabled($project_id)
{
return (int) $this->projectMetadataModel->get($project_id, 'financebuddy_enabled', 0) === 1;
}
/**
* Write the inert RecoReco config for a card: move-mode to Study, fire from anywhere but Done,
* daily (innocuous -- QualKard sets the due date on each grade), anchor 0 so RecoReco skips it
@@ -193,4 +205,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);
}
}

View File

@@ -48,6 +48,13 @@ class Plugin extends Base
}
}
});
// 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()
@@ -74,7 +81,7 @@ class Plugin extends Base
public function getPluginVersion()
{
return '0.4.0';
return '0.6.0';
}
public function getPluginHomepage()

12
Template/board/badge.php Normal file
View 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>

View File

@@ -1,28 +1,36 @@
<?php
// QualKard is inside the shared Integrations form, so the buttons use formaction (NOT nested <form>s)
// to post to QualKard's own controller. Set up is destructive; disabling only stops the automation.
$has = $this->QualKardHelper->hasRecoReco();
$fb = $this->QualKardHelper->fbEnabled($project['id']);
$enabled = $this->QualKardHelper->isEnabled($project['id']);
$blocked = ! $has || $fb;
?>
<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 ($enabled): ?>
<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'])): ?>
<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?') ?>');">
<?= $this->form->csrf() ?>
<button type="submit" class="btn btn-blue"><?= t('Set up QualKard study board') ?></button>
</form>
<p class="form-help"><?= t('QualKard is enabled on this board.') ?></p>
<div class="form-actions">
<button type="submit" class="btn" formaction="<?= $this->url->href('QualKardController', 'reset', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>" onclick="return confirm('<?= t('Reset every card to unread and move them to Drafts. Continue?') ?>');"><?= t('Reset all cards') ?></button>
<button type="submit" class="btn btn-red" formaction="<?= $this->url->href('QualKardController', 'disable', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>"><?= t('Disable QualKard machinery') ?></button>
</div>
<p class="form-help"><?= t('"Disable" only stops the QualKard automation -- it does not restructure the board or touch your cards.') ?></p>
<?php else: ?>
<p class="form-help"><?= t('QualKard is enabled on this board.') ?></p>
<form method="post" style="display:inline" action="<?= $this->url->href('QualKardController', 'reset', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>" onsubmit="return confirm('<?= t('Reset every card to unread and move them to Drafts. Continue?') ?>');">
<?= $this->form->csrf() ?>
<button type="submit" class="btn"><?= t('Reset all cards') ?></button>
</form>
<form method="post" style="display:inline" action="<?= $this->url->href('QualKardController', 'disable', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>">
<?= $this->form->csrf() ?>
<button type="submit" class="btn btn-red"><?= t('Disable QualKard') ?></button>
</form>
<p class="form-help">
<?php if (! $has): ?>
<?= t('QualKard needs the RecoReco plugin (its move engine).') ?>
<?php elseif ($fb): ?>
<?= t('Disabled while FinanceBuddy is enabled here -- QualKard would restructure the columns.') ?>
<?php else: ?>
<?= t('Set up turns this project into a study board: columns become Drafts | Study | Hairy | Hard | Medium | Easy | Done and every card moves to Drafts.') ?>
<?php endif ?>
</p>
<div class="form-actions"<?= $blocked ? ' style="opacity:0.5"' : '' ?>>
<button type="submit" class="btn btn-blue" <?= $blocked ? 'disabled="disabled"' : '' ?> formaction="<?= $this->url->href('QualKardController', 'setup', array('plugin' => 'QualKard', 'project_id' => $project['id'])) ?>" onclick="return confirm('<?= t('This restructures the board and moves all cards to Drafts. Continue?') ?>');"><?= t('Set up QualKard study board') ?></button>
</div>
<?php endif ?>
</div>

View File

@@ -1 +1 @@
QualKard v0.4
QualKard v0.6