Ejemplo n.º 1
0
 public static IContextOfBlock Init(this IContextOfBlock context, ModuleInfo dnnModule, ILog parentLog)
 {
     context.Init(parentLog);
     ((DnnSite)context.Site).TrySwap(dnnModule);
     ((DnnModule)context.Module).Init(dnnModule, parentLog);
     return(InitPageOnly(context));
 }
Ejemplo n.º 2
0
        private IView TryToGetTemplateBasedOnUrlParams(IContextOfBlock context, CmsRuntime cms)
        {
            var wrapLog = Log.Call <IView>("template override - check");

            if (context.Page.Parameters == null)
            {
                return(wrapLog("no params", null));
            }

            var urlParameterDict = context.Page.Parameters.ToDictionary(pair => pair.Key?.ToLowerInvariant() ?? "", pair =>
                                                                        $"{pair.Key}/{pair.Value}".ToLowerInvariant());

            var allTemplates = cms.Views.GetAll();

            foreach (var template in allTemplates.Where(t => !string.IsNullOrEmpty(t.UrlIdentifier)))
            {
                var desiredFullViewName = template.UrlIdentifier.ToLowerInvariant();
                if (desiredFullViewName.EndsWith("/.*"))   // match details/.* --> e.g. details/12
                {
                    var keyName = desiredFullViewName.Substring(0, desiredFullViewName.Length - 3);
                    if (urlParameterDict.ContainsKey(keyName))
                    {
                        return(wrapLog("template override - found:" + template.Name, template));
                    }
                }
                else if (urlParameterDict.ContainsValue(desiredFullViewName)) // match view/details
                {
                    return(wrapLog("template override - found:" + template.Name, template));
                }
            }

            return(wrapLog("template override - none", null));
        }
Ejemplo n.º 3
0
 protected void Init(IContextOfBlock context, IAppIdentity appId, ILog parentLog)
 {
     Init(parentLog);
     Context = context;
     ZoneId  = appId.ZoneId;
     AppId   = appId.AppId;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a module-content block
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="parentLog">a parent-log; can be null but where possible you should wire one up</param>
        ///// <param name="overrideParams">optional override parameters</param>
        public BlockFromModule Init(IContextOfBlock ctx, ILog parentLog)
        {
            Init(ctx, ctx.Module.BlockIdentifier, parentLog);
            var wrapLog = Log.Call <BlockFromModule>();

            IsContentApp = ctx.Module.IsPrimary;
            CompleteInit(null, ctx.Module.BlockIdentifier, ctx.Module.Id);
            return(wrapLog("ok", this));
        }
Ejemplo n.º 5
0
        internal IView PickView(IBlock block, IView configView, IContextOfBlock context, CmsRuntime cms)
        {
            //View = configView;
            // skip on ContentApp (not a feature there) or if not relevant or not yet initialized
            if (block.IsContentApp || block.App == null)
            {
                return(configView);
            }

            // #2 Change Template if URL contains the part in the metadata "ViewNameInUrl"
            var viewFromUrlParam = TryToGetTemplateBasedOnUrlParams(context, cms);

            return(viewFromUrlParam ?? configView);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Generate a delegate which will be used to build the configuration based on a new sxc-instance
        /// </summary>
        internal Func <App, IAppDataConfiguration> BuildForNewBlock(IContextOfBlock context, IBlock block)
        {
            var showDrafts = context.UserMayEdit;

            var wrapLog = Log.Call($"showDrafts: {showDrafts}");


            wrapLog("ok");
            return(appToUse =>
            {
                // check if we'll use the config already on the sxc-instance, or generate a new one
                var lookUpEngine = GetConfigProviderForModule(context, appToUse as IApp, block);

                // return results
                return new AppDataConfiguration(showDrafts, lookUpEngine);
            });
        }
Ejemplo n.º 7
0
        public static IContextOfBlock InitPageOnly(this IContextOfBlock context)
        {
            // Collect / assemble page information
            var activeTab = (context.Site as Site <PortalSettings>)?.UnwrappedContents?.ActiveTab;

            context.Page.Init(activeTab?.TabID ?? Eav.Constants.NullId);

            // the FullUrl will throw an error in DNN search scenarios
            try
            {
                ((Page)context.Page).Url = activeTab?.FullUrl;
            }
            catch
            {
                /* ignore */
            }

            return(context);
        }
Ejemplo n.º 8
0
        public JsContextEnvironment(string systemRootUrl, IContextOfBlock ctx)
        {
            WebsiteId = ctx.Site.Id;

            WebsiteUrl = "//" + ctx.Site.Url + "/";

            PageId  = ctx.Page.Id;
            PageUrl = ctx.Page.Url;

            InstanceId = ctx.Module.Id;

            SxcVersion = Settings.Version.ToString();

            SxcRootUrl = systemRootUrl;

            var userMayEdit = ctx.UserMayEdit;

            IsEditable = userMayEdit;
            parameters = ctx.Page.Parameters;
        }