Hello
I am new to using UI Builder and I want to try and display a context app on the member to display an audit log of some content pages that have been marked read or seen that we store in a custom DB table like so.
using System.ComponentModel.DataAnnotations.Schema;
namespace Infrastructure.Database.Tables;
/// <summary>
/// We only insert DB records for members that have read or seen a page
/// So if a member has not read or seen a page then there will be no record in the DB
/// A record will always exist with a seen date/time but possibly not a read date/time
/// </summary>
[Table("MustReadPages")]
public class MustReadPages
{
/// <summary>
/// This is the int based PK primary key for the DB table
/// </summary>
public int ID { get; set; }
/// <summary>
/// The GUID of the member
/// </summary>
public Guid UmbracoMemberKey { get; set; }
/// <summary>
/// The GUID of the content page that the member has read or seen
/// </summary>
public Guid UmbracoContentPageKey { get; set; }
/// <summary>
/// The date and time that the member has seen the page
/// </summary>
public DateTime? PageSeenAt { get; set; }
/// <summary>
/// The date and time that the member has marked the page as read
/// </summary>
/// <remarks>If null/empty then the page has not been read yet</remarks>
public DateTime? PageMarkedReadAt { get; set; }
}
Goals
Display a content/context app on the member to display just their entries and match the property UmbracoMemberKey
The list view of data needs to display the GUID/key of the content node as the friendly node name and perhaps a link back to the content node
I am trying to wrap my head around the docs and stuff I am finding to see if this can be done or not, so any pointers if this can be done or not and how I might achieve it would be fab
I think you would start out with a config that’s something like this:
public void Configure(UIBuilderConfigBuilder builder)
{
builder.WithSection(
"member",
withSectionConfig =>
{
withSectionConfig.WithTree(
"members",
withTreeConfig =>
{
withTreeConfig.AddContextApp(
"Comments",
contextAppConfig =>
{
contextAppConfig.AddCollection<MustReadPages>(
p => p.Id,
p => p.UmbracoMemberKey,
"Comments",
"A collection of comments",
"",
collectionConfig =>
{
// Collection configuration here
}
);
}
);
}
);
}
);
Then within the config you can define a listview however you like.
Be aware that the section and tree alias’ I’ve written here may not match, not sure what the core uses exactly.
This should atleast let you add a context app on members though.
Page key to be the name of the node could maybe be done somehow by fetching the node via the content cache and then using this to set the value in the listview: List Views | Umbraco UI Builder
The easier way would be to add properties to your model where you store the nodenames and then use those in your listview
You don’t nessecarily have to edit your db models, you can use the custom repository function in between to fetch your records, then look up names and then convert to a UI builder model you can return to the context app.