Repository: syncope Updated Branches: refs/heads/2_0_X 0355ec1c8 -> f4960db59
[SYNCOPE-1005] moved attributes sorting to JS code, centralized sorting config into app.js initialization; minor app.js refinements Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/f4960db5 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/f4960db5 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/f4960db5 Branch: refs/heads/2_0_X Commit: f4960db5978139442d7eabfe5eff5860cda5eb8a Parents: 0355ec1 Author: Andrea Patricelli <andrea.patrice...@tirasa.net> Authored: Thu Feb 2 11:05:36 2017 +0100 Committer: Andrea Patricelli <andrea.patrice...@tirasa.net> Committed: Thu Feb 2 12:15:47 2017 +0100 ---------------------------------------------------------------------- .../enduser/resources/SchemaResource.java | 12 -- .../resources/META-INF/resources/app/js/app.js | 130 ++++++++++++++----- .../app/js/controllers/UserController.js | 20 +-- .../resources/app/js/services/schemaService.js | 36 ++--- 4 files changed, 127 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/f4960db5/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java index d8c0d9d..c64e73d 100644 --- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java +++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/SchemaResource.java @@ -23,12 +23,10 @@ import java.util.Collections; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; -import org.apache.commons.collections4.ComparatorUtils; import org.apache.commons.collections4.IterableUtils; import org.apache.commons.collections4.Predicate; import org.apache.syncope.client.enduser.SyncopeEnduserSession; import org.apache.syncope.client.enduser.model.SchemaResponse; -import org.apache.syncope.common.lib.EntityTOUtils; import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.to.AbstractSchemaTO; import org.apache.syncope.common.lib.to.AnyTypeTO; @@ -128,16 +126,6 @@ public class SchemaResource extends AbstractBaseResource { } } - Collections.sort(plainSchemas, ComparatorUtils.transformedComparator( - ComparatorUtils.<String>naturalComparator(), - EntityTOUtils.keyTransformer())); - Collections.sort(derSchemas, ComparatorUtils.transformedComparator( - ComparatorUtils.<String>naturalComparator(), - EntityTOUtils.keyTransformer())); - Collections.sort(virSchemas, ComparatorUtils.transformedComparator( - ComparatorUtils.<String>naturalComparator(), - EntityTOUtils.keyTransformer())); - response.setTextEncoding(SyncopeConstants.DEFAULT_ENCODING); response.setWriteCallback(new AbstractResource.WriteCallback() { http://git-wip-us.apache.org/repos/asf/syncope/blob/f4960db5/client/enduser/src/main/resources/META-INF/resources/app/js/app.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/app.js b/client/enduser/src/main/resources/META-INF/resources/app/js/app.js index c74b6e8..e8f8fd7 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/app.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/app.js @@ -1,5 +1,3 @@ -/* global $templateCache */ - /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -25,7 +23,9 @@ angular.module('login', []); angular.module('language', []); angular.module('self', []); angular.module('info', []); -// Declare app level module which depends on views, and components +/* + * AngularJS application modules from which depend views and components + */ var app = angular.module('SyncopeEnduserApp', [ 'ui.router', 'ui.bootstrap', @@ -47,14 +47,23 @@ var app = angular.module('SyncopeEnduserApp', [ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$translateProvider', '$translatePartialLoaderProvider', function ($stateProvider, $urlRouterProvider, $httpProvider, $translateProvider, $translatePartialLoaderProvider) { - + /* + |-------------------------------------------------------------------------- + | Syncope Enduser AngularJS providers configuration + |-------------------------------------------------------------------------- + */ + + /* + * i18n provider + */ $translatePartialLoaderProvider.addPart('static'); $translatePartialLoaderProvider.addPart('dynamic'); $translateProvider.useLoader('$translatePartialLoader', { urlTemplate: 'languages/{lang}/{part}.json' - }) - .preferredLanguage('en'); - + }).preferredLanguage('en'); + /* + * State provider + */ $stateProvider .state('home', { url: '/', @@ -209,14 +218,19 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$translate url: '/mustchangepassword', templateUrl: 'views/mustchangepassword.html' }); - // catch all other routes - // send users to the home page + /* + * catch all other routes and send users to the home page + */ $urlRouterProvider.otherwise('/'); - // HTTP service configuration + /* + * HTTP provider + */ $httpProvider.defaults.withCredentials = true; $httpProvider.defaults.xsrfCookieName = 'XSRF-TOKEN'; $httpProvider.defaults.xsrfHeaderName = 'X-XSRF-TOKEN'; - //SYNCOPE-780 + /* + * SYNCOPE-780 + */ $httpProvider.defaults.headers.common["If-Modified-Since"] = "0"; $httpProvider.interceptors.push(function ($q, $rootScope, $location) { return { @@ -231,7 +245,6 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$translate return config || $q.when(config); }, 'response': function (response) { - //$http.pendingRequests.length $rootScope.spinner.off(); return response || $q.when(response); }, @@ -256,20 +269,14 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$translate }]); app.run(['$rootScope', '$location', '$state', 'AuthService', function ($rootScope, $location, $state, AuthService) { - // main program - // keep user logged in after page refresh - //If the route change failed due to authentication error, redirect them out - $rootScope.endReached = false; - - $rootScope.languages = { - availableLanguages: [ - {id: '1', name: 'Italiano', code: 'it', format: 'dd/MM/yyyy HH:mm'}, - {id: '2', name: 'English', code: 'en', format: 'MM/dd/yyyy HH:mm'}, - {id: '3', name: 'Deutsch', code: 'de', format: 'dd/MM/yyyy HH:mm'} - ] - }; - $rootScope.languages.selectedLanguage = $rootScope.languages.availableLanguages[1]; - + /* + |-------------------------------------------------------------------------- + | Main of Syncope Enduser application + | + | keep user logged in after page refresh + | If the route change failed due to authentication error, redirect them out + |-------------------------------------------------------------------------- + */ $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { if (rejection === 'Not Authenticated') { $location.path('/self'); @@ -305,7 +312,9 @@ app.run(['$rootScope', '$location', '$state', 'AuthService', $state.go('self'); } ); - //enable "finish" button on every page in create mode + /* + * enable "finish" button on every page in create mode + */ } else if (toState.name === 'create.finish') { $rootScope.endReached = true; } else { @@ -324,16 +333,36 @@ app.run(['$rootScope', '$location', '$state', 'AuthService', }]); app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', function ($scope, $rootScope, InfoService) { - // get syncope info and set cookie, first call $scope.initApplication = function () { + /* + * disable by default wizard buttons in self-registration + */ + $rootScope.endReached = false; + /* + |-------------------------------------------------------------------------- + | Syncope Enduser i18n initialization + |-------------------------------------------------------------------------- + */ + $rootScope.languages = { + availableLanguages: [ + { id: '1', name: 'Italiano', code: 'it', format: 'dd/MM/yyyy HH:mm' }, + { id: '2', name: 'English', code: 'en', format: 'MM/dd/yyyy HH:mm' }, + { id: '3', name: 'Deutsch', code: 'de', format: 'dd/MM/yyyy HH:mm' } + ] + }; + $rootScope.languages.selectedLanguage = $rootScope.languages.availableLanguages[1]; + /* + |-------------------------------------------------------------------------- + | Syncope Enduser properties initialization + | get info from InfoService API (info settings are initialized every time an user reloads the login page) + |-------------------------------------------------------------------------- + */ $rootScope.selfRegAllowed = false; $rootScope.pwdResetAllowed = false; $rootScope.version = ""; $rootScope.pwdResetRequiringSecurityQuestions = false; $rootScope.captchaEnabled = false; - //setting default validation $rootScope.validationEnabled = true; - // call info service (info settings are initialized every time an user reload the login page) InfoService.getInfo().then( function (response) { $rootScope.pwdResetAllowed = response.pwdResetAllowed; @@ -345,6 +374,9 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', function (response) { console.error("Something went wrong while accessing info resource", response); }); + /* + * configuration getters + */ $rootScope.isSelfRegAllowed = function () { return $rootScope.selfRegAllowed === true; }; @@ -354,7 +386,26 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', $rootScope.getVersion = function () { return $rootScope.version; }; - //Notification management + /* + * USER Attributes sorting strategies + */ + $rootScope.attributesSorting = { + ASC: function ( a, b ) { + var schemaNameA = a.key; + var schemaNameB = b.key; + return schemaNameA < schemaNameB ? -1 : schemaNameA > schemaNameB ? 1 : 0; + }, + DESC: function ( a, b ) { + var schemaNameA = a.key; + var schemaNameB = b.key; + return schemaNameA < schemaNameB ? 1 : schemaNameA > schemaNameB ? -1 : 0; + } + }; + /* + |-------------------------------------------------------------------------- + | Notification mgmt + |-------------------------------------------------------------------------- + */ $scope.notification = $('#notifications').kendoNotification().data("kendoNotification"); $scope.notification.setOptions({stacking: "down"}); $scope.notification.options.position["top"] = 20; @@ -420,9 +471,11 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', } } }; - //Intercepting location change event + /* + * Intercepting location change event + * When a location changes, old notifications should be removed + */ $rootScope.$on("$locationChangeStart", function (event, next, current) { - //When a location changes, old notifications should be removed $scope.hideNotifications(3000); }); //Intercepting xhr start event @@ -433,7 +486,11 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', $scope.$on('hideErrorMessage', function (event, popupMessage) { $scope.hideError(popupMessage, $scope.notification); }); - //wizard active element + /* + |-------------------------------------------------------------------------- + | Wizard configuration + |-------------------------------------------------------------------------- + */ $scope.wizard = { "credentials": {url: "/credentials"}, "groups": {url: "/groups"}, @@ -443,6 +500,11 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', "resources": {url: "/resources"}, "finish": {url: "/finish"} }; + /* + |-------------------------------------------------------------------------- + | Utilities + |-------------------------------------------------------------------------- + */ $scope.clearCache = function () { $templateCache.removeAll(); }; http://git-wip-us.apache.org/repos/asf/syncope/blob/f4960db5/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/UserController.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/UserController.js b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/UserController.js index ce9c170..9be5935 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/UserController.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/UserController.js @@ -64,9 +64,9 @@ angular.module("self").controller("UserController", ['$scope', '$rootScope', '$l // initialization is done here synchronously to have all schema fields populated correctly var schemaService; if (group) { - schemaService = SchemaService.getTypeExtSchemas(group); + schemaService = SchemaService.getTypeExtSchemas(group, $rootScope.attributesSorting.ASC); } else { - schemaService = SchemaService.getUserSchemas(anyTypeClass); + schemaService = SchemaService.getUserSchemas(anyTypeClass, $rootScope.attributesSorting.ASC); } schemaService.then(function (schemas) { if (group && (schemas.plainSchemas.length > 0 || schemas.derSchemas.length > 0 || schemas.virSchemas.length > 0)) @@ -74,14 +74,16 @@ angular.module("self").controller("UserController", ['$scope', '$rootScope', '$l //initializing user schemas values initSchemaValues(schemas); }, function (response) { - var errorMessage; - // parse error response - if (response !== undefined) { - errorMessage = response.split("ErrorMessage{{")[1]; - errorMessage = errorMessage.split("}}")[0]; + // parse error response and log + if ( response !== undefined ) { + var errorMessages = response.toString().split( "ErrorMessage{{" ); + if ( errorMessages.length > 1 ) { + console.error( "Error retrieving user schemas: ", response.toString().split( "ErrorMessage{{" )[1].split( "}}" )[0] ); + } else { + console.error( "Error retrieving user schemas: ", errorMessages ); + } } - console.error("Error retrieving user schemas: ", errorMessage); - }); + } ); }; var initSchemaValues = function (schemas) { http://git-wip-us.apache.org/repos/asf/syncope/blob/f4960db5/client/enduser/src/main/resources/META-INF/resources/app/js/services/schemaService.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/services/schemaService.js b/client/enduser/src/main/resources/META-INF/resources/app/js/services/schemaService.js index dd5ff3a..90fdee9 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/services/schemaService.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/services/schemaService.js @@ -19,22 +19,26 @@ 'use strict'; -angular.module('self') - .factory('SchemaService', ['$resource', '$q', '$http', - function ($resource, $q, $http) { - - var schemaService = {}; - - schemaService.getUserSchemas = function (anyTypeClass) { - var classParam = anyTypeClass ? "?anyTypeClass=" + encodeURI(anyTypeClass) : ""; - - return $http.get("/syncope-enduser/api/schemas" + classParam) - .then(function (response) { - return response.data; - }, function (response) { - console.error("Something went wrong during schema retrieval, exit with status: ", response); - return $q.reject(response.data || response.statusText); - }); +angular.module( 'self' ) + .factory( 'SchemaService', [ '$q', '$http', + function ( $q, $http ) { + + var schemaService = { }; + + schemaService.getUserSchemas = function ( anyTypeClass, sortingFunction ) { + var classParam = anyTypeClass ? "?anyTypeClass=" + encodeURI( anyTypeClass ) : ""; + + return $http.get( "/syncope-enduser/api/schemas" + classParam ) + .then( function ( response ) { + var schemas = response.data; + schemas.plainSchemas.sort( sortingFunction ); + schemas.derSchemas.sort( sortingFunction ); + schemas.virSchemas.sort( sortingFunction ); + return schemas; + }, function ( response ) { + console.error( "Something went wrong during schema retrieval, exit with status: ", response ); + return $q.reject( response.data || response.statusText ); + } ); }; schemaService.getTypeExtSchemas = function (group) {