Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Dec 5, 2024
1 parent 1a6f8e5 commit bac2292
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion amd/build/cardnumber.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/cardnumber.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions amd/src/cardnumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
* @author Stefan Hanauska <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import {alert as displayAlert} from 'core/notification';
import {get_string as getString} from 'core/str';

export const init = (element) => {
document.querySelectorAll('#' + element + ' .mod_kanban_card_number').forEach((el) => {
el.addEventListener('click', (event) => {
document.querySelector(
let card = document.querySelector(
`.mod_kanban_card[data-number="${event.target.dataset.id}"] .mod_kanban_detail_trigger`
).click();
);
if (card) {
card.click();
} else {
displayAlert(getString('cardnotfound', 'mod_kanban'));
}
});
});
};
4 changes: 2 additions & 2 deletions classes/boardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,13 @@ public function update_card(int $cardid, array $data): void {
);
helper::update_cached_timestamp($this->board->id, constants::MOD_KANBAN_CARD, $cardupdate['timemodified']);

if (!empty($this->kanban->usenumbers)) {
if (!empty($this->kanban->usenumbers) && !empty($this->kanban->linknumbers)) {
if (isset($cardupdate['description'])) {
$cardupdate['description'] = numberfilter::filter($cardupdate['description']);
}
}

$this->formatter->put('cards', $cardupdate);
$this->formatter->put('cards', $cardupdate, false);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions classes/external/get_kanban_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public static function execute(int $cmid, int $boardid, int $timestamp = 0, bool
'attachments',
$card->id
);
if ($common->usenumbers) {
if ($common->usenumbers && $common->linknumbers) {
$card->description = numberfilter::filter($card->description);
}
$card->attachments = helper::get_attachments($context->id, $card->id);
Expand Down Expand Up @@ -642,7 +642,8 @@ public static function get_discussion_update(int $cmid, int $boardid, int $cardi
self::validate_context($context);
require_capability('mod/kanban:view', $context);

$kanbanboard = helper::get_cached_board($boardid);
$boardmanager = new boardmanager($cmid, $boardid);
$kanbanboard = $boardmanager->get_board();

helper::check_permissions_for_user_or_group($kanbanboard, $context, $cminfo, constants::MOD_KANBAN_VIEW);

Expand All @@ -657,7 +658,10 @@ public static function get_discussion_update(int $cmid, int $boardid, int $cardi
$discussion->content = format_text($discussion->content, FORMAT_HTML);
$discussion->candelete = $discussion->userid == $USER->id || has_capability('mod/kanban:manageboard', $context);
$discussion->username = fullname(\core_user::get_user($discussion->userid));
$formatter->put('discussions', (array) $discussion);
if (!empty($boardmanager->kanban->usenumbers) && !empty($boardmanager->kanban->linknumbers)) {
$discussion->content = numberfilter::filter($discussion->content);
}
$formatter->put('discussions', (array) $discussion, false);
}
return [
'update' => $formatter->get_formatted_updates(),
Expand Down
2 changes: 1 addition & 1 deletion classes/numberfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function filter(string $text): string {
$pattern = '/#(\d+)/';
$text = preg_replace_callback($pattern, function ($matches) {
$number = (int)$matches[1];
return '<span class="mod_kanban_card_number" data-id="' . $number . '">#' . $number . '</span>';
return '<a class="mod_kanban_card_number" data-id="' . $number . '">#' . $number . '</a>';
}, $text);
return $text;
}
Expand Down
7 changes: 5 additions & 2 deletions classes/updateformatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ class updateformatter {
*
* @param string $name Name of the value to update
* @param array $data Fields to update, must contain 'id' field
* @param bool $sanitize Sanitize the output
*/
public function put(string $name, array $data) {
public function put(string $name, array $data, bool $sanitize = true) {
// Sanitize the output.
$data = json_decode(helper::sanitize_json_string(json_encode($data)), true);
if ($sanitize) {
$data = json_decode(helper::sanitize_json_string(json_encode($data)), true);
}
// Find int values covered as string.
foreach ($data as $key => $value) {
if ($key == 'sequence') {
Expand Down
3 changes: 2 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/kanban/db" VERSION="20230727" COMMENT="XMLDB file for mod/kanban"
<XMLDB PATH="mod/kanban/db" VERSION="20241205" COMMENT="XMLDB file for mod/kanban"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -14,6 +14,7 @@
<FIELD NAME="userboards" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="history" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="usenumbers" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="linknumbers" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="completioncreate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="completioncomplete" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
Expand Down
17 changes: 13 additions & 4 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function xmldb_kanban_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2024032701) {
// Define field usenumbers to be added to kanban.
if ($oldversion < 2024120501) {
// Define field usenumbers to be added to table kanban.
$table = new xmldb_table('kanban');
$field = new xmldb_field('usenumbers', XMLDB_TYPE_INTEGER, '2', null, null, null, '0', 'history');

Expand All @@ -42,7 +42,15 @@ function xmldb_kanban_upgrade($oldversion) {
$dbman->add_field($table, $field);
}

// Define field number to be added to kanban_card.
// Define field linknumbers to be added to table kanban.
$field = new xmldb_field('linknumbers', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'usenumbers');

// Conditionally launch add field linknumbers.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Define field number to be added to table kanban_card.
$table = new xmldb_table('kanban_card');
$field = new xmldb_field('number', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'timemodified');

Expand All @@ -64,9 +72,10 @@ function xmldb_kanban_upgrade($oldversion) {
}
$DB->set_field('kanban_card', 'number', $nextnumber, ['id' => $card->id]);
}
$cards->close();

// Kanban savepoint reached.
upgrade_mod_savepoint(true, 2024032701, 'kanban');
upgrade_mod_savepoint(true, 2024120501, 'kanban');
}
return true;
}
3 changes: 3 additions & 0 deletions lang/en/kanban.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$string['autohide'] = 'Auto hide closed cards';
$string['cachedef_board'] = 'Cache for a board instance';
$string['cachedef_timestamp'] = 'Timestamp of last modification of card, column or board instance';
$string['cardnotfound'] = 'Card not found';
$string['cardtitle'] = 'Card title';
$string['changegroup'] = 'Change group board';
$string['changeuser'] = 'Change user board';
Expand Down Expand Up @@ -97,6 +98,8 @@
$string['kanban:view'] = 'View a Kanban board';
$string['kanban:viewallboards'] = 'View all boards';
$string['kanban:viewhistory'] = 'View the history of the board';
$string['linknumbers'] = 'Link card numbers';
$string['linknumbers_help'] = 'Card numbers in card descriptions and discussion comments will be linked.';
$string['liveupdatetime'] = 'Interval for live update in seconds';
$string['liveupdatetimedescription'] = 'Boards will look for updates after this interval. Set to 0 to disable live update.';
$string['loading'] = 'Loading kanban board';
Expand Down
9 changes: 7 additions & 2 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public function definition(): void {
$mform->addHelpButton('history', 'enablehistory', 'mod_kanban');
}

$mform->addElement('advcheckbox', 'usenumbers', get_string('usenumbers', 'kanban'));
$mform->addHelpButton('usenumbers', 'usenumbers', 'kanban');
$mform->addElement('advcheckbox', 'usenumbers', get_string('usenumbers', 'mod_kanban'));
$mform->addHelpButton('usenumbers', 'usenumbers', 'mod_kanban');

$mform->addElement('advcheckbox', 'linknumbers', get_string('linknumbers', 'mod_kanban'));
$mform->addHelpButton('linknumbers', 'linknumbers', 'mod_kanban');
$mform->hideIf('linknumbers', 'usenumbers', 'notchecked');
$mform->setDefault('linknumbers', 1);

$this->standard_coursemodule_elements();

Expand Down
10 changes: 1 addition & 9 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ a.mod_kanban_attachment_item {
.mod_kanban_board:not(.mod_kanban_manageallcards):not(.mod_kanban_manageassignedcards) .mod_kanban_card:not(.mod_kanban_canedit) .mod_kanban_uncomplete_card,
.mod_kanban_board:not(.mod_kanban_manageallcards):not(.mod_kanban_manageassignedcards) .mod_kanban_card:not(.mod_kanban_canedit) .mod_kanban_move_card,
.mod_kanban_board:not(.mod_kanban_history) .mod_kanban_card_view_history,
.mod_kanban_board:not(.mod_kanban_usenumbers) .mod_kanban_number,
.mod_kanban_board:not(.mod_kanban_usenumbers) .mod_kanban_card_number,
.mod_kanban_board.mod_kanban_manageassignedcards:not(.mod_kanban_manageallcards) .mod_kanban_card:not(.mod_kanban_selfassigned)
.mod_kanban_complete_card,
.mod_kanban_board.mod_kanban_manageassignedcards:not(.mod_kanban_manageallcards) .mod_kanban_card:not(.mod_kanban_selfassigned)
Expand Down Expand Up @@ -442,15 +442,7 @@ a.mod_kanban_attachment_item {
display: none;
}

.mod_kanban_number {
font-weight: bold;
}

.mod_kanban_card_number {
cursor: pointer;
font-weight: bold;
}

.mod_kanban_card_number::before {
background-image: url([[pix:i/show]]);
}
2 changes: 1 addition & 1 deletion templates/card.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}}
<li style="{{#background}}background-color: {{background}}{{/background}}" class="mod_kanban_card card{{#completed}} mod_kanban_closed{{/completed}} {{^hasassignees}}mod_kanban_unassigned{{/hasassignees}} {{#hasdescription}}mod_kanban_hasdescription{{/hasdescription}} {{#hasattachment}}mod_kanban_hasattachment{{/hasattachment}} {{#hasdiscussion}}mod_kanban_hasdiscussion{{/hasdiscussion}} {{#selfassigned}}mod_kanban_selfassigned{{/selfassigned}} {{#discussion}}mod_kanban_hasdiscussion{{/discussion}} {{#canedit}}mod_kanban_canedit{{/canedit}}" id="mod_kanban_card-{{id}}" data-id="{{id}}" data-columnid="{{kanban_column}}" data-number="{{number}}">
<div class="card-body">
<div class="mod_kanban_card_title card-title"><span class="mod_kanban_number">#{{number}}</span>
<div class="mod_kanban_card_title card-title"><span class="mod_kanban_card_number">#{{number}}</span>
<span class="inplaceeditable inplaceeditable-text"{{#canedit}}{{^completed}} data-inplaceeditable="1" data-component="mod_kanban" data-itemtype="card" data-itemid="{{id}}"
data-value="{{{title}}}" data-type="text"{{/completed}}{{/canedit}}>
<a href="#" class="quickeditlink aalink"{{#canedit}}{{^completed}} data-inplaceeditablelink="1"{{/completed}}{{/canedit}}>
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$plugin->component = 'mod_kanban';
$plugin->release = '0.2.5';
$plugin->version = 2024032701;
$plugin->version = 2024120501;
$plugin->requires = 2022112800;
$plugin->supported = [401, 404];
$plugin->maturity = MATURITY_BETA;

0 comments on commit bac2292

Please sign in to comment.