mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +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.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
[DataContract]
|
||||
public class Item : IList<Item>
|
||||
public class Item //: IList<Item>
|
||||
{
|
||||
private List<Item> _Items;
|
||||
|
||||
|
|
@ -29,68 +30,73 @@ namespace AideDeJeuLib
|
|||
_Items = new List<Item>();
|
||||
}
|
||||
|
||||
public string Header { get; set; }
|
||||
|
||||
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()
|
||||
public async Task<IEnumerable<Item>> GetChildrenAsync()
|
||||
{
|
||||
return _Items?.GetEnumerator();
|
||||
return _Items;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _Items?.GetEnumerator();
|
||||
}
|
||||
//public string Header { get; set; }
|
||||
|
||||
//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()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int IndexOf(Item item)
|
||||
{
|
||||
return _Items.IndexOf(item);
|
||||
}
|
||||
//public int IndexOf(Item item)
|
||||
//{
|
||||
// return _Items.IndexOf(item);
|
||||
//}
|
||||
|
||||
public void Insert(int index, Item item)
|
||||
{
|
||||
_Items.Insert(index, item);
|
||||
}
|
||||
//public void Insert(int index, Item item)
|
||||
//{
|
||||
// _Items.Insert(index, item);
|
||||
//}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
_Items.RemoveAt(index);
|
||||
}
|
||||
//public void RemoveAt(int index)
|
||||
//{
|
||||
// _Items.RemoveAt(index);
|
||||
//}
|
||||
|
||||
public void Add(Item item)
|
||||
public void AddChild(Item item)
|
||||
{
|
||||
_Items.Add(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_Items.Clear();
|
||||
}
|
||||
//public void Clear()
|
||||
//{
|
||||
// _Items.Clear();
|
||||
//}
|
||||
|
||||
public bool Contains(Item item)
|
||||
{
|
||||
return _Items.Contains(item);
|
||||
}
|
||||
//public bool Contains(Item item)
|
||||
//{
|
||||
// return _Items.Contains(item);
|
||||
//}
|
||||
|
||||
public void CopyTo(Item[] array, int arrayIndex)
|
||||
{
|
||||
_Items.CopyTo(array, arrayIndex);
|
||||
}
|
||||
//public void CopyTo(Item[] array, int arrayIndex)
|
||||
//{
|
||||
// _Items.CopyTo(array, arrayIndex);
|
||||
//}
|
||||
|
||||
public bool Remove(Item item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
//public bool Remove(Item item)
|
||||
//{
|
||||
// throw new NotImplementedException();
|
||||
//}
|
||||
|
||||
[DataMember]
|
||||
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))
|
||||
{
|
||||
var property = App.Current.Properties[key] as string;
|
||||
if (property != null)
|
||||
{
|
||||
return ToItems(property);
|
||||
return await ToItems(property);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void LoadBookmarkCollection(string key)
|
||||
public async Task LoadBookmarkCollection(string key)
|
||||
{
|
||||
var items = GetBookmarkCollection(key);
|
||||
var items = await GetBookmarkCollection(key);
|
||||
BookmarkCollection.Clear();
|
||||
if (items != null)
|
||||
{
|
||||
|
|
@ -76,7 +76,7 @@ namespace AideDeJeu.ViewModels
|
|||
public async Task AddBookmarkAsync(string key, Item item)
|
||||
{
|
||||
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)
|
||||
{
|
||||
items = new List<Item>();
|
||||
|
|
@ -104,13 +104,13 @@ namespace AideDeJeu.ViewModels
|
|||
return md;
|
||||
}
|
||||
|
||||
public List<Item> ToItems(string md)
|
||||
public async Task<IEnumerable<Item>> ToItems(string md)
|
||||
{
|
||||
var item = Store.ToItem(null, md);
|
||||
//if(item is Items)
|
||||
//{
|
||||
var items = item; // as Items;
|
||||
return items.ToList();
|
||||
return await items.GetChildrenAsync();
|
||||
//}
|
||||
//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;
|
||||
public Item SelectedItem
|
||||
{
|
||||
|
|
@ -106,12 +119,14 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
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());
|
||||
Children = items;
|
||||
}
|
||||
else
|
||||
{
|
||||
Items = AllItems;
|
||||
Children = await AllItems.GetChildrenAsync();
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace AideDeJeu.ViewModels
|
|||
else //if (currentItem is Items)
|
||||
{
|
||||
var items = currentItem; // as Items;
|
||||
items.Add(subItem);
|
||||
items.AddChild(subItem);
|
||||
}
|
||||
enumerator.MoveNext();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
<tools:TextChangedBehavior />
|
||||
</SearchBar.Behaviors>
|
||||
</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>
|
||||
<DataTemplate>
|
||||
<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}" />-->
|
||||
</ContentPage.ToolbarItems>
|
||||
<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>
|
||||
<mdview:MarkdownView
|
||||
Theme="{StaticResource MonsterMarkdownTheme}"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeuUnitTest
|
||||
{
|
||||
|
|
@ -8,17 +9,15 @@ namespace AideDeJeuUnitTest
|
|||
public class UnitTest1
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestMethod1()
|
||||
public async Task TestMethod1()
|
||||
{
|
||||
var store = new StoreViewModel();
|
||||
var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md"));
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace AideDeJeuWeb.Controllers
|
|||
var md = await AideDeJeu.Tools.Helpers.GetResourceStringAsync("AideDeJeu.Data.spells_hd.md");
|
||||
var store = new StoreViewModel();
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue