Skip to content

Tasks Board Settings 5 16 Developer Guide

Ed Mozley edited this page Dec 1, 2026 · 1 revision

Tasks: what Complete sets, and Hide done's columns - developer guide

Two settings. #495 (5.16.0): Tasks β†’ Settings β†’ Statuses β†’ Completing a task sets, and Mark complete / Reopen removed from the board's right-click menu. #460 (5.17.0, raised by @Dr4inder): Tasks β†’ Settings β†’ Archive β†’ With Hide done on, the Done and Cancelled columns. The user's view: Tasks - Β§ Completing a task, and Β§ Filtering (the Hide done paragraph).

Both are the same shape: a behaviour that used to be fixed becomes an install-wide system_settings row, read with a default that is the old behaviour, so an install that never opens the setting sees no change. #495 replaces "the first closed status in the list" with a chosen status, on the server; #460 decides, in the browser, whether Hide done empties the closed columns or takes them off the board.

Why each is a setting rather than a fix:

  • #495 - one-click complete took the first closed status in the admin's order. That is Done on a standard install, but an install that sorted Cancelled above Done found every Complete button and subtask tick box cancelling the task, with nothing on screen saying so. Some installs want a different finishing status, so it is chosen, not hard-wired to a name.
  • #460 - #442 (5.13.0) asked for the closed columns to stay when Hide done is on, so a card can still be dragged to Done. #460 asked for them to go, because on a narrow board two empty columns cost the open work its width. Both are reasonable, so it is a choice, with #442's behaviour the default.

πŸ“ Files

