Skip to content

Commit

Permalink
Support for actions and events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Jan 8, 2024
1 parent 48246ea commit 8ceeb27
Show file tree
Hide file tree
Showing 18 changed files with 1,125 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using EasyMicroservices.UI.Cores;
using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.Generators.Components;
using EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI;
using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions;
using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events;
using EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems;
using EasyMicroservices.UI.TemplateGenerator.ViewModels.Forms;
using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators;
Expand All @@ -25,6 +27,9 @@
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(sp => new FormClient(baseAddress, sp.GetService<HttpClient>()));
builder.Services.AddScoped(sp => new NoParentFormItemClient(baseAddress, sp.GetService<HttpClient>()));
builder.Services.AddScoped(sp => new ActionClient(baseAddress, sp.GetService<HttpClient>()));
builder.Services.AddScoped(sp => new EventClient(baseAddress, sp.GetService<HttpClient>()));
builder.Services.AddScoped(sp => new FormItemEventClient(baseAddress, sp.GetService<HttpClient>()));

builder.Services.AddTransient<FilterFormsListViewModel>();
builder.Services.AddTransient<AddOrUpdateFormViewModel>();
Expand All @@ -47,6 +52,13 @@
builder.Services.AddTransient<TimeOnlyFormItemViewModel>();
builder.Services.AddTransient<DataGridFormItemViewModel>();

builder.Services.AddTransient<ActionsViewModel>();
builder.Services.AddTransient<AddOrUpdateFormItemEventViewModel>();
builder.Services.AddTransient<EventsViewModel>();
builder.Services.AddTransient<FormItemEventsListViewModel>();
builder.Services.AddTransient<AddOrUpdateEventActionViewModel>();
builder.Services.AddTransient<EventActionsListViewModel>();

builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft;
Expand Down Expand Up @@ -311,4 +323,91 @@ void LoadLanguage(string languageShortName)
ShortName = languageShortName,
Value = "Other Component"
});


