Commits

Anonymous committed 74172f9

adding the showing of notes

Comments (0)

Files changed (3)

gadgets/ui/dialogs/help.py

         win.addstr(row, 2, 'hit any key to exit help')
         win.move(row+1, 2)
         x = win.getch()
-        self._lock.release()
+        self._lock.release()

gadgets/ui/dialogs/notes.py

              (host text, method_id integer, timestamp integer, notes text)'''
 
     _insert = '''INSERT INTO notes VALUES(?, ?, ?, ?)'''
+    _notes_query = '''SELECT * FROM notes WHERE host = ? ORDER BY timestamp DESC LIMIT 10'''
 
     def __init__(self, socket, lock, db):
         self.name = None
         timestamp=datetime.datetime.now()
         self._db.save(self._insert, (self._name, method_id, int(timestamp.strftime('%s')), notes))
 
-    def __call__(self, screen, data, method_id=None):
-        self._lock.acquire()
-        win = self._get_subwin(screen)
-        self._add_title(win, self.__doc__)
+    def _get_notes(self, win):
         curses.echo()
         curses.curs_set(1)
         notes = ''
         curses.curs_set(0)
         if notes != '':
             self._save(notes, method_id)
+
+    def _show_notes(self, win):
+        notes = [note for note in self._db.execute(self._notes_query, self._name)]
+        row = 2
+        for note in notes:
+            win.addstr(row, 2, str(note[0]))
+            row += 1
+
+    def __call__(self, screen, data, method_id=None, command=None):
+        self._lock.acquire()
+        win = self._get_subwin(screen)
+        self._add_title(win, self.__doc__)
+        if command = 'n':
+            self._get_notes(win)
+        elif command = 'N':
+            self._show_notes(win)
         self._lock.release()
         
         self._dialogs = {
             ord('c'): self.Dialog(self._enter_command_mode, None),
             ord('C'): self.Dialog(Command(self, self._lock), None),
-            ord('n'): self.Dialog(Notes(self.sockets, self._lock, self._db), self._get_method_id),
+            ord('n'): self.Dialog(Notes(self.sockets, self._lock, self._db), self._get_notes_args),
+            ord('N'): self.Dialog(Notes(self.sockets, self._lock, self._db), self._get_notes_args),
             ord('m'): self.Dialog(Method(self.sockets, self._lock, self._db), None),
             ord('f'): self.Dialog(self._user_confirmed, None),
         }
     def add_dialog(self, key, DialogClass, dialog_kw):
         self._dialogs[ord(key)] = self.Dialog(DialogClass(self.sockets, self._lock, self._db), dialog_kw)
 
-    def _get_method_id(self):
-        return {'method_id': self._data.get('method', {}).get('_id')}
+    def _get_notes_args(self, command):
+        return {'command': command, 'method_id': self._data.get('method', {}).get('_id')}
 
     def set_data(self, data):
         self._data = data
         if dialog is not None:
             kw_factory = dialog.keyword_factory
             if kw_factory is not None:
-                kw = kw_factory()
+                kw = kw_factory(x)
             else:
                 kw = {}
             dialog.callable(self._screen, self._data, **kw)
         color = curses.A_BOLD | curses.A_STANDOUT | curses.color_pair(1)
         self._screen.addstr(self._row + 1, self._col, msg, color)
         if self._command_mode.is_active:
-            msg = 'COMMAND MODE'
-            self._screen.addstr(self._row + 1, self._col + ((self._width / 2 - (len(msg)/2))), msg, color)
+            msg = '{0} COMMAND MODE'.format(self._name)
+        else:
+            msg = self._name
+        self._screen.addstr(self._row + 1, self._col + ((self._width / 2 - (len(msg)/2))), msg, color)
 
     def _draw_bottom_bar(self):
         if len(self._data.get('errors', [])) > 0: