Skip to content

Commit c00af56

Browse files
committed
index items
1 parent 1ead9a4 commit c00af56

File tree

13 files changed

+101
-9
lines changed

13 files changed

+101
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace BangumiNet.Api.ExtraEnums;
2+
3+
/// <summary>目录关联类型</summary>
4+
public enum IndexRelatedCategory
5+
{
6+
Subject = 0,
7+
Character = 1,
8+
Person = 2,
9+
Episode = 3,
10+
Blog = 4,
11+
SubjectTopic = 5,
12+
GroupTopic = 6,
13+
}

BangumiNet.Shared/ItemType.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
public enum ItemType
44
{
5+
Unknown,
56
Subject,
67
Episode,
78
Character,
@@ -22,13 +23,16 @@ public static class EnumExtensions
2223
{
2324
public static string ToStringSC(this ItemType type) => type switch
2425
{
25-
ItemType.Subject => "项目",
26+
ItemType.Unknown => "未知",
27+
ItemType.Subject => "条目",
2628
ItemType.Episode => "话",
2729
ItemType.Character => "角色",
2830
ItemType.Person => "人物",
2931
ItemType.User => "用户",
3032
ItemType.Topic => "话题",
3133
ItemType.Group => "小组",
34+
ItemType.Timeline => "时间线",
35+
ItemType.Revision => "修订",
3236
ItemType.Blog => "日志",
3337
ItemType.Photo => "图片",
3438
ItemType.Index => "目录",

BangumiNet/Models/IndexRelation.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using BangumiNet.Api.ExtraEnums;
2+
using BangumiNet.Common;
3+
4+
namespace BangumiNet.Models;
5+
6+
public record class IndexRelation
7+
{
8+
public IndexRelatedCategory? Category { get; init; }
9+
public SubjectType? Type { get; init; }
10+
public int? Id { get; init; }
11+
public int? IndexId { get; init; }
12+
public int? ItemId { get; init; }
13+
public int? Order { get; init; }
14+
public string? Comment { get; init; }
15+
public string? Award { get; init; }
16+
public DateTimeOffset? CreationTime { get; init; }
17+
}

BangumiNet/ViewModels/IndexViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BangumiNet.Api.P1.Models;
1+
using BangumiNet.Api.ExtraEnums;
2+
using BangumiNet.Api.P1.Models;
23
using BangumiNet.Common.Extras;
34

45
namespace BangumiNet.ViewModels;
@@ -45,6 +46,7 @@ public IndexViewModel(IndexObject index)
4546
private void Init()
4647
{
4748
ItemType = ItemType.Index;
49+
RelatedItems = new(RelatedItemType.Subject, ItemType, Id);
4850

4951
Comments = new(ItemType, Id);
5052

@@ -63,6 +65,7 @@ private void Init()
6365
[Reactive] public partial int? CollectionCount { get; set; }
6466
[Reactive] public partial int? Award { get; set; }
6567
[Reactive] public partial CommentListViewModel? Comments { get; set; }
68+
[Reactive] public partial RelatedItemListViewModel? RelatedItems { get; set; }
6669

6770
public bool IsFull => Source is IndexObject;
6871
}

BangumiNet/ViewModels/ItemViewModelBase.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using BangumiNet.Converters;
2+
using BangumiNet.Models;
23
using BangumiNet.Shared.Extensions;
4+
using System.Reactive.Linq;
35
using System.Windows.Input;
46

57
namespace BangumiNet.ViewModels;
@@ -13,26 +15,26 @@ public ItemViewModelBase()
1315
OpenInNewWindowCommand = ReactiveCommand.Create(() => SecondaryWindow.Show(this));
1416
ShowNetworkCommand = ReactiveCommand.Create(() => SecondaryWindow.Show(new ItemNetworkViewModel(this)));
1517

16-
this.WhenAnyValue(x => x.Name, x => x.NameCn).Subscribe(x =>
18+
this.WhenAnyValue(x => x.ItemType, x => x.Name, x => x.NameCn).Skip(1).Subscribe(x =>
1719
{
1820
Title = $"{NameCnCvt.Convert(this) ?? $"{ItemType.ToStringSC()} {Id}"} - {Constants.ApplicationName}";
1921
});
2022
}
2123

2224
[Reactive] public partial object? Source { get; set; }
25+
[Reactive] public partial ItemType ItemType { get; set; }
2326
[Reactive] public partial int? Id { get; set; }
2427
[Reactive] public partial int? Order { get; set; }
2528
[Reactive] public partial int? Redirect { get; set; }
2629
[Reactive] public partial string? Name { get; set; }
2730
[Reactive] public partial string? NameCn { get; set; }
2831
[Reactive] public partial RevisionListViewModel? RevisionListViewModel { get; set; }
2932
[Reactive] public partial SubjectListViewModel? RelationItems { get; set; }
33+
[Reactive] public partial IndexRelation? IndexRelation { get; set; }
3034

3135
public ICommand? OpenInNewWindowCommand { get; set; }
3236
public ICommand? SearchWebCommand { get; set; }
3337
public ICommand? OpenInBrowserCommand { get; set; }
3438
public ICommand? ShowRevisionsCommand { get; set; }
3539
public ICommand? ShowNetworkCommand { get; set; }
36-
37-
public ItemType ItemType { get; protected set; }
3840
}

BangumiNet/ViewModels/RelatedItemListViewModel.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using BangumiNet.Api.Helpers;
33
using BangumiNet.Api.Interfaces;
44
using BangumiNet.Api.V0.Models;
5+
using BangumiNet.Common;
6+
using BangumiNet.Models;
57
using System.Reactive;
68
using System.Reactive.Linq;
79

@@ -106,6 +108,7 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
106108
RelatedItemType.Photo => await ApiC.P1.Blogs[id].Photos.GetAsync(c => c.Paging(Limit, Offset), ct),
107109
_ => throw new NotImplementedException(),
108110
},
111+
ItemType.Index => await ApiC.P1.Indexes[id].Related.GetAsync(c => c.Paging(Limit, Offset), ct),
109112
_ => throw new NotImplementedException(),
110113
};
111114
}
@@ -144,6 +147,7 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
144147
Api.P1.Models.Topic st => new TopicViewModel(st, ItemType.Subject),
145148
Api.P1.Models.BlogPhoto bp => new PhotoViewModel(bp),
146149
Api.P1.Models.SlimIndex si => new IndexViewModel(si),
150+
Api.P1.Models.IndexRelated ir => IndexRelatedToVM(ir),
147151
_ => new TextViewModel($"RelatedItemListViewModel.ConvertToVM: {obj}"),
148152
};
149153

