Skip to content

Commit

Permalink
Introduce float type
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetitcolas committed May 11, 2015
1 parent 7f7c2db commit 2a467d3
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 @@ -123,6 +124,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 @@ -25,7 +25,7 @@ define(function (require) {
entry: '&',
entity: '&'
},
link: function(scope, element, attr) {
link: function(scope, element) {
scope.field = scope.field();
scope.entry = scope.entry();
var type = scope.field.type();
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 @@ -11,6 +11,7 @@ define(function (require) {
fvp.registerFieldView('datetime', require('ng-admin/Crud/fieldView/DateFieldView'));
fvp.registerFieldView('email', require('ng-admin/Crud/fieldView/EmailFieldView'));
fvp.registerFieldView('file', require('ng-admin/Crud/fieldView/FileFieldView'));
fvp.registerFieldView('float', require('ng-admin/Crud/fieldView/FloatFieldView'));
fvp.registerFieldView('json', require('ng-admin/Crud/fieldView/JsonFieldView'));
fvp.registerFieldView('number', require('ng-admin/Crud/fieldView/NumberFieldView'));
fvp.registerFieldView('password', require('ng-admin/Crud/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
22 changes: 22 additions & 0 deletions src/javascripts/ng-admin/Crud/fieldView/FloatFieldView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(function(require) {
"use strict";

function getReadWidget() {
return '<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-float-column>';
}
function getLinkWidget() {
return '<a ng-click="gotoDetail()">' + getReadWidget() + '</a>';
}
function getFilterWidget() {
return '<ma-input-field type="number" step="any" field="::field" value="values[field.name()]"></ma-input-field>';
}
function getWriteWidget() {
return '<ma-input-field type="number" step="any" field="::field" value="entry.values[field.name()]"></ma-input-field>';
}
return {
getReadWidget: getReadWidget,
getLinkWidget: getLinkWidget,
getFilterWidget: getFilterWidget,
getWriteWidget: getWriteWidget
}
});
2 changes: 2 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DateField from "./Field/DateField";
import DateTimeField from "./Field/DateTimeField";
import EmailField from "./Field/EmailField";
import FileField from "./Field/FileField";
import FloatField from "./Field/FloatField";
import JsonField from "./Field/JsonField";
import NumberField from "./Field/NumberField";
import PasswordField from "./Field/PasswordField";
Expand Down Expand Up @@ -67,6 +68,7 @@ class Factory {
this.registerFieldType('date', DateField);
this.registerFieldType('datetime', DateTimeField);
this.registerFieldType('email', EmailField);
this.registerFieldType('float', FloatField);
this.registerFieldType('string', Field);
this.registerFieldType('file', FileField);
this.registerFieldType('json', JsonField);
Expand Down
11 changes: 11 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Field/FloatField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import NumberField from "./NumberField";

class FloatField extends NumberField {
constructor(name) {
super(name);
this._type = 'float';
this._format = '0.000';
}
}

export default FloatField;

0 comments on commit 2a467d3

Please sign in to comment.