Пример #1
0
        public IActionResult WidgetsList()
        {
            //find the active widgets
            var availableWidgets = _pluginAccountant.GetAvailableWidgets();
            var widgetModels     = availableWidgets.Where(x => !x.SkipDragging).Select(x => new WidgetModel()
            {
                PluginName       = x.PluginName,
                PluginSystemName = x.PluginSystemName,
                WidgetName       = x.WidgetDisplayName,
                WidgetSystemName = x.WidgetSystemName,
                WidgetZones      = x.WidgetZones
            });

            widgetModels = widgetModels.OrderBy(x => x.PluginName).ToList();
            var availableWidgetNames = widgetModels.Select(x => x.WidgetSystemName);
            var activeWidgets        = _pluginSettings.GetSiteWidgets()
                                       .Where(x => availableWidgetNames.Contains(x.WidgetSystemName))
                                       .GroupBy(x => x.ZoneName)
                                       .Select(x => new WidgetInfoModel()
            {
                ZoneName = x.Key,
                Widgets  = x.Select(y =>
                {
                    var widget = availableWidgets
                                 .FirstOrDefault(z => z.PluginSystemName == y.PluginSystemName && z.WidgetSystemName == y.WidgetSystemName);
                    var widgetModel = new WidgetModel()
                    {
                        PluginSystemName = y.PluginSystemName,
                        WidgetSystemName = y.WidgetSystemName,
                        PluginName       = widget?.PluginName,
                        WidgetName       = widget?.WidgetDisplayName,
                        HasConfiguration = widget?.HasConfiguration ?? false,
                        Id = y.Id
                    };
                    if (widgetModel.HasConfiguration)
                    {
                        widgetModel.ConfigurationUrl = widget?.ConfigurationUrl ?? ApplicationEngine.RouteUrl(AdminRouteNames.GetWidgetSettings, new { id = y.Id });
                    }
                    return(widgetModel);
                })
                           .ToList()
            })
                                       .ToList();

            //available zones
            var zones = ApplicationEngine.ActiveTheme.WidgetZones.Select(x => new ZoneModel()
            {
                Name       = x.Value,
                SystemName = x.Key
            })
                        .ToList();

            return(R.Success
                   .With("availableWidgets", widgetModels)
                   .With("activeWidgets", activeWidgets)
                   .With("zones", zones)
                   .Result);
        }
Пример #2
0
        public IActionResult ConfigureWidget(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }
            //validate if it's a valid widget
            var widgets = _pluginSettings.GetSiteWidgets();
            var widget  = widgets.FirstOrDefault(x => x.Id == id);

            if (widget == null)
            {
                return(NotFound());
            }

            var widgetInfo = _pluginAccountant.GetAvailableWidgets()
                             .FirstOrDefault(x => x.WidgetSystemName == widget.WidgetSystemName &&
                                             x.PluginSystemName == widget.PluginSystemName);

            if (widgetInfo == null)
            {
                return(NotFound());
            }
            var settings = _widgetService.LoadWidgetSettings(id, widgetInfo.WidgetInstance.SettingsType);

            var settingsModel = widgetInfo.WidgetInstance.GetViewObject(settings);

            return(R.Success.WithView($"{widget.WidgetSystemName}.Settings")
                   .With("settings", settingsModel)
                   .With("widgetId", id)
                   .Result);
        }
Пример #3
0
        public static void DeleteWidget(this PluginSettings pluginSettings, string id)
        {
            var widgets = pluginSettings.GetSiteWidgets();
            var widget  = widgets.FirstOrDefault(x => x.Id == id);

            if (widget != null)
            {
                widgets.Remove(widget);
            }
            pluginSettings.SaveWidgets(widgets, true);
        }
Пример #4
0
        public static string AddWidget(this PluginSettings pluginSettings, string widgetName, string pluginSystemName, string zoneName)
        {
            var siteWidgets = pluginSettings.GetSiteWidgets();
            //find widget count in zone
            var zoneWidgetCount = siteWidgets.Count(x => x.ZoneName == zoneName);
            var widgetId        = Guid.NewGuid().ToString();

            siteWidgets.Add(new WidgetStatus()
            {
                WidgetSystemName = widgetName,
                PluginSystemName = pluginSystemName,
                ZoneName         = zoneName,
                DisplayOrder     = zoneWidgetCount,
                Id = widgetId
            });

            pluginSettings.SaveWidgets(siteWidgets, true);
            return(widgetId);
        }