alaska-field-datetime
Advanced tools
Comparing version 0.11.13 to 0.12.0
56
index.js
@@ -1,31 +0,25 @@ | ||
// @flow | ||
'use strict'; | ||
import { Field } from 'alaska'; | ||
import moment from 'moment'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
export default class DatetimeField extends Field { | ||
static plain = Date; | ||
static dbOptions = ['min', 'max', 'expires']; | ||
static viewOptions = ['min', 'max', 'format', 'dateFormat', 'timeFormat']; | ||
static defaultOptions = { | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
dateFormat: 'YYYY-MM-DD', | ||
timeFormat: 'HH:mm:ss', | ||
cell: 'DatetimeFieldCell', | ||
view: 'DatetimeFieldView', | ||
filter: 'DatetimeFieldFilter', | ||
}; | ||
var _alaska = require('alaska'); | ||
format: string; | ||
dateFormat: string; | ||
timeFormat: string; | ||
var _moment = require('moment'); | ||
var _moment2 = _interopRequireDefault(_moment); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
class DatetimeField extends _alaska.Field { | ||
init() { | ||
let field = this; | ||
this.underscoreMethod('format', function (format) { | ||
return moment(this.get(field.path)).format(format || field.format); | ||
return (0, _moment2.default)(this.get(field.path)).format(format || field.format); | ||
}); | ||
} | ||
createFilter(filter: Object): any { | ||
createFilter(filter) { | ||
if (!filter) return null; | ||
@@ -41,3 +35,3 @@ let value; | ||
if (value) { | ||
let date = moment(value); | ||
let date = (0, _moment2.default)(value); | ||
if (!date.isValid()) { | ||
@@ -61,4 +55,4 @@ return null; | ||
if (bt && bt.length === 2) { | ||
let start = moment(bt[0]); | ||
let end = moment(bt[1]); | ||
let start = (0, _moment2.default)(bt[0]); | ||
let end = (0, _moment2.default)(bt[1]); | ||
if (start.isValid() && end.isValid()) { | ||
@@ -73,7 +67,7 @@ return { | ||
//比较 | ||
['gt', 'gte', 'lt', 'lte'].forEach((key) => { | ||
['gt', 'gte', 'lt', 'lte'].forEach(key => { | ||
let val = filter[key] || filter['$' + key]; | ||
if (val) { | ||
if (!(val instanceof Date)) { | ||
val = moment(val); | ||
val = (0, _moment2.default)(val); | ||
if (!val.isValid()) return; | ||
@@ -100,1 +94,13 @@ if (key[1] === 'g') { | ||
} | ||
exports.default = DatetimeField; | ||
DatetimeField.plain = Date; | ||
DatetimeField.dbOptions = ['min', 'max', 'expires']; | ||
DatetimeField.viewOptions = ['min', 'max', 'format', 'dateFormat', 'timeFormat']; | ||
DatetimeField.defaultOptions = { | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
dateFormat: 'YYYY-MM-DD', | ||
timeFormat: 'HH:mm:ss', | ||
cell: 'DatetimeFieldCell', | ||
view: 'DatetimeFieldView', | ||
filter: 'DatetimeFieldFilter' | ||
}; |
{ | ||
"name": "alaska-field-datetime", | ||
"version": "0.11.13", | ||
"version": "0.12.0", | ||
"description": "Alaska datetime field", | ||
@@ -9,10 +9,11 @@ "keywords": [ | ||
], | ||
"alaska": "field", | ||
"main": "index.js", | ||
"repository": "https://github.com/maichong/alaska/tree/master/packages/alaska-field-datetime", | ||
"repository": "https://github.com/maichong/alaska/tree/master/src/alaska-field-datetime", | ||
"author": "Liang <liang@maichong.it> (https://github.com/liangxingchen)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"moment": "^2.18.1", | ||
"react-datetime": "^2.8.10" | ||
"moment": "^2.19.2", | ||
"react-datetime": "^2.11.0" | ||
} | ||
} |
@@ -8,5 +8,4 @@ // @flow | ||
export default class DatetimeFieldCell extends React.Component { | ||
shouldComponentUpdate(props: Object) { | ||
export default class DatetimeFieldCell extends React.Component<Alaska$view$Field$Cell$Props> { | ||
shouldComponentUpdate(props: Alaska$view$Field$Cell$Props) { | ||
return props.value != this.props.value; | ||
@@ -13,0 +12,0 @@ } |
@@ -8,4 +8,10 @@ // @flow | ||
export default class DatetimeFieldFilter extends React.Component { | ||
type State = { | ||
mode: 1 | 2 | 3 | 4, | ||
value1: moment, | ||
value2: moment, | ||
error: boolean | ||
}; | ||
export default class DatetimeFieldFilter extends React.Component<Alaska$view$Field$Filter$Props, State> { | ||
static contextTypes = { | ||
@@ -15,17 +21,2 @@ t: PropTypes.func, | ||
props: { | ||
className: string, | ||
value: any, | ||
field: Object, | ||
onChange: Function, | ||
onClose: Function, | ||
}; | ||
state: { | ||
mode:1|2|3|4; | ||
value1:moment; | ||
value2:moment; | ||
error:boolean; | ||
}; | ||
handleMode1: () => void; | ||
@@ -36,3 +27,3 @@ handleMode2: () => void; | ||
constructor(props: Object) { | ||
constructor(props: Alaska$view$Field$Filter$Props) { | ||
super(props); | ||
@@ -80,3 +71,3 @@ let value = props.value || {}; | ||
handleMode(mode: 1|2|3|4) { | ||
handleMode(mode: 1 | 2 | 3 | 4) { | ||
this.setState({ mode }, () => this.handleBlur()); | ||
@@ -121,5 +112,7 @@ } | ||
render() { | ||
const t = this.context.t; | ||
const { t } = this.context; | ||
let { className, field, onClose } = this.props; | ||
const { mode, value1, value2, error } = this.state; | ||
const { | ||
mode, value1, value2, error | ||
} = this.state; | ||
const buttonClassName = 'btn btn-default'; | ||
@@ -147,15 +140,19 @@ const buttonClassNameActive = buttonClassName + ' btn-success'; | ||
onClick={this.handleMode1} | ||
>{t('equal')}</a> | ||
>{t('equal')} | ||
</a> | ||
<a | ||
className={mode === 2 ? buttonClassNameActive : buttonClassName} | ||
onClick={this.handleMode2} | ||
>{t('greater')}</a> | ||
>{t('greater')} | ||
</a> | ||
<a | ||
className={mode === 3 ? buttonClassNameActive : buttonClassName} | ||
onClick={this.handleMode3} | ||
>{t('lesser')}</a> | ||
>{t('lesser')} | ||
</a> | ||
<a | ||
className={mode === 4 ? buttonClassNameActive : buttonClassName} | ||
onClick={this.handleMode4} | ||
>{t('between')}</a> | ||
>{t('between')} | ||
</a> | ||
</div> | ||
@@ -162,0 +159,0 @@ <div className="form-group"> |
@@ -8,7 +8,4 @@ // @flow | ||
import moment from 'moment'; | ||
// $Flow | ||
import 'moment/locale/zh-cn'; | ||
export default class DatetimeFieldView extends React.Component { | ||
export default class DatetimeFieldView extends React.Component<Alaska$view$Field$View$Props> { | ||
static contextTypes = { | ||
@@ -18,24 +15,2 @@ settings: PropTypes.object | ||
props: { | ||
className: string, | ||
model: Object, | ||
field: Object, | ||
data: Object, | ||
errorText: string, | ||
disabled: boolean, | ||
value: string, | ||
onChange: Function, | ||
}; | ||
state: { | ||
value: Object; | ||
}; | ||
constructor(props: Object) { | ||
super(props); | ||
this.state = { | ||
value: moment(props.value) | ||
}; | ||
} | ||
componentWillMount() { | ||
@@ -45,9 +20,10 @@ moment.locale(this.context.settings.locale); | ||
shouldComponentUpdate(props: Object, state: Object) { | ||
return !shallowEqualWithout(props, this.props, 'data', 'onChange', 'model') | ||
|| !shallowEqualWithout(state, this.state); | ||
shouldComponentUpdate(props: Alaska$view$Field$View$Props) { | ||
return !shallowEqualWithout(props, this.props, 'record', 'onChange', 'model'); | ||
} | ||
render() { | ||
let { className, value, field, disabled, errorText, onChange } = this.props; | ||
let { | ||
className, value, field, disabled, errorText, onChange | ||
} = this.props; | ||
let valueString: string = ''; | ||
@@ -57,3 +33,3 @@ if (field.format && value) { | ||
} | ||
let help = field.help; | ||
let { help } = field; | ||
className += ' date-field'; | ||
@@ -72,6 +48,8 @@ if (errorText) { | ||
inputElement = <DateTime | ||
value={valueString||value} | ||
value={valueString || value} | ||
dateFormat={field.dateFormat} | ||
timeFormat={field.timeFormat} | ||
onChange={(value)=>{onChange(value.format())}} | ||
onChange={(v) => { | ||
onChange(v.format()); | ||
}} | ||
/>; | ||
@@ -78,0 +56,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10394
335
Updatedmoment@^2.19.2
Updatedreact-datetime@^2.11.0