Skip to content

Commit

Permalink
show parent title, improve docs, rename config command
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Dec 30, 2019
1 parent 95f0009 commit 5d71eef
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 17 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,49 @@ A PHP application to access your Kimai 2 installation via its API (http).
- cURL extension
- json extension
- iconv extension
- zlib extension

## Installation and updates

To install and update the Kimai console tools, execute the following commands:

```bash
wget curl -LJO https://github.com/kevinpapst/kimai2-console/releases/latest/download/kimai.phar
chmod +x kimai.phar
mv kimai.phar /usr/local/bin/kimai
```

Now you need to create a configuration file, which is required to connect to Kimai:
### Configuration file

Before using it the first time, you have to create a configuration file, which holds the connection infos for Kimai.
By default this config file will be located at `~/.kimai2-console.json`:

```bash
kimai configuration:create
```

Make sure the file is only readable for your own user:

```bash
kimai dump-configuration
chmod 600 ~/.kimai2-console.json
```

Afterwards edit the file and change the URL, username and API token to your needs.
That's it, you can use Kimai from the command line now.

By default the configuration file targets the demo installation and will work, but this is likely not want you intent to use ;-)
By default the configuration file targets the demo installation and will work... but now its time to target your own Kimai, so
edit the config file and change the settings: URL, username and API token.

That's it, you can use Kimai now with e.g. `kimai customer:list`.
## Available commands

You get a list of all available commands with `kimai`.

- `kimai customer:list` - show a list of customers
- `kimai project:list` - show a list of projects
- `kimai activity:list` - show a list of activities
- `kimai version` - show the full version string of the remote installation
- `kimai configuration:create` - creates the initial configuration file

To get help for a dedicated command use the `--help` switch, eg: `kimai project:list --help`

## Environment variables

Expand All @@ -36,3 +59,7 @@ The following environment variables are supported:
- `KIMAI_MEMORY_LIMIT` - configures the allowed memory limit (eg `128MB`, or `-1` for unlimited) (see [here](https://www.php.net/manual/en/ini.core.php#ini.memory-limit))
- `KIMAI_CONFIG` - path to your configuration file (defaults to: $HOME/.kimai2-console.json)

## How to build a release

- Execute `box compile`
-
7 changes: 7 additions & 0 deletions bin/kimai
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Kimai 2 - Remote Console.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
fwrite(STDERR, 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL);
exit(1);
Expand Down
5 changes: 3 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ protected function getDefaultCommands()
new Command\ActivityListCommand(),
new Command\ProjectListCommand(),
new Command\CustomerListCommand(),
new Command\DumpConfigurationCommand(),
new Command\ConfigurationCreateCommand(),
new Command\VersionCommand(),
]);

if ('phar:' === substr(__FILE__, 0, 5)) {
$commands[] = new Command\SelfUpdateCommand();
// TODO commented, until it is working
//$commands[] = new Command\SelfUpdateCommand();
}

return $commands;
Expand Down
30 changes: 30 additions & 0 deletions src/Client/Model/ActivityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ActivityCollection implements ModelInterface, ArrayAccess
'fixed_rate' => 'float',
'hourly_rate' => 'float',
'color' => 'string',
'parent_title' => 'string',
'project' => 'int',
'meta_fields' => '\KimaiConsole\Client\Model\ActivityMeta[]'
];
Expand All @@ -75,6 +76,7 @@ class ActivityCollection implements ModelInterface, ArrayAccess
'fixed_rate' => 'float',
'hourly_rate' => 'float',
'color' => null,
'parent_title' => null,
'project' => null,
'meta_fields' => null
];
Expand Down Expand Up @@ -112,6 +114,7 @@ public static function swaggerFormats()
'fixed_rate' => 'fixedRate',
'hourly_rate' => 'hourlyRate',
'color' => 'color',
'parent_title' => 'parentTitle',
'project' => 'project',
'meta_fields' => 'metaFields'
];
Expand All @@ -128,6 +131,7 @@ public static function swaggerFormats()
'fixed_rate' => 'setFixedRate',
'hourly_rate' => 'setHourlyRate',
'color' => 'setColor',
'parent_title' => 'setParentTitle',
'project' => 'setProject',
'meta_fields' => 'setMetaFields'
];
Expand All @@ -144,6 +148,7 @@ public static function swaggerFormats()
'fixed_rate' => 'getFixedRate',
'hourly_rate' => 'getHourlyRate',
'color' => 'getColor',
'parent_title' => 'getParentTitle',
'project' => 'getProject',
'meta_fields' => 'getMetaFields'
];
Expand Down Expand Up @@ -210,6 +215,7 @@ public function __construct(array $data = null)
$this->container['fixed_rate'] = $data['fixed_rate'] ?? null;
$this->container['hourly_rate'] = $data['hourly_rate'] ?? null;
$this->container['color'] = $data['color'] ?? null;
$this->container['parent_title'] = $data['parent_title'] ?? null;
$this->container['project'] = $data['project'] ?? null;
$this->container['meta_fields'] = $data['meta_fields'] ?? null;
}
Expand Down Expand Up @@ -403,6 +409,30 @@ public function setColor($color)
return $this;
}

/**
* Gets parent_title
*
* @return string
*/
public function getParentTitle()
{
return $this->container['parent_title'];
}

/**
* Sets parent_title
*
* @param string $parent_title parent_title
*
* @return $this
*/
public function setParentTitle($parent_title)
{
$this->container['parent_title'] = $parent_title;

return $this;
}

/**
* Gets project
*
Expand Down
30 changes: 30 additions & 0 deletions src/Client/Model/ProjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ProjectCollection implements ModelInterface, ArrayAccess
'hourly_rate' => 'float',
'color' => 'string',
'customer' => 'int',
'parent_title' => 'string',
'meta_fields' => '\KimaiConsole\Client\Model\ProjectMeta[]'
];

Expand All @@ -75,6 +76,7 @@ class ProjectCollection implements ModelInterface, ArrayAccess
'fixed_rate' => 'float',
'hourly_rate' => 'float',
'color' => null,
'parent_title' => null,
'customer' => null,
'meta_fields' => null
];
Expand Down Expand Up @@ -113,6 +115,7 @@ public static function swaggerFormats()
'hourly_rate' => 'hourlyRate',
'color' => 'color',
'customer' => 'customer',
'parent_title' => 'parentTitle',
'meta_fields' => 'metaFields'
];

Expand All @@ -129,6 +132,7 @@ public static function swaggerFormats()
'hourly_rate' => 'setHourlyRate',
'color' => 'setColor',
'customer' => 'setCustomer',
'parent_title' => 'setParentTitle',
'meta_fields' => 'setMetaFields'
];

Expand All @@ -145,6 +149,7 @@ public static function swaggerFormats()
'hourly_rate' => 'getHourlyRate',
'color' => 'getColor',
'customer' => 'getCustomer',
'parent_title' => 'getParentTitle',
'meta_fields' => 'getMetaFields'
];

Expand Down Expand Up @@ -211,6 +216,7 @@ public function __construct(array $data = null)
$this->container['hourly_rate'] = $data['hourly_rate'] ?? null;
$this->container['color'] = $data['color'] ?? null;
$this->container['customer'] = $data['customer'] ?? null;
$this->container['parent_title'] = $data['parent_title'] ?? null;
$this->container['meta_fields'] = $data['meta_fields'] ?? null;
}

Expand Down Expand Up @@ -403,6 +409,30 @@ public function setColor($color)
return $this;
}

/**
* Gets parent_title
*
* @return string
*/
public function getParentTitle()
{
return $this->container['parent_title'];
}

/**
* Sets parent_title
*
* @param string $parent_title parent_title
*
* @return $this
*/
public function setParentTitle($parent_title)
{
$this->container['parent_title'] = $parent_title;

return $this;
}

/**
* Gets customer
*
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ActivityListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$rows = [];
foreach ($collection as $activity) {
$project = '-';
if (null !== ($prj = $activity->getProject())) {
$project = $prj;
$project = '';
if (!empty($activity->getProject())) {
$project = '[' . $activity->getProject() . '] ' . $activity->getParentTitle();
}
$rows[] = [
$activity->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

final class DumpConfigurationCommand extends BaseCommand
final class ConfigurationCreateCommand extends BaseCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('dump-configuration')
->setDescription('Dumps a default configuration file')
->setName('configuration:create')
->setDescription('Create a default configuration file')
->setHelp('This command creates a default configuration file.')
;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Command/ProjectListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ protected function execute(InputInterface $input, OutputInterface $output)

$rows = [];
foreach ($collection as $project) {
$customer = $project->getCustomer();

$rows[] = [
$project->getId(),
$project->getName(),
$project->getCustomer(),
'[' . $project->getCustomer() . '] ' . $project->getParentTitle(),
];
}
$io->table(['Id', 'Name', 'Customer ID'], $rows);
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Constants
/**
* The current release version
*/
public const VERSION = '0.1';
public const VERSION = '0.1.1';
/**
* The software name
*/
Expand Down

0 comments on commit 5d71eef

Please sign in to comment.