Exemple #1
0
        /// <summary>
        /// Activiates the default Clarity theme, registers system-defined widget areas,
        /// then load some widgets.
        /// </summary>
        private async Task SetupThemeAndWidgets()
        {
            // Clarity theme
            await _themeService.ActivateThemeAsync("Clarity");

            // System-defined Areas
            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogSidebar1.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogSidebar2.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogBeforePost.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogAfterPost.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogBeforePostList.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogAfterPostList.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer1.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer2.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer3.Id);

            // Area: BlogSidebar1

            // Social Icons
            var socialIconsWidget = new SocialIconsWidget {
                Links = SocialIconsWidget.SocialLinkSeeds
            };
            var widgetInstId = await _widgetSvc.CreateWidgetAsync(socialIconsWidget, "SocialIcons");

            await _widgetSvc.AddWidgetToAreaAsync(widgetInstId, WidgetService.BlogSidebar1.Id, 0);

            // Blog Tags
            widgetInstId = await _widgetSvc.CreateWidgetAsync("BlogTags");

            await _widgetSvc.AddWidgetToAreaAsync(widgetInstId, WidgetService.BlogSidebar1.Id, 1);

            // Blog Categories
            widgetInstId = await _widgetSvc.CreateWidgetAsync("BlogCategories");

            await _widgetSvc.AddWidgetToAreaAsync(widgetInstId, WidgetService.BlogSidebar1.Id, 2);

            // Blog Archives
            widgetInstId = await _widgetSvc.CreateWidgetAsync("BlogArchives");

            await _widgetSvc.AddWidgetToAreaAsync(widgetInstId, WidgetService.BlogSidebar1.Id, 3);

            // Area: BlogAfterPost

            // Recent Blog Posts
            var recentBlogPostsWidget = new RecentBlogPostsWidget {
                ShowPostExcerpt = true
            };

            widgetInstId = await _widgetSvc.CreateWidgetAsync(recentBlogPostsWidget, "RecentBlogPosts");

            await _widgetSvc.AddWidgetToAreaAsync(widgetInstId, WidgetService.BlogAfterPost.Id, 0);
        }
Exemple #2
0
        public async void AddWidgetToAreaAsync_adds_widget_to_widget_area()
        {
            // Arrange
            Setup_MyWidget();
            Setup_Widget_Areas();

            // Act: user drags MyWidget to "my-area"
            // NOTE: area id is "my-area" not its meta key which is "mytheme-my-area"
            var widgetInst = await widgetService.AddWidgetToAreaAsync(MY_WIDGET_ID, MY_AREA_ID, index : 0);

            // Assert: repo UpdateAsync is called twice
            metaRepoMock.Verify(repo => repo.UpdateAsync(It.IsAny <Meta>()), Times.Exactly(2));

            // Once: update widget instance with widget id and widget area id
            var myWidget = new MyWidget {
                Id = MY_WIDGET_ID, AreaId = MY_AREA_ID, Folder = MY_WIDGET_FOLDER
            };

            metaRepoMock.Verify(repo => repo.UpdateAsync(
                                    It.Is <Meta>(m => m.Value == JsonConvert.SerializeObject(myWidget))), Times.Once);

            // Once: update widget area "my-area" with MyWidget of id 4
            var myArea = new WidgetArea {
                Id = MY_AREA_ID, WidgetIds = new int[] { MY_WIDGET_ID }
            };

            metaRepoMock.Verify(repo => repo.UpdateAsync(
                                    It.Is <Meta>(m => m.Value == JsonConvert.SerializeObject(myArea))), Times.Once);

            Assert.Equal(MY_WIDGET_ID, widgetInst.Id);
            Assert.Equal(MY_WIDGET_FOLDER, widgetInst.Folder);
            Assert.Equal(MY_AREA_ID, widgetInst.AreaId);
            Assert.Equal("My Widget", widgetInst.Title);
            Assert.Equal("/Widgets/MyWidgetSettings?widgetId=4", widgetInst.SettingsUrl);
        }
