nuPickers icon indicating copy to clipboard operation
nuPickers copied to clipboard

Migrate nuPickers to v8

Open bielu opened this issue 5 years ago • 23 comments

It is an initial version for v8, few things have to be still polished, but works! I am happy to continue to work on UI changes and/code optimizations. I think it is ready to be published as prerelease and check with other Umbraco developers if everything is working as intended

bielu avatar Aug 14 '19 07:08 bielu

I see the PickerPropertyValueConverter still uses the AssignedContentItem to determine the contextId and parentId, but Umbraco 8 now provides the owner IPublishedElement:

https://github.com/uComponents/nuPickers/blob/218212a98982944ab85a6ff820a69958daafbcf0/source/nuPickers/PickerPropertyValueConverter.cs#L84-L85

ronaldbarendse avatar Aug 14 '19 08:08 ronaldbarendse

@ronaldbarendse actually good catch, it was for now done to works, now I am doing additional refactor but I make PR with a version which is already working :)

bielu avatar Aug 14 '19 08:08 bielu

@ronaldbarendse moved to use owner :)

bielu avatar Aug 14 '19 10:08 bielu

@bielu,

Any chance we could change the GetPropertyValueType method in the PickerPropertyValueConverter to the following? Right now, the property value converter in this pull request sets the type to string. This affects how ModelsBuilder generates the nupicker properties on its models.

public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(Picker);

I forked off of your bielu/v8/develop branch and tried it out locally and confirmed that ModelsBuilder generates the nuPicker properties with type nuPickers.Picker after this change.

Thanks for all the hard work on this!

bowserm avatar Nov 07 '19 22:11 bowserm

I will look at that's tomorrow morning 😜

bielu avatar Nov 07 '19 22:11 bielu

@bowserm changed :)

bielu avatar Nov 08 '19 15:11 bielu

Hey @bielu , the saveFormat of the EnumPrefetchListPicker isn't getting saved. This is because the value is not being assigned.

-Joep

joepvtl avatar Jan 08 '20 14:01 joepvtl

@joepvtl I will look into that tomorrow morning :)

bielu avatar Jan 08 '20 18:01 bielu

I am seeing what I believe is the saveFormat error on the EnumRadioButtonPicker. When I look in the DB, this is what I am seeing as the prevalues for my datatype when I selected csv as the saveFormat:

{"useLabel":false,"dataSource":{"assemblyName":"ScientificGames.Core.dll","apiController":"EnumDataSourceApi","enumName":"ScientificGames.Core.Models.DataTypeDataSources.LeftRightTopBottomOrientation"},"customLabel":null,"layoutDirection":"horizontal","saveFormat":null,"items":[]}

I'll race you to a fix blielu :). I'll see if the same problem is happening to other editors.

bowserm avatar Jan 16 '20 19:01 bowserm

@bielu I made a PR to the v8/develop branch on your fork. I think I have it working.

bowserm avatar Jan 16 '20 20:01 bowserm

@bowserm thanks for the help, I reviewed that and merged code. Actually I am quite little less active now as I have crazy time but I am happy to merge PRs.

bielu avatar Jan 17 '20 10:01 bielu

Is this Likely to be the definitive upgrade path for nuPickers? im a bit confused between this and https://github.com/uComponents/Pikachu which says its a v8 rebuild.

is there any "official" word on plans for v8 its almost a year old now.

PezCo avatar Jan 27 '20 17:01 PezCo

@PezCo this is Upgrade of actual nuPickers which I started, as I needed use nuPickers in one of the projects, Pikachu was supposed to rebuild that for v8, not direct migration like that branch. @Hendy is responsible for the official part of that, but not sure what is his decision at all :).

bielu avatar Jan 28 '20 07:01 bielu

If you need an alternative to nuPickers for Umbraco 8, you might also be interested in Data List from @leekelleher: https://github.com/leekelleher/umbraco-contentment/blob/master/docs/editors/data-list.md.

ronaldbarendse avatar Jan 28 '20 08:01 ronaldbarendse

Ideally i want this branch. I have a fairly large public Umbraco v7 site that i'm upgrading to v8 that makes use of nuPickers. Unfortunately im not really experienced in umbraco plugins or its source code so not in much of a position to help here, im just looking for the least pain free way to migrate.

PezCo avatar Jan 28 '20 09:01 PezCo

Great work. I have made my own build of your branch to use on an Umbraco V8 installation (v. 8.6.1). But i ran into some problems with PanicExceptions getting thrown in PickerPropertyValueConverter when it tries to access the parent property. It looks like it's related to NuCache, but i can't seem to solve it by just rebuilding the cache. I'm using modelsbuilder and it happens when i try to get the values of the property that use the nupicker datatype. It's shows op fine in the Backoffice.

public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType,
            PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
        {
            int contextId = -1;
            int parentId = -1;

            IPublishedContent assignedContentItem = owner as IPublishedContent;

            if (assignedContentItem != null)
            {
                contextId = assignedContentItem.Id;

                if (assignedContentItem.Parent != null)
                {
                    parentId = assignedContentItem.Parent.Id;
                }
            }

            return new Picker(
                contextId,
                parentId,
                propertyType.EditorAlias,
                propertyType.DataType.Id,
                propertyType.Alias,
                inter);
        }

My workaround was to surround the failing code with a try/cacth and ignore the PanicException. It solves it in my case, but i have yet to discover if it has any sideeffects.

if (assignedContentItem != null)
            {
                contextId = assignedContentItem.Id;

                try
                {
                    if (assignedContentItem.Parent != null)
                    {
                        parentId = assignedContentItem.Parent.Id;
                    }
                }
                catch (PanicException e)
                {
                    //Ignore PanicException
                }
                
            }

jesperbrasmussen avatar Jun 05 '20 10:06 jesperbrasmussen

@jesperbrasmussen can you add which version of v8 are you using? and I will look into that issue when I will have time

bielu avatar Jun 05 '20 10:06 bielu

@jesperbrasmussen can you add which version of v8 are you using? and I will look into that issue when I will have time

Yes it's v. 8.6.1

jesperbrasmussen avatar Jun 05 '20 11:06 jesperbrasmussen

@jesperbrasmussen can you also paste exception log as maybe I will be find out that just by exception as I check Umbraco source code and not much change here about ConvertIntermediateToObject and I will need to recreate but would prefer be sure it is same exception if I will cause any :)

bielu avatar Jun 05 '20 11:06 bielu

I have just tested it on the lastest version of Umbraco which is v8.6.2, and I still get get the same error.

This is the first part of the exception:

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>invalid item type</ExceptionMessage>
<ExceptionType>Umbraco.Core.Exceptions.PanicException</ExceptionType>
<StackTrace> at Umbraco.Web.PublishedCache.NuCache.PublishedContent.GetGetterById() in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\PublishedContent.cs:line 123 at Umbraco.Web.PublishedCache.NuCache.PublishedContent.get_Parent() in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\PublishedContent.cs:line 261 at nuPickers.PickerPropertyValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview) in S:\Solutions (external)\nuPickers\source\nuPickers\PickerPropertyValueConverter.cs:line 118 at Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview) in D:\a\1\s\src\Umbraco.Core\Models\PublishedContent\PublishedPropertyType.cs:line 219 at Umbraco.Web.PublishedCache.NuCache.Property.GetValue(String culture, String segment) in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\Property.cs:line 211 at Umbraco.Web.PublishedPropertyExtension.Value[T](IPublishedProperty property, String culture, String segment, Fallback fallback, T defaultValue) in D:\a\1\s\src\Umbraco.Web\PublishedPropertyExtension.cs:line 39 at Umbraco.Web.PublishedContentExtensions.Value[T](IPublishedContent content, String alias, String culture, String segment, Fallback fallback, T defaultValue) in D:\a\1\s\src\Umbraco.Web\PublishedContentExtensions.cs:line 163 at MyProject.UmbracO2.Models.CustomerMember.get_AllowedTypesForMember() in S:\Solutions\MyProject\MyProject.com_v8\MyProject.UmbracO2\Models\CustomerMember.generated.cs:line 60 at MyProject.UmbracO2.Models.CustomerMember.MyProject.Core.Interfaces.Member.ICustomerMember.get_AllowedTypesForMember() in S:\Solutions\MyProject\MyProject.com_v8\MyProject.UmbracO2\Models\CustomerMember.cs:line 16 at MyProject.UmbracO2.Services.UmbracoMembershipService.GetAllowedTypes(Int32 memberId) in S:\Solutions\MyProject\MyProject.com_v8\MyProject.UmbracO2\Services\UmbracoMembershipService.cs:line 63 at MyProject.UmbracO2.Services.Member.MemberAdministrationService.GetAllowedTypes(Int32 memberId) in S:\Solutions\MyProject\MyProject.com_v8\MyProject.UmbracO2\Services\Member\MemberAdministrationService.cs:line 347 at MyProject.UmbracO2.Controllers.Backoffice.Section.AdminToolController.<>c__DisplayClass6_0.<ListUsers>b__3(IMember group) in S:\Solutions\MyProject\MyProject.com_v8\MyProject.UmbracO2\Controllers\Backoffice\Section\AdminToolController.cs:line 71 at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.ToLookup[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector) at MyProject.UmbracO2.Controllers.Backoffice.Section.AdminToolController.ListUsers(Boolean includeInactive) in 

jesperbrasmussen avatar Jun 08 '20 08:06 jesperbrasmussen

@jesperbrasmussen thanks that error log is helpful! Will look over weekend how to fix that issue! :)

bielu avatar Jun 08 '20 08:06 bielu

@jesperbrasmussen I tried on clear umbraco 8.6.2 today and can't reproduce that issue,

bielu avatar Jun 20 '20 11:06 bielu

@jesperbrasmussen I tried on clear umbraco 8.6.2 today and can't reproduce that issue,

Ok. I'll try to find time to do a test on a clean umbraco 8.6.2, and see if i can find a way to reproduce the error

jesperbrasmussen avatar Jun 22 '20 06:06 jesperbrasmussen