-
Notifications
You must be signed in to change notification settings - Fork 10
/
Events.razor
145 lines (127 loc) · 4.32 KB
/
Events.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@page "/admin/events"
@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IRepository<RobotEvent> _robotEventRepository
<DataTableCard TModel="RobotEvent" Headers="_headers" DataSource="_robotEventRepository.GetAll()" Title="@($"{_name}列表")" OnClickAdd="AddItem" @ref="dataTableCard"
Predicate="s => dataTableCard==null ||string.IsNullOrWhiteSpace(dataTableCard._search) || (s.Note.Contains(dataTableCard._search)|| s.Text.Contains(dataTableCard._search))">
<ItemColContent>
@if (context.Header.Value == "actions")
{
<MIcon Color="success"
Class="mr-2"
OnClick="()=>EditItem(context.Item)">mdi-pencil</MIcon>
}
else if (context.Header.Value == nameof(RobotEvent.Time))
{
@if (context.Item.Type == RobotEventType.ConditionalTriggering)
{
@("无")
}
else
{
@context.Item.Time.ToString("HH:mm:ss")
}
}
else if (context.Header.Value == nameof(RobotEvent.IsHidden))
{
<CnGalWebSite.RobotClientX.Components.Replies.EnableChip Enabled="!context.Item.IsHidden" />
}
else if (context.Header.Value == nameof(RobotEvent.Type))
{
<CnGalWebSite.RobotClientX.Components.Events.TypeChip Type="context.Item.Type" />
}
else if (context.Header.Value == nameof(RobotEvent.Text))
{
<div class=" text-truncate-2">
@context.Item.Text
</div>
}
else if (context.Header.Value == nameof(RobotEvent.Probability))
{
@if (context.Item.Type == RobotEventType.PreTime)
{
@context.Item.Probability.ToString("0.0")
}
else
{
@("无")
}
}
else if (context.Header.Value == nameof(RobotEvent.DelaySecond))
{
@if (context.Item.Type == RobotEventType.PreTime)
{
@context.Item.DelaySecond
}
else
{
@("无")
}
}
else
{
@context.Value
}
</ItemColContent>
</DataTableCard>
<MDialog @bind-Value="_editDialog"
MaxWidth="1200">
<CnGalWebSite.RobotClientX.Components.Events.EditCard Id="_editedItemId" AllowedScopes="_scopes" OnEdited="OnEdited" @ref="editCard" />
</MDialog>
@code {
private bool _editDialog;
private long _editedItemId;
private bool _detailDialog;
private string _name = "事件";
CnGalWebSite.RobotClientX.Components.Events.EditCard editCard;
private List<DataTableHeader<RobotEvent>> _headers = new List<DataTableHeader<RobotEvent>>
{
new ()
{
Text= "Id",
Align= DataTableHeaderAlign.Start,
Value= nameof(RobotEvent.Id)
},
new (){ Text= "备注", Value= nameof(RobotEvent.Note)},
new (){ Text= "消息", Value= nameof(RobotEvent.Text)},
new (){ Text= "触发方式", Value= nameof(RobotEvent.Type)},
new (){ Text= "开始触发时间", Value= nameof(RobotEvent.Time)},
new (){ Text= "有效时长(秒)", Value= nameof(RobotEvent.DelaySecond)},
new (){ Text= "概率", Value= nameof(RobotEvent.Probability)},
new (){ Text= "状态", Value= nameof(RobotEvent.IsHidden)},
new (){ Text= "操作", Value= "actions",Sortable=false }
};
List<KeyValuePair<string, string>> _scopes;
DataTableCard<RobotEvent> dataTableCard;
[CascadingParameter]
public ErrorHandler ErrorHandler { get; set; }
public void EditItem(RobotEvent item)
{
_editedItemId = item.Id;
_editDialog = true;
StateHasChanged();
if (editCard != null)
{
editCard.Refresh();
}
}
public void OnEdited(RobotEvent model)
{
_editDialog = false;
StateHasChanged();
if (dataTableCard != null)
{
dataTableCard.GetDataFromApi();
}
}
public void AddItem()
{
_editedItemId = 0;
_editDialog = true;
StateHasChanged();
if (editCard != null)
{
editCard.Refresh();
}
}
}