예제 #1
0
        private void MapFromTemplate(Page page)
        {
            HasTemplate = true;
            Layout      = page.Template.PageLayout;
            Settings    = page.Template.Settings;
            Access[PageTemplate.UnlinkOperationCode] = Access[(int)PageOperations.Update];
            Access[(int)PageOperations.Update]       = false;
            ICorePrincipal currentPrincipal = HttpContext.Current.CorePrincipal();
            var            widgetService    = ServiceLocator.Current.GetInstance <IWidgetService>();

            foreach (var widget in page.Template.Widgets.OrderBy(wd => wd.OrderNumber))
            {
                var widgetToShow = !widget.Widget.IsPlaceHolder
                                       ? widget
                                       : page.Widgets.Where(pageWidget => pageWidget.TemplateWidgetId == widget.Id).
                                   FirstOrDefault();
                if (widget.Widget.IsPlaceHolder)
                {
                    widgetToShow.PageSection  = widget.PageSection;
                    widgetToShow.ColumnNumber = widget.ColumnNumber;
                }
                PageWidget  widget1    = widgetToShow;
                ICoreWidget coreWidget =
                    widgetToShow.Widget != null?MvcApplication.Widgets.FirstOrDefault(wd => wd.Identifier == widget1.Widget.Identifier) : null;

                bool isWidetEnabled = widgetService.IsWidgetEnable(widget1.Widget);
                var  widgetModel    = new WidgetHolderViewModel
                {
                    WidgetInstance = new CoreWidgetInstance
                    {
                        InstanceId       = widgetToShow.InstanceId,
                        WidgetIdentifier =
                            coreWidget != null ? coreWidget.Identifier : null,
                        PageSettings =
                            new CorePageSettings {
                            PageId = page.Template.Id
                        },
                        PageWidgetId = widgetToShow.Id
                    },
                    Widget = widget1,
                    Access = coreWidget is BaseWidget
                                                       ? permissionService.GetAccess(
                        ((BaseWidget)coreWidget).Operations,
                        HttpContext.Current.CorePrincipal(), coreWidget.GetType(),
                        widget1.EntityId,
                        currentPrincipal != null && widget1.User != null &&
                        widget1.User.PrincipalId == currentPrincipal.PrincipalId)
                                                       : null,
                    PageAccess   = Access,
                    SystemWidget = (isWidetEnabled && coreWidget != null) ? coreWidget : null
                };
                if (!widget.Widget.IsPlaceHolder)
                {
                    widgetModel.Access[((BaseWidget)widgetModel.SystemWidget).ManageOperationCode]     = false;
                    widgetModel.Access[((BaseWidget)widgetModel.SystemWidget).PermissionOperationCode] = false;
                }
                Widgets.Add(widgetModel);

                if (coreWidget != null && coreWidget.Plugin != null)
                {
                    if (!PagePlugins.Any(t => t.PluginLocation == coreWidget.Plugin.PluginLocation))
                    {
                        PagePlugins.Add(coreWidget.Plugin);
                    }
                    if (coreWidget is BaseWorkflowWidget)
                    {
                        var workflowWidget = (BaseWorkflowWidget)coreWidget;
                        foreach (var innerPlugin in workflowWidget.InnerPlugins)
                        {
                            ICorePlugin plugin = innerPlugin;
                            if (!PagePlugins.Any(t => t.Identifier == plugin.Identifier))
                            {
                                PagePlugins.Add(plugin);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Maps from.
        /// </summary>
        /// <param name="from">From.</param>
        /// <returns></returns>
        public PageViewModel MapFrom(Page from)
        {
            Title          = from.Title;
            Url            = from.Url;
            HideInMainMenu = from.HideInMainMenu;
            Id             = from.Id;
            ParentPageId   = from.ParentPageId;
            var pageAccess = permissionService.GetAccess(from.Operations, HttpContext.Current.CorePrincipal(), typeof(Page), from.Id, IsPageOwner);

            Access   = pageAccess;
            PageMode = PageHelper.CurrentUserPageMode;
            if (from.Template == null)
            {
                MapFromPage(from);
            }
            else
            {
                MapFromTemplate(from);
            }
            IsTemplate = from.IsTemplate && from.Template == null;
            var plugins = ServiceLocator.Current.GetInstance <IPluginService>().FindPluginsByIdentifiers(PagePlugins.Select(t => t.Identifier).ToList());

            if (plugins.Any())
            {
                plugins.ForEach(t => { CssFileName += t.Id + "_"; });
                CssFileName = CssFileName.Remove(CssFileName.Length - 1);
            }
            IsServicePage = from.IsServicePage;

            return(this);
        }