November Happy Hour will be moved to Thursday December 5th.

Work with Dashboard via code.

Vote:
 

Hello,

Is it possible to work with dashboard via code.

For example: Create Tab and gadget inside it? Or delete it?

#199057
Nov 14, 2018 10:56
Vote:
 

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

#199073
Nov 14, 2018 18:46
Vote:
 

Hi Jake,

Thanks!

I`ll try it.

#199089
Nov 15, 2018 7:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.