Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Adding archetype support to Ditto #44

Closed
wants to merge 1 commit into from
Closed

Adding archetype support to Ditto #44

wants to merge 1 commit into from

Conversation

micklaw
Copy link

@micklaw micklaw commented Mar 8, 2015

Adds support for archetype via the existing UmbracoPropertyAttributeClass which now contains an isArchetype field.

This hooks in to the existing TypeConverters and flow of application. Archetypes POCOs should follow the same naming convention standards as the main ditto POCOs, though will inherit from a base class of ArchetypeModel instead of the IPublishedContent.

I have ran this against almost all of the existing data types and conversion seems OK, though as archetype values are strings one or two data types may have slipped through.

@leekelleher leekelleher self-assigned this Mar 8, 2015
@@ -32,6 +32,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="interfaces">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimum version has to be v6 based as we are supporting v6 from now on.

@JimBobSquarePants
Copy link

That's a big commit! Cheers! 👍 I'll try and set aside some time tonight to have a look at it though I see @leekelleher get's up earlier than me on a Sunday so he'll probably beat me to it. 😄

@@ -100,7 +100,9 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
return multiNodeTreePicker;
}

return base.ConvertFrom(context, culture, value);
// [ML] - return default list as its always nice to avoid null reference exceptions on lists =)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno about this. You're might be right but Microsoft guidelines indicate always using base converters as a fallback. https://msdn.microsoft.com/en-us/library/ayybcxe5.aspx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I think the base converters throw exceptions as values passed in are always strings from archetype, so some are unable to cast to the new type a flake out. Sure there will be some work around we can use.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same concern as @JimBobSquarePants - having the base converter as fallback.

@micklaw - Yup, I'm sure we can workaround issues in the body of the ConvertFrom.

@leekelleher
Copy link
Collaborator

Thanks for the pull request!

I'll review in more detail tomorrow, (as I'm out & about today).

To be upfront, I doubt we'll merge this in as is, as it ties Ditto too closely to Archetype. But I definitely think there should be a Ditto-like way for mapping Archetype data. Let's use this as a discussion point to move it forward. 👍

@micklaw
Copy link
Author

micklaw commented Mar 8, 2015

No worries, just for clarity, this amend doesn't have any dependency to archetype at all, so even if it's not in the solution this should still function alright.

Sent from my iPhone

On 8 Mar 2015, at 13:33, Lee Kelleher notifications@github.com wrote:

Thanks for the pull request!

I'll review in more detail tomorrow, (as I'm out & about today).

To be upfront, I doubt we'll merge this in as is, as it ties Ditto too closely to Archetype. But I definitely think there should be a Ditto-like way for mapping Archetype data. Let's use this as a discussion point to move it forward.


Reply to this email directly or view it on GitHub.

@leekelleher
Copy link
Collaborator

@micklaw Thanks again for your PR! I'm reviewing it now :-)

Given the size of the commit, I'll probably ask a lot of questions... don't feel disheartened if I nitpick ;-)

/// <summary>
/// Defines if property is an Archetype
/// </summary>
public bool IsArchetype { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this binds Ditto too much with Archetype (not in terms of assembly reference, but conceptually).

Should we consider other 3rd party property-editors with complex data? IsNuPicker, IsSirTrevor, IsVorto
It makes Ditto non-generic.

Let's look for an alternative solution - preferably using TypeConverters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leekelleher Type converters makes sense to me, could potentially extend the ArchetypeModel (https://github.com/imulus/Archetype/blob/master/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs) with a FieldSetAs method of something? Would these TypeConverters be completed in a separate assembly to avoid assembly dependency?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 That's where my thinking is at the moment - separate assembly to specifically to handle Archetype data.

@micklaw
Copy link
Author

micklaw commented Mar 9, 2015

Ha, no worries, I'm thick skinned ;)

At the GLUUG a few of the guys thought it was a good idea. I had already
done something similar and thought it may be useful. I mentioned to
@JimBobSquarePants https://github.com/JimBobSquarePants I'd fire
something over. I always thought the solution to this problem was always
going to be subjective, though the idea and principle seemed like a good
one to me.

On 9 March 2015 at 10:30, Lee Kelleher notifications@github.com wrote:

@micklaw https://github.com/micklaw Thanks again for your PR! I'm
reviewing it now :-)

Given the size of the commit, I'll probably ask a lot of questions...
don't feel disheartened if I nitpick ;-)


Reply to this email directly or view it on GitHub
#44 (comment)
.

Cheers

Michael Law

@leekelleher
Copy link
Collaborator

OK, hopefully I wasn't too much of an arsehole in my review?

In concept, I am 100% sure that we should find a way to have Ditto-like way for mapping Archetype data!

With the implementation, (as I keep going on about), I don't want the Ditto (core) to be aware of Archetype itself. I think there is a way by using TypeConverters - which I'd like us to explore.

❤️ Thanks again for the PR - much kudos to you! (For taking the time to get involved, it is appreciated!) I'll buy you a 🍺!

@leekelleher leekelleher mentioned this pull request Mar 9, 2015
@micklaw
Copy link
Author

micklaw commented Mar 10, 2015

@leekelleher @JimBobSquarePants Fellas, how would you feel if i refactored this code to be in the same wat as we discussed in a separate assembly and use a ArchetypeConverter to bind the data?

Had a look over again and don't think it would much longer. Plus also sort the issues above that need amended obviously =)

@leekelleher
Copy link
Collaborator

@micklaw - I think there is a definite need for Archetype POCO mapping.

Discussing with @mattbrailsford about it being part of the Ditto project, (see my comment on #46), we came to the conclusion that it is beyond the scope of Ditto - in terms of both concept and ongoing support.

Saying that, I don't want to discourage you (or anyone else) from developing a solution... so yes, please feel free to do it as a separate project.

@mattbrailsford @JimBobSquarePants - did you want to add comment on this?

@micklaw
Copy link
Author

micklaw commented Mar 10, 2015

@leekelleher Based on the previous pull request, I separated some of the logic to its own method for setting the value of the instance properties. I have taken this a step further and exposed the method in the class below as its own interfaced class with a single SetValue method.

https://github.com/micklaw/umbraco-ditto/blob/archetype/src/Our.Umbraco.Ditto/Extensions/PublishedContentExtensions.cs

As i see it in my tests, this would be the only change to the ditto source to make this class and interface public. The rest can be hooked in a separate assembly via type converters. This would mean the archetype integration could be completely separate from the ditto source.

Thinking about it if this method was made public, anyone could hook in to the Ditto model builder, so it would be possible to hook in Sir Trevor etc if anyone was interested.

@micklaw
Copy link
Author

micklaw commented Mar 10, 2015

Here's a sample project separated out, didn't take long to hook up. Core has no dependency on archtypes or anything else.

https://github.com/micklaw/umbraco-ditto/tree/archetype-refactor

Hooked using type converters and classes hanging off the Archetype models =)

@jbreuer
Copy link

jbreuer commented May 7, 2015

Hey did you read this topic about Archetype? modelsbuilder/ModelsBuilder.Original#13 Not really related to this, but more people want to generate models for Archetype ;-).

@micklaw
Copy link
Author

micklaw commented May 20, 2015

Hey, I defo think this has its place too. I'm a bit swamped for time at the
moment with other work but when i get some free time i think i'm going to
look in to creating an external assembly for Ditto which could potentially
map Archetype and Grid Type with POCOs.

On 7 May 2015 at 12:56, Jeroen Breuer notifications@github.com wrote:

Hey did you read this topic about Archetype? modelsbuilder/ModelsBuilder.Original#13
modelsbuilder/ModelsBuilder.Original#13 Not really
related to this, but more people want to generate models for Archetype ;-).


Reply to this email directly or view it on GitHub
#44 (comment)
.

Cheers

Michael Law

@leekelleher
Copy link
Collaborator

Closing this PR.

Thanks again @micklaw - stellar effort here! Noticed your new project/repo at Ditto.Resolvers, I think that's the best move going forwards. (I may even contribute to it! 😎)

@micklaw
Copy link
Author

micklaw commented May 26, 2015

No worries man, I think your spot on with the separate repository approach. I really like the new changes in the develop branch, defo makes the framework much more flexible =) Good work dudes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants