Created
March 14, 2017 18:46
-
-
Save beevelop/cdd948f030b2689cd121a19c4414f18b to your computer and use it in GitHub Desktop.
ng-admin for feathers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('feathers') | |
.config([ 'ngAdminJWTAuthConfiguratorProvider', function (jwt) { | |
jwt.setJWTAuthURL('http://sandbox.foobar.feathers/auth/local') | |
jwt.setCustomLoginTemplate('login.html') | |
jwt.setCustomAuthHeader({ | |
name: 'Authorization', | |
template: 'Bearer {{token}}' | |
}) | |
} ]) | |
.config(['NgAdminConfigurationProvider', 'groupEntity', function (nga, groupEntity) { | |
var admin = nga.application('Feathers Admin').baseApiUrl('http://sandbox.foobar.feathers/') | |
admin.addEntity(groupEntity(nga)) | |
nga.configure(admin) | |
} ]) | |
.config([ 'RestangularProvider', function (rest) { | |
rest.addResponseInterceptor(function (data, operation, what, url, response) { | |
// this is a stupid workaround ATM and might be quite simple to solve () | |
response.totalCount = 100000 | |
return data | |
}) | |
rest.addFullRequestInterceptor(function (element, operation, what, url, headers, params) { | |
if ('_page' in params && '_perPage' in params) { | |
params.$skip = (params._page - 1) * params._perPage | |
} | |
if ('_perPage' in params) { | |
params.$limit = params._perPage | |
} | |
if ('_filters' in params) { | |
_.forEach(params._filters, function (value, key) { | |
params[ key ] = value | |
}) | |
} | |
if (_.has(params, '_sortField')) { | |
params[ '$sort[' + params._sortField + ']' ] = params._sortDir === 'DESC' ? -1 : 1 | |
} | |
delete params._filters | |
delete params._page | |
delete params._perPage | |
delete params._sortField | |
delete params._sortDir | |
return { params: params } | |
}) | |
} ]) | |
.run(function ($rootScope, ngAdminJWTAuthService) { | |
if (ngAdminJWTAuthService.isAuthenticated() && localStorage.userData) { | |
$rootScope.USER = JSON.parse(localStorage.userData); | |
} | |
}) | |
.constant('groupEntity', function (nga) { | |
var group = nga.entity('groups') | |
group.updateMethod('patch') | |
group.createMethod('post') | |
var userField = cortex.costumes.reference(nga.field('user_id', 'reference') | |
.validation({ required: true }) | |
.targetEntity(nga.entity('users')) | |
.targetField(nga.field('email')) | |
.label('Admin') | |
.pinned(true)) | |
group.listView().fields([ | |
nga.field('name').validation({ | |
required: true, | |
maxlength: 15, | |
minlength: 4 | |
}).isDetailLink(true), | |
userField | |
]).filters([ | |
userField, | |
nga.field('name').label('Name Search') | |
]).listActions([ | |
'<ma-edit-button entry="::entry" entity="::entity" size="xs" label="Edit"></ma-edit-button>' | |
]) | |
var listFields = angular.copy(group.listView().fields()) | |
listFields.push([ | |
nga.field('wager', 'text'), | |
]) | |
var creationFields = angular.copy(listFields) | |
group.creationView().fields(creationFields) | |
// Edition | |
listFields.unshift([ nga.field('id').editable(false) ]) | |
group.editionView().title('Edit Group: {{ entry.values.name }}').fields(listFields) | |
return group | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Feathers Admin</title> | |
<link rel="stylesheet" href="node_modules/ng-admin/build/ng-admin.min.css"> | |
<link rel="stylesheet" href="css/style.css"> | |
</head> | |
<body ng-app="feathers"> | |
<div ui-view="ng-admin"></div> | |
<script src="node_modules/jquery/dist/jquery.min.js"></script> | |
<script src="node_modules/lodash/lodash.min.js"></script> | |
<script src="node_modules/ng-admin/build/ng-admin.min.js" type="text/javascript"></script> | |
<script src="node_modules/ng-admin.jwt-auth/build/ng-admin.jwt-auth.js" type="text/javascript"></script> | |
<script src="admin.js" type="text/javascript"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "feathers-admin", | |
"private": true, | |
"version": "0.0.1", | |
"description": "", | |
"repository": "", | |
"license": "UNLICENSED", | |
"devDependencies": { | |
"bower": "^1.7.7", | |
"http-server": "^0.9.0" | |
}, | |
"scripts": { | |
"update-deps": "npm update", | |
"start": "http-server -a 0.0.0.0 -p 8080 -c-1" | |
}, | |
"dependencies": { | |
"admin-config": "^0.12.1", | |
"angular": "^1.6.1", | |
"jquery": "^3.1.1", | |
"lodash": "^4.17.4", | |
"ng-admin": "^1.0.0", | |
"ng-admin.jwt-auth": "github:beevelop/ng-admin-jwt-auth#patch-1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment