Updates the checkbox html editor to store the string values, not int ids, renames the underlying confg editor and updates comments, updates the migration and we'll need to migrate the checkbox data too.
This commit is contained in:
@@ -128,7 +128,7 @@ namespace Umbraco.Core.Migrations.Upgrade
|
||||
To<UpdatePickerIntegerValuesToUdi>("{38C809D5-6C34-426B-9BEA-EFD39162595C}");
|
||||
To<RenameUmbracoDomainsTable>("{6017F044-8E70-4E10-B2A3-336949692ADD}");
|
||||
To<AddUserLoginDtoDateIndex>("98339BEF-E4B2-48A8-B9D1-D173DC842BBE");
|
||||
To<RadioButtonPropertyEditorsMigration>("{940FD19A-00A8-4D5C-B8FF-939143585726}");
|
||||
To<RadioButtonAndCheckboxPropertyEditorsMigration>("{940FD19A-00A8-4D5C-B8FF-939143585726}");
|
||||
|
||||
//FINAL
|
||||
|
||||
|
||||
@@ -1,81 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Cache;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
|
||||
{
|
||||
public class RadioButtonPropertyEditorsMigration : MigrationBase
|
||||
public class RadioButtonAndCheckboxPropertyEditorsMigration : MigrationBase
|
||||
{
|
||||
public RadioButtonPropertyEditorsMigration(IMigrationContext context)
|
||||
public RadioButtonAndCheckboxPropertyEditorsMigration(IMigrationContext context)
|
||||
: base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Migrate()
|
||||
{
|
||||
//need to convert the old drop down data types to use the new one
|
||||
var dataTypes = Database.Fetch<DataTypeDto>(Sql()
|
||||
.Select<DataTypeDto>()
|
||||
.From<DataTypeDto>()
|
||||
.Where<DataTypeDto>(x => x.EditorAlias == "Umbraco.RadioButtonList"));
|
||||
MigrateRadioButtons();
|
||||
MigrateCheckBoxes();
|
||||
}
|
||||
|
||||
private void MigrateCheckBoxes()
|
||||
{
|
||||
//fixme: complete this
|
||||
|
||||
var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.CheckBoxList);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void MigrateRadioButtons()
|
||||
{
|
||||
var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.RadioButtonList);
|
||||
|
||||
var refreshCache = false;
|
||||
foreach (var dataType in dataTypes)
|
||||
{
|
||||
ValueListConfiguration config;
|
||||
|
||||
if (!dataType.Configuration.IsNullOrWhiteSpace())
|
||||
if (dataType.Configuration.IsNullOrWhiteSpace())
|
||||
continue;
|
||||
|
||||
// parse configuration, and update everything accordingly
|
||||
try
|
||||
{
|
||||
// parse configuration, and update everything accordingly
|
||||
try
|
||||
{
|
||||
config = (ValueListConfiguration) new ValueListConfigurationEditor().FromDatabase(
|
||||
dataType.Configuration);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error<DropDownPropertyEditorsMigration>(
|
||||
ex,
|
||||
"Invalid drop down configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared",
|
||||
dataType.Configuration);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// get property data dtos
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto>(Sql()
|
||||
.Select<PropertyDataDto>()
|
||||
.From<PropertyDataDto>()
|
||||
.InnerJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeDto, PropertyDataDto>((pt, pd) => pt.Id == pd.PropertyTypeId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<DataTypeDto, PropertyTypeDto>((dt, pt) => dt.NodeId == pt.DataTypeId)
|
||||
.Where<PropertyTypeDto>(x => x.DataTypeId == dataType.NodeId));
|
||||
|
||||
// update dtos
|
||||
var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config));
|
||||
|
||||
// persist changes
|
||||
foreach (var propertyDataDto in updatedDtos) Database.Update(propertyDataDto);
|
||||
|
||||
UpdateDataType(dataType);
|
||||
refreshCache = true;
|
||||
config = (ValueListConfiguration)new ValueListConfigurationEditor().FromDatabase(
|
||||
dataType.Configuration);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error<DropDownPropertyEditorsMigration>(
|
||||
ex,
|
||||
"Invalid radio button configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared",
|
||||
dataType.Configuration);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// get property data dtos
|
||||
var propertyDataDtos = Database.Fetch<PropertyDataDto>(Sql()
|
||||
.Select<PropertyDataDto>()
|
||||
.From<PropertyDataDto>()
|
||||
.InnerJoin<PropertyTypeDto>()
|
||||
.On<PropertyTypeDto, PropertyDataDto>((pt, pd) => pt.Id == pd.PropertyTypeId)
|
||||
.InnerJoin<DataTypeDto>()
|
||||
.On<DataTypeDto, PropertyTypeDto>((dt, pt) => dt.NodeId == pt.DataTypeId)
|
||||
.Where<PropertyTypeDto>(x => x.DataTypeId == dataType.NodeId));
|
||||
|
||||
// update dtos
|
||||
var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config));
|
||||
|
||||
// persist changes
|
||||
foreach (var propertyDataDto in updatedDtos) Database.Update(propertyDataDto);
|
||||
|
||||
UpdateDataType(dataType);
|
||||
refreshCache = true;
|
||||
}
|
||||
|
||||
if (refreshCache)
|
||||
{
|
||||
//FIXME: trigger cache rebuild. Currently the data in the database tables is wrong.
|
||||
}
|
||||
}
|
||||
|
||||
private List<DataTypeDto> GetDataTypes(string editorAlias)
|
||||
{
|
||||
//need to convert the old drop down data types to use the new one
|
||||
var dataTypes = Database.Fetch<DataTypeDto>(Sql()
|
||||
.Select<DataTypeDto>()
|
||||
.From<DataTypeDto>()
|
||||
.Where<DataTypeDto>(x => x.EditorAlias == editorAlias));
|
||||
return dataTypes;
|
||||
}
|
||||
|
||||
private void UpdateDataType(DataTypeDto dataType)
|
||||
@@ -123,7 +140,8 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
|
||||
|
||||
if (!canConvert) return false;
|
||||
|
||||
propData.VarcharValue = string.Join(",", values);
|
||||
//The radio button only supports selecting a single value, so if there are multiple for some insane reason we can only use the first
|
||||
propData.VarcharValue = values.Count > 0 ? values[0] : string.Empty;
|
||||
propData.TextValue = null;
|
||||
propData.IntegerValue = null;
|
||||
return true;
|
||||
@@ -52,9 +52,6 @@
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Umbraco.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\Umbraco.Tests\bin\Debug\Umbraco.Web.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- note: NuGet deals with transitive references now -->
|
||||
@@ -389,7 +386,7 @@
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\PropertyEditorsMigration.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\RefactorMacroColumns.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\RefactorVariantsModel.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\RadioButtonPropertyEditorsMigration.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\RadioButtonAndCheckboxPropertyEditorsMigration.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\RenameUmbracoDomainsTable.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\SuperZero.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\TablesForScheduledPublishing.cs" />
|
||||
|
||||
@@ -42,7 +42,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
|
||||
return f.checked;
|
||||
}),
|
||||
function(m) {
|
||||
return m.key;
|
||||
return m.value;
|
||||
});
|
||||
//get all of the same values between the arrays
|
||||
var same = _.intersection($scope.model.value, selectedVals);
|
||||
@@ -54,7 +54,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
|
||||
$scope.selectedItems = [];
|
||||
|
||||
for (var i = 0; i < configItems.length; i++) {
|
||||
var isChecked = _.contains($scope.model.value, configItems[i].id);
|
||||
var isChecked = _.contains($scope.model.value, configItems[i].value);
|
||||
$scope.selectedItems.push({
|
||||
checked: isChecked,
|
||||
key: configItems[i].id,
|
||||
@@ -66,13 +66,13 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
|
||||
function changed(item) {
|
||||
var index = _.findIndex($scope.model.value,
|
||||
function (v) {
|
||||
return v === item.key;
|
||||
return v === item.value;
|
||||
});
|
||||
|
||||
if (item.checked) {
|
||||
//if it doesn't exist in the model, then add it
|
||||
if (index < 0) {
|
||||
$scope.model.value.push(item.key);
|
||||
$scope.model.value.push(item.value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<li ng-repeat="item in selectedItems track by item.key">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="checkboxlist"
|
||||
value="{{item.key}}"
|
||||
value="{{item.value}}"
|
||||
ng-model="item.checked"
|
||||
ng-change="changed(item)"
|
||||
ng-required="model.validation.mandatory && !model.value.length" />
|
||||
|
||||
@@ -8,11 +8,6 @@ namespace Umbraco.Web.PropertyEditors
|
||||
/// <summary>
|
||||
/// A property editor to allow multiple checkbox selection of pre-defined items.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Due to remaining backwards compatible, this stores the id of the checkbox items in the database
|
||||
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the string value is published
|
||||
/// in cache and not the int ID.
|
||||
/// </remarks>
|
||||
[DataEditor(Constants.PropertyEditors.Aliases.CheckBoxList, "Checkbox list", "checkboxlist", Icon="icon-bulleted-list", Group="lists")]
|
||||
public class CheckBoxListPropertyEditor : DataEditor
|
||||
{
|
||||
@@ -31,6 +26,6 @@ namespace Umbraco.Web.PropertyEditors
|
||||
protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IDataValueEditor CreateValueEditor() => new PublishValuesMultipleValueEditor(Logger, Attribute);
|
||||
protected override IDataValueEditor CreateValueEditor() => new MultipleValueEditor(Logger, Attribute);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
|
||||
protected override IDataValueEditor CreateValueEditor()
|
||||
{
|
||||
return new PublishValuesMultipleValueEditor(Logger, Attribute);
|
||||
return new MultipleValueEditor(Logger, Attribute);
|
||||
}
|
||||
|
||||
protected override IConfigurationEditor CreateConfigurationEditor() => new DropDownFlexibleConfigurationEditor(_textService);
|
||||
|
||||
@@ -11,23 +11,23 @@ using Umbraco.Web.Composing;
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom value editor to handle posted json data and to return json data for the multiple selected items
|
||||
/// A value editor to handle posted json array data and to return array data for the multiple selected csv items
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is re-used by editors such as the multiple drop down list or check box list
|
||||
/// </remarks>
|
||||
internal class PublishValuesMultipleValueEditor : DataValueEditor
|
||||
internal class MultipleValueEditor : DataValueEditor
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
internal PublishValuesMultipleValueEditor(ILogger logger, DataEditorAttribute attribute)
|
||||
internal MultipleValueEditor(ILogger logger, DataEditorAttribute attribute)
|
||||
: base(attribute)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override so that we can return a json array to the editor for multi-select values
|
||||
/// Override so that we can return an array to the editor for multi-select values
|
||||
/// </summary>
|
||||
/// <param name="property"></param>
|
||||
/// <param name="dataTypeService"></param>
|
||||
@@ -860,7 +860,7 @@
|
||||
<Compile Include="PropertyEditors\DateTimeValidator.cs" />
|
||||
<Compile Include="PropertyEditors\IntegerPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\MultipleTextStringPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\PublishValuesMultipleValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\MultipleValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\RadioButtonsPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\RichTextPreValueController.cs" />
|
||||
<Compile Include="PropertyEditors\RichTextConfigurationEditor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user