Products

Solutions

Learn More

Partners

Community

Blog

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Module Contest - SPAModule Contest - SPA
Previous
 
Next
New Post
12/16/2015 5:50 AM
 

Hi all,

I'm dealing with a problem regarding the SPA module type and Angular development. Because Angular loads the html views as needed (routing), I am not able to make use of the Token Replace. 

In DNN 7 I created a property in codebehind where I collect all information I need (which depends on the specific module) and inject this into Angular as JSON-String:

        protected string ModuleProperties
        {
            get
            {
                dynamic properties = new ExpandoObject();
                using (var rsxr = new ResXResourceReader(MapPath(LocalResourceFile + ".ascx.resx")))
                {
                    var res = rsxr.OfType<dictionaryentry>()
                        .ToDictionary(
                            entry => entry.Key.ToString().Replace(".", "_"),
                            entry => LocalizeString(entry.Key.ToString()));

                    properties.Resources = res;
                }
               
                properties.Settings = Settings;
                properties.Editable = ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, "edit", ModuleConfiguration) && IsEditable;
                properties.UserId = UserId;
                properties.ModuleId = ModuleId;
                properties.PortalId = PortalId;
                properties.HomeDirectory = PortalSettings.HomeDirectory.Substring(1);
                properties.RawUrl = Request.RawUrl;
               
                return ClientAPI.GetSafeJSString(JsonConvert.SerializeObject(properties));

            }
        }

and inject this into Angular as a JSON string:

<script>
    angular.element(document).ready(function () {

        function init(appName, moduleId, apiPath) {
            var sf = $.ServicesFramework(moduleId);
            var httpHeaders = { "ModuleId": sf.getModuleId(), "TabId": sf.getTabId(), "RequestVerificationToken": sf.getAntiForgeryValue() };
            var localAppName = appName + moduleId;
            var application = angular.module(localAppName, [appName])
                .constant("serviceRoot", sf.getServiceRoot(apiPath))
                .config(function($httpProvider) {
                    angular.extend($httpProvider.defaults.headers.common, httpHeaders);
                });
            return application;
        };

        var app = init("funStoryApp", <%=ModuleId%>, "BBFunStory_Module");
        app.constant("moduleProperties", '<%=ModuleProperties%>');
        var moduleContainer = document.getElementById("funStoryApp<%=ModuleId%>");
        angular.bootstrap(moduleContainer, [app.name]);
    });
</script>

In a DNN 8 SPA module there is no codebehind so this is no more a possible solution. Some of the properties are exposed via the ModuleContext Token (ModuleID etc.) but this is not complete and there is no possibility to get special information that is not included in ModuleContext.

As a first workaround I encapsulated my ModuleProperties as a WebApi method. But because some of the information is needed first before retrieving the data for the module I have to call the Properties first, wait for the result and then I can fetch my data. This is annoying and a backstep in speed and usability in opposite to the DNN 7 approach.

So I came to the idea to use the ModuleContext as a replacement for my ModuleProperties. But that needs a change in DNN. The method to sample all the needed infos could be placed into the BusinessController class with a fixed name. And the class where the ModuleContext is prepared could be extended like this:

 

            switch (propertyName.ToLower())
            {
                case "moduleid":
                    return _moduleContext.ModuleId.ToString();
                case "tabmoduleid":
                    return _moduleContext.TabModuleId.ToString();
                case "tabid":
                    return _moduleContext.TabId.ToString();
                case "portalid":
                    return _moduleContext.Configuration.OwnerPortalID.ToString();
                case "issuperuser":
                    return _moduleContext.PortalSettings.UserInfo.IsSuperUser.ToString();
                case "editmode":
                    return _moduleContext.EditMode.ToString();
                case "moduleproperties":
                    if (!string.IsNullOrEmpty(_moduleContext.Configuration.DesktopModule.BusinessControllerClass))
                    {
                        Instantiate businesscontroller class 'bcc' with reflection
                        if (bcc has method 'getModuleProperties')
                            return bcc.GetModuleProperties();
                    }
                default:
                    if (_moduleContext.Settings.ContainsKey(propertyName))
                    {
                        return (string)_moduleContext.Settings[propertyName];
                    }
                    break;
 

What do you think about this solution ? Is it worth a pull request or isn't this the right way to go for solving my annoying problem ?


Best wishes from Germany
Torsten Weggen

dotnetnuke.blog. DNN Usergroup German Speaking Area Eurepean Network of DotNetNuke Professionals
 
New Post
12/16/2015 9:09 AM
 

Why not enhance the tokens of SPA with your needs ?

For creating javascript object from the ascx file, you can also do :

app.constant("moduleProperties", {

homeDirectory : '<%=PortalSettings.HomeDirectory.Substring(1)%>',

....

});

This eliminate the c# transfer object and give you access to +/- all what you want in dnn.

 
New Post
12/16/2015 10:25 AM
 

FYI - This thread would have been much better placed in a public forum. There's some people I'd like to show it to that are intending to participate in the contest, but they're not yet an MVP.

Are there any objections to me moving it?


Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
12/16/2015 10:55 AM
 

@sacha: Because it is html and this syntax does not work here

@will : I tried before but no one has answered: http://www.dnnsoftware.com/forums/forumid/203/postid/525215/scope/posts#525215

Even my mails to Joe are not answered so I thought I try the MVP bonus ;-)   Move it if you want!


Best wishes from Germany
Torsten Weggen

dotnetnuke.blog. DNN Usergroup German Speaking Area Eurepean Network of DotNetNuke Professionals
 
New Post
12/16/2015 11:26 AM
 
@Torsten: Yes, that's a dilemma. For something like this then, perhaps next time posting the MVP forum asking help for the other thread might be useful to get the best of both worlds. I know it would be an extra step - and this is only a suggestion - but it would be a better way to help the overall community. We have way too much good knowledge locked up in this private forum.

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Module Contest - SPAModule Contest - SPA


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out