BaseViewModel.AppendLanguage("Event", new LanguageContract()
{
ShortName = languageShortName,
Value = "Event"
});
BaseViewModel.AppendLanguage("Events", new LanguageContract()
{
ShortName = languageShortName,
Value = "Events"
});
BaseViewModel.AppendLanguage("VariableName", new LanguageContract()
{
ShortName = languageShortName,
Value = "Variable Name"
});
BaseViewModel.AppendLanguage("Key", new LanguageContract()
{
ShortName = languageShortName,
Value = "Key"
});
BaseViewModel.AppendLanguage("Click", new LanguageContract()
{
ShortName = languageShortName,
Value = "Click"
});
BaseViewModel.AppendLanguage("TextChanged", new LanguageContract()
{
ShortName = languageShortName,
Value = "TextChanged"
});
BaseViewModel.AppendLanguage("ItemSelected", new LanguageContract()
{
ShortName = languageShortName,
Value = "ItemSelected"
});
BaseViewModel.AppendLanguage("Job", new LanguageContract()
{
ShortName = languageShortName,
Value = "Job"
});
BaseViewModel.AppendLanguage("Action", new LanguageContract()
{
ShortName = languageShortName,
Value = "Action"
});
BaseViewModel.AppendLanguage("Actions", new LanguageContract()
{
ShortName = languageShortName,
Value = "Actions"
});
BaseViewModel.AppendLanguage("Actions", new LanguageContract()
{
ShortName = languageShortName,
Value = "Actions"
});
BaseViewModel.AppendLanguage("OpenDialog", new LanguageContract()
{
ShortName = languageShortName,
Value = "OpenDialog"
});
BaseViewModel.AppendLanguage("OpenResponsibleDialog", new LanguageContract()
{
ShortName = languageShortName,
Value = "OpenResponsibleDialog"
});
BaseViewModel.AppendLanguage("OpenPage", new LanguageContract()
{
ShortName = languageShortName,
Value = "OpenPage"
});
BaseViewModel.AppendLanguage("CallExternalApi", new LanguageContract()
{
ShortName = languageShortName,
Value = "CallExternalApi"
});
BaseViewModel.AppendLanguage("SendResult", new LanguageContract()
{
ShortName = languageShortName,
Value = "SendResult"
});
BaseViewModel.AppendLanguage("Close", new LanguageContract()
{
ShortName = languageShortName,
Value = "Close"
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.17</Version>
<Version>0.0.0.18</Version>
<Description>TemplateGenerator UI compoents.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.UI.BlazorComponents" Version="*" />
<PackageReference Include="EasyMicroservices.UI.BlazorComponents" Version="0.0.0.20" />
<PackageReference Include="MudBlazor" Version="6.12.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@using EasyMicroservices.UI.Cores
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators
@using MudBlazor
@using TemplateGenerators.GeneratedServices
@inject ActionsViewModel viewModel;

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<MudSelect @bind-Value="viewModel.SelectedAction" Label="@viewModel.GetLanguage("Action")" OpenIcon="@Icons.Material.Filled.LocalDrink" AdornmentColor="Color.Secondary">
@foreach (var item in viewModel.Actions)
{
<MudSelectItem Value="@item">@viewModel.GetLanguage(@item.JobName)</MudSelectItem>
}
</MudSelect>
</MudRTLProvider>

@code {
public ActionsViewModel ViewModel
{
get
{
return viewModel;
}
}

protected override void OnInitialized()
{
ViewModel.BindSpecifiedPropertyChanged(nameof(ActionsViewModel.SelectedAction), () =>
{
SelectedActionChanged.InvokeAsync(SelectedAction);
});
base.OnInitialized();
}

[Parameter]
[Category(CategoryTypes.FormComponent.Data)]
public ActionContract SelectedAction
{
get
{
return ViewModel.SelectedAction;
}
set
{
ViewModel.SelectedAction = value;
}
}

[Parameter]
public EventCallback<ActionContract> SelectedActionChanged { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@using EasyMicroservices.UI.BlazorComponents
@using EasyMicroservices.UI.Cores
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators
@using MudBlazor
@using TemplateGenerators.GeneratedServices
@inject AddOrUpdateEventActionViewModel viewModel;

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<MudStack>
<Actions @ref="actionsView" @bind-SelectedAction="@viewModel.SelectedAction" />
<EventActionsList/>
</MudStack>
</MudRTLProvider>

@code {
public AddOrUpdateEventActionViewModel ViewModel
{
get
{
return viewModel;
}
}

protected override void OnInitialized()
{
ViewModel.BindPropertyChanged(StateHasChanged);
base.OnInitialized();
}

[Parameter]
[Category(CategoryTypes.FormComponent.Data)]
public ActionContract SelectedAction
{
get
{
return viewModel.SelectedAction;
}
set
{
viewModel.SelectedAction = value;
}
}

public Actions actionsView;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
@using EasyMicroservices.UI.BlazorComponents
@using EasyMicroservices.UI.Cores
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events
@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators
@using MudBlazor
@using TemplateGenerators.GeneratedServices
@inject EventActionsListViewModel viewModel;

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<MudDataGrid T="FormItemEventActionContract" Items="viewModel.Children">
<ToolBarContent>
<MudStack AlignItems="AlignItems.Center" Row="true" Spacing="5">
<MudFab Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="(arg) => ShowAddActionDialog()" />
<MudText Typo="Typo.h6" mar>
@viewModel.GetLanguage("Actions")
</MudText>
</MudStack>
</ToolBarContent>
<Columns>
<TemplateColumn CellClass="d-flex justify-end">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.KeyboardArrowUp" OnClick="(arg) => viewModel.IndexOrderingActions.MoveUp(context.Item)" />
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.KeyboardArrowDown" OnClick="(arg) => viewModel.IndexOrderingActions.MoveDown(context.Item)" />
</CellTemplate>
</TemplateColumn>
<PropertyColumn Property="x => x.OrderIndex" Title="@viewModel.GetLanguage("Index")" />
<PropertyColumn Property="x => viewModel.GetLanguage(x.Action.JobName)" Title="@viewModel.GetLanguage("Job")" />
<TemplateColumn CellClass="d-flex justify-end">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Edit" OnClick="(arg) => ShowUpdateDialog(context.Item)" />
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Delete" Color="Color.Error" OnClick="(arg) => ShowDeleteDialog(context.Item)" />
</CellTemplate>
</TemplateColumn>
</Columns>
</MudDataGrid>
<BaseDialog @ref="addOrUpdateActionDialog">
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Edit" Class="mr-3" />
Add
</MudText>
</TitleContent>
<DialogContent>
<AddOrUpdateEventAction @ref="AddOrUpdateEventActionView" />
</DialogContent>
<DialogActions>
<MudButton OnClick="() => addOrUpdateActionDialog.CloseDialog()">
@viewModel.GetLanguage("Cancel")
</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="()=>Save()">
<MudText>
@viewModel.GetLanguage("Save")
</MudText>
</MudButton>
</DialogActions>
</BaseDialog>

<BaseDialog @ref="deleteDialog">
<TitleContent>
<MudText>
@viewModel.GetLanguage("DeleteAction_Title")
</MudText>
</TitleContent>
<DialogContent>
@viewModel.GetLanguage("DeleteQuestion_Content")
</DialogContent>
<DialogActions>
<MudButton OnClick="() => deleteDialog.CloseDialog()">
@viewModel.GetLanguage("Cancel")
</MudButton>
<MudButton Color="Color.Error" Variant="Variant.Filled" Disabled="viewModel.IsBusy" OnClick="DoDelete">
<MudText>
@viewModel.GetLanguage("Delete")
</MudText>
</MudButton>
</DialogActions>
</BaseDialog>
</MudRTLProvider>

@code {
public EventActionsListViewModel ViewModel
{
get
{
return viewModel;
}
}

protected override void OnInitialized()
{
ViewModel.BindPropertyChanged(StateHasChanged);
base.OnInitialized();
}

BaseDialog addOrUpdateActionDialog;
BaseDialog deleteDialog;
AddOrUpdateEventAction AddOrUpdateEventActionView;
Actions actionsView;

void ShowAddActionDialog()
{
ViewModel.CurrentFormItemAction = currentUpdate = null;
addOrUpdateActionDialog.ShowDialog();
}

void Save()
{
if (AddOrUpdateEventActionView.ViewModel.SelectedAction != null)
{
if (currentUpdate != null)
viewModel.Children.Remove(currentUpdate);
viewModel.Children.Add(AddOrUpdateEventActionView.ViewModel.GetEventAction());
addOrUpdateActionDialog.CloseDialog();
}
}

void ShowDeleteDialog(FormItemEventActionContract item)
{
ViewModel.SelectedFormItemEventAction = item;
deleteDialog.ShowDialog();
}

void DoDelete()
{
viewModel.DoDeleteSelected();
deleteDialog.CloseDialog();
}

FormItemEventActionContract currentUpdate;
void ShowUpdateDialog(FormItemEventActionContract item)
{
currentUpdate = item;
addOrUpdateActionDialog.ShowDialog(() =>
{
AddOrUpdateEventActionView.ViewModel.CurrentFormItemAction = item;
AddOrUpdateEventActionView.ViewModel.SelectedAction = AddOrUpdateEventActionView.actionsView.ViewModel.Actions.FirstOrDefault(x => x.Id == item.ActionId);
});
}
}
Loading

0 comments on commit 8ceeb27

Please sign in to comment.