diff --git a/app/appdb.cls b/app/appdb.cls index f64024c..20d69a3 100644 --- a/app/appdb.cls +++ b/app/appdb.cls @@ -108,6 +108,7 @@ Say 'NO CONTACT FOUND' return END + return contacts[1] /* Rexx is 1-indexed */ /*************************** @@ -135,6 +136,46 @@ END return contacts + /*********************** + * Get Contact Details * + ***********************/ + ::METHOD getContactDetails + expose db + use arg contactID + + contact = self~getContact(contactId) + if contact \= .nil then do + /* Get Phone Numbers */ + psql = "SELECT * FROM phone_numbers WHERE contact_id = "contact["ID"] + phones = db~exec(psql,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES) + phone = phones[1] /* just grab the first phone */ + contact["PHONE_NUMBER"] = phone["NUMBER"] + contact["PHONE_TYPE"] = phone["TYPE"] + + /* Now get email addresses */ + esql = "SELECT * FROM email_addresses WHERE contact_id = "contact["ID"] + emails = db~exec(esql,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES) + email = emails[1] + contact["EMAIL_ADDRESS"] = email["EMAIL"] + contact["EMAIL_TYPE"] = email["TYPE"] + + /* Now get real physical address */ + asql = "SELECT * FROM addresses WHERE contact_id = "contact["ID"] + addresses = db~exec(asql,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES) + address = addresses[1] + contact["STREET"] = address["STREET"] + contact["CITY"] = address["CITY"] + contact["STATE"] = address["STATE"] + contact["POSTAL_CODE"] = address["POSTAL_CODE"] + contact["COUNTRY"] = address["COUNTRY"] + + end /* add contact details */ + RETURN contact + + + /*********************** + * Search All Contacts * + ***********************/ ::METHOD searchContacts expose db use arg searchTerm diff --git a/app/appui.cls b/app/appui.cls index 6788c2a..f633369 100644 --- a/app/appui.cls +++ b/app/appui.cls @@ -77,6 +77,8 @@ when clrset = 8 then panel~init_pair(9, panel~COLOR_CYAN, panel~COLOR_BLACK) /* blacken everything to give the appearance of disappearance */ when clrset = 9 then panel~init_pair(10, panel~COLOR_BLACK, panel~COLOR_BLACK) + /* red on black */ + when clrset = 10 then panel~init_pair(11, panel~COLOR_RED, panel~COLOR_BLACK) /* Default to white text on black background */ OTHERWISE DO clrset=0 @@ -97,8 +99,8 @@ max_y = win~lines max_x = win~cols - menu_height = 21 - menu_width = 40 + menu_height = 16 + menu_width = 30 start_y = (max_y - menu_height) % 2 start_x = (max_x - menu_width) % 2 clrset=1 @@ -106,8 +108,8 @@ with_box = .true menuwin = self~DrawSubPanel(menu_height, menu_width, start_y, start_x, clrset, title, with_box) - menu_items = .array~of("[A]dd Contact", "[D]elete Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit") - menu_keys = .array~of("a", "d", "e", "s", "l", "q") + menu_items = .array~of("[V]iew Contact", "[A]dd Contact", "[D]elete Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit") + menu_keys = .array~of("v", "a", "d", "e", "s", "l", "q") .environment~selected = 1 self~DrawMenu(menuwin, menu_items, .environment~selected, win) @@ -148,7 +150,7 @@ win~refresh self~setupMainMenu(win) menuwin~refresh() - RETURN + RETURN /********************** * Add new contact * @@ -261,7 +263,7 @@ end end /* add contact */ self~dropWindow(formwin) - return + RETURN /**************************** * Delete Contact Panel * @@ -272,21 +274,21 @@ /* Create a form panel */ max_y = win~lines max_x = win~cols - form_height = 14 + form_height = 12 form_width = 35 start_y = (max_y - form_height) % 2 start_x = (max_x - form_width) % 2 - delwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 0, "Delete A Contact", .true) + delwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 10, "Delete A Contact", .true) - delwin~mvaddstr(3, 2, "Contact ID: ") - delwin~mvaddstr(form_height-2, 2, "[Enter] to save, [Esc] to cancel") + delwin~mvaddstr(4, 2, "Contact ID: ") + delwin~mvaddstr(form_height-1, 2, "[Enter] to del, [Esc] to cancel") delwin~refresh() - contactId = self~getInputField(delwin, 3, 14, 10) + contactId = self~getInputField(delwin, 4, 14, 10) if contactId = .nil then do self~dropWindow(delwin) RETURN - END + END result = db~deleteContact(contactId) @@ -303,17 +305,95 @@ self~dropWindow(delwin) RETURN + /******************************** + * View Contact Selection Panel * + ********************************/ + ::METHOD viewContactSelectPanel + expose win db menuwin viewselectwin + + /* Create a form panel */ + max_y = win~lines + max_x = win~cols + form_height = 12 + form_width = 35 + start_y = (max_y - form_height) % 2 + start_x = (max_x - form_width) % 2 + viewselectwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 8, "View A Contact", .true) + + viewselectwin~mvaddstr(4, 2, "Contact ID: ") + viewselectwin~mvaddstr(form_height-1, 2, "[Enter] to sel., [Esc] to cancel") + viewselectwin~refresh() + + contactId = self~getInputField(viewselectwin, 4, 14, 10) + if contactId = .nil then do + self~dropWindow(viewselectwin) + RETURN + END + + result = db~getContact(contactId) + + if result = .nil then do /* should be a result id number */ + viewselectwin~mvaddstr(8, 2, "Contact not found.") + viewselectwin~refresh() + call SysWait 0.5 + self~dropWindow(viewselectwin) + RETURN + end + + /* launch a view panel with full contact details */ + self~dropWindow(viewselectwin) + self~viewContactDetailPanel(contactId) + RETURN + + /************************ + * View Contact Details * + ************************/ + ::METHOD viewContactDetailPanel + expose win db menuwin detailwin viewselectwin + use arg contactID + + /* Create a form panel */ + max_y = win~lines + max_x = win~cols + form_height = 14 + form_width = 40 + start_y = (max_y - form_height) % 2 + start_x = (max_x - form_width) % 2 + detailwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 1, "View Contact Details", .true) + + contactDetails = db~getContactDetails(contactId) + + /* Detail fields */ + detailwin~mvaddstr(4, 3, contactDetails~first_name); + detailwin~mvaddstr(4, LENGTH(contactDetails~first_name)+1+3, contactDetails~last_name); + detailwin~mvaddstr(5, 3, contactDetails~street) + detailwin~mvaddstr(6, 3, contactDetails~city); + detailwin~mvaddstr(6, LENGTH(contactDetails~city)+4, contactDetails~state); + detailwin~mvaddstr(6, LENGTH(contactDetails~city)+LENGTH(contactDetails~state)+5, contactDetails~postal_code); + detailwin~mvaddstr(6, LENGTH(contactDetails~city)+LENGTH(contactDetails~state)+LENGTH(contactDetails~postal_code)+6, contactDetails~country) + detailwin~mvaddstr(7, 3, contactDetails~email_address) + detailwin~mvaddstr(8, 3, contactDetails~phone_number) + + detailwin~mvaddstr(form_height-1, 2, "[Esc] to cancel") + detailwin~refresh() + + detailwin~getch() + self~dropWindow(detailwin) + RETURN + + RETURN + /**************************** * List all contacts * ****************************/ - ::method listAllContactsPanel + ::METHOD listAllContactsPanel expose win db menuwin /* Create a list panel */ max_y = win~lines max_x = win~cols - list_height = max_y - 5 - list_width = max_x - 23 + list_height = max_y - 10 + list_width = max_x - 30 start_y = (max_y - list_height) % 2 start_x = (max_x - list_width) % 2 @@ -324,11 +404,11 @@ /* Display column headers */ listwin~attron(listwin~A_BOLD) listwin~mvaddstr(4, 2, "ID") - listwin~mvaddstr(4, 6, "First Name") - listwin~mvaddstr(4, 18, "Last Name") - listwin~mvaddstr(4, 30, "Phone") - listwin~mvaddstr(4, 50, "Email") - listwin~mvaddstr(5, 2, "-- ---------- --------- --------------- -------------------------") + listwin~mvaddstr(4, 5, "First Name") + listwin~mvaddstr(4, 17, "Last Name") + listwin~mvaddstr(4, 29, "Phone") + listwin~mvaddstr(4, 45, "Email") + listwin~mvaddstr(5, 2, "-- ---------- --------- --------------- -------------------------") listwin~attroff(listwin~A_BOLD) contacts = db~getAllContacts() @@ -338,10 +418,10 @@ do i = 1 to contacts~items contact = contacts[i] listwin~mvaddstr(i+5, 2, contact['ID']) - listwin~mvaddstr(i+5, 6, contact['FIRST_NAME']) - listwin~mvaddstr(i+5, 18, contact['LAST_NAME']) - listwin~mvaddstr(i+5, 30, contact['PHONE_NUMBER']) - listwin~mvaddstr(i+5, 50, contact['EMAIL_ADDRESS']) + listwin~mvaddstr(i+5, 5, contact['FIRST_NAME']) + listwin~mvaddstr(i+5, 17, contact['LAST_NAME']) + listwin~mvaddstr(i+5, 29, contact['PHONE_NUMBER']) + listwin~mvaddstr(i+5, 45, contact['EMAIL_ADDRESS']) /* Break if we run out of screen space */ if i > list_height-7 then LEAVE end @@ -358,7 +438,7 @@ /**************************** * Search for contact * ****************************/ - ::method searchContactPanel + ::METHOD searchContactPanel expose win db menuwin menu_items /* Create a search panel */ @@ -401,23 +481,23 @@ /* Create a list panel */ max_y = win~lines max_x = win~cols - list_height = max_y - 5 - list_width = max_x - 23 + list_height = max_y - 15 + list_width = max_x - 30 start_y = (max_y - list_height) % 2 start_x = (max_x - list_width) % 2 - searchoutwin = self~DrawSubPanel(list_height, list_width, start_y, start_x, 1, "All Contacts", .true) - searchoutwin~scrollok(.true) - searchoutwin~Setscrreg(4,18) + searchoutwin = self~DrawSubPanel(list_height, list_width, start_y, start_x, 1, "Search Results", .true) + /* searchoutwin~scrollok(.true) + searchoutwin~Setscrreg(4,18) */ /* Display column headers */ searchoutwin~attron(searchoutwin~A_BOLD) searchoutwin~mvaddstr(4, 2, "ID") - searchoutwin~mvaddstr(4, 6, "First Name") - searchoutwin~mvaddstr(4, 18, "Last Name") - searchoutwin~mvaddstr(4, 30, "Phone") - searchoutwin~mvaddstr(4, 50, "Email") - searchoutwin~mvaddstr(5, 2, "-- ---------- --------- --------------- -------------------------") + searchoutwin~mvaddstr(4, 5, "First Name") + searchoutwin~mvaddstr(4, 17, "Last Name") + searchoutwin~mvaddstr(4, 29, "Phone") + searchoutwin~mvaddstr(4, 45, "Email") + searchoutwin~mvaddstr(5, 2, "-- ---------- --------- --------------- -------------------------") searchoutwin~attroff(searchoutwin~A_BOLD) contacts = db~searchContacts(term) @@ -427,10 +507,10 @@ do i = 1 to contacts~items contact = contacts[i] searchoutwin~mvaddstr(i+5, 2, contact['ID']) - searchoutwin~mvaddstr(i+5, 6, contact['FIRST_NAME']) - searchoutwin~mvaddstr(i+5, 18, contact['LAST_NAME']) - searchoutwin~mvaddstr(i+5, 30, contact['PHONE_NUMBER']) - searchoutwin~mvaddstr(i+5, 50, contact['EMAIL_ADDRESS']) + searchoutwin~mvaddstr(i+5, 5, contact['FIRST_NAME']) + searchoutwin~mvaddstr(i+5, 17, contact['LAST_NAME']) + searchoutwin~mvaddstr(i+5, 29, contact['PHONE_NUMBER']) + searchoutwin~mvaddstr(i+5, 45, contact['EMAIL_ADDRESS']) /* Break if we run out of screen space */ if i > list_height-7 then LEAVE end @@ -444,7 +524,6 @@ RETURN - /************************ * Get Input From Field * ************************/ @@ -567,7 +646,7 @@ self~deleteContactPanel() END when key_char = 'e' then do - menuwin~mvaddstr(19 - 3, 5, "TODO: Create an Edit Panel "); + menuwin~mvaddstr(menuwin~lines-15, 3, "TODO: Create Edit Panel"); menuwin~refresh END when key_char = 's' then do @@ -576,6 +655,9 @@ when key_char = 'l' then do self~listAllContactsPanel() END + when key_char = 'v' then do + self~viewContactSelectPanel() + END when key_char = 'q' then do menuwin~mvaddstr(19 - 3, 5, "Exiting the application... ") menuwin~refresh diff --git a/db/contacts.sqlite b/db/contacts.sqlite index 281ba8b..ba7c7b1 100644 Binary files a/db/contacts.sqlite and b/db/contacts.sqlite differ