1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Godbout\Alfred\Time\Menus\Toggl; |
4
|
|
|
|
5
|
|
|
use Godbout\Alfred\Time\Workflow; |
6
|
|
|
use Godbout\Alfred\Workflow\Icon; |
7
|
|
|
use Godbout\Alfred\Workflow\Item; |
8
|
|
|
use Godbout\Alfred\Time\Menus\Menu; |
9
|
|
|
use Godbout\Alfred\Workflow\ScriptFilter; |
10
|
|
|
|
11
|
|
|
class Setup extends Menu |
12
|
|
|
{ |
13
|
|
|
public static function scriptFilter() |
14
|
|
|
{ |
15
|
|
|
ScriptFilter::add( |
16
|
|
|
self::apikey(), |
17
|
|
|
self::state(), |
18
|
|
|
self::back() |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
private static function apikey() |
23
|
|
|
{ |
24
|
|
|
return Item::create() |
25
|
|
|
->title(self::apikeyTitle()) |
26
|
|
|
->subtitle(self::apikeySubtitle()) |
27
|
|
|
->arg('toggl_setup_apikey') |
28
|
|
|
->icon(Icon::create('resources/icons/toggl.png')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private static function apikeyTitle() |
32
|
|
|
{ |
33
|
|
|
return empty(Workflow::getConfig()->read('toggl.api_token')) ? 'Set API KEY' : 'Update API KEY'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private static function apikeySubtitle() |
37
|
|
|
{ |
38
|
|
|
$apikey = Workflow::getConfig()->read('toggl.api_token'); |
39
|
|
|
|
40
|
|
|
return empty($apikey) ? 'No API KEY found' : 'Current API KEY: ' . substr($apikey, 0, 11) . '...'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private static function state() |
44
|
|
|
{ |
45
|
|
|
return Item::create() |
46
|
|
|
->title(self::stateTitle()) |
47
|
|
|
->subtitle(self::stateSubtitle()) |
48
|
|
|
->arg('toggl_setup_state') |
49
|
|
|
->variable('toggl_enabled', Workflow::getConfig()->read('toggl.is_active') ? 'false' : 'true') |
50
|
|
|
->icon(Icon::create('resources/icons/toggl.png')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private static function stateTitle() |
54
|
|
|
{ |
55
|
|
|
return (Workflow::getConfig()->read('toggl.is_active') === true) ? 'Disable' : 'Enable'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private static function stateSubtitle() |
59
|
|
|
{ |
60
|
|
|
return (Workflow::getConfig()->read('toggl.is_active') === true) ? 'Currently enabled' : 'Currently disabled'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private static function back() |
64
|
|
|
{ |
65
|
|
|
return Item::create() |
66
|
|
|
->title('Back') |
67
|
|
|
->arg('setup') |
68
|
|
|
->icon(Icon::create('resources/icons/icon.png')); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|