diff options
| author | dam <dam@gudinoff> | 2023-08-15 01:11:30 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-08-15 01:11:30 +0100 |
| commit | 821ff8453d247d51922fcf11de36b2923b3171bc (patch) | |
| tree | e2dccd93d4f20aada923774fbcb6a0731b1dc41d | |
| parent | 6a33f413c7e1fd5c6b904d0a01e3f9e1b93bceb0 (diff) | |
| download | task-time-tracker-821ff8453d247d51922fcf11de36b2923b3171bc.tar.zst task-time-tracker-821ff8453d247d51922fcf11de36b2923b3171bc.zip | |
Fixed coalesce feature.
| -rw-r--r-- | ttt.jai | 43 |
1 files changed, 26 insertions, 17 deletions
@@ -523,6 +523,20 @@ add_task_time :: (db: *Database, index: s64, day: int, time: s64) { db.tasks[index].times[day] = add(db.tasks[index].times[day], time); } +// Adds the time on the day and task provided (and adjusts database totals). +add_task_times :: (db: *Database, index: s64, times: [7] s64) { + assert(db != null, ASSERT_NOT_NULL, "db"); + assert(is_valid_index(db, index), ASSERT_INVALID_INDEX, index); + + // Make sure we sync before applying the changes. + update_times(db); + + for times { + db.total_times[it_index] = add(db.total_times[it_index], it); + db.tasks[index].times[it_index] = add(db.tasks[index].times[it_index], it); + } +} + // Resets database to the initial state and deallocates all memory taken by tasks. reset_database :: (db: *Database) { assert(db != null, ASSERT_NOT_NULL, "db"); @@ -1626,6 +1640,8 @@ main :: () { case #char "S"; // TODO The initial part should only decide what's the sorting procedure... then we would would all in a single place. sort_by := read_input_char(selected_task_row, action_style, " Sort by (n) name, (1..7) day, or (t) total time. "); + show_processing(); + sort_procedure: (a: Task, b: Task) -> s64; active_task: Task = ifx db.active_idx >= 0 then db.tasks[db.active_idx] else .{}; if sort_by == { @@ -1671,23 +1687,23 @@ main :: () { case #char "w"; #through; case #char "W"; if (db != *database || db.tasks.count <= 0) continue; - if (read_enter_confirmation(selected_task_row, action_style, " Press enter to archive duplicates and reset all. ") == true) { - for db.tasks { - if (append_to_csv(it, ar_file_path) == false) { - print_error("Failed to archive entry."); // TODO Improve this. - } - reset_task_times(db, it_index); + if (read_enter_confirmation(selected_task_row, action_style, " Press enter to archive duplicates and reset all. ") == false) continue; + show_processing(); + + for db.tasks { + if (append_to_csv(it, ar_file_path) == false) { + print_error("Failed to archive entry."); // TODO Improve this. } - trigger_autosave(); + reset_task_times(db, it_index); } + trigger_autosave(); // Coalesce similar entries. case #char "c"; #through; case #char "C"; if (db.tasks.count <= 0) continue; if (read_enter_confirmation(selected_task_row, action_style, " Press enter to coalesce similar tasks. ") == false) continue; - - active_task: Task = ifx db.active_idx >= 0 then db.tasks[db.active_idx] else .{}; + show_processing(); head_idx := 0; while head_idx < db.tasks.count - 1 { @@ -1696,20 +1712,13 @@ main :: () { t_head := *db.tasks[head_idx]; t_tail := *db.tasks[tail_idx]; if compare(xx t_head.name, xx t_tail.name) == 0 { - for 0..6 { - t_head.times[it] = add(t_head.times[it], t_tail.times[it]); - } + add_task_times(db, head_idx, db.tasks[tail_idx].times); delete_task(db, tail_idx); } tail_idx -= 1; } head_idx += 1; } - update_total_times(db); // TODO Can we make this so that we don't need to do this? I bet we can... - - if db.active_idx >= 0 { - db.active_idx = find_similar_task(db, active_task); - } trigger_autosave(); case KEY_HOME; |
