Beispiel #1
0
        public void WebPartHelper_ShouldCreateAResponsivePlaceholderWebPartWithCorrectValues()
        {
            // Arrange
            ILogger    logger;
            IXmlHelper xmlHelper;

            using (var scope = UnitTestServiceLocator.BeginLifetimeScope())
            {
                logger    = scope.Resolve <ILogger>();
                xmlHelper = scope.Resolve <IXmlHelper>();
            }

            var webPartHelper = new WebPartHelper(xmlHelper, logger);

            // Define values for the placeholder
            var height          = 300;
            var backgroundColor = "#0092d7";
            var fontColor       = "#ffffff";
            var text            = "Testing";

            var expectedWebPartContent = string.Format(
                CultureInfo.InvariantCulture,
                "<div class='responsive-placeholder' style='height:{0}px;line-height:{0}px;background-color:{1};color:{2};text-align:center;'>{3}</div>",
                height,
                backgroundColor,
                fontColor,
                text);

            // Act
            var responsivePlaceholderWebPart = webPartHelper.CreateResponsivePlaceholderWebPart(height, backgroundColor, fontColor, text);

            // Assert
            Assert.IsNotNull(responsivePlaceholderWebPart);
            Assert.AreEqual(expectedWebPartContent, responsivePlaceholderWebPart.Content.InnerText);
        }
Beispiel #2
0
        private void CreateNewsListView(SPWeb web, SPList list)
        {
            // create new view with custom webpart
            SPViewCollection allviews = list.Views;
            string           viewName = Constants.NEWS_LISTPAGE;

            System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();

            var view = allviews.Add(viewName, viewFields, string.Empty, 1, true, true);

            WebPartHelper.HideXsltListViewWebParts(web, view.Url);
            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = view.Url,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 0,
                            ZoneId      = "Main",
                            WebpartName = "NewsListView.webpart"
                        }
                    }
                }
            });
            WebPartHelper.MoveWebPart(web, view.Url, "NewsListView.webpart", "Main", 0);

            view.Update();
            //list.Update();
        }
Beispiel #3
0
 private void BindNotInstalledWebParts()
 {
     grdAvailableParts.DataSource = WebPartHelper.GetUninstalledWebPartsFromAssemblies(siteSettings.SiteId, WebConfigSettings.AssembliesNotSearchedForWebParts);
     grdAvailableParts.DataBind();
     if (grdAvailableParts.Rows.Count == 0)
     {
         this.lblNoAvailableWebParts.Text = MyPageResources.WebPartAllInstalledMessage;
     }
 }
Beispiel #4
0
        private void CreateWebpartInNewsHomepage(SPWeb web, SPList list)
        {
            string pageUrl = Constants.NEWS_HOME_PAGE;
            string zoneId  = "Header";

            int latestIdx = WebPartHelper.GetLatestWebPartIndex(web, pageUrl, zoneId);

            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = pageUrl,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            AllowDuplicate = true,
                            Index          = latestIdx + 1,
                            ZoneId         = zoneId,
                            Title          = list.Title,
                            WebpartName    = "ViewNewsCategoryWebPart.webpart",
                            Properties     = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "WebID",
                                    Value = web.ID.ToString(),
                                    Type  = "string"
                                },
                                new Property()
                                {
                                    Name  = "ListID",
                                    Value = list.ID.ToString(),
                                    Type  = "string"
                                },
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = list.Title
                                },
                                new Property()
                                {
                                    Name  = "TitleUrl",
                                    Value = list.DefaultViewUrl
                                },
                                new Property()
                                {
                                    Name  = "Description",
                                    Value = ""
                                }
                            }
                        }
                    }
                }
            });
        }
Beispiel #5
0
        public static void AddCustomWebpart(string webPartName, string pageName, string title, SPWeb web, string zoneId, int zoneIndex)
        {
            var webPart = WebPartHelper.GetWebPart(web, webPartName);

            if (string.IsNullOrEmpty(webPart.Title))
            {
                webPart.Title = title;
            }
            WebPartHelper.AddWebPart(web, string.Format("{0}.aspx", pageName), webPart, zoneId, zoneIndex);
        }
        private void PersistSelectedFields(SPWeb web, string reportId, ReportFilterSelection fieldSelection, SPList list)
        {
            var userSettings = GetPersistedSettings(web, reportId);

            userSettings.FieldSelection = fieldSelection;
            userSettings.SiteId         = web.Site.ID;
            userSettings.UserId         = web.CurrentUser.ID.ToString();
            userSettings.WebId          = web.ID;
            userSettings.ListId         = list.ID;
            userSettings.WebPartId      = WebPartHelper.ConvertWebPartIdToGuid(reportId);

            PersistUserSettings(userSettings, web);
        }
Beispiel #7
0
        // Uncomment the method below to handle the event raised before a feature is deactivated.

        //public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}

        #region Functions
        private void ProvisionWebpart(SPWeb web, string xmlFile)
        {
            try
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                string xml = assembly.GetResourceTextFile(xmlFile);

                var webpartPage = SerializationHelper.DeserializeFromXml<WebpartPageDefinitionCollection>(xml);

                WebPartHelper.ProvisionWebpart(web, webpartPage);
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }
        private EpmChartUserSettings GetPersistedBubbleChartPersonalizations()
        {
            var web            = SPContext.Current.Web;
            var searchCriteria = new PersonalizationSearchCriteria
            {
                SiteId    = web.Site.ID,
                WebId     = web.ID,
                WebPartId = WebPartHelper.ConvertWebPartIdToGuid(ID),
                UserId    = web.CurrentUser.ID.ToString(),
                Key       = EpmChartUserSettings.Key
            };

            var repo = new EpmChartUserSettingsRepository(web);

            return(repo.GetChartSettings(searchCriteria));
        }
