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

Fix the date field in the attribute editor #3358

Merged
merged 1 commit into from
Jan 11, 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
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ globals:
inject: false
jsts: false
moment: false
DateFormatter: false
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
.*.swp
.transifexrc
/.transifexrc
/package-lock.json
/.build
/node_modules
/dist
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ GMF_APPS_LIBS_JS_FILES += \
node_modules/moment/moment.js \
node_modules/url-polyfill/url-polyfill.js \
third-party/jquery-ui/jquery-ui.js \
node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js \
$(CLOSURE_LIBRARY_PATH)/closure/goog/transpile.js
else
GMF_APPS_LIBS_JS_FILES += \
Expand All @@ -71,7 +72,8 @@ GMF_APPS_LIBS_JS_FILES += \
node_modules/jsts/dist/jsts.min.js \
node_modules/moment/min/moment.min.js \
node_modules/url-polyfill/url-polyfill.min.js \
third-party/jquery-ui/jquery-ui.min.js
third-party/jquery-ui/jquery-ui.min.js \
node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js
endif

BUILD_EXAMPLES_CHECK_TIMESTAMP_FILES := $(patsubst examples/%.html,.build/%.check.timestamp,$(EXAMPLES_HTML_FILES)) \
Expand Down
2 changes: 2 additions & 0 deletions buildtools/mako_build.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ _ngeo_folder = '' if ngeo_folder is UNDEFINED else ngeo_folder
"${_ngeo_folder}externs/jsts.js",
"${_ngeo_folder}externs/moment.js",
"${_ngeo_folder}externs/geo-admin-api.js",
"${_ngeo_folder}externs/php-date-formatter.js",
"${_ngeo_folder}externs/datetimepicker.js",
".build/externs/angular-1.6.js",
".build/externs/angular-1.6-q_templated.js",
".build/externs/angular-1.6-http-promise_templated.js",
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/desktop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyCYnqxEQA5sz13sWSgMr97ejzvUeGP8gz4"></script>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/desktop_alt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyCYnqxEQA5sz13sWSgMr97ejzvUeGP8gz4"></script>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/mobile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
</nav>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/mobile_alt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
</nav>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/oeedit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
</footer>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/oeview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
</footer>
<script src="../../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../../third-party/jquery-ui/jquery-ui.js"></script>
<script src="../../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.full.js"></script>
<script src="../../../../node_modules/angular/angular.js"></script>
<script src="../../../../node_modules/angular-animate/angular-animate.js"></script>
<script src="../../../../node_modules/angular-sanitize/angular-sanitize.js"></script>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/less/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import (inline) '../css/reset.css';
@import '../../../node_modules/bootstrap/less/bootstrap.less';
@import (inline) '../../../third-party/jquery-ui/jquery-ui.css';
@import (inline) '../../../node_modules/jquery-datetimepicker/build/jquery.datetimepicker.min.css';

@import 'vars.less';

