Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Mar 22, 2024
1 parent 9d26437 commit c17221a
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 5 deletions.
2 changes: 1 addition & 1 deletion amd/build/exporter.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/exporter.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions amd/src/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default class {
col.hascards = col.sequence != '';
col.autoclose = options.autoclose;
col.autohide = options.autohide;
if (options.wiplimit > 0) {
col.wiplimit = options.wiplimit;
}
if (col.hascards) {
let cardOrder = col.sequence.split(',');
col.cards = cardOrder.map((value) => {
Expand Down
76 changes: 75 additions & 1 deletion classes/boardmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use cm_info;
use context_module;
use context_system;
use core_h5p\core;
use core_user;
use moodle_exception;
use stdClass;

/**
Expand Down Expand Up @@ -541,6 +544,13 @@ public function move_card(int $cardid, int $aftercard, int $columnid = 0): void
} else {
$targetcolumn = $DB->get_record('kanban_column', ['id' => $columnid]);

$options = json_decode($targetcolumn->options);
$wiplimit = $options->wiplimit ?? 0;

if ($wiplimit > 0) {
self::check_wiplimit($columnid, $cardid, $wiplimit);
}

// Card needs to be processed first, because column sorting in frontend will only
// work if card is already moved in the right position.
$updatecard = ['id' => $cardid, 'kanban_column' => $columnid, 'timemodified' => time()];
Expand Down Expand Up @@ -599,6 +609,51 @@ public function move_card(int $cardid, int $aftercard, int $columnid = 0): void
helper::update_cached_timestamp($this->board->id, constants::MOD_KANBAN_COLUMN, $update['timemodified']);
}

/**
* Checks whether the WIP limit is reached for a certain column and card. Raises an exception if limit is reached.
* @param int $columnid Id of the column
* @param int $cardid Id of the current card
* @param int $wiplimit WIP limit
* @param array $assignees Array of user ids that should be checked for WIP limit. If empty, checking will be done
* for the current assignees.
* @throws moodle_exception
*/
public function check_wiplimit(int $columnid, int $cardid, int $wiplimit, array $assignees = []): void {
if (empty($assignees)) {
$assignees = $this->get_card_assignees($cardid);
}
$overlimit = [];
foreach ($assignees as $assignee) {
$wip = $this->get_wip($columnid, $assignee, $cardid);
if ($wip >= $wiplimit) {
$user = core_user::get_user($assignee);
$overlimit[] = fullname($user);
}
}
if (count($overlimit) > 0) {
throw new moodle_exception('wiplimitreached', 'mod_kanban', '', ['users' => implode(', ', $overlimit)]);
}
}

/**
* Returns the number of cards in a column a certain user is currently assigned to.
* @param int $columnid Id of the column
* @param int $userid Id of the user
* @param int $cardtoexclude Id of a card to exclude from the count
*/
public function get_wip(int $columnid, int $userid, int $cardtoexclude = 0): int {
global $DB;
$count = $DB->get_field_sql(
'SELECT COUNT(*)
FROM {kanban_card} c
INNER JOIN {kanban_assignee} a
ON a.kanban_card = c.id
WHERE a.userid = :userid AND c.kanban_column = :columnid AND c.id != :cardid',
['columnid' => $columnid, 'userid' => $userid, 'cardid' => $cardtoexclude]
);
return $count;
}

/**
* Assigns a user to a card.
*
Expand All @@ -608,8 +663,17 @@ public function move_card(int $cardid, int $aftercard, int $columnid = 0): void
*/
public function assign_user(int $cardid, int $userid): void {
global $DB, $OUTPUT, $USER;
$DB->insert_record('kanban_assignee', ['kanban_card' => $cardid, 'userid' => $userid]);
$card = $this->get_card($cardid);
$column = $this->get_column($card->kanban_column);
$options = json_decode($column->options);
$wiplimit = $options->wiplimit ?? 0;

if ($wiplimit > 0) {
self::check_wiplimit($card->kanban_column, $cardid, $wiplimit, [$userid]);
}

$DB->insert_record('kanban_assignee', ['kanban_card' => $cardid, 'userid' => $userid]);

$update = [
'id' => $cardid,
'timemodified' => time(),
Expand Down Expand Up @@ -876,6 +940,15 @@ public function update_card(int $cardid, array $data): void {
$cardupdate['assignees'] = $assignees;
}
$assignees = [];

$column = $this->get_column($cardupdate['kanban_column']);
$options = json_decode($column->options);
$wiplimit = $options->wiplimit ?? 0;

if ($wiplimit > 0) {
self::check_wiplimit($cardupdate['kanban_column'], $cardid, $wiplimit, $toinsert);
}

foreach ($toinsert as $assignee) {
$assignees[] = ['kanban_card' => $cardid, 'userid' => $assignee];
$user = \core_user::get_user($assignee);
Expand Down Expand Up @@ -944,6 +1017,7 @@ public function update_column(int $columnid, array $data): void {
$options = [
'autoclose' => $data['autoclose'],
'autohide' => $data['autohide'],
'wiplimit' => empty($data['wiplimitenable']) ? 0 : $data['wiplimit'],
];
if (isset($data['title'])) {
$data['title'] = s($data['title']);
Expand Down
12 changes: 12 additions & 0 deletions classes/form/edit_column_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function definition() {

$mform->addElement('advcheckbox', 'autohide', get_string('autohide', 'kanban'));
$mform->setType('autohide', PARAM_BOOL);

$wiparray = [];
$wiparray[] = $mform->createElement('advcheckbox', 'wiplimitenable', get_string('wiplimitenable', 'kanban'));
$wiparray[] = $mform->createElement('text', 'wiplimit', get_string('wiplimit', 'kanban'), ['size' => '5']);
$mform->addGroup($wiparray, 'wipgroup', '', '', false);

$mform->setType('wiplimit', PARAM_INT);
$mform->setType('wiplimitenable', PARAM_BOOL);

$mform->disabledIf('wiplimit', 'wiplimitenable', 'notchecked');
}

/**
Expand Down Expand Up @@ -124,6 +134,8 @@ public function set_data_for_dynamic_submission(): void {
$options = json_decode($column->options);
$column->autoclose = $options->autoclose;
$column->autohide = $options->autohide;
$column->wiplimitenable = !empty($options->wiplimit);
$column->wiplimit = (empty($options->wiplimit) ? 0 : $options->wiplimit);
$this->set_data($column);
}

Expand Down
3 changes: 3 additions & 0 deletions lang/en/kanban.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,6 @@
$string['userboards_help'] = 'Enables personal boards for the participants (only visible to them and to the trainers)';
$string['userboardsenabled'] = 'Personal boards enabled';
$string['userboardsonly'] = 'Personal boards only';
$string['wiplimit'] = 'WIP limit per person';
$string['wiplimitenable'] = 'Enable WIP limit';
$string['wiplimitreached'] = 'WIP limit is reached for {$a->users}.';
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ a.mod_kanban_attachment_item {
.mod_kanban_column.mod_kanban_autohide.mod_kanban_show_hidden [data-action="show_hidden"],
.mod_kanban_column:not(.mod_kanban_autohide) .mod_kanban_hidden_actions,
.mod_kanban_column.mod_kanban_autohide:not(.mod_kanban_show_hidden) .mod_kanban_card.mod_kanban_closed,
.mod_kanban_column:not(.mod_kanban_column_wiplimit) .mod_kanban_wiplimit,
.mod_kanban_card.mod_kanban_closed .mod_kanban_complete_card,
.mod_kanban_card.mod_kanban_closed .mod_kanban_duedate,
.mod_kanban_card:not(.mod_kanban_closed) .mod_kanban_uncomplete_card,
Expand Down
6 changes: 4 additions & 2 deletions templates/column.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"managecolumns": true,
"hascards": false,
"autohide": true,
"locked": false
"locked": false,
"wiplimit": 5
}
}}
<li class="mod_kanban_column col card{{#autohide}} mod_kanban_autohide{{/autohide}} {{#locked}}mod_kanban_locked_column{{/locked}}" id="mod_kanban_column-{{id}}" data-id="{{id}}">
<li class="mod_kanban_column col card{{#autohide}} mod_kanban_autohide{{/autohide}} {{#locked}}mod_kanban_locked_column{{/locked}} {{#wiplimit}}mod_kanban_column_wiplimit{{/wiplimit}}" id="mod_kanban_column-{{id}}" data-id="{{id}}">
<h5 class="mod_kanban_column_title card-title">
<span class="inplaceeditable inplaceeditable-text"{{#managecolumns}} {{^locked}}data-inplaceeditable="1" {{/locked}}data-component="mod_kanban" data-itemtype="column" data-itemid="{{id}}"
data-value="{{{title}}}" data-type="text"{{/managecolumns}}>
Expand All @@ -38,6 +39,7 @@
</a>
</span>
</h5>
<span class="badge rounded-pill text-bg-info mod_kanban_wiplimit">{{wiplimit}} / {{#pix}} t/user, core, {{#str}} wiplimit, mod_kanban{{/str}} {{/pix}}</span>
<div class="mod_kanban_hidden_actions">
<button data-action="show_hidden" class="btn btn-icon icon-no-margin p-0">{{#pix}} i/show, core, {{#str}} showhidden, mod_kanban {{/str}} {{/pix}}</button>
<button data-action="hide_hidden" class="btn btn-icon icon-no-margin p-0">{{#pix}} i/hide, core, {{#str}} hidehidden, mod_kanban {{/str}} {{/pix}}</button>
Expand Down

0 comments on commit c17221a

Please sign in to comment.