/// <summary> /// Gets the widget view model. /// </summary> /// <param name="pageWidget">The page widget.</param> /// <returns></returns> public static WidgetHolderViewModel GetWidgetViewModel(PageWidget pageWidget) { if (pageWidget == null || pageWidget.Widget == null) return null; ICoreWidget coreWidget = MvcApplication.Widgets.FirstOrDefault(wd => wd.Identifier == pageWidget.Widget.Identifier); var permissionService = ServiceLocator.Current.GetInstance<IPermissionCommonService>(); ICorePrincipal currentPrincipal = HttpContext.Current.CorePrincipal(); var widgetModel = new WidgetHolderViewModel { Widget = pageWidget, WidgetInstance = new CoreWidgetInstance { InstanceId = pageWidget.InstanceId, WidgetIdentifier = pageWidget.Widget.Identifier, PageSettings = new CorePageSettings { PageId = pageWidget.Page.Id }, PageWidgetId = pageWidget.Id }, SystemWidget = coreWidget, Access = coreWidget is BaseWidget ? permissionService.GetAccess(((BaseWidget)coreWidget).Operations, HttpContext.Current.CorePrincipal(), coreWidget.GetType(), pageWidget.EntityId, currentPrincipal != null && pageWidget.User != null && pageWidget.User.PrincipalId == currentPrincipal.PrincipalId) : null, PageAccess = permissionService.GetAccess(pageWidget.Page.Operations, currentPrincipal, typeof(Page), pageWidget.Page.Id, currentPrincipal != null && pageWidget.Page.User != null && pageWidget.Page.User.PrincipalId == currentPrincipal.PrincipalId), }; if (pageWidget.Page.IsTemplate && pageWidget.Widget.IsPlaceHolder) { widgetModel.Access[((BaseWidget)widgetModel.SystemWidget).PermissionOperationCode] = false; } return widgetModel; }
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); } } } } } }