Copied to clipboard

Flag this post as spam?

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


  • Desley 44 posts 169 karma points
    Apr 23, 2014 @ 10:45
    Desley
    1

    Dashboard.config

    Hi everyone,

    I was wondering if it is possible to load a .cshtml or controller so I can easily use razor for my dashboard in Umbraco 7. All the examples I could find are outdated.

    My config looks like below:

    <section alias="StartupDashboardSection">
        <areas>
          <area>content</area>
        </areas>
        <tab caption="Dashboard">
          <access>
            <grant>admin</grant>
          </access>
          <control showOnce="true" addPanel="true" panelCaption="">
                    views/dashboard/default/customdashboard.cshtml
                </control>      
        </tab>
      </section>
    

    Giving me the following error:

    Authorization error: Unauthorized access to URL: views/dashboard/default/customdashboard.cshtml

    If I load a regular .html file it works fine.

    Any ideas?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 23, 2014 @ 11:00
    Jan Skovgaard
    1

    Hi Desley

    If I'm not mistaken the dashboard section is now using Angular so I don't think you can use .cshtml for creating them. I can see that the "changepassword.html" is referring to som angular controllers so that is probably the way to go about it.

    Hope this helps.

    /Jan

  • Desley 44 posts 169 karma points
    Apr 23, 2014 @ 12:22
    Desley
    0

    Thanks. I suppose there aren't any examples to be found with the current conditions?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 23, 2014 @ 12:38
    Jan Skovgaard
    1

    Hi Desley

    Not that I know of unfortunately...

    /Jan

  • Desley 44 posts 169 karma points
    Apr 24, 2014 @ 13:47
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 24, 2014 @ 14:00
    Jan Skovgaard
    0

    Hi Desley

    Thanks for sharing - Had not seen that very useful blog-post by Dirk. Just bookmarked it for a later read :)

    Mind sharing the code for your solution as well?

    /Jan

  • Desley 44 posts 169 karma points
    Apr 28, 2014 @ 10:20
    Desley
    104

    There are probably better ways but this is all I could come up with as a beginner.

    package.manifest

    {
        propertyEditors:
        [ 
            {
                alias: "Aneto.Dash",
                name: "Aneto Dashboard",
                editor:
                {
                    view: "~/App_Plugins/Aneto/DashboardAd.html"
                }
            }
        ],
    
        javascript:
        [
            "~/App_Plugins/Aneto/Aneto.Ad.controller.js",
            "~/App_Plugins/Aneto/Aneto.Ad.resource.js"
        ]
     }
    

    DashboardAd.html

    <link href="/css/dashboard.css" rel="stylesheet" />
    <script src="Aneto.Ad.controller.js"></script>
    
    <div ng-controller="Aneto.DashController">
    
        <div class="DashboardAdvertenties">
            <h2><img src="/images/icons/Pages-icon.png" width="35" height="35" alt="" /> Advertenties</h2>
            <ul>
                <li>Totaal Aantal Advertenties: <span class="DashboardNr"> {{ TotaalAds }} </span></li>
                <li>Aantal Open Advertenties: <span class="DashboardNr"> {{ TotaalOpenAds }} </span></li>
                <li>Aantal Gesloten Advertenties: <span class="DashboardNr"> {{ TotaalGeslotenAds }} </span></li>
                <li>Aantal Reacties: <span class="DashboardNr"> {{ TotaalReacties }} </span></li>
            </ul>
        </div>
    
        <div class="DashboardAdvertenties">
            <h2><img src="/images/icons/Icon-user.png" width="25" height="25" alt="" /> Gebruikers</h2>
            <ul>
                <li>Aantal geregistreerde gebruikers: <span class="DashboardNr"> {{ TotaalGebruikers }} </span></li>
            </ul>
        </div>
    
    </div>
    

    Aneto.Ad.controller.js

    angular.module("umbraco").controller("Aneto.DashController", function ($scope, notificationsService, dashResource) {
    
        dashResource.getAdvertisementModel().then(function (response) {
            $scope.TotaalAds = response.data.TotaalAds;
            $scope.TotaalOpenAds = response.data.TotaalOpenAds;
            $scope.TotaalGeslotenAds = response.data.TotaalGeslotenAds;
            $scope.TotaalReacties = response.data.TotaalReacties;
            $scope.TotaalGebruikers = response.data.TotaalGebruikers;
    
        }, function(response) {
                            notificationsService.error("Error", "Error loading documents");
                            console.log(response.data);
                        });
        }
    );
    

    Aneto.Ad.resource.js

    angular.module('umbraco.resources').factory('dashResource', function ($q, $http) {
        return {
            getAdvertisementModel: function () {
                return $http.get("backoffice/Aneto/AnetoApi/GetAdvertisementModel");
            }
        };
    });
    

    AnetoApiController.cs

    using System.Linq;
    using umbraco;
    using Umbraco.Core.Models;
    using Umbraco.Web;
    using Umbraco.Web.Editors;
    using Umbraco.Web.Mvc;
    using Umbraco.Web.WebApi;
    
    namespace Web.Controllers.Api
    {
        [PluginController("Aneto")]
        [IsBackOffice]
        public class AnetoApiController : UmbracoAuthorizedJsonController
        {
            private int TotaalOpenAdsTemp;
            private int TotaalGeslotenAdsTemp;
    
            public AdvertismentTotalViewModel GetAdvertisementModel()
            {
                IPublishedContent homePage = Umbraco.TypedContentAtRoot().First();
                var advertentieOverview = homePage.Descendants("Advertenties");
                var advertentieItems = advertentieOverview.DescendantsOrSelf("AdvertentieItem");
    
                var alleAdvertentieItems = uQuery.GetDocument(1068).GetChildDocuments();
    
                foreach (var item in advertentieItems)
                {
                    var test = item.Properties.FirstOrDefault(p => p.PropertyTypeAlias == "status").Value.ToString();
                    if (item.Properties.FirstOrDefault(p => p.PropertyTypeAlias == "status").Value.ToString() == "Open")
                    {
                        TotaalOpenAdsTemp = TotaalOpenAdsTemp + 1;
                    }
                }
    
                return new AdvertismentTotalViewModel()
                {
                    TotaalAds = alleAdvertentieItems.Count(),
                    TotaalOpenAds = TotaalOpenAdsTemp,
                    TotaalGeslotenAds = alleAdvertentieItems.Count() - TotaalOpenAdsTemp,
                    TotaalReacties = 0,
                    TotaalGebruikers = umbraco.cms.businesslogic.member.Member.GetAll.Count()
                };
            }
    }
    
        public class AdvertismentTotalViewModel
        {
            public int TotaalAds { get; set; }
            public int TotaalOpenAds { get; set; }
            public int TotaalGeslotenAds { get; set; }
            public int TotaalReacties { get; set; }
    
            public int TotaalGebruikers { get; set; }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft