/// <summary> /// Creates and returns the <see cref="BaseItemsControlPage{TClass}.DataPresenter"/> /// </summary> /// <returns></returns> protected override IDataPresenter <DataGridPresenterMap> CreateDataPresenter() { var collapsibleDataGrid = new CollapsibleDataGrid <DataGridPresenterMap>() { Mapper = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value } .ShowData(x => x.Name) .ShowData(x => x.Description) .ShowData(x => x.DataGrids) .SetColorUIElement(x => x.Color) .SetDataPresenterSubElement(x => x.DataGrids, model => model.DataGrids.Count().ToString("grid", "grids", "No grids"), (model) => { var dataGrid = new CollapsibleDataGrid <DataGridMap>() { Translator = CeidDiplomatikiDataModelHelpers.DataGridMapTranslator.Value, Mapper = CeidDiplomatikiDataModelHelpers.DataGridMapMapper.Value } .ShowData(x => x.Type) .ShowData(x => x.AllowAdd) .ShowData(x => x.AllowEdit) .ShowData(x => x.AllowDelete) .ShowData(x => x.Columns) .ShowData(x => x.DateColumn) .ShowData(x => x.SearchColumns) .SetBooleanUIElement(x => x.AllowAdd) .SetBooleanUIElement(x => x.AllowEdit) .SetBooleanUIElement(x => x.AllowDelete) .SetCustomUIElement(x => x.DateColumn, (grid, row, model) => { return(new TextButton() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Text = model.DateColumn?.Name, BorderThickness = new Thickness(VisibleBorderThickness), Command = new RelayCommand(async() => { // Show the dialog var dialogResult = await DialogHelpers.ShowUniformGridSelectSingleDialogAsync(this, "Date column selection", null, model.Type.GetProperties().Where(x => x.PropertyType.IsDate()), (prop) => new InformationalButton() { Text = prop.Name }, null, IconPaths.CalendarCheckPath); // If we didn't get positive feedback... if (!dialogResult.Feedback) { // Return return; } // Update the model model.DateColumn = dialogResult.Model; var result = await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync(); // If there was an error... if (!result.Successful) { // Show the error await result.ShowDialogAsync(this); // Return return; } // Update the grid grid.Update(model); }) }); }, (grid, row, model, element) => element.Text = model.DateColumn?.Name) .SetDataPresenterSubElement(propertySelector: x => x.Columns, textValueExtractor: model => model.Columns?.Count().ToString("column", "columns", "No columns"), presenterImplementationFactory: model => { return(new DataGrid <PropertyInfo>() .ShowData(x => x.Name, RelationalAnalyzersHelpers.DbProviderColumnMapper.Value.GetTitle(x => x.ColumnName))); }, optionButtonConfiguration: (p, m, b) => { b.VectorSource = IconPaths.EditPath; b.Command = new RelayCommand(async() => { // Create the form var form = new OptionsSelectionForm <PropertyInfo>(); // For every column foreach (var column in m.Type.GetProperties()) { // Show it for selection form.ShowOption(column, column.Name, null, null, m.Columns.Any(x => x.Equals(column))); } // Show the dialog var dialogResult = await DialogHelpers.ShowSelectMultipleDialogAsync(this, "Columns selection", null, form); // If we didn't get positive feedback... if (!dialogResult.Feedback) { // Return return; } // Update the columns m.Columns = form.GetOptions(); // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Save the changes var result = await manager.SaveChangesAsync(); // If there was an error... if (!result.Successful) { // Show the error await result.ShowDialogAsync(this); // Return return; } p.SetItemsSource(m.Columns); DataPresenter.Update(model); }); }) .SetDataPresenterSubElement(propertySelector: x => x.SearchColumns, textValueExtractor: model => model.SearchColumns?.Count().ToString("column", "columns", "No columns"), presenterImplementationFactory: model => { return(new DataGrid <PropertyInfo>() .ShowData(x => x.Name, RelationalAnalyzersHelpers.DbProviderColumnMapper.Value.GetTitle(x => x.ColumnName))); }, optionButtonConfiguration: (p, m, b) => { b.VectorSource = IconPaths.EditPath; b.Command = new RelayCommand(async() => { // Create the form var form = new OptionsSelectionForm <PropertyInfo>(); // For every column foreach (var column in m.Type.GetProperties().Where(x => x.PropertyType == typeof(string))) { // Show it for selection form.ShowOption(column, column.Name, null, null, m.SearchColumns.Any(x => x.Equals(column))); } // Show the dialog var dialogResult = await DialogHelpers.ShowSelectMultipleDialogAsync(this, "Search columns selection", null, form); // If we didn't get positive feedback... if (!dialogResult.Feedback) { // Return return; } // Update the columns m.SearchColumns = form.GetOptions(); // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Save the changes var result = await manager.SaveChangesAsync(); // If there was an error... if (!result.Successful) { // Show the error await result.ShowDialogAsync(this); // Return return; } p.SetItemsSource(m.SearchColumns); DataPresenter.Update(model); }); }); dataGrid.ConfigureOptions((container, grid, row, model) => { container.AddEditOption("Data grid modification", null, () => { return(new DataForm <DataGridMap>() { Mapper = CeidDiplomatikiDataModelHelpers.DataGridMapMapper.Value } .ShowInput(x => x.AllowAdd) .ShowInput(x => x.AllowEdit) .ShowInput(x => x.AllowDelete)); }, async model => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync()); }); return(dataGrid); }); collapsibleDataGrid.ConfigureOptions((container, grid, row, model) => { container.AddEditOption("Data grid presenter modification", null, () => { return(new DataForm <DataGridPresenterMap>() { Mapper = CeidDiplomatikiDataModelHelpers.DataGridPresenterMapMapper.Value } .ShowInput(x => x.Name, settings => settings.IsRequired = true) .ShowInput(x => x.Description) .ShowStringColorInput(x => x.Color)); }, async model => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync()); container.AddDeleteOption("Data grid presenter deletion", null, async model => { // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Unregister the data presenter QueryMap.Remove(model); // Save the changes return(await manager.SaveChangesAsync()); }); }); return(collapsibleDataGrid); }