Skip to content

Commit

Permalink
Merge pull request #426 from marmelab/float_type
Browse files Browse the repository at this point in the history
[RFR] Introduce float type
  • Loading branch information
fzaninotto committed Jun 1, 2015
2 parents 82cee63 + cd21586 commit 9bb6a5d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 38 deletions.
5 changes: 4 additions & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
.fields([
nga.field('id').label('id'), // The default displayed name is the camelCase field name. label() overrides id
nga.field('title'), // the default list field type is "string", and displays as a string
nga.field('published_at', 'date'), // Date field type allows date formatting
nga.field('published_at', 'date'), // Date field type allows date formatting
nga.field('average_note', 'float'), // Float type also displays decimal digits
nga.field('views', 'number'),
nga.field('tags', 'reference_many') // a Reference is a particular type of field that references another entity
.targetEntity(tag) // the tag entity is defined later in this file
Expand Down Expand Up @@ -125,6 +126,8 @@
nga.field('pictures', 'json'),
nga.field('views', 'number')
.cssClasses('col-sm-4'),
nga.field('average_note', 'float')
.cssClasses('col-sm-4'),
nga.field('comments', 'referenced_list') // display list of related comments
.targetEntity(comment)
.targetReferenceField('post_id')
Expand Down
14 changes: 13 additions & 1 deletion examples/blog/stub-server.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/column/maColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define(function (require) {
entity: '&',
datastore: '&'
},
link: function(scope, element, attr) {
link: function(scope, element) {
scope.datastore = scope.datastore();
scope.field = scope.field();
scope.entry = scope.entry();
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/config/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function factories(fvp) {
fvp.registerFieldView('datetime', require('../fieldView/DateFieldView'));
fvp.registerFieldView('email', require('../fieldView/EmailFieldView'));
fvp.registerFieldView('file', require('../fieldView/FileFieldView'));
fvp.registerFieldView('float', require('../fieldView/FloatFieldView'));
fvp.registerFieldView('json', require('../fieldView/JsonFieldView'));
fvp.registerFieldView('number', require('../fieldView/NumberFieldView'));
fvp.registerFieldView('password', require('../fieldView/PasswordFieldView'));
Expand Down
3 changes: 2 additions & 1 deletion src/javascripts/ng-admin/Crud/field/maInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define(function (require) {
return {
scope: {
'type': '@',
'step': '@?',
'field': '&',
'value': '='
},
Expand All @@ -27,7 +28,7 @@ define(function (require) {
}
},
template:
'<input type="{{ type || text }}" ng-model="value" id="{{ name }}" name="{{ name }}" class="form-control"' +
'<input type="{{ type || text }}" ng-attr-step="{{ step }}" ng-model="value" id="{{ name }}" name="{{ name }}" class="form-control"' +
'ng-required="v.required" ng-minlength="v.minlength" ng-maxlength="v.maxlength" />'
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function () {

FieldViewConfiguration.prototype.registerFieldView = function(type, FieldView) {
this.fieldViews[type] = FieldView;
}
};

FieldViewConfiguration.prototype.$get = function () {
return this.fieldViews;
Expand Down
14 changes: 14 additions & 0 deletions src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
getReadWidget: function() {
return '<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-number-column>';
},
getLinkWidget: function() {
return '<a ng-click="gotoDetail()">' + this.getReadWidget() + '</a>';
},
getFilterWidget: function() {
return '<ma-input-field type="number" step="any" field="::field" value="values[field.name()]"></ma-input-field>';
},
getWriteWidget: function() {
return '<ma-input-field type="number" step="any" field="::field" value="entry.values[field.name()]"></ma-input-field>';
}
};
33 changes: 0 additions & 33 deletions src/javascripts/ng-admin/Main/config/factories.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/javascripts/test/unit/Crud/fieldView/FloatFieldView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var assert = require('chai').assert;
var FloatFieldView = require('../../../../ng-admin/Crud/fieldView/FloatFieldView');

describe('FloatFieldView', function() {
describe('getReadWidget', function() {
it('should return number column directive', function() {
var widget = FloatFieldView.getReadWidget();
assert.include(widget, '<ma-number-column');
});
});

describe('getLinkWidget', function() {
it('should return number column directive', function() {
var widget = FloatFieldView.getLinkWidget();
assert.include(widget, '<ma-number-column');
});
});

describe('getFilterWidget', function() {
it('should set step attribute to "any"', function() {
var widget = FloatFieldView.getFilterWidget();
assert.include(widget, 'step="any"');
});
});

describe('getWriteWidget', function() {
it('should set step attribute to "any"', function() {
var widget = FloatFieldView.getFilterWidget();
assert.include(widget, 'step="any"');
});
});
});

0 comments on commit 9bb6a5d

Please sign in to comment.