mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Modif item pour passage en bdd
This commit is contained in:
		
							parent
							
								
									a1c4166d19
								
							
						
					
					
						commit
						783044bab7
					
				
					 8 changed files with 82 additions and 62 deletions
				
			
		|  | @ -5,12 +5,13 @@ using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Runtime.Serialization; | using System.Runtime.Serialization; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  | using System.Threading.Tasks; | ||||||
| using System.Xml; | using System.Xml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib | namespace AideDeJeuLib | ||||||
| { | { | ||||||
|     [DataContract] |     [DataContract] | ||||||
|     public class Item : IList<Item> |     public class Item //: IList<Item> | ||||||
|     { |     { | ||||||
|         private List<Item> _Items; |         private List<Item> _Items; | ||||||
| 
 | 
 | ||||||
|  | @ -29,68 +30,73 @@ namespace AideDeJeuLib | ||||||
|             _Items = new List<Item>(); |             _Items = new List<Item>(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public string Header { get; set; } |         public async Task<IEnumerable<Item>> GetChildrenAsync() | ||||||
| 
 |  | ||||||
|         public int Count => _Items.Count(); |  | ||||||
| 
 |  | ||||||
|         public bool IsReadOnly => false; |  | ||||||
| 
 |  | ||||||
|         public Item this[int index] { get => _Items[index]; set => _Items[index] = value; } |  | ||||||
| 
 |  | ||||||
|         public IEnumerator<Item> GetEnumerator() |  | ||||||
|         { |         { | ||||||
|             return _Items?.GetEnumerator(); |             return _Items; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         IEnumerator IEnumerable.GetEnumerator() |         //public string Header { get; set; } | ||||||
|         { | 
 | ||||||
|             return _Items?.GetEnumerator(); |         //public int Count => _Items.Count(); | ||||||
|         } | 
 | ||||||
|  |         //public bool IsReadOnly => false; | ||||||
|  | 
 | ||||||
|  |         //public Item this[int index] { get => _Items[index]; set => _Items[index] = value; } | ||||||
|  | 
 | ||||||
|  |         //public IEnumerator<Item> GetEnumerator() | ||||||
|  |         //{ | ||||||
|  |         //    return _Items?.GetEnumerator(); | ||||||
|  |         //} | ||||||
|  | 
 | ||||||
|  |         ////IEnumerator IEnumerable.GetEnumerator() | ||||||
|  |         ////{ | ||||||
|  |         ////    return _Items?.GetEnumerator(); | ||||||
|  |         ////} | ||||||
| 
 | 
 | ||||||
|         public virtual FilterViewModel GetNewFilterViewModel() |         public virtual FilterViewModel GetNewFilterViewModel() | ||||||
|         { |         { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public int IndexOf(Item item) |         //public int IndexOf(Item item) | ||||||
|         { |         //{ | ||||||
|             return _Items.IndexOf(item); |         //    return _Items.IndexOf(item); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public void Insert(int index, Item item) |         //public void Insert(int index, Item item) | ||||||
|         { |         //{ | ||||||
|             _Items.Insert(index, item); |         //    _Items.Insert(index, item); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public void RemoveAt(int index) |         //public void RemoveAt(int index) | ||||||
|         { |         //{ | ||||||
|             _Items.RemoveAt(index); |         //    _Items.RemoveAt(index); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public void Add(Item item) |         public void AddChild(Item item) | ||||||
|         { |         { | ||||||
|             _Items.Add(item); |             _Items.Add(item); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public void Clear() |         //public void Clear() | ||||||
|         { |         //{ | ||||||
|             _Items.Clear(); |         //    _Items.Clear(); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public bool Contains(Item item) |         //public bool Contains(Item item) | ||||||
|         { |         //{ | ||||||
|             return _Items.Contains(item); |         //    return _Items.Contains(item); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public void CopyTo(Item[] array, int arrayIndex) |         //public void CopyTo(Item[] array, int arrayIndex) | ||||||
|         { |         //{ | ||||||
|             _Items.CopyTo(array, arrayIndex); |         //    _Items.CopyTo(array, arrayIndex); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         public bool Remove(Item item) |         //public bool Remove(Item item) | ||||||
|         { |         //{ | ||||||
|             throw new NotImplementedException(); |         //    throw new NotImplementedException(); | ||||||
|         } |         //} | ||||||
| 
 | 
 | ||||||
|         [DataMember] |         [DataMember] | ||||||
|         public virtual string Id { get; set; } |         public virtual string Id { get; set; } | ||||||
|  |  | ||||||
|  | @ -51,21 +51,21 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|         }  |         }  | ||||||
| 
 | 
 | ||||||
|         public List<Item> GetBookmarkCollection(string key) |         public async Task<IEnumerable<Item>> GetBookmarkCollection(string key) | ||||||
|         { |         { | ||||||
|             if (App.Current.Properties.ContainsKey(key)) |             if (App.Current.Properties.ContainsKey(key)) | ||||||
|             { |             { | ||||||
|                 var property = App.Current.Properties[key] as string; |                 var property = App.Current.Properties[key] as string; | ||||||
|                 if (property != null) |                 if (property != null) | ||||||
|                 { |                 { | ||||||
|                     return ToItems(property); |                     return await ToItems(property); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|         public void LoadBookmarkCollection(string key) |         public async Task LoadBookmarkCollection(string key) | ||||||
|         { |         { | ||||||
|             var items = GetBookmarkCollection(key); |             var items = await GetBookmarkCollection(key); | ||||||
|             BookmarkCollection.Clear(); |             BookmarkCollection.Clear(); | ||||||
|             if (items != null) |             if (items != null) | ||||||
|             { |             { | ||||||
|  | @ -76,7 +76,7 @@ namespace AideDeJeu.ViewModels | ||||||
|         public async Task AddBookmarkAsync(string key, Item item) |         public async Task AddBookmarkAsync(string key, Item item) | ||||||
|         { |         { | ||||||
|             var linkItem = new LinkItem() { Name = item.Name, AltName = item.AltName, Link = item.Id }; |             var linkItem = new LinkItem() { Name = item.Name, AltName = item.AltName, Link = item.Id }; | ||||||
|             var items = GetBookmarkCollection(key); |             var items = (await GetBookmarkCollection(key)).ToList(); | ||||||
|             if(items == null) |             if(items == null) | ||||||
|             { |             { | ||||||
|                 items = new List<Item>(); |                 items = new List<Item>(); | ||||||
|  | @ -104,13 +104,13 @@ namespace AideDeJeu.ViewModels | ||||||
|             return md; |             return md; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public List<Item> ToItems(string md) |         public async Task<IEnumerable<Item>> ToItems(string md) | ||||||
|         { |         { | ||||||
|             var item = Store.ToItem(null, md); |             var item = Store.ToItem(null, md); | ||||||
|             //if(item is Items) |             //if(item is Items) | ||||||
|             //{ |             //{ | ||||||
|             var items = item; // as Items; |             var items = item; // as Items; | ||||||
|                 return items.ToList(); |                 return await items.GetChildrenAsync(); | ||||||
|             //} |             //} | ||||||
|             //return new List<Item> { item }; |             //return new List<Item> { item }; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -58,6 +58,19 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public IEnumerable<Item> _Children = new List<Item>(); | ||||||
|  |         public IEnumerable<Item> Children | ||||||
|  |         { | ||||||
|  |             get | ||||||
|  |             { | ||||||
|  |                 return _Children; | ||||||
|  |             } | ||||||
|  |             set | ||||||
|  |             { | ||||||
|  |                 SetProperty(ref _Children, value); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         private Item _SelectedItem; |         private Item _SelectedItem; | ||||||
|         public Item SelectedItem |         public Item SelectedItem | ||||||
|         { |         { | ||||||
|  | @ -106,12 +119,14 @@ namespace AideDeJeu.ViewModels | ||||||
|             { |             { | ||||||
|                 if (Filter != null) |                 if (Filter != null) | ||||||
|                 { |                 { | ||||||
|                     var items = await Filter.FilterItems(AllItems, cancellationToken: cancellationToken); |                     var items = await Filter.FilterItems(await AllItems.GetChildrenAsync(), cancellationToken: cancellationToken); | ||||||
|                     Items = new Item(items.ToList()); |                     Items = new Item(items.ToList()); | ||||||
|  |                     Children = items; | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     Items = AllItems; |                     Items = AllItems; | ||||||
|  |                     Children = await AllItems.GetChildrenAsync(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             catch (OperationCanceledException ex) |             catch (OperationCanceledException ex) | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ namespace AideDeJeu.ViewModels | ||||||
|                             else //if (currentItem is Items) |                             else //if (currentItem is Items) | ||||||
|                             { |                             { | ||||||
|                                 var items = currentItem; // as Items; |                                 var items = currentItem; // as Items; | ||||||
|                                 items.Add(subItem); |                                 items.AddChild(subItem); | ||||||
|                             } |                             } | ||||||
|                             enumerator.MoveNext(); |                             enumerator.MoveNext(); | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|  | @ -53,7 +53,7 @@ | ||||||
|                         <tools:TextChangedBehavior /> |                         <tools:TextChangedBehavior /> | ||||||
|                     </SearchBar.Behaviors> |                     </SearchBar.Behaviors> | ||||||
|                 </SearchBar> |                 </SearchBar> | ||||||
|                 <ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> |                 <ListView Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="ItemsListView" ItemsSource="{Binding Children}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> | ||||||
|                     <ListView.ItemTemplate> |                     <ListView.ItemTemplate> | ||||||
|                         <DataTemplate> |                         <DataTemplate> | ||||||
|                             <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> |                             <ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop"> | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ | ||||||
|         <ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.Navigator.AboutCommand}" />--> |         <ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding Main.Navigator.AboutCommand}" />--> | ||||||
|     </ContentPage.ToolbarItems> |     </ContentPage.ToolbarItems> | ||||||
|     <Grid> |     <Grid> | ||||||
|         <ListView BackgroundColor="{StaticResource bgtan}" x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> |         <ListView BackgroundColor="{StaticResource bgtan}" x:Name="ItemsListView" ItemsSource="{Binding Children}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped"> | ||||||
|             <ListView.Header> |             <ListView.Header> | ||||||
|                 <mdview:MarkdownView  |                 <mdview:MarkdownView  | ||||||
|                 Theme="{StaticResource MonsterMarkdownTheme}"  |                 Theme="{StaticResource MonsterMarkdownTheme}"  | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| using AideDeJeu.ViewModels; | using AideDeJeu.ViewModels; | ||||||
| using AideDeJeuLib; | using AideDeJeuLib; | ||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||
|  | using System.Threading.Tasks; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuUnitTest | namespace AideDeJeuUnitTest | ||||||
| { | { | ||||||
|  | @ -8,17 +9,15 @@ namespace AideDeJeuUnitTest | ||||||
|     public class UnitTest1 |     public class UnitTest1 | ||||||
|     { |     { | ||||||
|         [TestMethod] |         [TestMethod] | ||||||
|         public void TestMethod1() |         public async Task TestMethod1() | ||||||
|         { |         { | ||||||
|             var store = new StoreViewModel(); |             var store = new StoreViewModel(); | ||||||
|             var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md")); |             var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md")); | ||||||
|             var md = item.Markdown; |             var md = item.Markdown; | ||||||
|             if(item is Items) |             var children = await item.GetChildrenAsync(); | ||||||
|  |             foreach(var iitem in children) | ||||||
|             { |             { | ||||||
|                 foreach(var iitem in item as Items) |                 md += iitem.Markdown; | ||||||
|                 { |  | ||||||
|                     md += iitem.Markdown; |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             Assert.IsNotNull(md); |             Assert.IsNotNull(md); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ namespace AideDeJeuWeb.Controllers | ||||||
|             var md = await AideDeJeu.Tools.Helpers.GetResourceStringAsync("AideDeJeu.Data.spells_hd.md"); |             var md = await AideDeJeu.Tools.Helpers.GetResourceStringAsync("AideDeJeu.Data.spells_hd.md"); | ||||||
|             var store = new StoreViewModel(); |             var store = new StoreViewModel(); | ||||||
|             var item = store.ToItem(null, md); |             var item = store.ToItem(null, md); | ||||||
|             var items = item as Items; |             var items = await item.GetChildrenAsync(); | ||||||
| 
 | 
 | ||||||
|             var fitems = items.Where(it => (it as Spell).Source.Contains(classe)).OrderBy(it => (it as Spell).Level).ThenBy(it => it.Name); |             var fitems = items.Where(it => (it as Spell).Source.Contains(classe)).OrderBy(it => (it as Spell).Level).ThenBy(it => it.Name); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez