mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +00:00 
			
		
		
		
	RootId + Like
This commit is contained in:
		
							parent
							
								
									2230ddea79
								
							
						
					
					
						commit
						9d83e524cd
					
				
					 8 changed files with 27 additions and 11 deletions
				
			
		|  | @ -34,12 +34,12 @@ namespace AideDeJeu.Droid | ||||||
|             //string dbPath = Path.Combine(path, databaseName); |             //string dbPath = Path.Combine(path, databaseName); | ||||||
|             //return dbPath; |             //return dbPath; | ||||||
|             var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); |             var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); | ||||||
|             var path = Path.Combine(documentsDirectoryPath, databaseName); |             var path = Path.Combine(documentsDirectoryPath, $"{databaseName}.db"); | ||||||
| 
 | 
 | ||||||
|             // This is where we copy in our pre-created database |             // This is where we copy in our pre-created database | ||||||
|             if (!File.Exists(path)) |             if (!File.Exists(path)) | ||||||
|             { |             { | ||||||
|                 using (var inStream = Android.App.Application.Context.Assets.Open(databaseName)) |                 using (var inStream = Android.App.Application.Context.Assets.Open($"{databaseName}.db")) | ||||||
|                 { |                 { | ||||||
|                     using (var outStream = new FileStream(path, FileMode.Create)) |                     using (var outStream = new FileStream(path, FileMode.Create)) | ||||||
|                     { |                     { | ||||||
|  |  | ||||||
|  | @ -26,12 +26,12 @@ namespace AideDeJeu.UWP | ||||||
|         public async Task<string> GetDatabasePathAsync(string databaseName) |         public async Task<string> GetDatabasePathAsync(string databaseName) | ||||||
|         { |         { | ||||||
|             var documentsDirectoryPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path; |             var documentsDirectoryPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path; | ||||||
|             var path = Path.Combine(documentsDirectoryPath, databaseName); |             var path = Path.Combine(documentsDirectoryPath, $"{databaseName}.db"); | ||||||
| 
 | 
 | ||||||
|             if (!File.Exists(path)) |             if (!File.Exists(path)) | ||||||
|             { |             { | ||||||
|                 var assembly = typeof(Version_UWP).GetTypeInfo().Assembly; |                 var assembly = typeof(Version_UWP).GetTypeInfo().Assembly; | ||||||
|                 using (var inStream = assembly.GetManifestResourceStream("AideDeJeu.UWP." + databaseName)) |                 using (var inStream = assembly.GetManifestResourceStream($"AideDeJeu.UWP.{databaseName}.db")) | ||||||
|                 { |                 { | ||||||
|                     using (var outStream = new FileStream(path, FileMode.Create)) |                     using (var outStream = new FileStream(path, FileMode.Create)) | ||||||
|                     { |                     { | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ namespace AideDeJeu.Droid | ||||||
| 
 | 
 | ||||||
|         public async Task<string> GetDatabasePathAsync(string databaseName) |         public async Task<string> GetDatabasePathAsync(string databaseName) | ||||||
|         { |         { | ||||||
|             return NSBundle.MainBundle.PathForResource("library", "db"); |             return NSBundle.MainBundle.PathForResource(databaseName, "db"); | ||||||
|             //var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", databaseName); |             //var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", databaseName); | ||||||
|             //return databasePath; |             //return databasePath; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| using AideDeJeu.ViewModels; | using AideDeJeu.ViewModels; | ||||||
|  | using SQLite; | ||||||
| using System; | using System; | ||||||
| using System.Collections; | using System.Collections; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
|  | @ -99,8 +100,12 @@ namespace AideDeJeuLib | ||||||
|         //} |         //} | ||||||
| 
 | 
 | ||||||
|         [DataMember] |         [DataMember] | ||||||
|  |         [PrimaryKey] | ||||||
|         public virtual string Id { get; set; } |         public virtual string Id { get; set; } | ||||||
|         [DataMember] |         [DataMember] | ||||||
|  |         [Indexed] | ||||||
|  |         public string RootId { get; set; } | ||||||
|  |         [DataMember] | ||||||
|         public string Name { get; set; } |         public string Name { get; set; } | ||||||
|         [DataMember] |         [DataMember] | ||||||
|         public int NameLevel { get; set; } |         public int NameLevel { get; set; } | ||||||
|  |  | ||||||
|  | @ -62,15 +62,26 @@ namespace AideDeJeu.ViewModels | ||||||
|             using (var context = await StoreViewModel.GetLibraryContextAsync()) |             using (var context = await StoreViewModel.GetLibraryContextAsync()) | ||||||
|             { |             { | ||||||
|                 var primary = await context.Items. |                 var primary = await context.Items. | ||||||
|                     Where(item => item.Name.Contains(searchText)). |                     Where(item => EF.Functions.Like(item.Name, $"%{searchText}%")). | ||||||
|                     Select(item => new SearchedItem() { Item = item, Preview = item.Name }). |                     Select(item => new SearchedItem() { Item = item, Preview = item.Name }). | ||||||
|                     ToListAsync(); |                     ToListAsync(); | ||||||
|                 var secondary = await context.Items. |                 var secondary = await context.Items. | ||||||
|                     Where(item => item.Markdown.Contains(searchText)). |                     Where(item => EF.Functions.Like(item.Markdown, $"%{searchText}%")). | ||||||
|                     Select(item => new SearchedItem() |                     Select(item => new SearchedItem() | ||||||
|                     { |                     { | ||||||
|                         Item = item, Preview = GetPreview(item.Markdown, searchText) |                         Item = item, Preview = GetPreview(item.Markdown, searchText) | ||||||
|                     }).ToListAsync(); |                     }).ToListAsync(); | ||||||
|  |                 //var primary = await context.Items. | ||||||
|  |                 //    Where(item => item.Name.Contains(searchText)). | ||||||
|  |                 //    Select(item => new SearchedItem() { Item = item, Preview = item.Name }). | ||||||
|  |                 //    ToListAsync(); | ||||||
|  |                 //var secondary = await context.Items. | ||||||
|  |                 //    Where(item => item.Markdown.Contains(searchText)). | ||||||
|  |                 //    Select(item => new SearchedItem() | ||||||
|  |                 //    { | ||||||
|  |                 //        Item = item, | ||||||
|  |                 //        Preview = GetPreview(item.Markdown, searchText) | ||||||
|  |                 //    }).ToListAsync(); | ||||||
|                 primary.AddRange(secondary); |                 primary.AddRange(secondary); | ||||||
|                 return primary.ToList(); |                 return primary.ToList(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -357,7 +357,7 @@ namespace AideDeJeu.ViewModels | ||||||
|                             { |                             { | ||||||
|                                 var anchors = new Dictionary<string, Item>(); |                                 var anchors = new Dictionary<string, Item>(); | ||||||
|                                 //MakeAnchors(source, anchors, item); |                                 //MakeAnchors(source, anchors, item); | ||||||
|                                 item.Id = $"{source}.md"; |                                 item.RootId = $"{source}.md"; | ||||||
|                                 _AllItems[source] = item; |                                 _AllItems[source] = item; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  | @ -404,7 +404,7 @@ namespace AideDeJeu.ViewModels | ||||||
| 
 | 
 | ||||||
|         public static async Task<AideDeJeuContext> GetLibraryContextAsync() |         public static async Task<AideDeJeuContext> GetLibraryContextAsync() | ||||||
|         { |         { | ||||||
|             var dbPath = await DependencyService.Get<INativeAPI>().GetDatabasePathAsync("library.db"); |             var dbPath = await DependencyService.Get<INativeAPI>().GetDatabasePathAsync("library"); | ||||||
|             return new AideDeJeuContext(dbPath); |             return new AideDeJeuContext(dbPath); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -417,7 +417,7 @@ namespace AideDeJeu.ViewModels | ||||||
|             } |             } | ||||||
|             using (var context = await GetLibraryContextAsync()) |             using (var context = await GetLibraryContextAsync()) | ||||||
|             { |             { | ||||||
|                 return await context.Items.Where(item => item.Id == id).FirstOrDefaultAsync(); |                 return await context.Items.Where(item => item.Id == id || item.RootId == id).FirstOrDefaultAsync(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ namespace AideDeJeu.Cmd | ||||||
| 
 | 
 | ||||||
|         public async Task<string> GetDatabasePathAsync(string databaseName) |         public async Task<string> GetDatabasePathAsync(string databaseName) | ||||||
|         { |         { | ||||||
|             return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\..\..\..\..\Data\" + databaseName); |             return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $@"..\..\..\..\..\Data\{databaseName}.db"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								Data/library.db
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Data/library.db
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez