private List LookupList(ListItemModelHost listItemModelHost, ListViewWebPartDefinition wpModel) { var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; List list = null; if (!string.IsNullOrEmpty(wpModel.ListUrl)) { list = web.QueryAndGetListByUrl(wpModel.ListUrl); } else if (!string.IsNullOrEmpty(wpModel.ListTitle)) { list = web.Lists.GetByTitle(wpModel.ListTitle); } else if (wpModel.ListId != default(Guid)) { list = web.Lists.GetById(wpModel.ListId.Value); } else { throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined."); } return list; }
private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, ListViewWebPartDefinition wpModel) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var list = LookupList(listItemModelHost, wpModel); View view = null; if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid)) view = list.Views.GetById(wpModel.ViewId.Value); else if (!string.IsNullOrEmpty(wpModel.ViewName)) view = list.Views.GetByTitle(wpModel.ViewName); context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; if (wpModel.TitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) result.TitleUrl = list.DefaultViewUrl; } return result; }
public void CanDeploy_WebpartToWikiPageContent_As_AddToPageContent() { // Some web part provision on wiki page give empty markup // https://github.com/SubPointSolutions/spmeta2/issues/693 // web part ID, zone and AddToPageContent must be as such // you can move these params into your web part definition var listViewWebPartDef = new ListViewWebPartDefinition { Title = String.Format("ListViewWebPartDefinition - {0}", Rnd.String()), Id = "g_" + Guid.NewGuid().ToString("D").Replace('-', '_'), ZoneIndex = 10, ZoneId = "wpz", AddToPageContent = true, ListUrl = BuiltInListDefinitions.SitePages.CustomUrl }; var webModel = SPMeta2Model .NewWebModel(web => { web .AddHostList(BuiltInListDefinitions.SitePages, list => { list .AddRandomWikiPage(page => { page.RegExcludeFromValidation(); page .AddListViewWebPart(listViewWebPartDef) .AddRandomWebpart(wpNode => { var wp = wpNode.Value as WebPartDefinition; wp.Id = "g_" + Guid.NewGuid().ToString("D").Replace('-', '_'); wp.ZoneId = "wpz"; wp.AddToPageContent = true; }) .AddRandomWebpart(wpNode => { var wp = wpNode.Value as WebPartDefinition; wp.Id = "g_" + Guid.NewGuid().ToString("D").Replace('-', '_'); wp.ZoneId = "wpz"; wp.AddToPageContent = true; }) .AddRandomWebpart(wpNode => { var wp = wpNode.Value as WebPartDefinition; wp.Id = "g_" + Guid.NewGuid().ToString("D").Replace('-', '_'); wp.ZoneId = "wpz"; wp.AddToPageContent = true; }) ; }); }); }); TestModel(webModel); }
private ClientXsltListViewWebPartDefinitionValidator.ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, ListViewWebPartDefinition wpModel) { var result = new ClientXsltListViewWebPartDefinitionValidator.ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var list = LookupList(listItemModelHost, wpModel); View view = null; if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid)) view = list.Views.GetById(wpModel.ViewId.Value); else if (!string.IsNullOrEmpty(wpModel.ViewName)) view = list.Views.GetByTitle(wpModel.ViewName); else if (!string.IsNullOrEmpty(wpModel.ViewUrl)) { var views = list.Views; context.Load(views, v => v.Include(r => r.ServerRelativeUrl)); context.ExecuteQueryWithTrace(); view = views.ToArray() .FirstOrDefault(v => v.ServerRelativeUrl.ToUpper().EndsWith(wpModel.ViewUrl.ToUpper())); } context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; if (wpModel.TitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) result.TitleUrl = list.DefaultViewUrl; } return result; }
public static ModelNode AddListViewWebPart(this ModelNode model, ListViewWebPartDefinition definition, Action<ModelNode> action) { return model.AddDefinitionNode(definition, action); }
public static ModelNode AddListViewWebPart(this ModelNode model, ListViewWebPartDefinition definition) { return AddListViewWebPart(model, definition, null); }