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()
|
self.manage()
|
||||||
|
|
||||||
elif menu == 't':
|
elif menu == 't':
|
||||||
self.manage_timeslot()
|
self.manage_time_slot_menu()
|
||||||
self.manage_menu()
|
self.manage_menu()
|
||||||
|
|
||||||
elif menu == '<':
|
elif menu == '<':
|
||||||
|
@ -78,10 +78,13 @@ q - exit
|
||||||
self.params.update('done', not done)
|
self.params.update('done', not done)
|
||||||
self.screen.add_message('parameter "done" has been toggled')
|
self.screen.add_message('parameter "done" has been toggled')
|
||||||
|
|
||||||
def manage_timeslot(self):
|
def manage_time_slot_menu(self):
|
||||||
self.manage_timeslot_menu()
|
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 = '''
|
about = '''
|
||||||
Short instruction
|
Short instruction
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -91,7 +94,7 @@ Short instruction
|
||||||
< - back
|
< - back
|
||||||
q - exit
|
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()
|
menu = self.screen.print()
|
||||||
|
|
||||||
if menu == 'q':
|
if menu == 'q':
|
||||||
|
@ -99,7 +102,7 @@ q - exit
|
||||||
|
|
||||||
elif menu == '?':
|
elif menu == '?':
|
||||||
self.screen.activate_about()
|
self.screen.activate_about()
|
||||||
self.manage_timeslot_menu()
|
self.manage_time_slot_menu()
|
||||||
|
|
||||||
elif menu == '+':
|
elif menu == '+':
|
||||||
self.add_time_slot()
|
self.add_time_slot()
|
||||||
|
@ -112,47 +115,38 @@ q - exit
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.screen.add_fail('This is not implemented...')
|
self.screen.add_fail('This is not implemented...')
|
||||||
self.manage_timeslot_menu()
|
self.manage_time_slot_menu()
|
||||||
|
|
||||||
def add_time_slot(self):
|
def add_time_slot(self):
|
||||||
self.screen.print_init('Adding time slot')
|
self.screen.print_init('Adding time slot')
|
||||||
name = input('Name (short): ')
|
name = input('Name (short): ')
|
||||||
description = input('Description: ')
|
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.screen.add_message('time slot has been created')
|
||||||
self.manage()
|
self.manage_time_slot_menu()
|
||||||
|
|
||||||
def search_tag(self, tid=None):
|
def remove_time_slot(self):
|
||||||
tagsData = self.model.get_all_tags()
|
ts_id = self.select_time_slot()
|
||||||
if not tagsData:
|
if ts_id is not None:
|
||||||
self.add_tag()
|
self.model.remove_time_slot(ts_id)
|
||||||
tagsData = self.model.get_all_tags()
|
self.screen.add_message('time_slot has been deleted')
|
||||||
|
|
||||||
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:
|
else:
|
||||||
self.screen.add_fail('Tag was not selected...')
|
self.screen.add_fail('Time slot was not selected...')
|
||||||
|
|
||||||
def remove_tag(self, tid=None):
|
self.manage_time_slot_menu()
|
||||||
tagsData = self.model.get_all_tags()
|
|
||||||
if not tagsData:
|
|
||||||
self.screen.add_fail('Where is no tags...')
|
|
||||||
self.manage_tag_menu()
|
|
||||||
|
|
||||||
tags = []
|
def select_time_slot(self):
|
||||||
for t in tagsData:
|
tsData = self.model.get_all_time_slots()
|
||||||
tags.append(t['name'])
|
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:
|
if selected:
|
||||||
self.model.remove_tag_by_name(selected[0])
|
return ts_ids[selected[0]]
|
||||||
self.screen.add_message('tag has been deleted')
|
|
||||||
self.manage_tag()
|
|
||||||
else:
|
|
||||||
self.screen.add_fail('Tag was not selected...')
|
|
||||||
|
|
30
model.py
30
model.py
|
@ -158,3 +158,33 @@ class Model:
|
||||||
cursor.execute(query, (task_id, tag['id']))
|
cursor.execute(query, (task_id, tag['id']))
|
||||||
|
|
||||||
self.conn.commit()
|
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 model import Model
|
||||||
from screen import Screen
|
from screen import Screen
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class Tag:
|
class Tag:
|
||||||
|
@ -9,6 +10,7 @@ class Tag:
|
||||||
self.model = Model()
|
self.model = Model()
|
||||||
self.fzf = FzfPrompt()
|
self.fzf = FzfPrompt()
|
||||||
self.screen = Screen()
|
self.screen = Screen()
|
||||||
|
self.config = Config()
|
||||||
|
|
||||||
self.header = ''
|
self.header = ''
|
||||||
self.info = None
|
self.info = None
|
||||||
|
@ -37,11 +39,13 @@ Short instruction
|
||||||
/ - search tag
|
/ - search tag
|
||||||
+ - add tag
|
+ - add tag
|
||||||
- - remove tag
|
- - remove tag
|
||||||
|
@ - append to time slot
|
||||||
|
0 - list tags without time_slot
|
||||||
& - search linked tasks
|
& - search linked tasks
|
||||||
< - back
|
< - back
|
||||||
q - exit
|
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()
|
menu = self.screen.print()
|
||||||
|
|
||||||
if menu == 'q':
|
if menu == 'q':
|
||||||
|
@ -61,6 +65,10 @@ q - exit
|
||||||
elif menu == '-':
|
elif menu == '-':
|
||||||
self.remove_tag(tid)
|
self.remove_tag(tid)
|
||||||
|
|
||||||
|
elif menu == '@':
|
||||||
|
self.add_to_time_slot(tid)
|
||||||
|
self.manage_tag(tid)
|
||||||
|
|
||||||
elif menu == '<':
|
elif menu == '<':
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -109,3 +117,15 @@ q - exit
|
||||||
self.manage_tag()
|
self.manage_tag()
|
||||||
else:
|
else:
|
||||||
self.screen.add_fail('Tag was not selected...')
|
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