@@ -153,6 +157,42 @@ public async Task<bool> LoadPage(CancellationToken ct = default)
153157
_ => ConvertToVM(obj),
154158
};
155159

160+
public static ViewModelBase IndexRelatedToVM(Api.P1.Models.IndexRelated related)
161+
{
162+
ItemViewModelBase item;
163+
if (related.Subject != null)
164+
item = new SubjectViewModel(related.Subject);
165+
else if (related.Character != null)
166+
item = new CharacterViewModel(related.Character);
167+
else if (related.Person != null)
168+
item = new PersonViewModel(related.Person);
169+
else if (related.Episode != null)
170+
item = new EpisodeViewModel(related.Episode);
171+
else if (related.Blog != null)
172+
item = new BlogViewModel(related.Blog);
173+
else if (related.GroupTopic != null)
174+
item = new TopicViewModel(related.GroupTopic, false);
175+
else if (related.SubjectTopic != null)
176+
item = new TopicViewModel(related.SubjectTopic, false);
177+
else
178+
throw new NotImplementedException();
179+
180+
item.Order = related.Order;
181+
item.IndexRelation = new IndexRelation
182+
{
183+
Category = (IndexRelatedCategory?)related.Cat,
184+
Type = (SubjectType?)related.Type,
185+
Id = related.Id,
186+
IndexId = related.Rid,
187+
ItemId = related.Sid,
188+
Order = related.Order,
189+
Comment = related.Comment,
190+
Award = related.Award,
191+
CreationTime = CommonUtils.ParseBangumiTime(related.CreatedAt),
192+
};
193+
return item;
194+
}
195+
156196
[Reactive] public partial RelatedItemType Type { get; set; }
157197
[Reactive] public partial ItemType ParentType { get; set; }
158198
[Reactive] public partial int? ParentId { get; set; }

BangumiNet/Views/CharacterBadgeView.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<HyperlinkButton Content="{Binding Name}"
2121
Command="{Binding OpenInNewWindowCommand}"
2222
Classes="Title"/>
23-
<TextBlock Text="{Binding Relation}" TextWrapping="Wrap"/>
23+
<TextBlock Text="{Binding Relation}" TextWrapping="Wrap"
24+
IsVisible="{Binding Relation,Converter={StaticResource NEWCvt}}"/>
2425
</StackPanel>
2526
</Border>
2627
<Grid.ContextFlyout>

BangumiNet/Views/IndexStatsView.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
<InfoBadge Label="章节" Text="{Binding Episode}"/>
2121
<InfoBadge Label="日志" Text="{Binding Blog}"/>
2222
<InfoBadge Label="小组话题" Text="{Binding GroupTopic}"/>
23-
<InfoBadge Label="条目话题" Text="{Binding SubjectTopic}"/>
23+
<InfoBadge Label="条目讨论" Text="{Binding SubjectTopic}"/>
2424
</WrapPanel>
2525
</UserControl>

BangumiNet/Views/IndexView.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</StackPanel>
4343

4444
<StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
45+
<bn:RelatedItemListView DataContext="{Binding RelatedItems}"/>
4546
<Expander Header="吐槽箱" HorizontalAlignment="Stretch" IsExpanded="True">
4647
<bn:CommentListView DataContext="{Binding Comments}"/>
4748
</Expander>

BangumiNet/Views/IndexView.axaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public IndexView()
2323
.Subscribe(async vm =>
2424
{
2525
vm.Comments?.LoadPageCommand.Execute().Subscribe();
26+
vm.RelatedItems?.LoadPageCommand.Execute().Subscribe();
2627
});
2728
}
2829
}

0 commit comments

Comments
 (0)