Skip to content

Commit 19c1a82

Browse files
committed
Rename main file to ng-navigation-service.js
* Rename main file to ng-navigation-service so it matches the package name. * Update to README for better explanation of dependency on ng-authentication-service. * Update version to 1.0.0.
1 parent 0a8e53f commit 19c1a82

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,57 @@ A navigation helper service for Angular client applications.
99

1010
* AngularJS - http://angularjs.org
1111
* Lodash - http://lodash.com
12+
* ng-authentication-service - https://github.com/justinsa/angular-authentication-service
13+
14+
The ng-navigation-service was designed in tandem with the ng-authentication-service, but it is not a hard requirement. The configured security service must support the following API:
15+
16+
1. ```boolean isAuthenticated()```
17+
2. ```[String] roles()```
1218

1319
##Basic Setup
1420

15-
1. Add this module to your app as a dependency:
21+
Add this module to your app as a dependency:
1622
```JAVASCRIPT
1723
var app = angular.module('yourApp', ['navigation.service']);
1824
```
19-
2. Configure a security service to use with the navigation provider:
25+
26+
Configure a security service to use with the navigation provider:
2027
```JAVASCRIPT
2128
app.config(['$navigationProvider', function ($navigationProvider) {
2229
$navigationProvider.configure({
23-
securityService: 'authentication.service'
30+
securityService: '$authentication'
2431
});
2532
}]);
2633
```
27-
3. Inject $navigation as a parameter in declarations that require it:
34+
35+
Inject $navigation as a parameter in declarations that require it:
2836
```JAVASCRIPT
2937
app.controller('yourController', function($scope, $navigation){ ... });
3038
```
3139

3240
##Configuration Options
3341

34-
The default configuration is:
42+
To override the default configuration options, configure the module with an options argument during application configuration and provide overrides for any of the following options.
3543

36-
1. securityService: undefined - this string value must be provided during configuration and must be a loaded service that supports the following API:
37-
1. function ```isAuthenticated()```
38-
2. function ```roles()```
39-
2. roleToAudienceMapFunction: function returns the userRole provided.
40-
3. inAudienceValidationFunction: function determines if the userRoles are in the audiences.
41-
4. activeLinkDecorator: mixed
42-
5. inactiveLinkDecorator: mixed
43-
44-
To override the default configuration options, configure the module with an options argument during application configuration:
4544
```JAVASCRIPT
4645
app.config(['$navigationProvider', function ($navigationProvider) {
4746
$navigationProvider.configure({
48-
securityService: 'authentication.service',
49-
roleToAudienceMapFunction: function (userRole) { ... },
50-
inAudienceValidationFunction: function (userRoles, audiences) { ... }
47+
activeLinkDecorator: undefined,
48+
inactiveLinkDecorator: undefined,
49+
securityService: undefined,
50+
roleToAudienceMapFunction: function (userRole) {
51+
return userRole;
52+
},
53+
inAudienceValidationFunction: function (userRoles, audiences) {
54+
var userAudiences = _.flatten(userRoles, this.roleToAudienceMapFunction);
55+
return !_.isEmpty(userAudiences) && !_.isEmpty(audiences) &&
56+
(_.find(audiences, function (audience) { return _.includes(userAudiences, audience); }) !== undefined);
57+
}
5158
});
5259
}]);
5360
```
5461

55-
The ng-navigation-service was designed in tandem with the following projects:
56-
57-
* https://github.com/justinsa/angular-authentication-service
58-
59-
##Basic Usage
62+
##API
6063

6164
###inAudience
6265
```JAVASCRIPT

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"homepage": "https://github.com/justinsa/angular-navigation-service",
1414
"license": "MIT",
15-
"main": "./angular-navigation-service.js",
15+
"main": "./ng-navigation-service.js",
1616
"ignore": [
1717
".jshintrc",
1818
"gulpfile.js",

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var gulp = require('gulp');
33
var jshint = require('gulp-jshint');
44
gulp.task('js:lint', function() {
5-
return gulp.src(['./angular-navigation-service.js', './gulpfile.js', './tests.js'])
5+
return gulp.src(['./ng-navigation-service.js', './gulpfile.js', './tests.js'])
66
.pipe(jshint())
77
.pipe(jshint.reporter('default'));
88
});

angular-navigation-service.js renamed to ng-navigation-service.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
(function (root, factory) {
33
'use strict';
44
if (typeof module !== 'undefined' && module.exports) {
5-
if (typeof angular === 'undefined') {
6-
factory(
7-
typeof _ === 'undefined' ? require('lodash') : root._,
8-
require('angular')
9-
);
10-
} else {
11-
factory(root._, root.angular);
12-
}
5+
factory(
6+
typeof _ === 'undefined' ? require('lodash') : root._,
7+
typeof angular === 'undefined' ? require('angular') : root.angular
8+
);
139
module.exports = 'ng-navigation-service';
1410
} else if (typeof define === 'function' && define.amd) {
1511
define(['lodash', 'angular'], factory);
@@ -55,7 +51,7 @@
5551
secService = $injector.get(configuration.securityService);
5652
_.each(['isAuthenticated', 'roles'], function (methodName) {
5753
if (!_.has(secService, methodName)) {
58-
$log.error('Matching service is missing method: ', methodName);
54+
$log.error('Matching securityService is missing method: ', methodName);
5955
return undefined;
6056
}
6157
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-navigation-service",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"author": "Justin Saunders (https://github.com/justinsa)",
55
"contributors": [
66
"Justin Saunders (https://github.com/justinsa)"

test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<script src="./node_modules/angular/angular.js"></script>
1919
<script src="./node_modules/angular-mocks/angular-mocks.js"></script>
2020

21-
<script src="./angular-navigation-service.js"></script>
21+
<script src="./ng-navigation-service.js"></script>
2222

2323
<script src="./tests.js"></script>
2424

0 commit comments

Comments
 (0)