mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 17:31:37 +00:00
encapsulated render logic into a function to be able to call it recursively
This commit is contained in:
parent
dbdcdef83c
commit
4f836e2dfb
@ -1,4 +1,4 @@
|
|||||||
@attribute [Route(Routes.ASSISTANT_DYNAMIC)]
|
@attribute [Route(Routes.ASSISTANT_DYNAMIC)]
|
||||||
@using AIStudio.Components
|
@using AIStudio.Components
|
||||||
@using AIStudio.Settings
|
@using AIStudio.Settings
|
||||||
@using AIStudio.Tools.PluginSystem.Assistants.DataModel
|
@using AIStudio.Tools.PluginSystem.Assistants.DataModel
|
||||||
@ -6,6 +6,18 @@
|
|||||||
|
|
||||||
@foreach (var component in this.RootComponent!.Children)
|
@foreach (var component in this.RootComponent!.Children)
|
||||||
{
|
{
|
||||||
|
@this.RenderComponent(component)
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private RenderFragment RenderChildren(IEnumerable<IAssistantComponent> children) => @<text>
|
||||||
|
@foreach (var child in children)
|
||||||
|
{
|
||||||
|
@this.RenderComponent(child)
|
||||||
|
}
|
||||||
|
</text>;
|
||||||
|
|
||||||
|
private RenderFragment RenderComponent(IAssistantComponent component) => @<text>
|
||||||
@switch (component.Type)
|
@switch (component.Type)
|
||||||
{
|
{
|
||||||
case AssistantComponentType.TEXT_AREA:
|
case AssistantComponentType.TEXT_AREA:
|
||||||
@ -31,8 +43,7 @@
|
|||||||
AutoGrow="@true"
|
AutoGrow="@true"
|
||||||
MaxLines="12"
|
MaxLines="12"
|
||||||
Class='@MergeClass(textArea.Class, "mb-3")'
|
Class='@MergeClass(textArea.Class, "mb-3")'
|
||||||
Style="@this.GetOptionalStyle(textArea.Style)"
|
Style="@this.GetOptionalStyle(textArea.Style)" />
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AssistantComponentType.IMAGE:
|
case AssistantComponentType.IMAGE:
|
||||||
@ -43,7 +54,7 @@
|
|||||||
{
|
{
|
||||||
var image = assistantImage;
|
var image = assistantImage;
|
||||||
<div Class="mb-4">
|
<div Class="mb-4">
|
||||||
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@this.GetOptionalStyle(image.Style)" Elevation="20"/>
|
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@this.GetOptionalStyle(image.Style)" Elevation="20" />
|
||||||
@if (!string.IsNullOrWhiteSpace(image.Caption))
|
@if (!string.IsNullOrWhiteSpace(image.Caption))
|
||||||
{
|
{
|
||||||
<MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText>
|
<MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText>
|
||||||
@ -60,7 +71,7 @@
|
|||||||
ProviderSettings="@this.providerSettings"
|
ProviderSettings="@this.providerSettings"
|
||||||
@bind-AgentIsRunning="@webState.AgentIsRunning"
|
@bind-AgentIsRunning="@webState.AgentIsRunning"
|
||||||
@bind-Preselect="@webState.Preselect"
|
@bind-Preselect="@webState.Preselect"
|
||||||
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent"/>
|
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent" />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -72,7 +83,6 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AssistantComponentType.DROPDOWN:
|
case AssistantComponentType.DROPDOWN:
|
||||||
if (component is AssistantDropdown assistantDropdown)
|
if (component is AssistantDropdown assistantDropdown)
|
||||||
{
|
{
|
||||||
@ -82,14 +92,14 @@
|
|||||||
Label="@assistantDropdown.Label"
|
Label="@assistantDropdown.Label"
|
||||||
Icon="@Icons.Material.Filled.Translate"
|
Icon="@Icons.Material.Filled.Translate"
|
||||||
Class="@assistantDropdown.Class"
|
Class="@assistantDropdown.Class"
|
||||||
Style="@assistantDropdown.Style"/>
|
Style="@assistantDropdown.Style" />
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AssistantComponentType.BUTTON:
|
case AssistantComponentType.BUTTON:
|
||||||
if (component is AssistantButton assistantButton)
|
if (component is AssistantButton assistantButton)
|
||||||
{
|
{
|
||||||
var button = assistantButton;
|
var button = assistantButton;
|
||||||
<div >
|
<div>
|
||||||
<MudButton Variant="@button.GetButtonVariant()"
|
<MudButton Variant="@button.GetButtonVariant()"
|
||||||
Color="@AssistantComponentPropHelper.GetColor(button.Color, Color.Default)"
|
Color="@AssistantComponentPropHelper.GetColor(button.Color, Color.Default)"
|
||||||
OnClick="@(() => this.ExecuteButtonActionAsync(button))"
|
OnClick="@(() => this.ExecuteButtonActionAsync(button))"
|
||||||
@ -103,7 +113,8 @@
|
|||||||
Class='@MergeClass(button.Class, "mb-3")'
|
Class='@MergeClass(button.Class, "mb-3")'
|
||||||
Style="@this.GetOptionalStyle(button.Style)">
|
Style="@this.GetOptionalStyle(button.Style)">
|
||||||
@button.Text
|
@button.Text
|
||||||
</MudButton></div>
|
</MudButton>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AssistantComponentType.BUTTON_GROUP:
|
case AssistantComponentType.BUTTON_GROUP:
|
||||||
@ -118,26 +129,7 @@
|
|||||||
DropShadow="@buttonGroup.DropShadow"
|
DropShadow="@buttonGroup.DropShadow"
|
||||||
Class='@MergeClass(buttonGroup.Class, "mb-3")'
|
Class='@MergeClass(buttonGroup.Class, "mb-3")'
|
||||||
Style="@this.GetOptionalStyle(buttonGroup.Style)">
|
Style="@this.GetOptionalStyle(buttonGroup.Style)">
|
||||||
@foreach (var child in buttonGroup.Children)
|
@this.RenderChildren(buttonGroup.Children)
|
||||||
{
|
|
||||||
if (child is AssistantButton childButton)
|
|
||||||
{
|
|
||||||
<MudButton Variant="@childButton.GetButtonVariant()"
|
|
||||||
Color="@AssistantComponentPropHelper.GetColor(childButton.Color, Color.Default)"
|
|
||||||
OnClick="@(() => this.ExecuteButtonActionAsync(childButton))"
|
|
||||||
Size="@AssistantComponentPropHelper.GetComponentSize(childButton.Size, Size.Medium)"
|
|
||||||
FullWidth="@childButton.IsFullWidth"
|
|
||||||
StartIcon="@AssistantComponentPropHelper.GetIconSvg(childButton.StartIcon)"
|
|
||||||
EndIcon="@AssistantComponentPropHelper.GetIconSvg(childButton.EndIcon)"
|
|
||||||
IconColor="@AssistantComponentPropHelper.GetColor(childButton.IconColor, Color.Inherit)"
|
|
||||||
IconSize="@AssistantComponentPropHelper.GetComponentSize(childButton.IconSize, Size.Medium)"
|
|
||||||
Disabled="@this.IsButtonActionRunning(childButton.Name)"
|
|
||||||
Class="@childButton.Class"
|
|
||||||
Style="@this.GetOptionalStyle(childButton.Style)">
|
|
||||||
@childButton.Text
|
|
||||||
</MudButton>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</MudButtonGroup>
|
</MudButtonGroup>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -246,9 +238,10 @@
|
|||||||
Rounded="@rounded"
|
Rounded="@rounded"
|
||||||
Elevation="@elevation"
|
Elevation="@elevation"
|
||||||
Style="@($"color: {this.colorPickerFields[colorPicker.Name]};")"
|
Style="@($"color: {this.colorPickerFields[colorPicker.Name]};")"
|
||||||
Class="@MergeClass(colorPicker.Class, "mb-3")"/>
|
Class="@MergeClass(colorPicker.Class, "mb-3")" />
|
||||||
</MudItem>
|
</MudItem>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
</text>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -571,5 +571,4 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
|||||||
var time = this.AddUserRequest(await this.CollectUserPromptAsync());
|
var time = this.AddUserRequest(await this.CollectUserPromptAsync());
|
||||||
await this.AddAIResponseAsync(time);
|
await this.AddAIResponseAsync(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user