diff --git a/admin/app/controllers/fdd/emailmessage/emailmessageoption.controller.js b/admin/app/controllers/fdd/emailmessage/emailmessageoption.controller.js index 06195354..970be75a 100644 --- a/admin/app/controllers/fdd/emailmessage/emailmessageoption.controller.js +++ b/admin/app/controllers/fdd/emailmessage/emailmessageoption.controller.js @@ -11,14 +11,14 @@ app.controller('EmailMessageOptionController', function( endDate: moment() }; $scope.dtOptions = { - timePicker: false, + timePicker: true, timePicker24Hour: true, timePickerIncrement: 1, timePickerSeconds: true, startView:2, autoApply: true, locale:{ - format: 'YYYY-MM-DD', + format: 'YYYY-MM-DDTHH:mm:ss', applyLabel: "OK", cancelLabel: "Cancel", }, @@ -30,11 +30,12 @@ app.controller('EmailMessageOptionController', function( }; $scope.execute = function() { - var datestart, dateend; + var startdatetime, enddatetime; var query = { - datestart: $scope.daterange.startDate.format().slice(0, 10), - dateend: $scope.daterange.endDate.format().slice(0, 10) + startdatetime: $scope.daterange.startDate.format().slice(0, 19), + enddatetime: $scope.daterange.endDate.format().slice(0, 19) }; + $scope.$emit('handleEmitEmailMessageOptionChanged', { load: true, period:$scope.currentPeriod diff --git a/admin/app/services/fdd/emailmessageanalysis.service.js b/admin/app/services/fdd/emailmessageanalysis.service.js index be596a7a..be0a6ab9 100644 --- a/admin/app/services/fdd/emailmessageanalysis.service.js +++ b/admin/app/services/fdd/emailmessageanalysis.service.js @@ -3,7 +3,7 @@ app.factory('EmailMessageAnalysisService', function($http) { return { getAnalysisResult: function(query, headers, callback) { - $http.get(getAPI()+"emailmessages"+"/from/"+query.datestart+"/to/"+query.dateend, {headers}) + $http.get(getAPI()+"emailmessages?" + 'startdatetime=' + query.startdatetime + '&enddatetime=' + query.enddatetime, {headers}) .then(function (response) { callback(response); }, function (response) { diff --git a/admin/views/fdd/emailmessage.html b/admin/views/fdd/emailmessage.html index d1ce6262..a052bfb0 100644 --- a/admin/views/fdd/emailmessage.html +++ b/admin/views/fdd/emailmessage.html @@ -4,8 +4,8 @@
diff --git a/myems-api/app.py b/myems-api/app.py index a6bf2b8e..4e81c2f0 100644 --- a/myems-api/app.py +++ b/myems-api/app.py @@ -170,7 +170,7 @@ api.add_route('/distributionsystems/{id_}', api.add_route('/distributionsystems/{id_}/distributioncircuits', distributionsystem.DistributionSystemDistributionCircuitCollection()) -api.add_route('/emailmessages/from/{startdate}/to/{enddate}', +api.add_route('/emailmessages', emailmessage.EmailMessageCollection()) api.add_route('/emailmessages/{id_}', emailmessage.EmailMessageItem()) diff --git a/myems-api/core/emailmessage.py b/myems-api/core/emailmessage.py index eab41ee5..050dbfbb 100644 --- a/myems-api/core/emailmessage.py +++ b/myems-api/core/emailmessage.py @@ -13,35 +13,45 @@ class EmailMessageCollection: pass @staticmethod - def on_options(req, resp, startdate, enddate): + def on_options(req, resp): resp.status = falcon.HTTP_200 @staticmethod - def on_get(req, resp, startdate, enddate): + def on_get(req, resp): access_control(req) - try: - start_datetime_local = datetime.strptime(startdate, '%Y-%m-%d') - except Exception: - raise falcon.HTTPError(falcon.HTTP_400, - title='API.BAD_REQUEST', - description='API.INVALID_START_DATE_FORMAT') - try: - end_datetime_local = datetime.strptime(enddate, '%Y-%m-%d') - except Exception: - raise falcon.HTTPError(falcon.HTTP_400, - title='API.BAD_REQUEST', - description='API.INVALID_END_DATE_FORMAT') + print(req.params) + start_datetime_local = req.params.get('startdatetime') + end_datetime_local = req.params.get('enddatetime') timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - start_datetime_utc = start_datetime_local.replace(tzinfo=timezone.utc) - start_datetime_utc -= timedelta(minutes=timezone_offset) + if start_datetime_local is None: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description="API.INVALID_START_DATETIME_FORMAT") + else: + start_datetime_local = str.strip(start_datetime_local) + try: + start_datetime_utc = datetime.strptime(start_datetime_local, + '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ + timedelta(minutes=timezone_offset) + except ValueError: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description="API.INVALID_START_DATETIME_FORMAT") - end_datetime_utc = end_datetime_local.replace(tzinfo=timezone.utc) - end_datetime_utc -= timedelta(minutes=timezone_offset) - end_datetime_utc += timedelta(days=1) + if end_datetime_local is None: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description="API.INVALID_END_DATETIME_FORMAT") + else: + end_datetime_local = str.strip(end_datetime_local) + try: + end_datetime_utc = datetime.strptime(end_datetime_local, + '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ + timedelta(minutes=timezone_offset) + except ValueError: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description="API.INVALID_END_DATETIME_FORMAT") if start_datetime_utc >= end_datetime_utc: raise falcon.HTTPError(falcon.HTTP_400,