Expand Down
72 changes: 70 additions & 2 deletions contribs/gmf/src/directives/editfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,38 @@ gmf.EditfeatureController.prototype.$onInit = function() {
* @export
*/
gmf.EditfeatureController.prototype.save = function() {
const feature = this.feature;
goog.asserts.assert(this.attributes);

const feature = this.feature.clone();
feature.setId(this.feature.getId());
const id = this.featureId;

this.pending = true;

const dateFormatter = new DateFormatter();
for (const attribute of this.attributes) {
if (attribute.format) {
if (this.feature.get(attribute.name)) {
const name = this.feature.get(attribute.name);
goog.asserts.assertString(name);
const value = dateFormatter.parseDate(name, attribute.format);
let jsonFormat = 'Y-m-d\\TH:i:s';
if (attribute.type === 'date') {
jsonFormat = 'Y-m-d';
} else if (attribute.type === 'time') {
jsonFormat = 'H:i:s';
} else if (attribute.type === 'datetime') {
// Time zone correction
value.setMinutes(value.getMinutes() + value.getTimezoneOffset());
}
feature.set(attribute.name, dateFormatter.formatDate(value, jsonFormat));
} else {
// Shouldn't be set to an empty string
feature.set(attribute.name, null);
}
}
}

const promise = id ?
this.gmfEditFeature_.updateFeature(
this.editableNode_.id,
Expand Down Expand Up @@ -716,12 +743,24 @@ gmf.EditfeatureController.prototype.handleEditFeature_ = function(resp) {


/**
* @param {Array.<ngeox.Attribute>} attributes Attributes.
* @param {!Array.<ngeox.Attribute>} attributes Attributes.
* @private
*/
gmf.EditfeatureController.prototype.setAttributes_ = function(attributes) {
// Set attributes
this.attributes = attributes;
for (const attribute of attributes) {
if (attribute.type == 'date') {
attribute.format = 'Y-m-d';
attribute.mask = '9999-19-39';
} else if (attribute.type == 'time') {
attribute.format = 'H:i';
attribute.mask = '29:59';
} else if (attribute.type == 'datetime') {
attribute.format = 'Y-m-d H:i';
attribute.mask = '9999-19-39 29:59';
}
}

// Get geom type from attributes and set
const geomAttr = ngeo.format.XSDAttribute.getGeometryAttribute(
Expand All @@ -738,9 +777,38 @@ gmf.EditfeatureController.prototype.setAttributes_ = function(attributes) {
* @private
*/
gmf.EditfeatureController.prototype.handleFeatureAdd_ = function(evt) {
this.feature = null;
this.timeout_(() => {
goog.asserts.assert(this.attributes);
const feature = evt.element;
goog.asserts.assertInstanceof(feature, ol.Feature);
const dateFormatter = new DateFormatter();
for (const attribute of this.attributes) {
if (attribute.format) {
if (feature.get(attribute.name)) {
let value;
if (attribute.type === 'datetime') {
value = new Date(feature.get(attribute.name));
// Time zone correction
value.setMinutes(value.getMinutes() - value.getTimezoneOffset());
} else {
let jsonFormat = '';
if (attribute.type === 'date') {
jsonFormat = 'Y-m-d';
} else if (attribute.type === 'time') {
jsonFormat = 'H:i:s';
}
const name = this.feature.get(attribute.name);
goog.asserts.assertString(name);
value = dateFormatter.parseDate(name, jsonFormat);
}
feature.set(attribute.name, dateFormatter.formatDate(value, attribute.format));
} else {
// Shouldn't be set to an empty string
feature.set(attribute.name, null);
}
}
}
this.feature = feature;
this.createActive = false;
if (!feature.getId()) {
Expand Down
11 changes: 11 additions & 0 deletions externs/datetimepicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param {Object.<string,*>} options
*/
jQuery.prototype.datetimepicker = function(options) {};

jQuery.datetimepicker = {};

/**
* @param {string} lang
*/
jQuery.datetimepicker.setLocale = function(lang) {};
18 changes: 18 additions & 0 deletions externs/php-date-formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @constructor
*/
var DateFormatter = function() {};

/**
* @param {!Date} date
* @param {string} format
* @return {string}
*/
DateFormatter.prototype.formatDate = function(date, format) {};

/**
* @param {string} date
* @param {string} format
* @return {!Date}
*/
DateFormatter.prototype.parseDate = function(date, format) {};
16 changes: 15 additions & 1 deletion options/ngeox.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,21 @@ ngeox.Attribute.prototype.type;


/**
* The options to use when creating a filter uwing the `ngeo.RuleHelper`
* The format used in the date, time and datetime type.
* @type {string|undefined}
*/
ngeox.Attribute.prototype.format;


/**
* The mask used in the date, time and datetime type.
* @type {string|undefined}
*/
ngeox.Attribute.prototype.mask;


/**
* The options to use when creating a filter using the `ngeo.RuleHelper`
* service.
*
* @typedef {{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"gaze": "1.1.2",
"jasmine-core": "2.7.0",
"jquery": "3.2.1",
"jquery-datetimepicker": "2.5.16",
"jsdoc": "3.5.5",
"jsdom": "9.12.0",
"jsts": "1.4.0",
Expand Down
26 changes: 4 additions & 22 deletions src/directives/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ goog.provide('ngeo.attributesComponent');
goog.require('ol.ObjectEventType');
goog.require('ngeo');
goog.require('ngeo.EventHelper');
/** @suppress {extraRequire} */
goog.require('ngeo.datetimepickerDirective');


/**
* Component used to render the attributes of a feature into a form.
Expand Down Expand Up @@ -42,15 +45,14 @@ ngeo.module.component('ngeoAttributes', ngeo.attributesComponent);
/**
* @param {!angular.Scope} $scope Angular scope.
* @param {!ngeo.EventHelper} ngeoEventHelper Ngeo event helper service
* @param {!angularGettext.Catalog} gettextCatalog service.
* @constructor
* @private
* @struct
* @ngInject
* @ngdoc controller
* @ngname ngeoAttributesController
*/
ngeo.AttributesController = function($scope, ngeoEventHelper, gettextCatalog) {
ngeo.AttributesController = function($scope, ngeoEventHelper) {

/**
* The list of attributes to create the form with.
Expand Down Expand Up @@ -93,23 +95,6 @@ ngeo.AttributesController = function($scope, ngeoEventHelper, gettextCatalog) {
*/
this.ngeoEventHelper_ = ngeoEventHelper;

/**
* The gettext catalog
* @type {!angularGettext.Catalog}
* @private
*/
this.gettextCatalog_ = gettextCatalog;

/**
* Datepicker options
* @type {Object}
* @export
*/
this.dateOptions = {
'changeMonth': true,
'changeYear': true
};

/**
* While changes happen from the form (from the template), they are applied
* to the feature inner properties. The 'propertychange' event registered
Expand Down Expand Up @@ -142,9 +127,6 @@ ngeo.AttributesController.prototype.$onInit = function() {
),
true
);

const lang = this.gettextCatalog_.getCurrentLanguage();
$['datepicker']['setDefaults']($['datepicker']['regional'][lang]);
};


Expand Down
Loading