Copied to clipboard

Flag this post as spam?

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


  • André Lange 108 posts 410 karma points
    Apr 15, 2020 @ 09:43
    André Lange
    0

    Adding logic to Dashboard created programmatically

    How do i add a controller, so i can add logic to my view?

    I have created my dashboard programmatically in C#

    [Weight(-10)]
        public class TestDashboard : IDashboard
        {
            public string[] Sections => new[] { "content" };
    
            public IAccessRule[] AccessRules => Array.Empty<IAccessRule>();
    
            public string Alias => "TestCustomDashboard";
    
            public string View => "/Business/Dashboards/Test/View/test.html";
        }
    

    My file structure:

    enter image description here

    using a package.manifest i write which controller to use in that. But now that i dont have that, how do i add the controller ?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 10:15
    Alex Skrypnyk
    100

    Hi André

    You have to create custom controller and ask work with it via Angular controller, so there is no way to register C# controller in the Dashboard class implementation, have a look at this tutorial - https://our.umbraco.com/documentation/tutorials/Creating-a-Custom-Dashboard/

    Thanks, Alex

  • André Lange 108 posts 410 karma points
    Apr 15, 2020 @ 10:20
    André Lange
    0

    So i just need to include a manifest, that just registers the controller.

    so something like this ?

    {
      "javascript": [
      "~/Business/Dashboards/Test/Controller/test.controller.js"
      ]
    }
    

    and then the controller is something like this?

    angular.module("umbraco").controller("my.testDashboardController", function ($scope) {
        var vm = this;
        vm.headline = "My Custom Dashboard With Controller js";
    });
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 10:22
    Alex Skrypnyk
    0

    Yes, and if you need some serverside logic, you need to call it via AJAX request.

  • André Lange 108 posts 410 karma points
    Apr 15, 2020 @ 10:25
    André Lange
    0

    Cool, thx for the clarification.

    Hope its okey to ask two more things ^^

    in chrome it says "The controller with the name 'my.testDashboardController' is not registered."

    in my view it looks like this now.

    <umb-box>
        <umb-box-content>
            <div ng-controller="my.testDashboardController as vm">
                <h3>{{vm.headline}}</h3>
                <p>Dette er en test for at se om jeg kan lave et dashboard.</p>
            </div>
        </umb-box-content>
    </umb-box>
    

    Can you see what i am doing wrong ?

    And the second question ^^ https://our.umbraco.com/forum/using-umbraco-and-getting-started//101853-umbraco-8-dashboard-language-files-programmatically

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 10:28
    Alex Skrypnyk
    0

    Check that "test.controller.js" loaded on the page correctly.

  • André Lange 108 posts 410 karma points
    Apr 15, 2020 @ 10:30
    André Lange
    0

    i am not seeing under sources in chrome. I'm not sure how else to register it?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 10:33
    Alex Skrypnyk
    0

    It should be loaded with client dependency, so try to increase client dependency versions and restart the application.

  • André Lange 108 posts 410 karma points
    Apr 15, 2020 @ 10:35
    André Lange
    0

    updated the number and rebuild and started the application again. Did not seem to change anything, still getting the same error.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 11:19
    Alex Skrypnyk
    0

    then probably the issue with angular controller path "~/Business/Dashboards/Test/Controller/test.controller.js" or controller name in HTML

  • André Lange 108 posts 410 karma points
    Apr 16, 2020 @ 06:13
    André Lange
    0

    I moved the "dashboard" to App_Plugins, and then everything worked.

Please Sign in or register to post replies

Write your reply to:

Draft