Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

ng-admin role-based system #8

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 136 additions & 91 deletions build/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions build/ng-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ng-admin.min.js.map

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions js/categories/config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
export default function (nga, admin) {
export default function (nga, admin, isAdminRole) {

var categories = admin.getEntity('categories');
categories.listView()
.fields([
nga.field('name'),
])
.listActions(['<ma-filtered-list-button entity-name="products" filter="{ category_id: entry.values.id }" size="xs" label="Related products"></ma-filtered-list-button>', 'edit', 'delete']);
categories.creationView()
.fields([
nga.field('name')
.validation({ required: true }),
nga.field('', 'template')
.label('')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="products" filter="{ category_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')
if (isAdminRole) {
categories.listView()
.listActions(['<ma-filtered-list-button entity-name="products" filter="{ category_id: entry.values.id }" size="xs" label="Related products"></ma-filtered-list-button>', 'edit', 'delete']);
categories.creationView()
.fields([
nga.field('name')
.validation({ required: true }),
nga.field('', 'template')
.label('')
.template('<span class="pull-right"><ma-filtered-list-button entity-name="products" filter="{ category_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')

]);
categories.editionView()
.fields(categories.creationView().fields());
]);
categories.editionView()
.fields(categories.creationView().fields());
} else {
categories.listView()
.batchActions([])
.listActions();
}

return categories;
}
8 changes: 6 additions & 2 deletions js/commands/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default function (nga, admin) {
export default function (nga, admin, isAdminRole) {

if (!isAdminRole) {
return null;
}

var commands = admin.getEntity('commands');
commands.listView()
Expand Down Expand Up @@ -40,7 +44,7 @@ export default function (nga, admin) {
{ label: 'cancelled', value: 'cancelled' }
]),
nga.field('date_gte', 'datetime')
.label('Passed since'),
.label('Passed after'),
nga.field('date_lte', 'datetime')
.label('Passed before'),
nga.field('total_gte', 'amount')
Expand Down
174 changes: 89 additions & 85 deletions js/customers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fromNow = v => moment(v).fromNow();

var segments = require('../segments/segments').choices;

export default function (nga, admin) {
export default function (nga, admin, isAdminRole) {

var customer = admin.getEntity('customers');
customer.listView()
Expand All @@ -19,11 +19,13 @@ export default function (nga, admin) {
nga.field('last_seen', 'datetime')
.map(fromNow)
.cssClasses('hidden-xs'),
nga.field('nb_commands', 'number')
nga.field('nb_commands', 'template')
.label('Commands')
.cssClasses(entry => entry.values.nb_commands ? 'hidden-xs' : 'transparent hidden-xs'),
nga.field('total_spent', 'amount')
.cssClasses(entry => entry.values.total_spent ? 'hidden-xs' : 'transparent hidden-xs'),
.template('{{ entry.values.nb_commands ? entry.values.nb_commands : "" }}')
.cssClasses('hidden-xs'),
nga.field('total_spent', 'template')
.template('<div class="amount" ng-if="::entry.values[field.name()]">$<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-number-column></div>')
.cssClasses('hidden-xs text-right'),
nga.field('latest_purchase', 'datetime')
.cssClasses('hidden-xs'),
nga.field('has_newsletter', 'boolean')
Expand All @@ -49,86 +51,88 @@ export default function (nga, admin) {
.sortField('first_seen')
.sortDir('DESC')
.listActions(['edit']);
customer.editionView()
.title('<img src="{{ entry.values.avatar }}" width="50" style="vertical-align: text-bottom"/> {{ entry.values.first_name }} {{ entry.values.last_name }}\'s details')
.fields([
nga.field('first_name'),
nga.field('last_name'),
nga.field('email', 'email'),
nga.field('address', 'text'),
nga.field('zipcode'),
nga.field('city'),
nga.field('birthday', 'date'),
nga.field('first_seen', 'datetime')
.editable(false),
nga.field('latest_purchase', 'datetime')
.editable(false),
nga.field('last_seen', 'datetime')
.editable(false),
nga.field('has_newsletter', 'boolean'),
nga.field('groups', 'choices')
.choices(segments),
nga.field('commands', 'referenced_list')
.label('Latest commands')
.targetEntity(admin.getEntity('commands'))
.targetReferenceField('customer_id')
.targetFields([
nga.field('date')
.map(fromNow),
nga.field('reference')
.isDetailLink(true),
nga.field('nb_items')
.map((v,e) => e.basket.length),
nga.field('total', 'amount'),
nga.field('status')
])
.perPage(5)
.sortField('date')
.sortDir('DESC'),
nga.field('commands button', 'template')
.label('')
.template('<ma-filtered-list-button entity-name="commands" filter="{ customer_id: entry.values.id }"></ma-filtered-list-button>'),
nga.field('reviews', 'referenced_list')
.label('Latest reviews')
.targetEntity(admin.getEntity('reviews'))
.targetReferenceField('customer_id')
.targetFields([
nga.field('date')
.label('Posted')
.map(fromNow)
.isDetailLink(true),
nga.field('rating', 'template')
.template('<star-rating stars="{{ entry.values.rating }}"></star-rating>'),
nga.field('comment')
.map(function truncate(value) {
if (!value) {
return '';
}
return value.length > 50 ? value.substr(0, 50) + '...' : value;
}),
nga.field('status', 'choice')
.choices([
{ label: 'accepted', value: 'accepted' },
{ label: 'rejected', value: 'rejected' },
{ label: 'pending', value: 'pending' }
])
.cssClasses(function(entry) { // add custom CSS classes to inputs and columns
if (entry.values.status == 'accepted') {
return 'text-center bg-success';
}
if (entry.values.status == 'rejected') {
return 'text-center bg-danger';
}
return 'text-center bg-warning';
}),
])
.perPage(5)
.sortField('date')
.sortDir('DESC'),
nga.field('reviews button', 'template')
.label('')
.template('<ma-filtered-list-button entity-name="reviews" filter="{ customer_id: entry.values.id }"></ma-filtered-list-button>'),
])

if (isAdminRole) { //
customer.editionView()
.title('<img src="{{ entry.values.avatar }}" width="50" style="vertical-align: text-bottom"/> {{ entry.values.first_name }} {{ entry.values.last_name }}\'s details')
.fields([
nga.field('first_name'),
nga.field('last_name'),
nga.field('email', 'email'),
nga.field('address', 'text'),
nga.field('zipcode'),
nga.field('city'),
nga.field('birthday', 'date'),
nga.field('first_seen', 'datetime')
.editable(false),
nga.field('latest_purchase', 'datetime')
.editable(false),
nga.field('last_seen', 'datetime')
.editable(false),
nga.field('has_newsletter', 'boolean'),
nga.field('groups', 'choices')
.choices(segments),
nga.field('commands', 'referenced_list')
.label('Latest commands')
.targetEntity(admin.getEntity('commands'))
.targetReferenceField('customer_id')
.targetFields([
nga.field('date')
.map(fromNow),
nga.field('reference')
.isDetailLink(true),
nga.field('nb_items')
.map((v,e) => e.basket.length),
nga.field('total', 'amount'),
nga.field('status')
])
.perPage(5)
.sortField('date')
.sortDir('DESC'),
nga.field('commands button', 'template')
.label('')
.template('<ma-filtered-list-button entity-name="commands" filter="{ customer_id: entry.values.id }"></ma-filtered-list-button>'),
nga.field('reviews', 'referenced_list')
.label('Latest reviews')
.targetEntity(admin.getEntity('reviews'))
.targetReferenceField('customer_id')
.targetFields([
nga.field('date')
.label('Posted')
.map(fromNow)
.isDetailLink(true),
nga.field('rating', 'template')
.template('<star-rating stars="{{ entry.values.rating }}"></star-rating>'),
nga.field('comment')
.map(function truncate(value) {
if (!value) {
return '';
}
return value.length > 50 ? value.substr(0, 50) + '...' : value;
}),
nga.field('status', 'choice')
.choices([
{ label: 'accepted', value: 'accepted' },
{ label: 'rejected', value: 'rejected' },
{ label: 'pending', value: 'pending' }
])
.cssClasses(function(entry) { // add custom CSS classes to inputs and columns
if (entry.values.status == 'accepted') {
return 'text-center bg-success';
}
if (entry.values.status == 'rejected') {
return 'text-center bg-danger';
}
return 'text-center bg-warning';
}),
])
.perPage(5)
.sortField('date')
.sortDir('DESC'),
nga.field('reviews button', 'template')
.label('')
.template('<ma-filtered-list-button entity-name="reviews" filter="{ customer_id: entry.values.id }"></ma-filtered-list-button>'),
])
}
return customer;
}
Loading