Exemple #3
0
        /// <summary>
        /// When user drags a widget from info to an area or from an area to anther area.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAddAsync([FromBody] AddWidgetDto dto)
        {
            WidgetInstance widgetInst = null;

            // user drags a widget from infos to an area
            if (dto.AreaFromId.IsNullOrEmpty())
            {
                var widgetId = await _widgetService.CreateWidgetAsync(dto.Folder);

                widgetInst = await _widgetService.AddWidgetToAreaAsync(widgetId, dto.AreaToId, dto.Index);
            }
            else // user drags a widget from area to another
            {
                await _widgetService.RemoveWidgetFromAreaAsync(dto.WidgetId, dto.AreaFromId);

                widgetInst = await _widgetService.AddWidgetToAreaAsync(dto.WidgetId, dto.AreaToId, dto.Index);
            }

            return(new JsonResult(widgetInst));
        }
Exemple #4
0
        /// <summary>
        /// Activiates the default Clarity theme and plugins and registers system-defined widget areas,
        /// then load some widgets.
        /// </summary>
        private async Task SetupThemePluginsAndWidgetsAsync()
        {
            // Clarity theme
            await _themeService.ActivateThemeAsync("Clarity");

            // Activate plugins

            await pluginService.ActivatePluginAsync("Editor.md");

            await pluginService.ActivatePluginAsync("ForkMeRibbon");

            await pluginService.ActivatePluginAsync("Shortcodes");

            // System-defined Areas
            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogSidebar1.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogSidebar2.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogBeforePost.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogAfterPost.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogBeforePostList.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.BlogAfterPostList.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.PageSidebar1.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.PageSidebar2.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.PageBeforeContent.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.PageAfterContent.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer1.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer2.Id);

            await _widgetSvc.RegisterAreaAsync(WidgetService.Footer3.Id);

            // Area: BlogSidebar1

            // Social Icons
            var socialIconsWidget = new SocialIconsWidget {
                Links = SocialIconsWidget.SocialLinkSeeds
            };
            var socialIconsWidgetInstId = await _widgetSvc.CreateWidgetAsync(socialIconsWidget, "SocialIcons");

            await _widgetSvc.AddWidgetToAreaAsync(socialIconsWidgetInstId, WidgetService.BlogSidebar1.Id, 0);

            // Blog Tags
            var blogTagsWidgetInstId = await _widgetSvc.CreateWidgetAsync("BlogTags");

            await _widgetSvc.AddWidgetToAreaAsync(blogTagsWidgetInstId, WidgetService.BlogSidebar1.Id, 1);

            // Blog Categories
            var blogCatsWidgetInstId = await _widgetSvc.CreateWidgetAsync("BlogCategories");

            await _widgetSvc.AddWidgetToAreaAsync(blogCatsWidgetInstId, WidgetService.BlogSidebar1.Id, 2);

            // Blog Archives
            var blogArchivesWidgetInstId = await _widgetSvc.CreateWidgetAsync("BlogArchives");

            await _widgetSvc.AddWidgetToAreaAsync(blogArchivesWidgetInstId, WidgetService.BlogSidebar1.Id, 3);

            // Area: BlogAfterPost

            // Recent Blog Posts
            var recentBlogPostsWidgetInstId = await _widgetSvc.CreateWidgetAsync("RecentBlogPosts");

            await _widgetSvc.AddWidgetToAreaAsync(recentBlogPostsWidgetInstId, WidgetService.BlogAfterPost.Id, 0);

            // Area: PageSidebar1

            // Social Icons
            socialIconsWidgetInstId = await _widgetSvc.CreateWidgetAsync(socialIconsWidget, "SocialIcons");

            await _widgetSvc.AddWidgetToAreaAsync(socialIconsWidgetInstId, WidgetService.PageSidebar1.Id, 0);

            // Recent Blog Posts
            recentBlogPostsWidgetInstId = await _widgetSvc.CreateWidgetAsync("RecentBlogPosts");

            await _widgetSvc.AddWidgetToAreaAsync(recentBlogPostsWidgetInstId, WidgetService.PageSidebar1.Id, 1);

            // Area: PageSidebar2

            // Page Navigation
            var pageNavWidgetInstId = await _widgetSvc.CreateWidgetAsync("PageNavigation");

            await _widgetSvc.AddWidgetToAreaAsync(pageNavWidgetInstId, WidgetService.PageSidebar2.Id, 0);

            _logger.LogInformation("Theme and widgets created");
        }