From e029441326e05eb5bc73d2f2f2cc13773c7305c2 Mon Sep 17 00:00:00 2001 From: ccbrowndev <46230726+ccbrowndev@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:23:07 -0500 Subject: [PATCH 01/65] Menu backup commit --- Model/UserList.cs | 11 +++++ Model/UserListItem.cs | 10 ++++ ViewModel/MainViewModel.cs | 99 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 Model/UserList.cs create mode 100644 Model/UserListItem.cs create mode 100644 ViewModel/MainViewModel.cs diff --git a/Model/UserList.cs b/Model/UserList.cs new file mode 100644 index 0000000..e2cf795 --- /dev/null +++ b/Model/UserList.cs @@ -0,0 +1,11 @@ +namespace menu.Model +{ + public class UserList + { + public int Id { get; set; } + public int UserId { get; set; } + public string Name { get; set; } + + public List ListItems { get; set; } + } +} diff --git a/Model/UserListItem.cs b/Model/UserListItem.cs new file mode 100644 index 0000000..5b71627 --- /dev/null +++ b/Model/UserListItem.cs @@ -0,0 +1,10 @@ +namespace menu.Model +{ + public class UserListItem + { + public int Id { get; set; } + public int ListId { get; set; } + public string Text { get; set; } + public bool Completed { get; set; } + } +} diff --git a/ViewModel/MainViewModel.cs b/ViewModel/MainViewModel.cs new file mode 100644 index 0000000..885a68f --- /dev/null +++ b/ViewModel/MainViewModel.cs @@ -0,0 +1,99 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using menu.Model; +using System.Collections.ObjectModel; + +namespace menu.ViewModel +{ + public partial class MainViewModel : ObservableObject + { + public MainViewModel() + { + ListsVisible = false; + Lists = new ObservableCollection(); + Items = new ObservableCollection(); + ActiveList = new UserList() + { + Id = 1 + }; + Lists.Add(ActiveList); + } + + [ObservableProperty] + bool listsVisible; + + [ObservableProperty] + ObservableCollection lists; + + [ObservableProperty] + UserList activeList; + + [ObservableProperty] + ObservableCollection items; + + [ObservableProperty] + string text; + + [ObservableProperty] + bool completed; + + [RelayCommand] + void AddItem() + { + if (string.IsNullOrWhiteSpace(Text)) + return; + + UserListItem newItem = new() + { + Text = Text, + Completed = Completed + }; + + Items.Add(newItem); + Text = String.Empty; + ActiveList.ListItems = Items.ToList(); + } + + [RelayCommand] + void DeleteItem(UserListItem item) + { + if (Items.Contains(item)) + { + Items.Remove(item); + ActiveList.ListItems = Items.ToList(); + } + } + + [RelayCommand] + void AddList() + { + //Save items on existing list + ActiveList.ListItems = Items.ToList(); + int activeListID = ActiveList.Id; + ActiveList = new UserList() + { + Id = activeListID + 1 + }; + Items = new ObservableCollection(); + Lists.Add(ActiveList); + } + + [RelayCommand] + void ToggleListView() + { + ListsVisible = !ListsVisible; + } + + [RelayCommand] + void LoadList() + { + if (ActiveList.ListItems == null) + { + Items = new ObservableCollection(); + return; + } + + Items = new ObservableCollection(ActiveList.ListItems); + } + } +} From be9fe96fac2fe23ee843d49054c327902113890a Mon Sep 17 00:00:00 2001 From: ccbrowndev <46230726+ccbrowndev@users.noreply.github.com> Date: Sun, 26 Nov 2023 11:37:46 -0500 Subject: [PATCH 02/65] Fix backup branch --- .gitattributes | 63 ---------- .gitignore | 9 +- App.xaml.cs | 2 +- AppShell.xaml | 4 +- AppShell.xaml.cs | 2 +- App_Data/MenuLocalDatabase.db | Bin 32768 -> 0 bytes App_Data/SQLiteConnection.cs | 17 --- Data/MenuDatabase.cs | 138 +++++++++++++++++++++ Domain/DatabaseInitializer.cs | 18 --- Domain/IMenuManager.cs | 12 -- Domain/MenuManager.cs | 93 -------------- Domain/User.cs | 11 -- Domain/UserList.cs | 14 --- Domain/UserListItem.cs | 16 --- MainPage.xaml | 109 ++++++++++++----- MainPage.xaml.cs | 25 ++-- MauiProgram.cs | 12 +- Model/UserList.cs | 11 -- Model/UserListItem.cs | 10 -- Models/ListItem.cs | 20 +++ Models/UserList.cs | 17 +++ Platforms/Android/MainActivity.cs | 2 +- Platforms/Android/MainApplication.cs | 2 +- Platforms/MacCatalyst/AppDelegate.cs | 2 +- Platforms/MacCatalyst/Program.cs | 2 +- Platforms/Tizen/Main.cs | 2 +- Platforms/Windows/App.xaml.cs | 3 +- Platforms/Windows/Package.appxmanifest | 2 +- Platforms/iOS/AppDelegate.cs | 2 +- Platforms/iOS/Program.cs | 2 +- README.md | 3 - Resources/Fonts/OpenSans-Regular.ttf | Bin 107144 -> 107168 bytes Resources/Fonts/OpenSans-Semibold.ttf | Bin 111072 -> 111060 bytes Services/AppConfiguration.cs | 39 ------ Services/IAppConfiguration.cs | 13 -- ViewModel/MainViewModel.cs | 99 --------------- ViewModels/MainViewModel.cs | 161 +++++++++++++++++++++++++ menu.csproj | 8 +- menu.sln | 18 +-- 39 files changed, 467 insertions(+), 496 deletions(-) delete mode 100644 .gitattributes delete mode 100644 App_Data/MenuLocalDatabase.db delete mode 100644 App_Data/SQLiteConnection.cs create mode 100644 Data/MenuDatabase.cs delete mode 100644 Domain/DatabaseInitializer.cs delete mode 100644 Domain/IMenuManager.cs delete mode 100644 Domain/MenuManager.cs delete mode 100644 Domain/User.cs delete mode 100644 Domain/UserList.cs delete mode 100644 Domain/UserListItem.cs delete mode 100644 Model/UserList.cs delete mode 100644 Model/UserListItem.cs create mode 100644 Models/ListItem.cs create mode 100644 Models/UserList.cs delete mode 100644 README.md delete mode 100644 Services/AppConfiguration.cs delete mode 100644 Services/IAppConfiguration.cs delete mode 100644 ViewModel/MainViewModel.cs create mode 100644 ViewModels/MainViewModel.cs diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1ff0c42..0000000 --- a/.gitattributes +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### -* text=auto - -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp - -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary - -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary - -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 154e127..104b544 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +## Get latest from `dotnet new gitignore` + +# dotenv files +.env # User-specific files *.rsuser @@ -399,6 +402,7 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +.idea ## ## Visual studio for Mac @@ -475,3 +479,6 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# Vim temporary swap files +*.swp diff --git a/App.xaml.cs b/App.xaml.cs index 29213f5..3c87388 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -9,4 +9,4 @@ public App() MainPage = new AppShell(); } } -} \ No newline at end of file +} diff --git a/AppShell.xaml b/AppShell.xaml index 215e7e0..c6c3df0 100644 --- a/AppShell.xaml +++ b/AppShell.xaml @@ -4,10 +4,10 @@ xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:menu" - Shell.FlyoutBehavior="Disabled"> + Shell.FlyoutBehavior="Flyout"> diff --git a/AppShell.xaml.cs b/AppShell.xaml.cs index 050aadb..0997d77 100644 --- a/AppShell.xaml.cs +++ b/AppShell.xaml.cs @@ -7,4 +7,4 @@ public AppShell() InitializeComponent(); } } -} \ No newline at end of file +} diff --git a/App_Data/MenuLocalDatabase.db b/App_Data/MenuLocalDatabase.db deleted file mode 100644 index 012b038019b9553a6e6fc40c291e0a2c0fc2f514..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeI&&uiLX7{KwQYElKY7s*L@3CNU|jnTsnyUewj1k>2sgw2z<`VIpASZfNUu!H*t zw?AjcC2qP{+I7$ja`+0t_syH<^?5!oIlR1{pE*G&#i#kzbQFq1WlvF6<&6-EqU54$ zH@eoJLe$8wJJGkAXg}1^Xj*%TIp22mphfpLm}Kp009ILKmY** z5I_I{1TrnKJl1rh(NMp3!_miy^cV8V2^OIp%4xE#AN8%aX9=(U*0F?{95O|-R5XLJ zS+rfx>R5f@_B`SGjw5{6KJ%@EXgHKNp;`2-4_@4R7s$!@a1#*Ux|mNtPh=?XnI;-O z?b|2q{y=oCK{Ng-(e}Nb?M6wRSgzM9wO;9((QT+oFdNI8#pNX08V*O-;e6E}Cet0h zO!jt{T3$Emb#*!1s(<}V;r_b+spi>eDmOJhTEUBgW*pTYtKd)e+G$QR_V?AnD(~MV zFXZL5oL$H}-TYP+cLtkro(EB6>sHl`T1{QP-%!L1J6pl4rT-7*Kikoa*R{Wu|Eu)P z-o6~aR(qL#w@3~F1Q0*~0R#|0009ILKmY**o+wa?(); + db.CreateTable(); + } + + public List GetUserLists() + { + List lists = db.Query("SELECT * FROM user_lists"); + + if (lists == null || lists.Count == 0) + { + db.Insert(defaultUserList); + + lists = db.Query("SELECT * FROM user_lists"); + int defaultListId = lists.First().Id; + + foreach (ListItem li in defaultUserList.ListItems) + { + li.UserListId = defaultListId; + db.Insert(li); + } + } + + return lists; + } + + public int SaveUserList(UserList list) + { + if (list.Id != 0) + { + return db.Update(list); + } + else + { + return db.Insert(list); + } + } + + public UserList DeleteUserList(UserList list) + { + int result = db.Delete(list); + if (result == 0) + { + return null; + } else if (result == 1) + { + return list; + } else + { + throw new Exception(string.Format("Error occurred trying to delete UserList {0}", list)); + } + } + + + + public List GetListItemsByListId(int id) + { + return db.Table().Where(li => li.UserListId == id).ToList(); + } + + public ListItem GetListItemById(int id) + { + return db.Table().Where(li => li.Id == id).FirstOrDefault(); + } + + public int SaveListItem(ListItem li) + { + if (li.Id != 0) + { + return db.Update(li); + } else + { + return db.Insert(li); + } + } + + public ListItem DeleteListItem(ListItem li) + { + int result = db.Delete(li); + if (result == 0) + { + return null; + } else if (result == 1) + { + return li; + } else + { + throw new Exception(string.Format("Error occurred trying to delete ListItem {0}", li)); + } + } + + private readonly UserList defaultUserList = new() + { + Name = "Welcome", + ListItems = new List() + { + changeTitleItem, addListItemItem, addListItem, deleteListItemItem + } + }; + + private static readonly ListItem changeTitleItem = new() + { + Text = "Tap \"Welcome\" to change the list title.", + IsComplete = false + }; + + private static readonly ListItem addListItemItem = new() + { + Text = "Type into the placeholder below to add items.", + IsComplete = false + }; + + private static readonly ListItem addListItem = new() + { + Text = "Click the add button to create a new list.", + IsComplete = false + }; + + private static readonly ListItem deleteListItemItem = new() + { + Text = "Swipe to the left on an item to reveal the delete button.", + IsComplete = false + }; + } +} diff --git a/Domain/DatabaseInitializer.cs b/Domain/DatabaseInitializer.cs deleted file mode 100644 index 820aedb..0000000 --- a/Domain/DatabaseInitializer.cs +++ /dev/null @@ -1,18 +0,0 @@ -using SQLite; -using menu.Domain; - -namespace menu.Services -{ - public static class DatabaseInitializer - { - public static void Initialize() - { - using (var db = SQLiteDb.GetConnection()) - { - db.CreateTable(); - db.CreateTable(); - db.CreateTable(); - } - } - } -} diff --git a/Domain/IMenuManager.cs b/Domain/IMenuManager.cs deleted file mode 100644 index 2b61aae..0000000 --- a/Domain/IMenuManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using menu.Domain; - -namespace menu.Services -{ - public interface IMenuManager - { - int AddUser(User user); - void AddUserList(UserList userList); - void AddUserListItem(UserListItem userListItem); - } -} diff --git a/Domain/MenuManager.cs b/Domain/MenuManager.cs deleted file mode 100644 index 2a3ea71..0000000 --- a/Domain/MenuManager.cs +++ /dev/null @@ -1,93 +0,0 @@ -using SQLite; -using menu; -using menu.Domain; -using menu.Services; - -namespace UserSchedule.Services -{ - public class MenuManager : IMenuManager - { - /* Initialize database connection */ - - private readonly SQLiteConnection db; - - public MenuManager() - { - db = SQLiteDb.GetConnection(); - } - - /* Add new Users or lists or Items */ - - // Add a new User - public int AddUser(User user) - { - int currentCount = db.Table().Count(); - user.id = currentCount + 1; - db.Insert(user); - return user.id; - } - - // Add a new List - public void AddUserList(UserList userList) - { - db.Insert(userList); - } - - // Add a new Item - public void AddUserListItem(UserListItem userListItem) - { - db.Insert(userListItem); - } - - // Upload the changes made to the local database (SQLite) - public void SaveChanges() - { - db.Commit(); - } - - - /* Delete Lists or Items */ - - // Delete an existing List - public void DeleteList(int id) - { - var list = GetListByid(id); - if (list != null) - { - db.Delete(id); - } - } - - // Delete an existing Item - public void DeleteItem(int id) - { - var list = GetListByid(id); - if (list != null) - { - var item = GetItemByid(id); - if(item != null) - { - db.Delete(id); - } - } - } - - /* Seek for Lists or Items*/ - - // Seek for Lists - public UserList GetListByid(int listid) - { - var list = db.Table().FirstOrDefault(u => u.id == listid); - return list; - } - - // Seek for items - public UserListItem GetItemByid(int itemid) - { - var item = db.Table().FirstOrDefault(u => u.id == itemid); - return item; - } - - - } -} diff --git a/Domain/User.cs b/Domain/User.cs deleted file mode 100644 index c0aba1b..0000000 --- a/Domain/User.cs +++ /dev/null @@ -1,11 +0,0 @@ -using SQLite; - -namespace menu.Domain -{ - [SQLite.Table("USER")] - public class User - { - [PrimaryKey] public int id { get; set; } - [SQLite.MaxLength(50)] public string name { get; set; } - } -} diff --git a/Domain/UserList.cs b/Domain/UserList.cs deleted file mode 100644 index 0e21302..0000000 --- a/Domain/UserList.cs +++ /dev/null @@ -1,14 +0,0 @@ -using SQLite; -using System.ComponentModel.DataAnnotations.Schema; - -namespace menu.Domain -{ - [SQLite.Table("LIST")] - public class UserList - { - [PrimaryKey] public int id { get; set; } - [ForeignKey("User")] public int Userid { get; set; } - [SQLite.MaxLength(50)]public string name { get; set; } - public List listItems { get; set; } - } -} diff --git a/Domain/UserListItem.cs b/Domain/UserListItem.cs deleted file mode 100644 index 0535229..0000000 --- a/Domain/UserListItem.cs +++ /dev/null @@ -1,16 +0,0 @@ -using SQLite; -using System.ComponentModel.DataAnnotations.Schema; - -namespace menu.Domain -{ - [SQLite.Table("LIST_ITEM")] - public class UserListItem - { - [PrimaryKey] public int id { get; set; } - [ForeignKey("UserList")] public int UserListid { get; set; } - public List subItems { get; set; } - public string text { get; set; } - public bool completed { get; set; } - public DateTime deadline{ get; set; } - } -} \ No newline at end of file diff --git a/MainPage.xaml b/MainPage.xaml index c4600fa..f5b94e5 100644 --- a/MainPage.xaml +++ b/MainPage.xaml @@ -1,41 +1,88 @@  + +