mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 15:36:07 +00:00 
			
		
		
		
	Anchors
This commit is contained in:
		
							parent
							
								
									649c1acd14
								
							
						
					
					
						commit
						d738fc87b4
					
				
					 2 changed files with 68 additions and 32 deletions
				
			
		|  | @ -1,4 +1,5 @@ | ||||||
| using AideDeJeuLib; | using AideDeJeu.Tools; | ||||||
|  | using AideDeJeuLib; | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||||
|  | @ -18,20 +19,58 @@ namespace AideDeJeu.ViewModels | ||||||
|             set => SetProperty(ref _isLoading, value); |             set => SetProperty(ref _isLoading, value); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private Dictionary<string, Item> _AllItems = new Dictionary<string, Item>(); |         void AddAnchor(Dictionary<string, Item> anchors, Item item) | ||||||
|         public async Task<Item> GetItemFromDataAsync(string source) |         { | ||||||
|  |             if (item != null) | ||||||
|  |             { | ||||||
|  |                 var basename = Helpers.IdFromName(item.Name); | ||||||
|  |                 var name = basename; | ||||||
|  |                 int index = 0; | ||||||
|  |                 while (true) | ||||||
|  |                 { | ||||||
|  |                     if (!anchors.ContainsKey(name)) | ||||||
|  |                     { | ||||||
|  |                         anchors.Add(name, item); | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|  |                     index++; | ||||||
|  |                     name = $"{basename}{index}"; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         void MakeAnchors(Dictionary<string, Item> anchors, Item baseItem) | ||||||
|  |         { | ||||||
|  |             AddAnchor(anchors, baseItem); | ||||||
|  |             if(baseItem is Items) | ||||||
|  |             { | ||||||
|  |                 foreach(var item in (baseItem as Items)) | ||||||
|  |                 { | ||||||
|  |                     MakeAnchors(anchors, item); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public class ItemWithAnchors | ||||||
|  |         { | ||||||
|  |             public Item Item { get; set; } | ||||||
|  |             public Dictionary<string, Item> Anchors { get; set; } = new Dictionary<string, Item>(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         private Dictionary<string, ItemWithAnchors> _AllItems = new Dictionary<string, ItemWithAnchors>(); | ||||||
|  |         public async Task<Item> GetItemFromDataAsync(string source, string anchor) | ||||||
|         { |         { | ||||||
|             if (!_AllItems.ContainsKey(source)) |             if (!_AllItems.ContainsKey(source)) | ||||||
|             { |             { | ||||||
|                 //var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{source}.md"); |                 //var md = await Tools.Helpers.GetStringFromUrl($"https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/{source}.md"); | ||||||
|                 var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md"); |                 var md = await Tools.Helpers.GetResourceStringAsync($"AideDeJeu.Data.{source}.md"); | ||||||
|                 //return Tools.MarkdownExtensions.ToItem(md); |  | ||||||
|                 if (md != null) |                 if (md != null) | ||||||
|                 { |                 { | ||||||
|                     var item = Tools.MarkdownExtensions.ToItem(md); |                     var item = Tools.MarkdownExtensions.ToItem(md); | ||||||
|                     if (item != null) |                     if (item != null) | ||||||
|                     { |                     { | ||||||
|                         _AllItems[source] = item; |                         var anchors = new Dictionary<string, Item>(); | ||||||
|  |                         MakeAnchors(anchors, item); | ||||||
|  |                         _AllItems[source] = new ItemWithAnchors() { Item = item, Anchors = anchors }; | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
|  | @ -43,7 +82,15 @@ namespace AideDeJeu.ViewModels | ||||||
|                     return null; |                     return null; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             return _AllItems[source]; |             var itemWithAnchors = _AllItems[source]; | ||||||
|  |             if (!string.IsNullOrEmpty(anchor)) | ||||||
|  |             { | ||||||
|  |                 if (itemWithAnchors.Anchors.ContainsKey(anchor)) | ||||||
|  |                 { | ||||||
|  |                     return itemWithAnchors.Anchors[anchor]; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             return itemWithAnchors.Item; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public Command LoadItemsCommand { get; private set; } |         public Command LoadItemsCommand { get; private set; } | ||||||
|  |  | ||||||
|  | @ -73,7 +73,7 @@ namespace AideDeJeu.ViewModels | ||||||
|                 var with = match.Groups["with"].Value; |                 var with = match.Groups["with"].Value; | ||||||
|                 Main.IsBusy = true; |                 Main.IsBusy = true; | ||||||
|                 Main.IsLoading = true; |                 Main.IsLoading = true; | ||||||
|                 var item = await Main.GetItemFromDataAsync(file); |                 var item = await Main.GetItemFromDataAsync(file, anchor); | ||||||
|                 Main.IsBusy = false; |                 Main.IsBusy = false; | ||||||
|                 Main.IsLoading = false; |                 Main.IsLoading = false; | ||||||
|                 if (item != null) |                 if (item != null) | ||||||
|  | @ -81,37 +81,26 @@ namespace AideDeJeu.ViewModels | ||||||
|                     if (item is Items) |                     if (item is Items) | ||||||
|                     { |                     { | ||||||
|                         var items = item as Items; |                         var items = item as Items; | ||||||
|                         if (!string.IsNullOrEmpty(anchor)) |                         var filterViewModel = items.GetNewFilterViewModel(); | ||||||
|  |                         var itemsViewModel = new ItemsViewModel() { AllItems = items, Filter = filterViewModel }; | ||||||
|  |                         itemsViewModel.LoadItemsCommand.Execute(null); | ||||||
|  |                         if(!string.IsNullOrEmpty(with)) | ||||||
|                         { |                         { | ||||||
|                             var subitem = items.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); |                             var swith = with.Split('_'); | ||||||
|                             if (subitem != null) |                             for (int i = 0; i < swith.Length / 2; i++) | ||||||
|                             { |                             { | ||||||
|                                 await GotoItemDetailPageAsync(subitem); |                                 var key = swith[i * 2 + 0]; | ||||||
|  |                                 var val = swith[i * 2 + 1]; | ||||||
|  |                                 filterViewModel.FilterWith(key, val); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  |                         if (filterViewModel == null) | ||||||
|  |                         { | ||||||
|  |                             await GotoItemsPageAsync(itemsViewModel); | ||||||
|  |                         } | ||||||
|                         else |                         else | ||||||
|                         { |                         { | ||||||
|                             var filterViewModel = items.GetNewFilterViewModel(); |                             await GotoFilteredItemsPageAsync(itemsViewModel); | ||||||
|                             var itemsViewModel = new ItemsViewModel() { AllItems = items, Filter = filterViewModel }; |  | ||||||
|                             itemsViewModel.LoadItemsCommand.Execute(null); |  | ||||||
|                             if(!string.IsNullOrEmpty(with)) |  | ||||||
|                             { |  | ||||||
|                                 var swith = with.Split('_'); |  | ||||||
|                                 for (int i = 0; i < swith.Length / 2; i++) |  | ||||||
|                                 { |  | ||||||
|                                     var key = swith[i * 2 + 0]; |  | ||||||
|                                     var val = swith[i * 2 + 1]; |  | ||||||
|                                     filterViewModel.FilterWith(key, val); |  | ||||||
|                                 } |  | ||||||
|                             } |  | ||||||
|                             if (filterViewModel == null) |  | ||||||
|                             { |  | ||||||
|                                 await GotoItemsPageAsync(itemsViewModel); |  | ||||||
|                             } |  | ||||||
|                             else |  | ||||||
|                             { |  | ||||||
|                                 await GotoFilteredItemsPageAsync(itemsViewModel); |  | ||||||
|                             } |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez