← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16749: tracker capture - centralized date formatting to a service

 

------------------------------------------------------------
revno: 16749
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-18 16:53:56 +0200
message:
  tracker capture - centralized date formatting to a service
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-09-05 12:52:43 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-09-18 14:53:56 +0000
@@ -234,7 +234,7 @@
                 
                 if($scope.currentEvent.notes){
                     angular.forEach($scope.currentEvent.notes, function(note){
-                        note.storedDate = moment(note.storedDate).format('YYYY-MM-DD @ hh:mm A');
+                        note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
                     });
 
                     if($scope.currentEvent.notes.length > 0 ){
@@ -263,7 +263,7 @@
         if(!angular.isUndefined( $scope.currentEvent.notes)){
             $scope.currentEvent.notes = orderByFilter($scope.currentEvent.notes, '-storedDate');            
             angular.forEach($scope.currentEvent.notes, function(note){
-                note.storedDate = moment(note.storedDate).format('DD.MM.YYYY @ hh:mm A');
+                note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
             });
         }
 
@@ -383,9 +383,8 @@
             return false;
         }
         else{
-            var rawDate = $filter('date')($scope.currentEvent.eventDate, 'yyyy-MM-dd'); 
-            var convertedDate = moment($scope.currentEvent.eventDate, 'YYYY-MM-DD')._d;
-            convertedDate = $filter('date')(convertedDate, 'yyyy-MM-dd'); 
+            var rawDate = angular.copy($scope.currentEvent.eventDate);
+            var convertedDate = DateUtils.format($scope.currentEvent.eventDate);
 
             if(rawDate !== convertedDate){
                 $scope.invalidDate = true;
@@ -430,9 +429,8 @@
             return false;
         }
         else{
-            var rawDate = $filter('date')($scope.currentEvent.dueDate, 'yyyy-MM-dd'); 
-            var convertedDate = moment($scope.currentEvent.dueDate, 'YYYY-MM-DD')._d;
-            convertedDate = $filter('date')(convertedDate, 'yyyy-MM-dd'); 
+            var rawDate = angular.copy($scope.currentEvent.dueDate);
+            var convertedDate = DateUtils.format($scope.currentEvent.dueDate);           
 
             if(rawDate !== convertedDate){
                 $scope.invalidDate = true;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-09-17 14:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-09-18 14:53:56 +0000
@@ -83,11 +83,11 @@
                 
                 var incidentDate = $scope.selectedEnrollment ? $scope.selectedEnrollment.dateOfIncident : new Date();
 
-                angular.forEach($scope.selectedProgram.programStages, function(stage){                
-                    stage.dueDate = moment(moment(incidentDate).add('d', stage.minDaysFromStart), 'YYYY-MM-DD')._d;
-                    stage.dueDate = Date.parse(stage.dueDate);
-                    stage.dueDate = DateUtils.format(stage.dueDate);//$filter('date')(stage.dueDate, 'yyyy-MM-dd');
-                    $scope.programStages.push(stage);               
+                angular.forEach($scope.selectedProgram.programStages, function(stage){                    
+                    
+                    stage.dueDate = DateUtils.format(incidentDate);
+                    stage.dueDate = moment(moment(incidentDate).add('d', stage.minDaysFromStart))._d;
+                    stage.dueDate = DateUtils.format(stage.dueDate);
                 });
             }
             else{//prepare for possible enrollment

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js	2014-09-08 10:13:18 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/notes/notes-controller.js	2014-09-18 14:53:56 +0000
@@ -34,7 +34,7 @@
                 if(!angular.isUndefined( $scope.selectedEnrollment.notes)){
                     $scope.selectedEnrollment.notes = orderByFilter($scope.selectedEnrollment.notes, '-storedDate');            
                     angular.forEach($scope.selectedEnrollment.notes, function(note){
-                        note.storedDate = moment(note.storedDate).format('YYYY-MM-DD @ hh:mm A');
+                        note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
                     });
                 }
             });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js	2014-08-29 14:15:09 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/program-summary-controller.js	2014-09-18 14:53:56 +0000
@@ -151,6 +151,7 @@
     function($scope, 
             $modalInstance,
             orderByFilter,
+            DateUtils,
             ProgramStageFactory,
             dhis2Event,
             selectedTei,
@@ -168,7 +169,7 @@
     if(!angular.isUndefined( $scope.currentEvent.notes)){
         $scope.currentEvent.notes = orderByFilter($scope.currentEvent.notes, '-storedDate');            
         angular.forEach($scope.currentEvent.notes, function(note){
-            note.storedDate = moment(note.storedDate).format('YYYY-MM-DD @ hh:mm A');
+            note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
         });
     }
     

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js	2014-08-27 11:18:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/tei-report-controller.js	2014-09-18 14:53:56 +0000
@@ -1,7 +1,6 @@
 //conroller for tei report
 trackerCapture.controller('TeiReportController',
         function($scope,
-                $filter,
                 CurrentSelection,
                 storage,
                 DateUtils,
@@ -105,9 +104,7 @@
         $scope.selectedReport = $scope.report[pr.id];
         
         //today as report date
-        $scope.today = moment();
-        $scope.today = Date.parse($scope.today);
-        $scope.today = $filter('date')($scope.today, 'yyyy-MM-dd');
+        $scope.today = DateUtils.format(moment());
 
         //process tei attributes, this is to have consistent display so that the tei 
         //contains program attributes whether it has value or not
@@ -138,7 +135,7 @@
             //format report data values
             angular.forEach($scope.selectedReport.enrollments[enr], function(ev){
                 angular.forEach(ev.notes, function(note){
-                    note.storedDate = moment(note.storedDate).format('DD.MM.YYYY @ hh:mm A');
+                    note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
                 }); 
 
                 if(ev.dataValues){
@@ -155,7 +152,7 @@
                 enrollment.dateOfEnrollment = DateUtils.format(enrollment.dateOfEnrollment);
                 enrollment.dateOfIncident = DateUtils.format(enrollment.dateOfIncident);            
                 angular.forEach(enrollment.notes, function(note){
-                    note.storedDate = moment(note.storedDate).format('DD.MM.YYYY @ hh:mm A');
+                    note.storedDate = DateUtils.formatToHrsMins(note.storedDate);
                 });            
                 $scope.enrollments.push(enrollment);               
             });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-09-18 13:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2014-09-18 14:53:56 +0000
@@ -5,14 +5,12 @@
                 $translate,
                 orderByFilter,
                 DateUtils,                
-                TEIService,
                 Paginator,
                 EventReportService,
                 TEIGridService,
                 TranslationService,
                 AttributesFactory,
                 ProgramFactory,
-                DHIS2EventFactory,
                 storage) {
 
     TranslationService.translate();

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-09-18 13:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-09-18 14:53:56 +0000
@@ -1199,17 +1199,18 @@
             dateValue = Date.parse(dateValue);
             dateValue = $filter('date')(dateValue, 'yyyy-MM-dd');
             return dateValue;
+        },
+        formatToHrsMins: function(dateValue) {            
+            return moment(dateValue).format('YYYY-MM-DD @ hh:mm A');
         }
     };            
 })
 
-.service('EventUtils', function($filter, OrgUnitService){
+.service('EventUtils', function($filter, DateUtils, OrgUnitService){
     return {
         createDummyEvent: function(programStage, orgUnit, enrollment){
             
-            var today = moment();
-            today = Date.parse(today);
-            today = $filter('date')(today, 'yyyy-MM-dd');
+            var today = DateUtils.format(moment());
     
             var dueDate = this.getEventDueDate(programStage, enrollment);
             var dummyEvent = {programStage: programStage.id, 
@@ -1227,9 +1228,7 @@
             return dummyEvent;        
         },
         getEventStatusColor: function(dhis2Event){    
-            var today = moment();
-            today = Date.parse(today);
-            today = $filter('date')(today, 'yyyy-MM-dd');
+            var today = DateUtils.format(moment());
             var eventDate = today;
             
             if(dhis2Event.eventDate){
@@ -1250,9 +1249,9 @@
             }            
         },
         getEventDueDate: function(programStage, enrollment){
-            var dueDate = moment(moment(enrollment.dateOfIncident).add('d', programStage.minDaysFromStart), 'YYYY-MM-DD')._d;
-            dueDate = Date.parse(dueDate);
-            dueDate = $filter('date')(dueDate, 'yyyy-MM-dd');
+            var dueDate = DateUtils.format(enrollment.dateOfIncident);
+            dueDate = moment(dueDate).add('d', programStage.minDaysFromStart)._d;
+            dueDate = DateUtils.format(dueDate);
             return dueDate;
         },
         getEventOrgUnitName: function(orgUnitId){