2018-02-25 20:31:42 +00:00
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
|
|
|
|
from model import Model
|
|
|
|
from params import Params
|
2019-01-07 06:58:44 +00:00
|
|
|
from screen import Screen
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self):
|
|
|
|
self.model = Model()
|
|
|
|
self.params = Params()
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen = Screen()
|
|
|
|
|
2018-02-25 20:31:42 +00:00
|
|
|
self.fzf = FzfPrompt()
|
2019-01-07 06:58:44 +00:00
|
|
|
self.info = ''
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
def manage(self):
|
2018-03-13 20:49:47 +00:00
|
|
|
active = 'off'
|
|
|
|
if self.params.get('active'):
|
|
|
|
active = 'on'
|
2019-01-07 06:58:44 +00:00
|
|
|
self.info = 'Show current tasks: [' + active + ']\n'
|
2018-03-13 20:49:47 +00:00
|
|
|
|
2018-02-25 20:31:42 +00:00
|
|
|
done = 'off'
|
|
|
|
if self.params.get('done'):
|
|
|
|
done = 'on'
|
2019-01-07 06:58:44 +00:00
|
|
|
self.info += 'Show done tasks: [' + done + ']\n'
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
self.manage_menu()
|
|
|
|
|
|
|
|
def manage_menu(self):
|
2019-01-07 06:58:44 +00:00
|
|
|
about = '''
|
|
|
|
Short instruction
|
|
|
|
-----------------
|
|
|
|
? - help (this dialog)
|
|
|
|
! - toggle active tasks
|
|
|
|
v - toggle done tasks
|
|
|
|
t - manage time slots
|
|
|
|
# - backup/restore
|
|
|
|
< - back
|
|
|
|
q - exit
|
|
|
|
'''
|
|
|
|
self.screen.change_path('~config', '?!vt#<q', about, 'Managing configs', self.info)
|
|
|
|
menu = self.screen.print()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
if menu == 'q':
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.bye()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
elif menu == '?':
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.activate_about()
|
2018-02-25 21:06:11 +00:00
|
|
|
self.manage_menu()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
2018-03-13 20:49:47 +00:00
|
|
|
elif menu == '!':
|
|
|
|
self.toggle_active()
|
|
|
|
self.manage()
|
|
|
|
|
2018-02-25 20:31:42 +00:00
|
|
|
elif menu == 'v':
|
|
|
|
self.toggle_done()
|
2018-02-25 21:06:11 +00:00
|
|
|
self.manage()
|
|
|
|
|
|
|
|
elif menu == 't':
|
|
|
|
self.manage_timeslot()
|
|
|
|
self.manage_menu()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
elif menu == '<':
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_fail('This is not implemented...')
|
2018-02-25 20:31:42 +00:00
|
|
|
self.manage_menu()
|
|
|
|
|
2018-03-13 20:49:47 +00:00
|
|
|
def toggle_active(self):
|
|
|
|
active = self.params.get('active')
|
|
|
|
self.params.update('active', not active)
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_message('parameter "active" has been toggled')
|
2018-03-13 20:49:47 +00:00
|
|
|
|
2018-02-25 20:31:42 +00:00
|
|
|
def toggle_done(self):
|
|
|
|
done = self.params.get('done')
|
|
|
|
self.params.update('done', not done)
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_message('parameter "done" has been toggled')
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
def manage_timeslot(self):
|
|
|
|
self.manage_timeslot_menu()
|
|
|
|
|
|
|
|
def manage_timeslot_menu(self):
|
2019-01-07 06:58:44 +00:00
|
|
|
about = '''
|
|
|
|
Short instruction
|
|
|
|
-----------------
|
|
|
|
? - help (this dialog)
|
|
|
|
+ - add time slot
|
|
|
|
- - remove time slot
|
|
|
|
< - back
|
|
|
|
q - exit
|
|
|
|
'''
|
|
|
|
self.screen.change_path('~config/time_slot', '?+-<q', about, 'Managing time slots')
|
|
|
|
menu = self.screen.print()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
if menu == 'q':
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.bye()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
elif menu == '?':
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.activate_about()
|
|
|
|
self.manage_timeslot_menu()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
elif menu == '+':
|
|
|
|
self.add_time_slot()
|
|
|
|
|
|
|
|
elif menu == '-':
|
|
|
|
self.remove_time_slot()
|
|
|
|
|
|
|
|
elif menu == '<':
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_fail('This is not implemented...')
|
|
|
|
self.manage_timeslot_menu()
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
def add_time_slot(self):
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.print_init('Adding time slot')
|
2018-02-25 20:31:42 +00:00
|
|
|
name = input('Name (short): ')
|
|
|
|
description = input('Description: ')
|
|
|
|
tid = self.model.create_time_slot(name, description)
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_message('time slot has been created')
|
2018-02-25 20:31:42 +00:00
|
|
|
self.manage()
|
|
|
|
|
|
|
|
def search_tag(self, tid=None):
|
|
|
|
tagsData = self.model.get_all_tags()
|
|
|
|
if not tagsData:
|
|
|
|
self.add_tag()
|
|
|
|
tagsData = self.model.get_all_tags()
|
|
|
|
|
|
|
|
tags = []
|
|
|
|
for t in tagsData:
|
|
|
|
tags.append(t['name'])
|
|
|
|
|
|
|
|
selected = self.fzf.prompt(tags)
|
|
|
|
if selected:
|
|
|
|
tag = self.model.get_tag_by_name(selected[0])
|
|
|
|
self.manage_tag(tag['id'])
|
|
|
|
else:
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_fail('Tag was not selected...')
|
2018-02-25 20:31:42 +00:00
|
|
|
|
|
|
|
def remove_tag(self, tid=None):
|
|
|
|
tagsData = self.model.get_all_tags()
|
|
|
|
if not tagsData:
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_fail('Where is no tags...')
|
2018-02-25 20:31:42 +00:00
|
|
|
self.manage_tag_menu()
|
|
|
|
|
|
|
|
tags = []
|
|
|
|
for t in tagsData:
|
|
|
|
tags.append(t['name'])
|
|
|
|
|
|
|
|
selected = self.fzf.prompt(tags)
|
|
|
|
if selected:
|
|
|
|
self.model.remove_tag_by_name(selected[0])
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_message('tag has been deleted')
|
2018-02-25 20:31:42 +00:00
|
|
|
self.manage_tag()
|
|
|
|
else:
|
2019-01-07 06:58:44 +00:00
|
|
|
self.screen.add_fail('Tag was not selected...')
|