Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Add interactive "start" when the project or activity are not mentioned #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

eliandoran
Copy link

@eliandoran eliandoran commented Jun 6, 2022

Greetings @infeeeee,

First, I find this CLI tool to be great and I would like to use it in my daily routine. However, to be personally more efficient I thought to start an activity faster directly from the CLI.

If the user knows the project and activity to start, they can use this:

$ kimai2-cmd start [project] [activity]

However, there are two different cases which are not currently covered by this command.

Interactive selection of the activity

At work it is usually more convenient to select the activity from a list but to prefill the project, as such:

$ kimai2-cmd start [project]

Attempting to do this at the moment will result in an exception:

npm run start start "Sandbox"                                                                                                                      

> [email protected] start
> node kimai2-cmd.js "start" "Sandbox"

/home/elian/Projects/kimai2-cmd/kimai2-cmd.js:336
                   if (element.name.toLowerCase() == name.toLowerCase()) {
                                                          ^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
   at /home/elian/Projects/kimai2-cmd/kimai2-cmd.js:336:60
   at processTicksAndRejections (node:internal/process/task_queues:96:5)

Node.js v17.7.2

After this PR, the user is taken straight to the activity list (equivalent to kimai2-cmd -> "Start new measurement" -> select the project).

Interactive selection of the project

If the user is extra lazy and simply wants to start an activity, but without knowing the project or the activity:

$ kimai2-cmd start [project]

At the moment, this results in an exception:

> [email protected] start
> node kimai2-cmd.js "start"

/home/elian/Projects/kimai2-cmd/kimai2-cmd.js:340
                    if (element.name.toLowerCase() == name.toLowerCase()) {
                                                           ^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at /home/elian/Projects/kimai2-cmd/kimai2-cmd.js:340:60
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Node.js v17.7.2

After this PR, the user is simply sent to the normal UI workflow for starting an activity (select project, then select activity).

Motivation

As mentioned previously, this can save the user for a few keystrokes. This is especially useful when the user does not have many projects or has a specific schedule. I want to use this at work to save a few keystrokes (since I usually have ~16 activities for an 8-hours workday).

If this modification does not fit your expectations for the classic CLI (especially since we are mixing the classic CLI with the interactive one), feel free to tell me. I have also tried to keep the modifications to the code as minimal as possible.

If the user attempts to run the classic CLI via "start [project]" (but
without the "[activity]", an exception would occur because the application
expects the activity ID.

If the user does not provide the activity ID, then ask for it
interactively.
@eliandoran eliandoran marked this pull request as ready for review June 6, 2022 20:37
@infeeeee
Copy link
Owner

infeeeee commented Jun 7, 2022

Woah, seems nice, thank you!

I will take a more in-depth look in the following days.

I don't use kimai nowadays, so if you have other ideas you want to implement feel free to create PRs.

@eliandoran
Copy link
Author

Thank you, @infeeeee . Let me know if it's OK for you.
I will probably want to do some more similar changes to the stop command as well, will keep you posted.

If I may, did you switch to some other time tracking solution? Or do you no longer need to track your time?

@infeeeee
Copy link
Owner

infeeeee commented Jun 8, 2022

I started to work at a company, I'm not self employed any more, I used kimai alone. I'm trying to convince the company to switch to kimai, but they are not ready yet.

I also don't code in js anymore, switched to python nowadays for projects like this.

Copy link
Owner

@infeeeee infeeeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can you also update readme.md? And write about this in the .description at line 942

kimai2-cmd.js Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants