Esempio n. 1
0
        public async Task <ActionResult> Index()
        {
            var model = new SelectThemesViewModel
            {
                SiteThemeName  = await _siteThemeService.GetCurrentThemeNameAsync(),
                AdminThemeName = await _adminThemeService.GetAdminThemeNameAsync()
            };

            return(View(model));
        }
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var themesState = step as ThemesDeploymentStep;

            if (themesState == null)
            {
                return;
            }

            result.Steps.Add(new JObject(
                                 new JProperty("name", "Themes"),
                                 new JProperty(nameof(ThemeStepModel.Site), await _siteThemeService.GetCurrentThemeNameAsync()),
                                 new JProperty(nameof(ThemeStepModel.Admin), await _adminThemeService.GetAdminThemeNameAsync())
                                 ));
        }
Esempio n. 3
0
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            var routeData = _httpContextAccessor.HttpContext.GetRouteData()?.Values;

            if (routeData == null)
            {
                return(null);
            }

            if (routeData["area"]?.ToString() == "OrchardCore.Users")
            {
                bool useSiteTheme = false;

                switch (routeData["controller"]?.ToString())
                {
                case "Account":
                    useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As <LoginSettings>().UseSiteTheme;
                    break;

                case "Registration":
                    useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As <RegistrationSettings>().UseSiteTheme;
                    break;

                case "ResetPassword":
                    useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As <ResetPasswordSettings>().UseSiteTheme;
                    break;

                default:
                    return(null);
                }

                string adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();

                if (String.IsNullOrEmpty(adminThemeName))
                {
                    return(null);
                }

                return(new ThemeSelectorResult
                {
                    Priority = useSiteTheme ? -100 : 100,
                    ThemeName = adminThemeName
                });
            }

            return(null);
        }
Esempio n. 4
0
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                string adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();

                if (String.IsNullOrEmpty(adminThemeName))
                {
                    return(null);
                }

                return(new ThemeSelectorResult
                {
                    Priority = 100,
                    ThemeName = adminThemeName
                });
            }

            return(null);
        }
Esempio n. 5
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                // Even if the Admin attribute is not applied we might be using the admin theme, for instance in Login views.
                // In this case don't render Layers.
                var selectedTheme = (await _themeManager.GetThemeAsync())?.Id;
                var adminTheme    = await _adminThemeService.GetAdminThemeNameAsync();

                if (selectedTheme == adminTheme)
                {
                    await next.Invoke();

                    return;
                }

                var widgets = await _memoryCache.GetOrCreateAsync("OrchardCore.Layers.LayerFilter:AllWidgets", entry =>
                {
                    entry.AddExpirationToken(_signal.GetToken(LayerMetadataHandler.LayerChangeToken));
                    return(_layerService.GetLayerWidgetsAsync(x => x.Published));
                });

                var layers = (await _layerService.GetLayersAsync()).Layers.ToDictionary(x => x.Name);

                dynamic layout = await _layoutAccessor.GetLayoutAsync();

                var updater = _modelUpdaterAccessor.ModelUpdater;

                var engine = _scriptingManager.GetScriptingEngine("js");
                var scope  = engine.CreateScope(_scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), _serviceProvider, null, null);

                var layersCache = new Dictionary <string, bool>();

                foreach (var widget in widgets)
                {
                    var layer = layers[widget.Layer];

                    if (layer == null)
                    {
                        continue;
                    }

                    bool display;
                    if (!layersCache.TryGetValue(layer.Name, out display))
                    {
                        if (String.IsNullOrEmpty(layer.Rule))
                        {
                            display = false;
                        }
                        else
                        {
                            display = Convert.ToBoolean(engine.Evaluate(scope, layer.Rule));
                        }

                        layersCache[layer.Rule] = display;
                    }

                    if (!display)
                    {
                        continue;
                    }

                    var widgetContent = await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, updater);

                    widgetContent.Classes.Add("widget");
                    widgetContent.Classes.Add("widget-" + widget.ContentItem.ContentType.HtmlClassify());

                    var wrapper = new WidgetWrapper
                    {
                        Widget  = widget.ContentItem,
                        Content = widgetContent
                    };

                    wrapper.Metadata.Alternates.Add("Widget_Wrapper__" + widget.ContentItem.ContentType);
                    wrapper.Metadata.Alternates.Add("Widget_Wrapper__Zone__" + widget.Zone);

                    var contentZone = layout.Zones[widget.Zone];
                    contentZone.Add(wrapper);
                }
            }

            await next.Invoke();
        }