Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up fix datepicker #3901

Merged
merged 5 commits into from
May 24, 2018
Merged
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
2 changes: 1 addition & 1 deletion contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
</div>
</div>
<ngeo-modal ng-model="mainCtrl.modalShareShown">
<gmf-share gmf-share-email="true"></gmf-share>
<gmf-share ng-if="mainCtrl.modalShareShown" gmf-share-email="true"></gmf-share>
</ngeo-modal>
<ngeo-modal
ngeo-modal-closable="false"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"karma": "2.0.2",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.2",
"karma-coverage-istanbul-reporter": "1.4.3",
"karma-coverage-istanbul-reporter": "2.0.1",
"karma-jasmine": "1.1.1",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "3.0.0",
Expand Down
25 changes: 11 additions & 14 deletions src/filter/ruleComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ exports.RuleController_ = class {
*/
this.timeRangeMode = {
widget: 'datepicker',
maxValue: this.createDate_(),
minValue: this.createWeekAgoDate_(),
maxDefValue: null,
minDefValue: null,
maxValue: null,
minValue: null,
maxDefValue: this.createDate_(),
minDefValue: this.createWeekAgoDate_(),
mode: 'range',
interval: [0, 1, 0, 0]
};
Expand All @@ -244,10 +244,10 @@ exports.RuleController_ = class {
*/
this.timeValueMode = {
widget: 'datepicker',
maxValue: this.createDate_(),
minValue: this.createDate_(),
maxDefValue: null,
minDefValue: null,
maxValue: null,
minValue: null,
maxDefValue: this.createDate_(),
minDefValue: this.createDate_(),
mode: 'value',
interval: [0, 1, 0, 0]
};
Expand Down Expand Up @@ -424,24 +424,21 @@ exports.RuleController_ = class {
this.unlisteners_.push(this.scope_.$watch(
() => this.clone.getExpression(),
(newVal) => {
const value = newVal === null ? this.createDate_() : newVal;
this.timeValueMode.minValue = value;
this.timeValueMode.minValue = newVal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that is this code for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not idea.
But since we now handle the null value correctly I suppose the ternary operation can be removed.

}
));
// Watch 'lowerBoundary'
this.unlisteners_.push(this.scope_.$watch(
() => this.clone.lowerBoundary,
(newVal) => {
const value = newVal === null ? this.createWeekAgoDate_() : newVal;
this.timeRangeMode.minValue = value;
this.timeRangeMode.minValue = newVal;
}
));
// Watch 'upperBoundary'
this.unlisteners_.push(this.scope_.$watch(
() => this.clone.upperBoundary,
(newVal) => {
const value = newVal === null ? this.createDate_() : newVal;
this.timeRangeMode.maxValue = value;
this.timeRangeMode.maxValue = newVal;
}
));
} else if (this.clone.type === ngeoFormatAttributeType.GEOMETRY) {
Expand Down
35 changes: 25 additions & 10 deletions src/misc/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
*/
const exports = function() {};

/**
* @param {number|string|null} value The value
* @param {Date} defaultValue The default value
* @return {Date} the date
*/
exports.prototype.createDate = function(value, defaultValue = null) {
return value !== null ? new Date(value) : defaultValue;
};

/**
* @param {Date} date The date
* @param {number|null=} defaultValue The default value
* @return {number|null} the time
*/
exports.prototype.getTime = function(date, defaultValue = null) {
return date ? date.getTime() : defaultValue;
};

/**
* Get options regarding the time property of a node;
Expand All @@ -25,21 +42,19 @@ const exports = function() {};
*/
exports.prototype.getOptions = function(time) {

const minDate = new Date(time.minValue);
const maxDate = new Date(time.maxValue);
const minDate = this.createDate(time.minValue);
const maxDate = this.createDate(time.maxValue);

const minDefaultDate = (time.minDefValue) ?
new Date(time.minDefValue) : minDate;
const maxDefaultDate = (time.maxDefValue) ?
new Date(time.maxDefValue) : maxDate;
const minDefaultDate = this.createDate(time.minDefValue, minDate);
const maxDefaultDate = this.createDate(time.maxDefValue, maxDate);

const defaultValues = (time.mode === 'range') ?
[minDefaultDate.getTime(), maxDefaultDate.getTime()] :
minDefaultDate.getTime();
[this.getTime(minDefaultDate), this.getTime(maxDefaultDate)] :
this.getTime(minDefaultDate);

return {
minDate: minDate.getTime(),
maxDate: maxDate.getTime(),
minDate: this.getTime(minDate),
maxDate: this.getTime(maxDate),
values: defaultValues
};
};
Expand Down
14 changes: 7 additions & 7 deletions src/misc/datepickerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ exports.Controller_ = function($scope, $injector,
if (angular.isDate(sDate) && (!this.isModeRange || angular.isDate(eDate))) {
this.onDateSelected({
time: {
start: sDate.getTime(),
end: eDate ? eDate.getTime() : null
start: this.ngeoTime_.getTime(sDate),
end: this.ngeoTime_.getTime(eDate)
}
});
}
Expand All @@ -226,17 +226,17 @@ exports.Controller_ = function($scope, $injector,
exports.Controller_.prototype.init = function() {
//fetch the initial options for the component
const initialOptions_ = this.ngeoTime_.getOptions(this.time);
this.initialMinDate = new Date(initialOptions_.minDate);
this.initialMaxDate = new Date(initialOptions_.maxDate);
this.initialMinDate = this.ngeoTime_.createDate(initialOptions_.minDate);
this.initialMaxDate = this.ngeoTime_.createDate(initialOptions_.maxDate);
this.isModeRange = this.time.mode === 'range';

if (this.isModeRange) {
googAsserts.assertArray(initialOptions_.values);
this.sdate = new Date(initialOptions_.values[0]);
this.edate = new Date(initialOptions_.values[1]);
this.sdate = this.ngeoTime_.createDate(initialOptions_.values[0]);
this.edate = this.ngeoTime_.createDate(initialOptions_.values[1]);
} else {
googAsserts.assertNumber(initialOptions_.values);
this.sdate = new Date(initialOptions_.values);
this.sdate = this.ngeoTime_.createDate(initialOptions_.values);
}
};

Expand Down