umbraco-fluidity icon indicating copy to clipboard operation
umbraco-fluidity copied to clipboard

Adding custom functionality to a view

Open c9mb opened this issue 4 years ago • 3 comments

Trying to wrap my head around how to create an extension to a Fluidity view for managing a many-to-many relationship table when editing one of the source tables.

Basically, I'll have a few custom tables created with PetaPoco.

  • Products
  • Catalogues
  • Catalogues_Products

Catalogues_Products needs to maintain a many-to-many relationship between Products and Catalogues, and would need its own advanced property-editor to manage the relationships - I guess the classic drag from box-1 to box-2 type of thing - which I suspect would perhaps need to read/update using a UmbracoAuthorizedJsonController.

Ideally, I'd like to offer the opportunity to edit the relationship when creating/updating either a Product or Catalogue using Fludity - i.e. if creating/updating a Product, allow the user to update the Catalogues it's related to - and similarly if creating/updating a Catalogue allow updating of the Products it's related to.

However, I'm not sure how to deal with it using fluidity - i.e. how to add the functionality of the custom property editor to the Fluidity view without requiring that Fluidity manage it - intercepting the read/update cycle to handle the custom property editor's needs - perhaps Fluidity.SavingEntity is one option for updating, but not sure about the read/load cycle?

Or perhaps I'm just too confused and can't see the forest for the trees.

c9mb avatar Jul 15 '20 08:07 c9mb

Actually, I suspect that what I'm really looking for is how to add a custom fields to the Fluidity views, that will be treated as a 'non-fluidity' fields and require that I handle the data needs of those by hooking into the appropriate load/save promise in the view controller - adding my own promise resource calling an UmbracoAuthorizedJsonController - and how to provide some attributes to those custom fields so that I can identify them and manage them when rendered in the view.

c9mb avatar Jul 16 '20 09:07 c9mb

Hey @c9mbundy Fluidity uses property editors for all it's field editors so to create a custom input for fluidity is actually to create a custom Umbraco property editor.

I'm not sure if it's suitable, but you could look at whether using nuPickers with a SQL data source might be a good enough option. With this you could create 2 property editors for picking either end of the relationship which would be displayed in either editor view. I'm not sure how to map this to a match table though so you may need a custom repository too to be able to store the values differently.

Alternatively you could create your own property editor to wrap that functionality.

mattbrailsford avatar Jul 17 '20 09:07 mattbrailsford

Hi Matt - thanks for that.

I'm quite prepared to write my own property editor to handle the relationship management, as I think that's probably the only way to be sure of the custom functionality I want, but I'm just struggling (i.e. probably means I'm too dumb) to see how I configure that as a field in a Fluidity editor, and how my property editor would know the entity (table.row) it is dealing with.

Would I be right in guessing that something like editorConfig.AddField(p => p.id).SetDataType("myPropertyEditorAlias") would place the custom field on the editor and provide it with the necessary row reference and that I'd need to configure the custom propertyeditor with a prevalue of the table-name so it can then get/set via an UmbracoAuthorizedJsonController?

c9mb avatar Jul 17 '20 11:07 c9mb