Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mathias 51 posts 205 karma points
    Jan 20, 2020 @ 12:28
    Mathias
    0

    Developing package for Umbraco - workflow, errors, cannot load javascript etc etc

    Please excuse my annoyed tone ;)

    So, I'm developing this custom backoffice section for a client, but the experience of writing a custom plugin to Umbraco is (from my current perspective) one of the worst developer experiences I've had.. Maybe I'm doing something horrible wrong, I really hope that I am.

    I've followed this tutorial from the docs: https://our.umbraco.com/documentation/Extending/Section-Trees/sections

    The problem I'm running into is two-fold.

    1. When making the smallest possible chance to the view, the changes aren't displayed on the screen. Sometimes it's enough to rebuild and refresh the page, sometimes it's enough to touch web.config and force the app-pool to recycle (running Umbraco from visual studio which should be supported as per the documentation). And sometimes I just furiosuly refresh the page and voila! my change appears

    2. It seems like my package.manifest aren't loading the relevant javascript to the leads.html view. As the browser console tells me: "The controller with name 'Rexolution.GodMode.LeadsController' is not registered

    I've tried to put the javascript inside a script-tag right in the leads.html view, but that doesn't allow me to register the controller either.

    PLEASE, if you are a package developer, tell me or guide me through your workflow. Because I'm pulling my hair out right now........

    My relevant files are as follows:

    package.manifest

    {
      "sections": [
        {
          "alias": "rexelGodMode",
          "name": "God Mode"
        }
      ],
      "javascript": [
        "~/App_Plugins/RexelGodMode/backoffice/rexelGodModeTree/leads.controller.js"
      ]
    }
    

    GodModeTreeController.cs

    [Tree("rexelGodMode", "rexelGodModeTree", TreeTitle = "God mode", SortOrder = 1)]
        [PluginController("RexelGodMode")]
        public class GodModeTreeController : TreeController
        {
            protected override MenuItemCollection GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings)
            {
                // this tree does not support any menu item collections
                return new MenuItemCollection();
            }
    
            protected override TreeNodeCollection GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings)
            {
                // this tree doesn't support rendring more than 1 level of tree nodes
                if (id != "-1")
                    throw new NotSupportedException();
    
                // create our node collection
                var nodes = new TreeNodeCollection();
    
                // add tree nodes, each node representing
                nodes.Add(CreateTreeNode("leads", "-1", queryStrings, "Leads", "icon-wallet", false, $"/rexelGodMode/rexelGodModeTree/leads"));
    
                return nodes;
            }
        }
    

    leads.html

    <div ng-controller="Rexolution.GodMode.LeadsController">
        <h1>Leads</h1>
    
        <table style="width: 100%">
            <thead>
                <tr>
                    <th>Datum</th>
                    <th>4-fas</th>
                    <th>3-fas</th>
                    <th>Kontakt</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>2020-01-20</td>
                    <td>10</td>
                    <td>0</td>
                    <td>Pelle Svanslös</td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </div>
    

    leads.controller.js

    'use strict';
    (function () {
        //create the controller
        function leadsController($scope) {
            console.log('hello from the leads controller');
        };
        //register the controller
        angular.module("umbraco").controller('Rexolution.GodMode.LeadsController', leadsController);
    })();
    

    File structure

    enter image description here

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jan 20, 2020 @ 14:02
    Dennis Adolfi
    100

    When building custom apps/plugins for Umbraco, I always find it best to "Always Bump the ClientDependencyFramework version number" after each change. As you mentioned, sometimes it's enough to just reload, but most of the times it's not. Bumping CDF version always makes sure I am looking at the lastest changes.

    Try that and let me know if it helps! :D Cheers.

    Explination of "Bumping the Client Dependency Framework version:" In your /config/ClientDependency.config, up the version number by 1.

  • Mathias 51 posts 205 karma points
    Jan 20, 2020 @ 14:32
    Mathias
    0

    Thanks alot Dennis, I will try it out!

    EDIT: It workes, and now my 'hello from leadsController' get's printed to the browser console.

    Thank you alot Dennis, you deserve a high five and a beer. If you're even in Jönköping, Sweden - gimme a holla!

  • Garðar Þorsteinsson 119 posts 565 karma points
    Jan 20, 2020 @ 17:17
    Garðar Þorsteinsson
    0

    Hi Mathias,

    Are you sure you are working in debug mode ?

    Umbraco heavily caches these files for production but if you run the site in Debug mode you should only have to refresh and empty cache in the browser to see the changes.

    The debug attribute on Compilation in the web.config file should be true.

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2019

  • Mathias 51 posts 205 karma points
    Jan 21, 2020 @ 06:34
    Mathias
    0

    Hey Garthar, the debug option is set to true, I just checked

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 20, 2020 @ 17:19
    Lee Kelleher
    0

    For point 1 - when working with AngularJS views in the backoffice, I'd recommend opening your browser's dev tools and disabling the cache.

    Further details here: https://stackoverflow.com/a/7000899/12787

    I found that Chrome would aggressively cache HTML requests, (more than CSS or JS requests) ... so this is more your browser doing it than Umbraco.

Please Sign in or register to post replies

Write your reply to:

Draft