/// <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); }
/// <summary> /// Creates and returns the <see cref="BaseItemsControlPage{TClass}.DataPresenter"/> /// </summary> /// <returns></returns> protected override IItemsControl <PropertyMap> CreateItemsControl() { return(new CollapsibleDataGrid <PropertyMap>() { Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value } .ShowData(x => x.TableName) .ShowData(x => x.ColumnName) .ShowData(x => x.ValueType) .ShowData(x => x.Name) .ShowData(x => x.Description) .ShowData(x => x.Attributes) .ShowData(x => x.Color) .ShowData(x => x.DefaultValue) .ShowData(x => x.Order) .ShowData(x => x.IsEditable) .ShowData(x => x.IsRequired) .ShowData(x => x.IsPreview) .SetColorUIElement(x => x.Color) .SetLabelUIElement(x => x.ValueType, model => model.ValueType.ToLocalizedString(), model => model.ValueType.ToColorHex()) .SetBooleanUIElement(x => x.IsEditable) .SetBooleanUIElement(x => x.IsRequired) .SetBooleanUIElement(x => x.IsPreview) .SetSubElement(x => x.Attributes, model => model.Attributes?.Count().ToString("attribute", "attributes", "No attributes"), async(row, model) => { var itemsControl = new WrapPanelItemsControl <ColumnAttribute, BorderedTextBlock>(x => { var label = ControlsFactory.CreateLabelTag(x.Name, x.Color); label.Margin = new Thickness(NormalUniformMargin); return label; }) { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center }; itemsControl.SetItemsSource(model.Attributes); return await Task.FromResult(itemsControl); }, (row, model, element) => element.SetItemsSource(model.Attributes)) .SetTextInputUIElement(x => x.Order, async(row, model, value) => { var result = await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync(); return new Failable <PropertyMap>() { ErrorMessage = result.ErrorMessage }; }) .ConfigureOptions((container, grid, row, model) => { container.AddEditOption("Property map modification", null, () => { return new DataForm <PropertyMap>() { Mapper = CeidDiplomatikiDataModelHelpers.PropertyMapMapper.Value } .ShowInput(x => x.Name, settings => settings.IsRequired = true) .ShowInput(x => x.Description) .ShowStringColorInput(x => x.Color) .ShowSelectMultipleOptionsInput(x => x.Attributes, (form, propertyInfo) => new DropDownMenuOptionsFormInput <ColumnAttribute>(form, propertyInfo, ColumnAttributes.Data.Value, x => x.Name), settings => settings.IsRequired = true) .ShowNumericInput(x => x.Order) .ShowInput(x => x.DefaultValue) .ShowInput(x => x.IsEditable) .ShowInput(x => x.IsRequired) .ShowInput(x => x.IsPreview); }, async(model) => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync(), null, IconPaths.TableColumnPath); container.AddDeleteOption("Property map deletion", null, async(model) => { // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Unregister the map QueryMap.Remove(model); // Save the changes return await manager.SaveChangesAsync(); }, null, IconPaths.TableColumnPath); })); }