2017 © Pedro Peláez
 

component angular-worldskills-utils

image

worldskills/angular-worldskills-utils

  • Thursday, June 1, 2017
  • by fabian
  • Repository
  • 6 Watchers
  • 0 Stars
  • 889 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 18 Versions
  • 1 % Grown

The README.md

WorldSkills AngularJS Utils

Installation

Install with Bower:, (*1)

bower install angular-worldskills-utils --save

Load the JavaScript in your HTML file:, (*2)

<script src="bower_components/angular-worldskills-utils/src/angular-worldskills-utils.js"></script>

Usage

Add the dependency to your AngularJS module:, (*3)

angular.module('yourApp', ['worldskills.utils']);

Define the following constants (don't forget to replace your client id):, (*4)

angular.module('yourApp').constant('WORLDSKILLS_CLIENT_ID', '<your client id>');
angular.module('yourApp').constant('WORLDSKILLS_API_AUTH', 'https://api.worldskills.org/auth');
angular.module('yourApp').constant('WORLDSKILLS_AUTHORIZE_URL', 'https://auth.worldskills.org/oauth/authorize');
angular.module('yourApp').constant('LOAD_CHILD_ENTITY_ROLES', false);
angular.module('yourApp').constant('FILTER_AUTH_ROLES', [<array of application codes>]);

Authentication

To use any of the following authentication functions, make sure to use the auth object in at least one controller, e.g.:, (*5)

angular.module('yourApp').controller('ContainerCtrl', function($scope, auth) {
    $scope.auth = auth;
});

Return to state

To load the previous state after the user has logged in on WorldSkills Auth, you can use sessionStorage.getItem('redirect_to_state'). Configure the $urlRouterProvider as following:, (*6)

angular.module('yourApp').config(function($urlRouterProvider) {
    $urlRouterProvider.otherwise(function ($injector, $location) {
        // check for existing redirect
        var $state = $injector.get('$state');
        var redirectToState = sessionStorage.getItem('redirect_to_state');
        var redirectToParams = sessionStorage.getItem('redirect_to_params');
        sessionStorage.removeItem('redirect_to_state');
        sessionStorage.removeItem('redirect_to_params');
        if (redirectToState) {
            if (redirectToParams) {
                redirectToParams = angular.fromJson(redirectToParams);
            } else {
                redirectToParams = {};
            }
            $state.go(redirectToState, redirectToParams);
        } else {
            $state.go('your.home.state');
        }
    });
});

Require authenticated user

To require an authenticated user for certain states, add requireLoggedIn: true in the state data:, (*7)

.state('your.state', {
    url: '/your/url',
    templateUrl: 'views/template.html',
    controller: 'YourCtrl',
    data: {
        requireLoggedIn: true
    }
})

You can also require specific roles for a state with requiredRoles:, (*8)

.state('your.state', {
    url: '/your/url',
    templateUrl: 'views/template.html',
    controller: 'YourCtrl',
    data: {
        requireLoggedIn: true,
        requiredRoles: [
            {code: 100, role: 'Admin'}
        ]
    }
})

Custom fallbacks for forbidden state

Custom fallback in order to handle forbidden redirect manually rather than to redirect to login url automatically. Add forbiddenFallbad: function to app.js, (*9)

.state('people', {
  url: '/people?search',
  templateUrl: 'views/people.html',
  controller: 'PersonnelCtrl',
  data:{
    requireLoggedIn: true,        
    forbiddenCallback: function(auth, $state){
      //state passed from $rootScope.$state
      $state.go('person.view', {'pid': auth.user.person_id});          
    },
    requiredRoles: [
      {code: 600, role: APP_ROLES.ADMIN},
      {code: 600, role: APP_ROLES.MANAGER}
    ]
  }
})

Also now allows custom fallbacks for login error state, use case: redirect to a signup page instead of auth.loginUrl, (*10)

   .state('restrictedState', {
     url: '/needsLogin',
     templateUrl: 'views/restricted.html',
     controller: 'RestrictedCtrl',     
     data: {
      requireLoggedIn: true,
      unAuthenticatedCallback: function(auth, $state){
        $state.go('signup');
      },
       requiredRoles: [
         {code: 1800, role: APP_ROLES.ADMIN},
         {code: 1800, role: APP_ROLES.MANAGER},
         {code: 1800, role: APP_ROLES.USER}
       ]
     }
   })

   .state('signup', {
    url: '/signup',
    controller: 'SignupCtrl',
    templateUrl: 'views/signup.html',
    data: {
      requireLoggedIn: false
    }
   })

Spinner directive

Show an animated loading indicator graphic., (*11)

<ws-spinner ng=show="loading"></ws-spinner>

TextSpinner directive

Show a loading indicator on a button., (*12)

<button type="submit" class="btn btn-success">
    Save
    <ws-text-spinner ng-show="loading" class="ng-hide"></ws-text-spinner>
</button>

Spinner sizes

Added small and big versions, (*13)

<ws-spinner class='bigSpinner'></ws-spinner>
<ws-spinner class='smallSpinner'></ws-spinner>

The Versions

01/06 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

01/06 2017

v0.1.7

0.1.7.0

  Sources   Download

MIT

The Requires

 

23/02 2016

v0.1.6

0.1.6.0

  Sources   Download

MIT

The Requires

 

22/02 2016

v0.1.5

0.1.5.0

  Sources   Download

MIT

The Requires

 

06/11 2015

v0.1.3

0.1.3.0

  Sources   Download

MIT

The Requires

 

05/11 2015

v0.1.2

0.1.2.0

  Sources   Download

MIT

The Requires

 

03/11 2015

v0.1.1

0.1.1.0

  Sources   Download

MIT

The Requires

 

14/10 2015

v0.0.25

0.0.25.0

  Sources   Download

MIT

The Requires

 

18/09 2015

v0.0.24

0.0.24.0

  Sources   Download

MIT

The Requires

 

14/07 2015

v0.0.23

0.0.23.0

  Sources   Download

MIT

The Requires

 

26/06 2015

v0.0.22

0.0.22.0

  Sources   Download

MIT

The Requires

 

25/06 2015

v0.0.21

0.0.21.0

  Sources   Download

MIT

The Requires

 

25/06 2015

v0.0.20

0.0.20.0

  Sources   Download

MIT

The Requires

 

24/06 2015

v0.0.19

0.0.19.0

  Sources   Download

MIT

The Requires

 

18/06 2015

v0.0.18

0.0.18.0

  Sources   Download

MIT

The Requires

 

11/02 2015

v0.0.17

0.0.17.0

  Sources   Download

MIT

The Requires

 

10/02 2015

v0.0.16

0.0.16.0

  Sources   Download

MIT

The Requires

 

26/11 2014

v0.0.15

0.0.15.0

  Sources   Download

MIT

The Requires