/// <summary> /// Moves the control to another section and column in the given position /// </summary> /// <param name="newColumn">New column that will host the control</param> /// <param name="position">New position for the control in the new column</param> public void MovePosition(ICanvasColumn newColumn, int position) { var currentColumn = Column; MovePosition(newColumn); ReindexColumn(currentColumn); MovePosition(position); }
/// <summary> /// Moves the control to another section and column while keeping it's current position /// </summary> /// <param name="newColumn">New column that will host the control</param> public void MovePosition(ICanvasColumn newColumn) { var currentColumn = Column; section = newColumn.Section; column = newColumn; ReindexColumn(currentColumn); ReindexColumn(Column); }
/// <summary> /// Moves the control to another section and column while keeping it's current position /// </summary> /// <param name="newSection">New section that will host the control</param> public void MovePosition(ICanvasSection newSection) { var currentSection = Section; section = newSection; column = newSection.DefaultColumn; ReindexSection(currentSection); ReindexSection(Section); }
private void ReindexColumn(ICanvasColumn column) { var index = 0; foreach (var control in this.column.Section.Page.Controls.Where(c => c.Section == column.Section && c.Column == column).OrderBy(c => c.Order)) { index++; (control as CanvasControl).order = index; } }
internal void MoveTo(ICanvasSection newSection, ICanvasColumn newColumn) { section = newSection; column = newColumn; }
/// <summary> /// Moves the control to another section and column /// </summary> /// <param name="newColumn">New column that will host the control</param> /// <param name="order">New order for the control in the new column</param> public void Move(ICanvasColumn newColumn, int order) { Move(newColumn); this.order = order; }
/// <summary> /// Moves the control to another section and column /// </summary> /// <param name="newColumn">New column that will host the control</param> public void Move(ICanvasColumn newColumn) { section = newColumn.Section; column = newColumn; }
/// <summary> /// Moves the control to another section and column /// </summary> /// <param name="newSection">New section that will host the control</param> public void Move(ICanvasSection newSection) { section = newSection; column = newSection.DefaultColumn; }
private void GenerateTargetCanvasControl(IPage targetPage, List <PageComponent> componentsToAdd, int controlOrder, ICanvasColumn targetColumn, Model.CanvasControl control, Dictionary <string, string> globalTokens, Guid taskId) { // Prepare a web part control container IPageComponent baseControl = null; switch (control.ControlType) { case Model.CanvasControlType.ClientSideText: // Here we add a text control var text = targetPage.NewTextPart(); text.Text = control["Text"] as string; // Add the actual text control to the page targetPage.AddControl(text, targetColumn, controlOrder); // Log the just executed action logger.LogInformation( TransformationResources.Info_CreatedTextControl .CorrelateString(taskId)); break; case Model.CanvasControlType.CustomClientSideWebPart: // Parse the control ID to support generic web part placement scenarios var ControlId = control["ControlId"] as string; // Check if this web part belongs to the list of "usable" web parts for this site baseControl = componentsToAdd.FirstOrDefault(p => p.Id.Equals($"{{{ControlId}}}", StringComparison.InvariantCultureIgnoreCase)); logger.LogInformation( TransformationResources.Info_UsingCustomModernWebPart .CorrelateString(taskId)); break; case Model.CanvasControlType.DefaultWebPart: // Determine the actual default web part var webPartType = (DefaultWebPart)Enum.Parse(typeof(DefaultWebPart), control["WebPartType"] as string); var webPartName = targetPage.DefaultWebPartToWebPartId(webPartType); var webPartTitle = control["Title"] as string; var webPartProperties = control["Properties"] as Dictionary <string, string>; var jsonControlData = control["JsonControlData"] as string; if (webPartType == DefaultWebPart.ClientWebPart) { var addinComponents = componentsToAdd.Where(p => p.Name.Equals(webPartName, StringComparison.InvariantCultureIgnoreCase)); foreach (var addin in addinComponents) { // Find the right add-in web part via title matching...maybe not bullet proof but did find anything better for now JObject wpJObject = JObject.Parse(addin.Manifest); // As there can be multiple classic web parts (via provider hosted add ins or SharePoint hosted add ins) we're looping to find the first one with a matching title foreach (var addinEntry in wpJObject["preconfiguredEntries"]) { if (addinEntry["title"]["default"].Value <string>() == webPartTitle) { baseControl = addin; var jsonProperties = addinEntry; // Fill custom web part properties in this json. Custom properties are listed as child elements under clientWebPartProperties, // replace their "default" value with the value we got from the web part's properties jsonProperties = PopulateAddInProperties(jsonProperties, webPartProperties); // Override the JSON data we read from the model as this is fully dynamic due to the nature of the add-in client part jsonControlData = jsonProperties.ToString(Newtonsoft.Json.Formatting.None); logger.LogInformation( TransformationResources.Info_ContentUsingAddinWebPart .CorrelateString(taskId), baseControl.Name); break; } } } } else { baseControl = componentsToAdd.FirstOrDefault(p => p.Name.Equals(webPartName, StringComparison.InvariantCultureIgnoreCase)); logger.LogInformation( TransformationResources.Info_ContentUsingModernWebPart .CorrelateString(taskId), webPartType); } // If we found the web part as a possible candidate to use then add it if (baseControl != null) { var jsonDecoded = WebUtility.HtmlDecode(this.tokenParser.ReplaceTargetTokens(targetPage.PnPContext, jsonControlData, webPartProperties, globalTokens)); var myWebPart = targetPage.NewWebPart(baseControl); myWebPart.Order = controlOrder; myWebPart.PropertiesJson = jsonDecoded; // Add the actual text control to the page targetPage.AddControl(myWebPart, targetColumn, controlOrder); logger.LogInformation( TransformationResources.Info_AddedClientSideWebPartToPage .CorrelateString(taskId), webPartTitle); } else { logger.LogWarning( TransformationResources.Warning_ContentWarnModernNotFound .CorrelateString(taskId)); } break; default: break; } }