Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi Roman,
It's not something I've worked with before but you'll want to make use of the PersonalizedViewSettingsManager and/or the IPersonalizedViewSettingsRepository Interface.
I just put together this sample which shows creating a tab, naming it 'Test' and adding a Notes gadget to it:
var viewManager = ServiceLocator.Current.GetInstance<IViewManager>();
var personalizedViewSettingsManager = ServiceLocator.Current.GetInstance<PersonalizedViewSettingsManager>();
var componentManager = ServiceLocator.Current.GetInstance<IComponentManager>();
var user = HttpContext.User;
const string dashboardViewName = "/episerver/dashboard";
ICompositeView compositeView = viewManager.CreateView(dashboardViewName, user);
// Get the tab container, this should always be below our root container
var tabContainer = (TabContainer)compositeView.RootContainer.Components.First(x => x.DefinitionName.Equals(typeof(TabContainer)
.FullName));
PersonalizedViewSettings personalizedViewSettings;
IContainer container;
tabContainer = (TabContainer)personalizedViewSettingsManager.GetOrCreatePersonalizedComponent(user,
dashboardViewName, tabContainer.Id, out personalizedViewSettings, out container);
// Create a ComponentContainer for our new tab
var singleTabContainer = (ComponentContainer)componentManager.CreateComponent(typeof(ComponentContainer).FullName, user);
tabContainer.Add(singleTabContainer);
var notesComponent = componentManager.CreateComponent("EPiServer.Cms.Shell.UI.Controllers.NotesController", user);
// Set the heading & add the notes gadget
singleTabContainer.Settings["personalizableHeading"] = "Test";
singleTabContainer.Add(notesComponent);
personalizedViewSettingsManager.Repository.Save(personalizedViewSettings);
There are very likely some improvements that can be made to this - but it should give you a starting point.
/Jake
Hello,
Is it possible to work with dashboard via code.
For example: Create Tab and gadget inside it? Or delete it?