Ejemplo n.º 1
0
        public IActionResult AppendWidget(WidgetBase widget)
        {
            if (widget == null || widget.PageID.IsNullOrWhiteSpace())
            {
                return(NotFound());
            }
            //set design environment
            HttpContext.RequestServices.GetService <IApplicationContextAccessor>().Current.PageMode = Filter.PageViewMode.Design;
            var page = HttpContext.RequestServices.GetService <IPageService>().Get(widget.PageID);
            WidgetViewModelPart widgetPart = null;

            if (page != null)
            {
                var layout = HttpContext.RequestServices.GetService <Layout.ILayoutService>().Get(page.LayoutId);
                layout.Page = page;
                ControllerContext.HttpContext.TrySetLayout(layout);

                widgetPart = _widgetService.ApplyTemplate(widget, ControllerContext);
            }
            if (widgetPart == null)
            {
                widgetPart = new HtmlWidget {
                    PartialView = "Widget.HTML", HTML = "<h1 class='text-danger'><hr/>Error<hr/></h1>"
                }.ToWidgetViewModelPart();
            }
            return(PartialView("AppendWidget", new DesignWidgetViewModel(widgetPart, widget.PageID)));
        }
Ejemplo n.º 2
0
        public PartialViewResult AppendWidget(WidgetBase widget)
        {
            var widgetPart = _widgetService.ApplyTemplate(widget, ControllerContext);

            if (widgetPart == null)
            {
                widgetPart = new HtmlWidget {
                    PartialView = "Widget.HTML", HTML = "<h1 class='text-danger'><hr/>操作失败,找不到数据源,刷新页面后该消息会消失。<hr/></h1>"
                }.ToWidgetPart();
            }
            return(PartialView("AppendWidget", new DesignWidgetViewModel(widgetPart, widget.PageID)));
        }
Ejemplo n.º 3
0
        public PartialViewResult AppendWidget(WidgetBase widget)
        {
            var widgetPart = _widgetService.ApplyTemplate(widget, HttpContext);

            if (widgetPart == null)
            {
                widgetPart = new HtmlWidget {
                    PartialView = "Widget.HTML", HTML = "<label class='text-danger'>模板已被删除,添加失败!</label>"
                }.ToWidgetPart();
            }
            return(PartialView("DesignWidget", new DesignWidgetViewModel(widgetPart, widget.PageID)));
        }
Ejemplo n.º 4
0
        public PartialViewResult AppendWidget(WidgetBase widget)
        {
            HttpContext.RequestServices.GetService <IApplicationContextAccessor>().Current.PageMode = Filter.PageViewMode.Design;
            var widgetPart = _widgetService.ApplyTemplate(widget, ControllerContext);

            if (widgetPart == null)
            {
                widgetPart = new HtmlWidget {
                    PartialView = "Widget.HTML", HTML = "<h1 class='text-danger'><hr/>操作失败,找不到数据源,刷新页面后该消息会消失。<hr/></h1>"
                }.ToWidgetViewModelPart();
            }
            return(PartialView("AppendWidget", new DesignWidgetViewModel(widgetPart, widget.PageID)));
        }
Ejemplo n.º 5
0
        public PartialViewResult AppendWidget(WidgetBase widget)
        {
            //set design environment
            HttpContext.RequestServices.GetService <IApplicationContextAccessor>().Current.PageMode = Filter.PageViewMode.Design;
            var page   = HttpContext.RequestServices.GetService <IPageService>().Get(widget.PageID);
            var layout = HttpContext.RequestServices.GetService <Layout.ILayoutService>().Get(page.LayoutId);

            layout.Page = page;
            ControllerContext.HttpContext.TrySetLayout(layout);

            var widgetPart = _widgetService.ApplyTemplate(widget, ControllerContext);

            if (widgetPart == null)
            {
                widgetPart = new HtmlWidget {
                    PartialView = "Widget.HTML", HTML = "<h1 class='text-danger'><hr/>操作失败,找不到数据源,刷新页面后该消息会消失。<hr/></h1>"
                }.ToWidgetViewModelPart();
            }
            return(PartialView("AppendWidget", new DesignWidgetViewModel(widgetPart, widget.PageID)));
        }
 /// <summary>
 ///     Saves a widget
 /// </summary>
 /// <param name="widget">The widget to save</param>
 /// <param name="cancellationToken">The cancellation token</param>
 public async Task SaveNewWidgetAsync(
     HtmlWidget widget,
     CancellationToken cancellationToken = default)
 => await PostAsync <HtmlWidget, HtmlWidget>(widget, "dashboard/widgets", cancellationToken).ConfigureAwait(false);
Ejemplo n.º 7
0
        /// <summary>
        ///		Create and insert an HTML widget
        ///		along with all the other needed entities.
        ///		It will have the provided name and HTML.
        ///		It will display in the provided widget zone
        ///		with the given display order.
        /// </summary>
        /// <returns>
        ///		The ID of the inserted HTML widget.
        /// </returns>
        public async Task <int> InsertHtmlWidgetAsync(
            string name, string html, string widgetZone, int displayOrder)
        {
            HtmlWidget widget = new HtmlWidget();

            widget.Name            = name;
            widget.Visible         = true;
            widget.HtmlContent     = html;
            widget.LimitedToStores = false;
            await _htmlWidgetRepository.InsertAsync(widget);

            Schedule schedule = new Schedule();

            schedule.EntityType              = EntityType.HtmlWidget;
            schedule.EntityId                = widget.Id;
            schedule.EntityFromDate          = null;
            schedule.EntityToDate            = null;
            schedule.SchedulePatternType     = SchedulePatternType.Everyday;
            schedule.SchedulePatternFromTime = TimeSpan.Zero;
            schedule.SchedulePatternToTime   = TimeSpan.Zero;
            schedule.ExactDayValue           = 1;
            schedule.EveryMonthFromDayValue  = 1;
            schedule.EveryMonthToDayValue    = 1;
            await _scheduleRepository.InsertAsync(schedule);

            Condition condition = new Condition();

            condition.Name   = null;
            condition.Active = true;
            await _conditionRepository.InsertAsync(condition);

            EntityCondition entityCondition = new EntityCondition();

            entityCondition.ConditionId     = condition.Id;
            entityCondition.EntityType      = EntityType.HtmlWidget;
            entityCondition.EntityId        = widget.Id;
            entityCondition.LimitedToStores = false;
            await _entityConditionRepository.InsertAsync(entityCondition);

            ConditionGroup conditionGroup = new ConditionGroup();

            conditionGroup.ConditionId = condition.Id;
            await _conditionGroupRepository.InsertAsync(conditionGroup);

            ConditionStatement conditionStatement = new ConditionStatement();

            conditionStatement.ConditionType     = ConditionType.Default;
            conditionStatement.ConditionProperty = 0;
            conditionStatement.OperatorType      = OperatorType.EqualTo;
            conditionStatement.Value             = "Fail";
            conditionStatement.ConditionGroupId  = conditionGroup.Id;
            await _conditionStatementRepository.InsertAsync(conditionStatement);

            EntityWidgetMapping widgetMapping = new EntityWidgetMapping();

            widgetMapping.EntityType   = EntityType.HtmlWidget;
            widgetMapping.EntityId     = widget.Id;
            widgetMapping.WidgetZone   = widgetZone;
            widgetMapping.DisplayOrder = displayOrder;
            await _widgetMappingRepository.InsertAsync(widgetMapping);

            return(widget.Id);
        }