Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Jan 29, 2015 @ 11:48
    Jason Espin
    0

    Custom dashboard - Umbraco update service

    Hi all,

    I have been using Umbraco for some time as the main CMS of choice when developing new sites for our clients. As part of our development, we create travel sites for small to medium sized tour operators that link to the desktop software product we have written via web services. The aim of this is for the user to edit information about their products on their desktop without having to touch the website or CMS in any way as we use a combination of nightly calls to the web services of the desktop software and the Umbraco content service to present the information from the desktop product on the website with the correct formatting.

    Currently, the update process is triggered by a scheduled task on the server which calls a url to trigger the update process:

    /umbraco/webservices.aspx?type=product

    This is also the way in which our clients can manually trigger updates to their website. However, this is reasonably insecure as ultimately anyone who has access to the website can trigger and update at any point. We would therefore like to port over our update process to a set of WebApi methods instead which will have a parameter passed along to them to identify that the user is allowed to run an update (or is the automatic process triggered by the server).

    With regards to the WebApi method, I pretty much have this sorted but I am really struggling with regards to implementing a custom dashboard in the Umbraco back office that consists of a simple button that will trigger the update process, display a loading screen whilst the process is running and then finally display a popup notification when the process is complete.

    I have attended the Umbraco Level 2 certification course last year and so far have been following the documentation I was given there but it doesn't really explain the process in any depth or detail so therefore I will need to some pointers or direction on how this can be done as the Umbraco documentation also isn't very clear on this sort of thing.

    My controller is stored in my controllers folder and is as follows:

    public class AxumController : UmbracoApiController
    {
       private AxumController(){
           // setup global variables here
       } 
    
       public string GetAllGroupTours(){
          try{
              // web service calls and update logic go here
          }catch(Exception){
              Log.Error("Exception", ex);
              throw;
          }
    
          // Return a string with the number of updates that have been conducted
          return "" + webservice_tours.Count + " tours have been updated";
       } 
    }
    

    As I mentioned I am pretty happy with this however it is the Angular side of things that is a little confusing.

    I have the following two files setup:

    AxumSynchronisation.service.js

    angular.module("umbraco.services").factory("AxumSynchronisationService", function ($http) {
        return {
            getAll: function () {
                return $http.get("/umbraco/api/Axum/GetAllGroupTours");
            }
        }
    })
    

    AxumSynchronisation.controller.js

    angular.module("umbraco")
        .controller("Iceland_Mountain_Guides_Prototyping.AxumController",
        function ($scope, $http, AxumSynchronisationService) {
            AxumSynchronisationService.getAll().success(function (data) {
                $scope.result = data;
            });
        });
    

    The question now is, how do i wire this up to my dashboard html so that it is initialised when a button is clicked and what is the best practice for triggering the built in Umbraco loading screen and notification bubbles?

    Any help would be greatly appreciated as like I mention the documentation for this is somewhat lacking.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jan 29, 2015 @ 12:56
    Sebastiaan Janssen
    100

    You can combine all the things you learned in the Umbraco Level 2 masterclass exercise.

    Change your AxumSynchronisation.controller.js to add the getAll function to the scope, that way you can trigger it from your view (see below). This is what the L2 exercise does when deleting a like. Also, add an info object like what's done in the L2 customeditor exercise.

    angular.module("umbraco")
        .controller("Iceland_Mountain_Guides_Prototyping.AxumController",
        function ($scope, $http, AxumSynchronisationService) {
            $scope.getAll = function() {
                $scope.info = "Getting all, please wait...";
                AxumSynchronisationService.getAll().success(function (data) {
                    $scope.result = data;
                    $scope.info = "Done!";
                });
            };
        });
    

    In your view handle the button click to execute that new $scope.getAll:

    <input type="button" ng-click="getall()" />

    Also add an info span to show the message when done (see the $scope.info above):

    <span ng-bind="info"></span>

  • Jason Espin 368 posts 1335 karma points
    Jan 29, 2015 @ 13:18
    Jason Espin
    0

    Hi Sebastiaan,

    Thanks for the response. I have modified my code to reflect your comments above and now have a button that is displayed however, when I click it, nothing happens.

    Any ideas why?

  • Jason Espin 368 posts 1335 karma points
    Jan 29, 2015 @ 13:24
    Jason Espin
    0

    The following is how I have everything setup now (the names are different because i deleted everything prior out of sheer frustration):

    axumupdateservice.html

    <div ng-controller="AxumUpdateService">
       Trigger Update:
       <input type="button" ng-click="getall()" />
       <span ng-bind="info"></span>
    </div>
    

    AxumUpdateService.controller.js

    angular.module("umbraco")
        .controller("AxumUpdateService",
        function ($scope, $http, AxumUpdateService) {
            $scope.getAll = function () {
                $scope.info = "Retreiving updates, please wait..."
                AxumUpdateService.getAll().success(function (data){
                    $scope.result = data;
                    $scope.info = data;
                });   
            };
        });
    

    AxumUpdateService.service.js

    angular.module("umbraco.services").factory("AxumUpdateService", function ($http) {
        return {
            getAll: function () {
                return $http.get("/umbraco/api/Axum/GetAllGroupTours");
            }
        }
    });
    

    package.manifest

    {
      javascript:[
        "~/app_plugins/Dashboards/AxumUpdateService.controller.js",
        "~/app_plugins/Dashboards/AxumUpdateService.service.js"
      ]
    }
    
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jan 29, 2015 @ 13:25
    Sebastiaan Janssen
    0

    getAll is with a capital a, make sure to update your view: <input type="button" ng-click="getAll()" />.

    As always, use the debugging tools in your browser as well, it would've told you that I had a bug in my code ;-)

  • Jason Espin 368 posts 1335 karma points
    Jan 29, 2015 @ 13:34
    Jason Espin
    0

    You absolute legend! Well spotted and thanks for your help. That's all I really needed as a lot of the documentation I was given from Level 2 had bits missing at the time (think it may have been updated now). Anyway at least now I have a foundation to build on top of. Sebastiaan to the rescue again!

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jan 29, 2015 @ 13:37
    Sebastiaan Janssen
    0

    Yeah depends a bit on when you did the certification of course. All the v7 stuff has been continually updated based on all the feedback we got! Glad to hear it's working now.

Please Sign in or register to post replies

Write your reply to:

Draft