예제 #1
0
        private async Task <string> RenderBootstrapperAsync(AngularModuleRouteLibrary routeLibrary, object options)
        {
            var args = string.Empty;

            if (_hostingEnvironment.IsDevelopment())
            {
                // use strict DI when in debug mode to throw up errors
                args = ", { strictDi: true }";
            }

            // Might need to add more info at some point, but right now we just need roles.
            var user = await _userContextService.GetCurrentContextByUserAreaAsync(CofoundryAdminUserArea.AreaCode);

            var role = await _queryExecutor.ExecuteAsync(new GetRoleDetailsByIdQuery(user.RoleId));

            var currentUserInfo = new {
                PermissionCodes = role
                                  .Permissions
                                  .Select(p => p.GetUniqueCode())
                                  .ToList()
            };

            var tokens = _antiforgery.GetAndStoreTokens(_httpContextAccessor.HttpContext);
            var canShowDeveloperException = _debugSettings.CanShowDeveloperExceptionPage(_hostingEnvironment);

            return(@"<script>angular.element(document).ready(function() {
                        angular.module('" + _adminRouteLibrary.Shared.Angular.AngularModuleName + @"')
                               .constant('csrfToken', '" + tokens.RequestToken + @"')
                               .constant('csrfHeaderName', '" + tokens.HeaderName + @"')"
                   + GetConstant(_adminRouteLibrary.Shared, "showDevException", canShowDeveloperException)
                   + GetConstant(routeLibrary, "options", options)             // not sure why the current module is loaded into the shared module - seems like a mistake?
                   + GetConstant(_adminRouteLibrary.Shared, "currentUser", currentUserInfo) + @";
                        angular.bootstrap(document, ['" + routeLibrary.Angular.AngularModuleName + "']" + args + @");
                    });</script>");
        }
        private AngularModuleRouteLibrary GetRouteLibrary(IStandardAngularModuleRegistration registration)
        {
            AngularModuleRouteLibrary routeLibrary;

            if (registration is IInternalAngularModuleRegistration)
            {
                // Internal modules are in a different folder format to prevent name clashes
                routeLibrary = new AngularModuleRouteLibrary(
                    _adminSettings,
                    registration.RoutePrefix,
                    RouteConstants.InternalModuleResourcePathPrefix
                    );
            }
            else if (registration is IPluginAngularModuleRegistration)
            {
                // Plugin modules are in a different folder format to prevent name clashes
                routeLibrary = new AngularModuleRouteLibrary(
                    _adminSettings,
                    registration.RoutePrefix,
                    RouteConstants.PluginModuleResourcePathPrefix
                    );
            }
            else
            {
                routeLibrary = new AngularModuleRouteLibrary(_adminSettings, registration.RoutePrefix);
            }

            return(routeLibrary);
        }
예제 #3
0
        private static string GetConstant <TValue>(AngularModuleRouteLibrary routeLibrary, string name, TValue value)
        {
            if (value != null)
            {
                var valueJson = JsonConvert.SerializeObject(value);
                return(".constant('" + routeLibrary.Angular.AngularModuleIdentifier + "." + name + "', " + valueJson + ")");
            }

            return(string.Empty);
        }
예제 #4
0
        /// <summary>
        /// Adds scripts/templates for the core angular framework and the
        /// specified module and then bootstraps it.
        /// </summary>
        /// <param name="routeLibrary">Js routing library for the module to bootstrap,</param>
        public async Task <IHtmlContent> BootstrapAsync(AngularModuleRouteLibrary routeLibrary, object options = null)
        {
            var bootstrapScript = await RenderBootstrapperAsync(routeLibrary, options);

            var script = string.Concat(
                _staticResourceReferenceRenderer.ScriptTag(_adminRouteLibrary.Shared, _adminRouteLibrary.Shared.Angular.MainScriptName),
                _staticResourceReferenceRenderer.ScriptTag(_adminRouteLibrary.Shared, _adminRouteLibrary.Shared.Angular.TemplateScriptName),
                _staticResourceReferenceRenderer.ScriptTagIfExists(_adminRouteLibrary.SharedAlternate, _adminRouteLibrary.SharedAlternate.Angular.MainScriptName),
                _staticResourceReferenceRenderer.ScriptTagIfExists(_adminRouteLibrary.SharedAlternate, _adminRouteLibrary.SharedAlternate.Angular.TemplateScriptName),
                _staticResourceReferenceRenderer.ScriptTag(routeLibrary, routeLibrary.Angular.MainScriptName),
                _staticResourceReferenceRenderer.ScriptTag(routeLibrary, routeLibrary.Angular.TemplateScriptName),
                bootstrapScript
                );

            return(new HtmlString(script));
        }
        private async Task <string> RenderBootstrapperAsync(AngularModuleRouteLibrary routeLibrary, object options)
        {
            var args = string.Empty;

            if (_webHostEnvironment.IsDevelopment())
            {
                // use strict DI when in debug mode to throw up errors
                args = ", { strictDi: true }";
            }

            var user = await _userContextService.GetCurrentContextByUserAreaAsync(CofoundryAdminUserArea.Code);

            var role = await _queryExecutor.ExecuteAsync(new GetRoleDetailsByIdQuery(user.RoleId));

            var currentUserInfo = new
            {
                UserId          = user.UserId,
                IsSuperAdmin    = user.IsSuperAdmin(),
                PermissionCodes = role
                                  .Permissions
                                  .Select(p => p.GetUniqueIdentifier())
                                  .ToList()
            };

            var tokens = _antiforgery.GetAndStoreTokens(_httpContextAccessor.HttpContext);
            var canShowDeveloperException = _debugSettings.CanShowDeveloperExceptionPage(_webHostEnvironment);

            return(@"<script>angular.element(document).ready(function() {
                        angular.module('" + _adminRouteLibrary.Shared.Angular.AngularModuleName + @"')
                               .constant('csrfToken', '" + tokens.RequestToken + @"')
                               .constant('csrfHeaderName', '" + tokens.HeaderName + @"')"
                   + GetConstant(_adminRouteLibrary.Shared, "showDevException", canShowDeveloperException)
                   + GetConstant(_adminRouteLibrary.Shared, "serviceBase", "/" + _adminSettings.DirectoryName + "/api/")
                   + GetConstant(_adminRouteLibrary.Shared, "pluginServiceBase", "/" + _adminSettings.DirectoryName + "/api/plugins/")
                   + GetConstant(_adminRouteLibrary.Shared, "urlBaseBase", "/" + _adminSettings.DirectoryName + "/")
                   + GetConstant(_adminRouteLibrary.Shared, "internalContentPath", _adminRouteLibrary.Shared.GetStaticResourceUrlPath() + "/")
                   + GetConstant(_adminRouteLibrary.Shared, "pluginContentPath", _adminRouteLibrary.SharedPlugin.GetStaticResourceUrlPath() + "/")
                   + GetConstant(_adminRouteLibrary.Shared, "contentPath", _adminRouteLibrary.SharedAlternate.GetStaticResourceUrlPath() + "/")
                   + GetConstant(routeLibrary, "options", options)             // not sure why the current module is loaded into the shared module - seems like a mistake?
                   + GetConstant(_adminRouteLibrary.Shared, "currentUser", currentUserInfo) + @";
                        angular.bootstrap(document, ['" + routeLibrary.Angular.AngularModuleName + "']" + args + @");
                    });</script>");
        }
예제 #6
0
        /// <summary>
        /// Adds scripts/templates for the core angular framework and the
        /// specified module and then bootstraps it.
        /// </summary>
        /// <param name="routeLibrary">Js routing library for the module to bootstrap,</param>
        public async Task <IHtmlContent> BootstrapAsync(AngularModuleRouteLibrary routeLibrary, object options = null)
        {
            var bootstrapScript = await RenderBootstrapperAsync(routeLibrary, options);

            var formattedPluginScripts = GetPluginScripts();

            var scripts = new List <string>();

            AddScript(scripts, _adminRouteLibrary.Shared, _adminRouteLibrary.Shared.Angular.MainScriptName);
            AddScript(scripts, _adminRouteLibrary.Shared, _adminRouteLibrary.Shared.Angular.TemplateScriptName);
            scripts.AddRange(formattedPluginScripts);
            AddScript(scripts, _adminRouteLibrary.SharedAlternate, _adminRouteLibrary.SharedAlternate.Angular.MainScriptName, true);
            AddScript(scripts, _adminRouteLibrary.SharedAlternate, _adminRouteLibrary.SharedAlternate.Angular.TemplateScriptName, true);
            AddScript(scripts, routeLibrary, routeLibrary.Angular.MainScriptName);
            AddScript(scripts, routeLibrary, routeLibrary.Angular.TemplateScriptName);
            scripts.Add(bootstrapScript);

            var script = string.Concat(scripts);

            return(new HtmlString(script));
        }
예제 #7
0
 private static string GetOptions(AngularModuleRouteLibrary routeLibrary, object options)
 {
     return(GetConstant(routeLibrary, "options", options));
 }