File What
includes/services/tasks.php New TasksService::completeStatusId()
api/tasks/get_task_statuses.php Each status now carries is_completion
api/tasks/toggle_subtask.php Ticking a subtask sets completeStatusId()
assets/js/tasks.js completeFromWork() picks is_completion; hideDoneDropsColumns(), buildBoardColumns(), setHideDone(), renderBoard(), updateHideDoneCount()
assets/js/tasks-ctx-menu.js (v10) The complete action and its label removed (commit 97a3faa51)
tasks/index.php The Mark complete / Reopen menu item removed; #hideDoneCount beside Hide done; window.TASK_HIDE_DONE_COLUMNS
includes/task_archive.php New taskHideDoneColumns()
api/tasks/get_settings.php Returns complete_status_id, complete_status_effective and hide_done_columns
api/tasks/save_settings.php Accepts and validates both keys
tasks/settings/manifest.php tasks_complete_status_id on the statuses tab, tasks_hide_done_columns on the archive tab
tasks/settings/index.php The two dropdowns and their load / save code
api/system/db_verify.php The two defaults: tasks_complete_status_id = '', tasks_hide_done_columns = 'keep'
lang/*/tasks.php complete_status_* and hide_done_columns_*; context.mark_complete / context.reopen removed from all 23 files

No table or column changes - both are system_settings rows, seeded by Database Verify with INSERT IGNORE and read with the same default when absent.

βœ… Completing a task sets (#495)

The one rule - completeStatusId()

public static function completeStatusId(PDO $conn): ?int
{
    $chosen = (int)self::evidenceSetting($conn, 'tasks_complete_status_id', '0');
    if ($chosen > 0) {
        $s = $conn->prepare("SELECT id FROM task_statuses WHERE id = ? AND is_closed = 1 AND is_active = 1");
        $s->execute([$chosen]);
        if ($s->fetchColumn()) return $chosen;
    }
    $id = $conn->query("SELECT id FROM task_statuses WHERE is_closed = 1 AND is_active = 1
                         ORDER BY display_order ASC, id ASC LIMIT 1")->fetchColumn();
    return $id ? (int)$id : null;
}
  • The chosen status is used only while it is still an active closed status. A status deactivated, deleted or changed to open after it was chosen falls back silently to the old rule, so completing never sets an open status or fails because of a stale setting.
  • The fall-back is the old rule exactly: the first closed status in the admin's order. That is why the default ('') changes nothing.
  • It sits beside skipStatusId() (Tasks β†’ Settings β†’ Evidence, the status a skipped repeat moves to), which is the mirror image - last closed status by default, Cancelled on a standard install.
  • TRAP: ask completeStatusId(), never "the first closed one". Sorting Cancelled above Done turned every one-click complete into a cancel. Any new place that completes a task in one click must use this.

Who asks it

Where How
A subtask's tick box - api/tasks/toggle_subtask.php Server side: WHERE id = ? AND is_closed = 1 AND is_active = 1 with completeStatusId(). Unticking (reopening) is unchanged: the default open status, else the first open one
The Complete button in a task's Work view - completeFromWork() Browser side, from the is_completion flag
Tasks β†’ Settings β†’ Statuses Shows the effective choice (Automatic - the first closed status (Done))

The tick box:

$newStatusStmt->execute($task['status_is_closed'] ? [] : [(int)TasksService::completeStatusId($conn)]);

The browser never repeats the rule. get_task_statuses.php marks the one status it returns:

$completeId = TasksService::completeStatusId($conn);
foreach ($statuses as &$s) {
    $s['is_completion'] = $completeId !== null && (int)$s['id'] === $completeId;
    ...
}

and the Work view reads the flag:

const target = (statusList || []).find(s => s.is_completion) || (statusList || []).find(s => Number(s.is_closed) === 1);
if (!target) { showToast(window.t('tasks.context.no_status_for_that'), 'error'); return; }
await saveField('status', target.name);

The second find() is only a safety net for a status list that came from somewhere without the flag. saveField() is the same path as the Status box, so the completion check and the people-involved questions are asked exactly as when the status is changed by hand.

The setting

tasks/settings/index.php draws a dropdown under the statuses table. Its choices are the active closed statuses from the same list the table shows, redrawn after every status change (loadLookup('status') calls renderCompleteStatus()), and the empty option names the status Automatic would pick:

const closed = (lookupCache.status || []).filter(s => s.is_closed && s.is_active);
const first = closed[0];
box.innerHTML = `<option value="">${escapeHtml(t('tasks.settings.complete_status_auto', { name: first ? first.name : '-' }))}</option>`
    + closed.map(s => `<option value="${Number(s.id)}">${escapeHtml(s.name)}</option>`).join('');
box.value = closed.some(s => String(s.id) === completeStatusSaved) ? completeStatusSaved : '';

A saved status that is no longer an active closed one shows as Automatic - which is also what the server is doing with it.

Validation in save_settings.php, shared with the Evidence tab's skip status:

} elseif ($key === 'evidence_skip_status_id' || $key === 'complete_status_id') {
    $value = (string)(int)$value === '0' ? '' : (string)(int)$value;
    if ($value !== '') {
        $chk = $conn->prepare("SELECT 1 FROM task_statuses WHERE id = ? AND is_closed = 1 AND is_active = 1");
        $chk->execute([(int)$value]);
        if (!$chk->fetchColumn()) continue;
    }
  • Empty or 0 is stored as '' (Automatic).
  • Anything else must be an active closed status, or the key is not written. Like every other key in that endpoint, a refused value is skipped, not reported - the response is still success.
  • Writing it needs the statuses tab's capability (Cap::TASKS_STATUSES) - the manifest's setting_keys is what analystCanWriteSettingKey() checks.

Mark complete / Reopen removed

The board's right-click menu had Mark complete (on an open task) and Reopen (on a closed one). It saved the same field as Status, chose its status by the order of the list, and suggested a difference that was not there. Commit 97a3faa51 took it out of tasks/index.php and tasks-ctx-menu.js (the [data-action="complete"] handler and the ctxCompleteLabel text), and dropped context.mark_complete / context.reopen from the 23 language files. Status lists every status with the current one ticked, in both directions, as the table and timeline menus always did. task.status_is_closed is still read in the menu - it decides whether Archive is offered.

πŸ™ˆ With Hide done on, the Done and Cancelled columns (#460)

Two different settings meet here, and they must not be confused:

Hide done ...the Done and Cancelled columns
Where the tick box in the sidebar's Show section Tasks β†’ Settings β†’ Archive
Whose per analyst - user_preferences tasks_hide_done, window.TASK_HIDE_DONE the whole install - system_settings tasks_hide_done_columns, window.TASK_HIDE_DONE_COLUMNS
Does leaves done tasks out of the board and the list decides what Hide done does to the closed columns - nothing at all while Hide done is off

Reading it - taskHideDoneColumns()

function taskHideDoneColumns(PDO $conn): string
{
    try {
        $st = $conn->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'tasks_hide_done_columns'");
        $st->execute();
        return $st->fetchColumn() === 'drop' ? 'drop' : 'keep';
    } catch (Throwable $e) {
        return 'keep';
    }
}

Only the exact string drop drops; a missing row, a missing table or anything else is keep. save_settings.php accepts only the two values (in_array($value, ['keep', 'drop'], true)), and writing it needs the archive tab's capability (Cap::TASKS_ARCHIVE).

The board page prints it, rather than fetching it, so the first draw is already right:

window.TASK_HIDE_DONE_COLUMNS = <?php echo json_encode(taskHideDoneColumns(connectToDatabase())); ?>;   // GH #460

The board

function hideDoneDropsColumns() {
    return hideDone && window.TASK_HIDE_DONE_COLUMNS === 'drop';
}

buildBoardColumns() builds one column per status, and leaves out the closed ones only when that is true:

const all = statusList.length ? statusList : DEFAULT_STATUSES;
// GH #460: ...unless the setting drops them, for boards where they cost the open work its width.
const cols = hideDoneDropsColumns() ? all.filter(s => !Number(s.is_closed)) : all;
  • By the is_closed flag, never by name - a renamed Done, or a third closed status, follows the same rule.
  • TRAP: the columns are built, not just drawn. buildBoardColumns() normally runs once after the statuses load, so setHideDone() has to call it again before renderBoard() - otherwise ticking Hide done would hide the cards but leave the columns until the page was reloaded:
function setHideDone(on) {
    hideDone = !!on;
    saveTaskPreference('tasks_hide_done', hideDone ? 'on' : '');
    if (currentView === 'board') { buildBoardColumns(); renderBoard(); }
    else renderList();
}
  • With keep (the default), a closed column stays and, empty, says what is hidden: 12 hidden by Hide done (tasks.board.done_hidden, #442), so the column is never a mystery and a card can still be dragged there.
  • The board grouped by analyst builds its own columns (renderBoardByAnalyst()), so the setting does not touch it; Hide done still leaves the done cards out.
  • A dropped column takes its archive button (Archive the tasks in this column) with it. Archiving by hand from the right-click menu, and archiving by itself after N days, are unaffected.

The count moves to the switch

With the columns gone nothing on the board says how many are hidden, so the number moves beside the tick box - Hide done (12):

function updateHideDoneCount() {
    const el = document.getElementById('hideDoneCount');
    if (!el) return;
    const n = hideDoneDropsColumns()
        ? tasks.filter(t => taskIsDone(t) && taskMatchesSearch(t) && taskMatchesTag(t) && taskMatchesProject(t)
                         && taskMatchesContractor(t) && taskMatchesStatusLink(t)).length
        : 0;
    el.textContent = n ? '(' + n + ')' : '';
}
  • It counts the done tasks the board's other filters let through - the same filters as columnTasks() - so the number matches what turning Hide done off would show.
  • renderBoard() calls it first, so every redraw (a filter, a search, a drag, a save) keeps it current.
  • With keep it is always empty: the columns say it themselves, and saying it twice would be noise.

The <span id="hideDoneCount"> sits inside the Hide done <label> in tasks/index.php.

πŸ§ͺ Tests

Test Checks
tests/tasks-complete-status.php 6. completeStatusId() unset β†’ the first closed status; set to the second closed status β†’ that one, whatever the order; an open status saved by mistake β†’ ignored, back to the first closed; a status that no longer exists β†’ ignored too. Twice, get_task_statuses.php is run in process and must flag exactly one status is_completion - the same one. Skips (with a message) when the database has fewer than two active closed statuses. The setting is put back in finally
tests/tasks-hide-done-columns.php 6. taskHideDoneColumns(): never saved β†’ keep; drop β†’ drop; 'DROP ' β†’ keep. Then source checks: save_settings.php accepts only keep / drop; tasks.js drops only closed columns and only with Hide done on; tasks/index.php hands the board the setting. The setting is put back exactly as it was

Run with FREEITSM_TEST_DATABASE=<test db> php tests/<file>.

See also

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally