Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 469 posts 1633 karma points
    Apr 14, 2016 @ 13:21
    Adriano Fabri
    0

    How to get all users with angular

    Hi, I'm new with angular and I'm trying to update my tool to a new version that use angular controllers.

    I created all necessary files (treecontroller, manifest, controllers and html files) and I correctly see my new custom section, the tree and when I click on the User Cleanup treenode, I correctly view the title, subtitle and description.

    Now I want to display all umbraco users into a table but I don't know how can I do that.

    This is my actual code of my controller "Users-Cleanup.js"

    'use strict';
    (function () {
        // Create Edit controller
        function UsersCleanupController($scope, $routeParams, userService) {
            // Set a property on the scope equal to the current route id
            $scope.id = $routeParams.id;
            $scope.title = "Users Manager";
            $scope.subtitle = "Cleanup users";
            $scope.description = "With this tool you can delete one or more users.";
    
            var getCurrentUser = userService.getCurrentUser().then(function(userObj) {
                var user = userObj;
                $scope.currentUser = user.id;
            });
    
            var totalUsers = 0;
            var allUsers = userService.GetAll;
            $scope.allUsers = allUsers;
        };
    
        // Register the controller
        angular.module("umbraco").controller("FALM.Housekeeping.UsersCleanupController", UsersCleanupController);
    })();
    

    This is the code of my view "Users-Cleanup.html"

    <div ng-controller="FALM.Housekeeping.UsersCleanupController">
        <umb-panel>
            <umb-header>
                <div class="umb-headline-editor-wrapper span12 ng-scope">
                    <h1 class="ng-binding">F.A.L.M. Housekeeping</h1>
                </div>
            </umb-header>
            <umb-content>
                <div class="umb-pane" style="margin-top: 120px;">
                    <div ng-switch="id">
                        <h2>{{title}}</h2>
                        <h3>{{subtitle}}</h3>
                        <h4>{{description}}</h4>
                    </div>
                    <div>
                        <!-- ### HERE I WANT TO INSERT THE TABLE WITH ALL USERS ### -->
                    </div>
                </div>
            </umb-content>
            <umb-footer>
                <div class="umb-dialog-footer">
                    <p style="margin: 20px;">Questo รจ il footer della pagina</p>
                </div>
            </umb-footer>
        </umb-panel>
    </div>
    

    What changes can I do to display all users?

    Thank you for the help

    Adriano

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 14, 2016 @ 14:32
    David Brendel
    0

    Hi Adriano,

    don't know if you can do it with the entityResource but you can have a look at it. https://umbraco.github.io/Belle/#/api/umbraco.resources.entityResource

    If not you can always call a custom API controller to get all user using the UserService.

    Regards David

  • Adriano Fabri 469 posts 1633 karma points
    Apr 15, 2016 @ 08:19
    Adriano Fabri
    0

    Hi David, thank you for your answer...I'm trying to create my custom API controller with my customs methods (including the "get all user" method).

    How can I use those methods in my angular controller?

    I must use a directive? You can give me an example please?

    Thanks,

    Adriano

  • Adriano Fabri 469 posts 1633 karma points
    Apr 15, 2016 @ 09:53
    Adriano Fabri
    0

    OK finally I found the solution :-)

    I had to modify the users resource file to call my custom methods and add the [PluginController("myCustomAPIController")] attribute to my UsersApiController.cs

    Finally I see all users.

    Thanks for support.

    Adriano

Please Sign in or register to post replies

Write your reply to:

Draft