manage time slots
This commit is contained in:
parent
398504a863
commit
7eaa4f7be2
3 changed files with 83 additions and 39 deletions
70
config.py
70
config.py
|
@ -58,7 +58,7 @@ q - exit
|
|||
self.manage()
|
||||
|
||||
elif menu == 't':
|
||||
self.manage_timeslot()
|
||||
self.manage_time_slot_menu()
|
||||
self.manage_menu()
|
||||
|
||||
elif menu == '<':
|
||||
|
@ -78,10 +78,13 @@ q - exit
|
|||
self.params.update('done', not done)
|
||||
self.screen.add_message('parameter "done" has been toggled')
|
||||
|
||||
def manage_timeslot(self):
|
||||
self.manage_timeslot_menu()
|
||||
def manage_time_slot_menu(self):
|
||||
tsData = self.model.get_all_time_slots()
|
||||
if tsData:
|
||||
self.info = ' | '.join(['%s:%s' % (t['name'], t['description']) for t in tsData]) + '\n'
|
||||
else:
|
||||
self.info = None
|
||||
|
||||
def manage_timeslot_menu(self):
|
||||
about = '''
|
||||
Short instruction
|
||||
-----------------
|
||||
|
@ -91,7 +94,7 @@ Short instruction
|
|||
< - back
|
||||
q - exit
|
||||
'''
|
||||
self.screen.change_path('~config/time_slot', '?+-<q', about, 'Managing time slots')
|
||||
self.screen.change_path('~config/time_slot', '?+-<q', about, 'Managing time slots', self.info)
|
||||
menu = self.screen.print()
|
||||
|
||||
if menu == 'q':
|
||||
|
@ -99,7 +102,7 @@ q - exit
|
|||
|
||||
elif menu == '?':
|
||||
self.screen.activate_about()
|
||||
self.manage_timeslot_menu()
|
||||
self.manage_time_slot_menu()
|
||||
|
||||
elif menu == '+':
|
||||
self.add_time_slot()
|
||||
|
@ -112,47 +115,38 @@ q - exit
|
|||
|
||||
else:
|
||||
self.screen.add_fail('This is not implemented...')
|
||||
self.manage_timeslot_menu()
|
||||
self.manage_time_slot_menu()
|
||||
|
||||
def add_time_slot(self):
|
||||
self.screen.print_init('Adding time slot')
|
||||
name = input('Name (short): ')
|
||||
description = input('Description: ')
|
||||
tid = self.model.create_time_slot(name, description)
|
||||
self.model.create_time_slot(name, description)
|
||||
self.screen.add_message('time slot has been created')
|
||||
self.manage()
|
||||
self.manage_time_slot_menu()
|
||||
|
||||
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'])
|
||||
def remove_time_slot(self):
|
||||
ts_id = self.select_time_slot()
|
||||
if ts_id is not None:
|
||||
self.model.remove_time_slot(ts_id)
|
||||
self.screen.add_message('time_slot has been deleted')
|
||||
else:
|
||||
self.screen.add_fail('Tag was not selected...')
|
||||
self.screen.add_fail('Time slot was not selected...')
|
||||
|
||||
def remove_tag(self, tid=None):
|
||||
tagsData = self.model.get_all_tags()
|
||||
if not tagsData:
|
||||
self.screen.add_fail('Where is no tags...')
|
||||
self.manage_tag_menu()
|
||||
self.manage_time_slot_menu()
|
||||
|
||||
tags = []
|
||||
for t in tagsData:
|
||||
tags.append(t['name'])
|
||||
def select_time_slot(self):
|
||||
tsData = self.model.get_all_time_slots()
|
||||
if not tsData:
|
||||
self.screen.add_fail('Where is no time slots...')
|
||||
return
|
||||
|
||||
selected = self.fzf.prompt(tags)
|
||||
ts_ids = {}
|
||||
ts = []
|
||||
for t in tsData:
|
||||
ts.append('%s:%s' % (t['name'], t['description']))
|
||||
ts_ids['%s:%s' % (t['name'], t['description'])] = t['id']
|
||||
|
||||
selected = self.fzf.prompt(ts)
|
||||
if selected:
|
||||
self.model.remove_tag_by_name(selected[0])
|
||||
self.screen.add_message('tag has been deleted')
|
||||
self.manage_tag()
|
||||
else:
|
||||
self.screen.add_fail('Tag was not selected...')
|
||||
return ts_ids[selected[0]]
|
||||
|
|
30
model.py
30
model.py
|
@ -158,3 +158,33 @@ class Model:
|
|||
cursor.execute(query, (task_id, tag['id']))
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
def create_time_slot(self, name, description):
|
||||
query = 'INSERT INTO time_slot (name, description) VALUES (?, ?)'
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(query, (name, description))
|
||||
self.conn.commit()
|
||||
|
||||
return cursor.lastrowid
|
||||
|
||||
def get_all_time_slots(self):
|
||||
query = 'SELECT t.* FROM time_slot t'
|
||||
|
||||
return self.conn.execute(query)
|
||||
|
||||
def remove_time_slot(self, tid):
|
||||
query = 'DELETE FROM time_slot WHERE id = ?'
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(query, (tid,))
|
||||
self.conn.commit()
|
||||
|
||||
def add_tag_to_time_slot(self, t_id, ts_id):
|
||||
query = 'DELETE FROM tag_time_slot WHERE tag_id = ?'
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(query, (t_id,))
|
||||
self.conn.commit()
|
||||
|
||||
query = 'INSERT INTO tag_time_slot (tag_id, time_slot_id) VALUES (?, ?)'
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(query, (t_id, ts_id))
|
||||
self.conn.commit()
|
||||
|
|
22
tag.py
22
tag.py
|
@ -2,6 +2,7 @@ from pyfzf.pyfzf import FzfPrompt
|
|||
|
||||
from model import Model
|
||||
from screen import Screen
|
||||
from config import Config
|
||||
|
||||
|
||||
class Tag:
|
||||
|
@ -9,6 +10,7 @@ class Tag:
|
|||
self.model = Model()
|
||||
self.fzf = FzfPrompt()
|
||||
self.screen = Screen()
|
||||
self.config = Config()
|
||||
|
||||
self.header = ''
|
||||
self.info = None
|
||||
|
@ -37,11 +39,13 @@ Short instruction
|
|||
/ - search tag
|
||||
+ - add tag
|
||||
- - remove tag
|
||||
@ - append to time slot
|
||||
0 - list tags without time_slot
|
||||
& - search linked tasks
|
||||
< - back
|
||||
q - exit
|
||||
'''
|
||||
self.screen.change_path('~tag', '?/+-&<q', about, self.header, self.info)
|
||||
self.screen.change_path('~tag', '?/+-&@0<q', about, self.header, self.info)
|
||||
menu = self.screen.print()
|
||||
|
||||
if menu == 'q':
|
||||
|
@ -61,6 +65,10 @@ q - exit
|
|||
elif menu == '-':
|
||||
self.remove_tag(tid)
|
||||
|
||||
elif menu == '@':
|
||||
self.add_to_time_slot(tid)
|
||||
self.manage_tag(tid)
|
||||
|
||||
elif menu == '<':
|
||||
return
|
||||
|
||||
|
@ -109,3 +117,15 @@ q - exit
|
|||
self.manage_tag()
|
||||
else:
|
||||
self.screen.add_fail('Tag was not selected...')
|
||||
|
||||
def add_to_time_slot(self, tid):
|
||||
if tid is None:
|
||||
self.screen.add_fail('Tag is not selected...')
|
||||
return
|
||||
|
||||
ts_id = self.config.select_time_slot()
|
||||
if ts_id is None:
|
||||
self.screen.add_fail('Time slot was not selected...')
|
||||
return
|
||||
|
||||
self.model.add_tag_to_time_slot(tid, ts_id)
|
||||
|
|
Reference in a new issue