Beispiel #9
0
        private static void AddUserControlToPage(SPWeb web, string pageName, string pageTitle, string positionName, int positionNumber, string userControlName)
        {
            var webUrl = web.ServerRelativeUrl;

            if (webUrl.Equals("/"))
            {
                webUrl = "";
            }
            ContainerWebPart containerWebPart = WebPartHelper.GetContainerWebPart(web);

            if (containerWebPart != null)
            {
                containerWebPart.Title = pageTitle;
                //containerWebPart.UserControlPath = "UserControls/" + userControlName + ".ascx";
                containerWebPart.UserControlPath = webUrl + "/" + ListsName.InternalName.ResourcesList + "/" + userControlName + ".ascx";
                WebPartHelper.AddWebPart(web, pageName + ".aspx", containerWebPart, positionName, positionNumber);
            }
        }
        private ReportFilterUserSettings GetPersistedSettings(SPWeb web, string reportId)
        {
            var repo           = new ReportFilterUserSettingsRepository(web);
            var searchCriteria = new ReportFilterSearchCriteria
            {
                SiteId    = web.Site.ID,
                UserId    = web.CurrentUser.ID.ToString(),
                WebId     = web.ID,
                WebPartId = WebPartHelper.ConvertWebPartIdToGuid(reportId)
            };

            ReportFilterUserSettings userSettings = null;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                userSettings = repo.GetUserSettings(searchCriteria);
            });

            return(userSettings);
        }
        private void LoadChartUserSettings()
        {
            if (string.IsNullOrEmpty(PropChartWebPartId))
            {
                return;
            }

            var web            = SPContext.Current.Web;
            var repo           = new EpmChartUserSettingsRepository(web);
            var searchCriteria = new PersonalizationSearchCriteria
            {
                WebPartId = WebPartHelper.ConvertWebPartIdToGuid(PropChartWebPartId),
                WebId     = web.ID,
                SiteId    = web.Site.ID,
                UserId    = web.CurrentUser.ID.ToString(),
                Key       = EpmChartUserSettings.Key
            };

            _chartUserSettings = repo.GetChartSettings(searchCriteria);
        }
        private void PersistBubbleChartPersonalizations()
        {
            var web  = SPContext.Current.Web;
            var repo = new EpmChartUserSettingsRepository(web);

            var chartSettings = new EpmChartUserSettings
            {
                SiteId          = web.Site.ID,
                WebId           = web.ID,
                WebPartId       = WebPartHelper.ConvertWebPartIdToGuid(ID),
                UserId          = web.CurrentUser.ID.ToString(),
                ListId          = web.Lists[PropChartSelectedList].ID,
                XaxisField      = GetXaxisFieldSelection(),
                XaxisFieldLabel = GetXaxisFieldLabel(),
                YaxisFields     = GetYaxisSelections(),
                YaxisFieldLabel = GetYaxisFieldLabel(),
                ZaxisField      = GetZaxisFieldSelection(),
                ZaxisFieldLabel = GetZaxisFieldLabel(),
                ZaxisColorField = GetZaxisColorFieldSelection()
            };

            repo.PersistChartSettings(chartSettings);
        }
Beispiel #13
0
        private void CreateDetailNewsPage(SPWeb web, SPList list)
        {
            var rootFolder = list.RootFolder;

            var dispFormUrl = string.Format("{0}/{1}/{2}.aspx", web.ServerRelativeUrl.TrimEnd('/'), rootFolder.Url, Constants.NEWS_DISPLAYPAGE);
            var dispForm    = web.GetFile(dispFormUrl);

            if (dispForm != null && dispForm.Exists)
            {
                dispForm.Delete();      // delete & recreate our display form
            }
            // create a new DispForm
            dispForm = rootFolder.Files.Add(dispFormUrl, SPTemplateFileType.FormPage);

            WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
            {
                new WebpartPageDefinition()
                {
                    PageUrl  = dispForm.Url,
                    Title    = list.Title,
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 0,
                            ZoneId      = "Main",
                            WebpartName = "NewsDetailView.webpart",
                            Properties  = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = list.Title
                                },
                                new Property()
                                {
                                    Name  = "ChromeType",
                                    Type  = "chrometype",
                                    Value = "2"
                                }
                            }
                        }
                    }
                },
                new WebpartPageDefinition()
                {
                    PageUrl  = dispForm.Url,
                    Title    = "Other news",
                    Webparts = new System.Collections.Generic.List <WebpartDefinition>()
                    {
                        new DefaultWP()
                        {
                            Index       = 2,
                            ZoneId      = "Main",
                            WebpartName = "OtherNewsListView.webpart",
                            Properties  = new System.Collections.Generic.List <Property>()
                            {
                                new Property()
                                {
                                    Name  = "Title",
                                    Value = "Other news"
                                }
                            }
                        }
                    }
                }
            });

            dispForm.Update();
            //list.Update();
        }