Interface IViewModel
- Namespace
- GroupeIsa.Neos.Designer.UIAbstractions
- Assembly
- GroupeIsa.Neos.Designer.UIAbstractions.dll
Provides the functionalities of the MVVM view model of a UI view.
public interface IViewModel : IBaseViewModel
- Inherited Members
Properties
Actions
Gets the actions.
IViewModelActions Actions { get; }
Property Value
AddingUIViewName
Gets or sets the name of the UI view that opens to add a new item.
string? AddingUIViewName { get; set; }
Property Value
CanMoveNextPage
Gets a value indicating whether navigating to the next page is possible.
bool CanMoveNextPage { get; }
Property Value
CanMovePreviousPage
Gets a value indicating whether navigating to the previous page is possible.
bool CanMovePreviousPage { get; }
Property Value
CreatedItems
Gets the new items of the datasource.
IReadOnlyCollection<IUIView> CreatedItems { get; }
Property Value
CreationAllowed
Gets or sets a value indicating whether creating a new item is allowed.
bool CreationAllowed { get; set; }
Property Value
CreationMode
Gets or sets a value indicating whether the view is in creation mode.
In creation mode, add item, clone item and refresh actions are disabled.
bool CreationMode { get; set; }
Property Value
DataSorts
Gets the collection of the sorts set on the datasource.
IReadOnlyCollection<Sort> DataSorts { get; }
Property Value
Datafilter
Gets the current data filter applied to the datasource.
Filter Datafilter { get; }
Property Value
Datasource
Gets the datasource.
IDatasource<IUIView> Datasource { get; }
Property Value
DatasourceCurrent
Gets the item at the Position in the datasource.
Null
when Position is -1 or greater than the position of the last item of the datasource.
Warning : not to be confused with the Item
property of actions / event rules which designates the datasource item on which an action / event rule is triggered.
In most cases, you should use the Item
property when available instead of DatasourceCurrent.
IUIView? DatasourceCurrent { get; }
Property Value
Examples
The following example shows the access to the instance at the current position.
If the position is valid, the OrderedAt property of the instance is set to the current date.
if (DatasourceCurrent != null)
{
DatasourceCurrent.OrderedAt = DateTime.Now;
}
Description
Gets the description.
[Obsolete("Use the Title property instead.")]
string Description { get; }
Property Value
EditingLinkPropertyName
Gets or sets the name of the property on which a link for editing the item is displayed.
string? EditingLinkPropertyName { get; set; }
Property Value
EditingUIViewName
Gets or sets the name of the UI view that opens to edit an item.
string? EditingUIViewName { get; set; }
Property Value
EntityName
Gets the name of the entity.
string? EntityName { get; }
Property Value
EntityViewName
Gets the name of the entity view.
string? EntityViewName { get; }
Property Value
GroupDescriptions
Gets the description of the groups made when grouping by a property.
List<string> GroupDescriptions { get; }
Property Value
HasChanges
Gets a value indicating whether the datasource has changes.
Modified items include both new and modified items. Relations and embedded collections (addition / deletion) are also taken into account recursively.
bool HasChanges { get; }
Property Value
HasErrors
Gets a value indicating whether the datasource has errors.
Relations are also taken into account recursively.
bool HasErrors { get; }
Property Value
HasMoreData
Gets a value indicating whether more data can be retrieved.
bool HasMoreData { get; }
Property Value
Icon
Gets the icon.
string Icon { get; }
Property Value
InitSelectionOnLoad
Gets or sets a value indicating whether the selection must be initialized on load.
bool InitSelectionOnLoad { get; set; }
Property Value
IsMain
Gets a value indicating whether the view model is the main view model.
bool IsMain { get; }
Property Value
Loading
Gets a value indicating whether data is being loaded.
bool Loading { get; }
Property Value
ModifiedItems
Gets the modified items of the datasource.
IReadOnlyCollection<IUIView> ModifiedItems { get; }
Property Value
MonoRecord
Gets or sets a value indicating whether the UI view is in mono-record mode.
bool MonoRecord { get; set; }
Property Value
PageNumber
Gets or sets the number of the current page in the paginated data source.
int PageNumber { get; set; }
Property Value
PersistenceErrorItems
Gets the elements with at least one persistence error.
IReadOnlyCollection<IUIView> PersistenceErrorItems { get; }
Property Value
Position
Gets or sets the current position in the datasource.
int Position { get; set; }
Property Value
Examples
The following example shows how to set the position to the last element.
Position = Datasource.Count - 1;
RecordsByPage
Gets or sets the maximum number of records retrieved by page.
int RecordsByPage { get; set; }
Property Value
Relations
Gets the relationships between the view model and the view models of the sub-views.
[Obsolete("Use Relationships instead.")]
IReadOnlyCollection<IViewModelRelation> Relations { get; }
Property Value
Relationships
Gets the relationships between the view model and the view models of the sub-views.
IReadOnlyCollection<IViewModelRelation> Relationships { get; }
Property Value
SelectedItems
Gets the selected items in the datasource.
IReadOnlyCollection<IUIView> SelectedItems { get; }
Property Value
Title
Gets the title.
string Title { get; }
Property Value
TotalRecordCount
Gets the total record count.
int TotalRecordCount { get; }
Property Value
UIViewName
Gets the name of the UI view.
string UIViewName { get; }
Property Value
UrlContext
Gets the URL context which contains additional parameters added to the URL.
IUrlContext UrlContext { get; }
Property Value
ValidateLocalizableString
Gets or sets a value indicating whether the localizable strings with a missing translation generate an error / warning.
bool ValidateLocalizableString { get; set; }
Property Value
ViewContext
Gets the view context which contains values shared between the UI view and its sub-views. Updates to the view context are applied on the UI view and all its sub-views.
When opening another UI view from the current UI view, the values of the current UI view are copied in the opened UI view. Updates to the current view context are not applied to opened UI view. Updates to the opened UI view are not applied to the current UI view.
IViewContext ViewContext { get; }
Property Value
ViewModelId
Gets the view model identifier defined in the UI view template using the "id" attribute.
string? ViewModelId { get; }
Property Value
Methods
AcceptChanges()
Accepts all the changes made to the datasource since data was loaded or the last time the AcceptChanges() or RejectChanges() was called.
void AcceptChanges()
AddAsync(params IUIView[])
Adds the specified items at the end of the datasource.
Task<bool> AddAsync(params IUIView[] items)
Parameters
items
IUIView[]Items to add.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if items have been added,false
otherwise.
Examples
The following example shows how to add an item to the data source.
Order item = new Order();
if (await AddAsync(item))
{
Console.WriteLine("Item added");
}
else
{
Console.WriteLine("Item not added");
}
AddAsync(IEnumerable<IUIView>, bool)
Adds the specified items at the end of the datasource.
Task<bool> AddAsync(IEnumerable<IUIView> items, bool asNewItem = false)
Parameters
items
IEnumerable<IUIView>Items to add.
asNewItem
boolA value indicating whether added items should be considered new items.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if items have been added,false
otherwise.
AddNewAsync()
Creates a new item and adds it at the end of the datasource.
Task<IUIView?> AddNewAsync()
Returns
- Task<IUIView>
A Task representing the asynchronous operation. The task result contains the new item or
null
if adding has been canceled.
Examples
The following example shows how to create and add a new item to the data source.
IOrder? item = await AddNewAsync();
ClearSort()
Clears the sorts set on the datasource.
void ClearSort()
CloneAsync(IUIView)
Creates a new item that is a copy of the specified source item and adds it at the end of the datasource.
Task<IUIView?> CloneAsync(IUIView source)
Parameters
source
IUIViewThe source item from which the new item will be cloned.
Returns
- Task<IUIView>
A Task representing the asynchronous operation. The task result contains the new item that is the result of the cloning operation or
null
if cloning has been canceled.
CloseAsync(bool, NavigationResult?)
Closes the current view.
Task CloseAsync(bool displayUnsavedChangesMessage = true, NavigationResult? result = null)
Parameters
displayUnsavedChangesMessage
boolA value indicating whether the unsaved changes message is displayed.
result
NavigationResultThe navigation result.
Returns
CreateNewItem()
Creates a new item.
IUIView CreateNewItem()
Returns
- IUIView
The created item.
Remarks
The item is not added to the datasource.
CreateServerDataExportOptions(string, ExportFormat)
Creates the server data export options from the current context.
ServerDataExportOptions CreateServerDataExportOptions(string fileName, ExportFormat format)
Parameters
fileName
stringThe file name.
format
ExportFormatThe format.
Returns
- ServerDataExportOptions
The server data export options.
DeleteDataAsync(params IUIView[])
Removes the specified items from the server via an API call.
Task<bool> DeleteDataAsync(params IUIView[] items)
Parameters
items
IUIView[]Items to remove.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains a value indicating whether the items have been removed.
DeleteDataAsync(IEnumerable<IUIView>)
Removes the specified items from the server via an API call.
Task<bool> DeleteDataAsync(IEnumerable<IUIView> items)
Parameters
items
IEnumerable<IUIView>Items to remove.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains a value indicating whether the items have been removed.
DeleteSelectedItemsAsync()
Deletes the selected items.
Task<bool> DeleteSelectedItemsAsync()
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains a value indicating whether the items have been removed.
ExecuteRemoveActionAsync()
Executes the Remove action.
Task ExecuteRemoveActionAsync()
Returns
- Task
A Task representing the asynchronous operation. The task result contains a value indicating whether the items have been removed.
ExecuteReportAsync(string, Filter?, Dictionary<string, object>?)
Executes a report.
Task ExecuteReportAsync(string reportName, Filter? filter = null, Dictionary<string, object>? parameters = null)
Parameters
reportName
stringReport name.
filter
FilterFilter to apply to the data.
parameters
Dictionary<string, object>Parameters to pass to the report.
Returns
ExecuteReportWithOptionsAsync(ExecuteReportOptions)
Executes a report.
Task ExecuteReportWithOptionsAsync(ExecuteReportOptions options)
Parameters
options
ExecuteReportOptionsOptions.
Returns
FindSort(string)
Finds the sort set on the specified property.
Sort? FindSort(string propertyName)
Parameters
propertyName
stringThe property name.
Returns
- Sort
The sort found set on the specified property; otherwise
null
.
FindSortIndex(string)
Find the index of the sort set on the specified property within DataSorts.
int FindSortIndex(string propertyName)
Parameters
propertyName
stringThe property name.
Returns
- int
The index of the sort set on the specified property; otherwise
-1
.
FindSubViewModel<T>(string)
Gets the view model of the sub-view associated to the specified relation property.
ViewModel<T>? FindSubViewModel<T>(string relationPropertyName) where T : class, IUIView
Parameters
relationPropertyName
stringThe relation property name.
Returns
- ViewModel<T>
The view model of the sub-view or
null
if it does not exist.
Type Parameters
T
Type of the sub-view managed by the sub-view view model.
Remarks
The search based on the relation property name is not case sensitive.
FindViewModelById<T>(string)
Finds a view model by identifier.
ViewModel<T>? FindViewModelById<T>(string id) where T : class, IUIView
Parameters
id
stringThe identifier.
Returns
- ViewModel<T>
The view model or
null
if it does not exist.
Type Parameters
T
Type of UI view managed by the view model.
FindViewModelOfViewContainer<TContainerUIView>(string)
Finds the view model of a view container in the current UI view corresponding to the specified container identifier.
ViewModel<TContainerUIView>? FindViewModelOfViewContainer<TContainerUIView>(string containerId) where TContainerUIView : class, IUIView
Parameters
containerId
stringThe container identifier.
Returns
- ViewModel<TContainerUIView>
The view model of the found view container or
null
when the view container was not found.
Type Parameters
TContainerUIView
The type of the UI view loaded in the view container.
GetAction(string)
Gets the view model of the specified action.
IViewModelAction GetAction(string name)
Parameters
name
stringThe action name.
Returns
- IViewModelAction
The view model of the action.
Exceptions
- Exception
The action does not exist.
GetCloningAllowed(IUIView)
Gets a value indicating whether cloning an item is allowed.
bool GetCloningAllowed(IUIView item)
Parameters
item
IUIViewItem on which the
CloningAllowed
value must be checked.
Returns
- bool
true
if the item can be cloned; otherwise,false
.
GetDeletionAllowed(IUIView)
Gets a value indicating whether deleting an item is allowed.
bool GetDeletionAllowed(IUIView item)
Parameters
item
IUIViewItem on which the
DeletionAllowed
value must be checked.
Returns
- bool
true
if the item can be deleted; otherwise,false
.
GetDisplayableProperties()
Gets the displayable properties.
IReadOnlyCollection<IViewModelProperty> GetDisplayableProperties()
Returns
- IReadOnlyCollection<IViewModelProperty>
The displayable properties.
GetFilterableProperties()
Gets the filterable properties.
IReadOnlyCollection<IViewModelProperty> GetFilterableProperties()
Returns
- IReadOnlyCollection<IViewModelProperty>
The properties.
GetFullDatasource()
Gets the original datasource when the UI view datasource comes from a computed source.
When a parent UI view displays in its template the current UI view, it can provide a computed source. This source can contain different items from the ones that should originally be included in the datasource. This is typically used to provide a filtered datasource to a sub-view.
GetFullDatasource() gets the original datasource instead on the one from the computed source.
IDatasource<IUIView> GetFullDatasource()
Returns
- IDatasource<IUIView>
The original datasource.
Remarks
If the datasource does not come from a computed source, GetFullDatasource() return the same value as Datasource.
GetOwnerFrame()
Gets the owner frame of this UI view.
IFrame? GetOwnerFrame()
Returns
- IFrame
The owner frame or
null
if this UI view does not belong to a frame.
GetParentItem<TParentUIView>()
Gets the parent item that this data source is in relation with.
TParentUIView? GetParentItem<TParentUIView>() where TParentUIView : class, IUIView
Returns
- TParentUIView
Parent item or
null
when this data source does not belong to a relationship.
Type Parameters
TParentUIView
Type of the parent item.
Examples
The following example shows how to affect a 10% discount when adding an order line in an order placed on a Monday.
if (GetParentItem<Order>()?.OrderedAt.DayOfWeek == System.DayOfWeek.Monday)
{
Item.Discount = 0.1M;
}
GetProperties()
Gets the properties.
IReadOnlyCollection<IViewModelProperty> GetProperties()
Returns
- IReadOnlyCollection<IViewModelProperty>
The properties.
GetProperty(string)
Gets the view model of the specified property.
IViewModelProperty GetProperty(string name)
Parameters
name
stringThe property name.
Returns
- IViewModelProperty
The view model of the property.
Exceptions
- Exception
The property does not exist.
GetSubViewModel<T>(string)
Gets the view model of the sub-view associated to the specified relation property.
ViewModel<T> GetSubViewModel<T>(string relationPropertyName) where T : class, IUIView
Parameters
relationPropertyName
stringThe relation property name.
Returns
- ViewModel<T>
The view model of the sub-view.
Type Parameters
T
Type of the sub-view managed by the sub-view view model.
Remarks
The search based on the relation property name is not case sensitive.
Exceptions
- Exception
The sub-view view model does not exist.
GetUpdateAllowed(IUIView)
Gets a value indicating whether updating an item is allowed.
bool GetUpdateAllowed(IUIView item)
Parameters
item
IUIViewItem on which the
UpdateAllowed
value must be checked.
Returns
- bool
true
if the item can be updated; otherwise,false
.
GetViewModelById<T>(string)
Gets a view model by identifier.
ViewModel<T> GetViewModelById<T>(string id) where T : class, IUIView
Parameters
id
stringThe identifier.
Returns
- ViewModel<T>
The view model.
Type Parameters
T
Type of UI view managed by the view model.
Exceptions
- Exception
The view model does not exist.
GetViewModelOfViewContainer<TContainerUIView>(string)
Gets the view model of a view container in the current UIView by the specified container identifier.
ViewModel<IUIView> GetViewModelOfViewContainer<TContainerUIView>(string containerId) where TContainerUIView : class, IUIView
Parameters
containerId
stringThe container identifier.
Returns
Type Parameters
TContainerUIView
The type of the uiview loaded in the view container.
GetVisibleProperties()
Gets the visible properties.
IReadOnlyCollection<IViewModelProperty> GetVisibleProperties()
Returns
- IReadOnlyCollection<IViewModelProperty>
The visible properties.
ImportAsync<TItem>(IEnumerable<TItem>, bool)
Imports the specified items at the end of the datasource.
Task<bool> ImportAsync<TItem>(IEnumerable<TItem> items, bool asNewItem = false)
Parameters
items
IEnumerable<TItem>Items to import.
asNewItem
boolA value indicating whether imported items should be considered new items.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if the items have been imported,false
otherwise.
Type Parameters
TItem
Item type (must contain same properties as IUIView).
ImportAsync<TItem>(params TItem[])
Imports the specified items at the end of the datasource.
Task<bool> ImportAsync<TItem>(params TItem[] items)
Parameters
items
TItem[]Items to import.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if the item have been imported,false
otherwise.
Type Parameters
TItem
Item type (must contain the same properties as IUIView).
Examples
The following example shows how to add an item to the data source.
Order item = new Order();
if (await AddAsync(item))
{
Console.WriteLine("Item added");
}
else
{
Console.WriteLine("Item not added");
}
InsertAsync(int, params IUIView[])
Inserts the specified items at the specified position.
Task<bool> InsertAsync(int position, params IUIView[] items)
Parameters
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if items have been inserted,false
otherwise.
InsertAsync(int, IEnumerable<IUIView>, bool)
Inserts the specified items at the specified position.
Task<bool> InsertAsync(int position, IEnumerable<IUIView> items, bool asNewItem = false)
Parameters
position
intPosition.
items
IEnumerable<IUIView>Items to insert.
asNewItem
boolA value indicating whether inserted items should be considered new items.
Returns
- Task<bool>
A Task representing the asynchronous operation. The task result contains
true
if the items have been inserted,false
otherwise.
InsertNewAsync(int)
Creates a new item and inserts it at the specified position.
Task<IUIView?> InsertNewAsync(int position)
Parameters
position
intPosition.
Returns
- Task<IUIView>
A Task representing the asynchronous operation. The task result contains the new item or
null
if inserting has been canceled.
IsSelected(IUIView)
Gets a value indicating whether the specified item is selected.
bool IsSelected(IUIView item)
Parameters
item
IUIViewThe item.
Returns
- bool
true
if the item is selected, otherwisefalse
.
LoadDataAsync()
Loads data from the server via an API call.
Task LoadDataAsync()
Returns
NavigateAsync(NavigationOptions)
Navigates to a view.
Task NavigateAsync(NavigationOptions options)
Parameters
options
NavigationOptionsNavigation options.
Returns
PromptSaveAsync()
Displays the save dialog if the view model has changes.
Task<bool> PromptSaveAsync()
Returns
- Task<bool>
A Task representing the asynchronous operation. The result is a value indicating whether the saving operation has succeeded or was canceled by the user.
RejectChanges()
Rejects all the changes made to the datasource since data was loaded or the last time the AcceptChanges() or RejectChanges() was called.
void RejectChanges()
RemoveSort(string)
Removes the sort set on the specified property.
void RemoveSort(string propertyName)
Parameters
propertyName
stringThe property name.
SaveDataAsync()
Persists the changed items on the server.
Task<bool> SaveDataAsync()
Returns
- Task<bool>
A Task representing the asynchronous operation. The result is a value indicating whether the saving operation has succeeded.
SelectAllItemsAsync()
Select all the items of the current datasource.
Task SelectAllItemsAsync()
Returns
SelectItemAsync(IUIView)
Selects the specified item of the datasource.
Task SelectItemAsync(IUIView item)
Parameters
item
IUIViewThe item to select.
Returns
SelectItemAsync(int)
Selects the item at the specified index in the datasource.
Task SelectItemAsync(int index)
Parameters
index
intThe index of the item to select.
Returns
SetCloningAllowed(bool)
Sets a value indicating whether cloning an item is allowed.
void SetCloningAllowed(bool value)
Parameters
value
boolValue to set.
SetDeletionAllowed(bool)
Sets a value indicating whether deleting an item is allowed.
void SetDeletionAllowed(bool value)
Parameters
value
boolValue to set.
SetFilter(Filter)
Sets the filter to apply to the datasource.
void SetFilter(Filter filter)
Parameters
filter
FilterThe filter.
SetSort(string, SortDirection)
Sets the sort on the specified property name.
void SetSort(string propertyName, SortDirection direction)
Parameters
propertyName
stringThe property name.
direction
SortDirectionThe sort direction to set.
SetUpdateAllowed(bool)
Sets a value indicating whether updating an item is allowed.
void SetUpdateAllowed(bool value)
Parameters
value
boolValue to set.
ShowReportAsync(ShowReportOptions)
Shows a report.
Task ShowReportAsync(ShowReportOptions options)
Parameters
options
ShowReportOptionsOptions.
Returns
SortAsync()
Sorts the data in the datasource based on the sorts set in DataSorts.
When all data is loaded or when sorting an embedded sub-view model, sorting is done on the client side. Otherwise, sorting is done on the server side and sorted data is sent back to the client.
Task SortAsync()
Returns
UnselectAllItemsAsync()
Unselects all the items of the current datasource.
Task UnselectAllItemsAsync()
Returns
UnselectItemAsync(IUIView)
Unselects the specified item of the datasource.
Task UnselectItemAsync(IUIView item)
Parameters
item
IUIViewThe item to unselect.
Returns
UnselectItemAsync(int)
Unselects the item at the specified index in the datasource.
Task UnselectItemAsync(int index)
Parameters
index
intThe index of the item to unselect.
Returns
ValidateDataAsync()
Validates the data according to the input constraints and the validation rules.
Task<bool> ValidateDataAsync()