← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15903: tracker capture - UI for new event creation

 

------------------------------------------------------------
revno: 15903
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Mon 2014-06-30 09:19:37 +0200
message:
  tracker capture - UI for new event creation
modified:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json


--
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-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-06-27 15:42:43 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-06-30 07:19:37 +0000
@@ -22,6 +22,7 @@
     $scope.$on('dashboard', function(event, args) {  
         $scope.showDataEntryDiv = false;
         $scope.showEventCreationDiv = false;
+        $scope.showDummyEventDiv = false;        
         $scope.currentDummyEvent = null;
         $scope.currentEvent = null;
             
@@ -62,11 +63,15 @@
                     //create dummy events for the selected enrollment                        
                     angular.forEach($scope.selectedProgram.programStages, function(programStage){                                                        
                         var dummyEvent = EventUtils.createDummyEvent(programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
-                        $scope.dummyEvents.push(dummyEvent);                            
+                        $scope.dummyEvents.push(dummyEvent);                         
                     });
 
                     $scope.dummyEvents = orderByFilter($scope.dummyEvents, '-eventDate');
-                    $scope.dummyEvents.reverse();                        
+                    //$scope.dummyEvents.reverse();            
+                    
+                    if($scope.dummyEvents){
+                        $scope.showEventCreationDiv = true;
+                    }
                 }
             }
             else{
@@ -110,11 +115,54 @@
                 });
 
                 $scope.dhis2Events = orderByFilter($scope.dhis2Events, '-eventDate');
-                $scope.dhis2Events.reverse();                    
+                $scope.dhis2Events.reverse();   
+                
+                $scope.dummyEvents = $scope.checkForEventCreation($scope.dhis2Events, $scope.selectedProgram);
             }
         });          
     };
     
+    $scope.checkForEventCreation = function(availableEvents, program){
+        
+        var dummyEvents = [];
+        
+        for(var i=0; i<program.programStages.length; i++){
+            var stageHasEvent = false;
+            for(var j=0; j<availableEvents.length && !program.programStages[i].repeatable && !stageHasEvent; j++){
+                if(program.programStages[i].id === availableEvents[j].stage){
+                    stageHasEvent = true;
+                }
+            }
+            
+            if(!stageHasEvent){
+                $scope.allowEventCreation = true;
+                var dummyEvent = EventUtils.createDummyEvent(program.programStages[i], $scope.selectedOrgUnit, $scope.selectedEnrollment);
+                dummyEvents.push(dummyEvent);
+            }
+        }        
+        return dummyEvents;
+    };
+    
+    $scope.showEventCreation = function(){
+        $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
+    };
+    
+    $scope.showDummyEventCreation = function(dummyEvent){
+        
+        if(dummyEvent){    
+            
+            if($scope.currentDummyEvent == dummyEvent){ 
+                //clicked on the same stage, do toggling
+                $scope.currentDummyEvent = null;
+                $scope.showDummyEventDiv = !$scope.showDummyEventDiv;                
+            }
+            else{
+                $scope.currentDummyEvent = dummyEvent;
+                $scope.showDummyEventDiv = !$scope.showDummyEventDiv;
+            }   
+        }
+    };   
+    
     $scope.createEvent = function(){
         //check for form validity
         $scope.eventCreationForm.submitted = true;        
@@ -151,22 +199,6 @@
                 $scope.showDataEntry(newEvent);
             }
         });
-    };
-    
-    $scope.showEventCreation = function(dummyEvent){
-        
-        if(dummyEvent){    
-            
-            if($scope.currentDummyEvent == dummyEvent){ 
-                //clicked on the same stage, do toggling
-                $scope.currentDummyEvent = null;
-                $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
-            }
-            else{
-                $scope.currentDummyEvent = dummyEvent;
-                $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
-            }   
-        }
     };   
     
     $scope.showDataEntry = function(event){
@@ -319,6 +351,6 @@
     
     $scope.closeEventCreation = function(){
         $scope.currentDummyEvent = null;
-        $scope.showEventCreationDiv = !$scope.showEventCreationDiv;
+        $scope.showDummyEventDiv = !$scope.showDummyEventDiv;
     };
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-06-30 05:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2014-06-30 07:19:37 +0000
@@ -1,8 +1,174 @@
 <div class="panel panel-primary" ng-controller="DataEntryController">
     <div class="panel-heading">
+        <span ng-show="!showEventCreationDiv">{{dataentryWidget.title| translate}}</span>
+        <span ng-show="showEventCreationDiv">
+            <a href ng-click="showEventCreation()" title="{{'create_new_event'| translate}}"><span class="bold">{{dataentryWidget.title| translate}}</span></a>
+        </span>
+        <span class="nav-pills" ng-show="allowEventCreation">
+            | <a href ng-click="showEventCreation()" title="{{'create_new_event'| translate}}"><span class="bold">{{'create_new_event'| translate}}</span></a>
+        </span>
+        <span class="pull-right">
+            <a class="small-horizonal-spacing" href ng-click="expandCollapse(dataentryWidget)">
+                <span ng-show="dataentryWidget.expand"><i class="fa fa-chevron-up" title="{{'collapse'| translate}}"></i></span>
+                <span ng-show="!dataentryWidget.expand"><i class="fa fa-chevron-down" title="{{'expand'| translate}}"></i></span>
+            </a>
+            <a class="small-horizonal-spacing" href ng-click="removeWidget(dataentryWidget)" title="{{'remove'| translate}}"><i class="fa fa-times-circle"></i></a>            
+        </span>        
+    </div>
+
+    <div ng-show="dataentryWidget.expand" class="panel-body dashboard-widget-container">
+        <div ng-show="dhis2Events && !showEventCreationDiv">            
+            <table class="table-borderless">
+                <tbody>
+                    <tr>
+                        <td class="inline-block" ng-repeat="dhis2Event in dhis2Events">
+                            <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
+                            <span class="stage-container"                                                     
+                                  ng-class="{'current-stage': currentEvent && currentEvent.event == dhis2Event.event, '{{dhis2Event.statusColor}}': true}"                                                      
+                                  ng-click="showDataEntry(dhis2Event)">
+                                {{dhis2Event.name}}<br/>
+                                {{dhis2Event.eventDate}}         
+                            </span>
+                            <i class="fa fa-arrow-right" ng-show="$index < dhis2Events.length - 1"></i>
+                        </td>                        
+                    </tr>
+                </tbody>                
+            </table>
+        </div>     
+        <div ng-show="!dhis2Events && selectedEnrollment" class="alert alert-warning">{{'no_event_is_yet_created'| translate}}</div>
+        <div ng-show="dhis2Events && showEventCreationDiv" class="alert alert-warning">{{'event_creation'| translate}}</div>
+        <div ng-show="dummyEvents && showEventCreationDiv">            
+            <table class="table-borderless">
+                <tbody>
+                    <tr>
+                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents">
+                            <span class="block align-center">{{dhis2Event.orgUnitName}}</span>                                              
+                            <span class="stage-container"                                                     
+                                  ng-class="{'current-stage': currentDummyEvent && currentDummyEvent.programStage == dummyEvent.programStage, '{{dummyEvent.statusColor}}': true}"                                                      
+                                  ng-click="showDummyEventCreation(dummyEvent)">
+                                {{dummyEvent.name}}<br/>
+                                {{dummyEvent.dueDate}}         
+                            </span>
+                            <i class="fa fa-arrow-right" ng-show="$index < dummyEvents.length - 1"></i>
+                        </td>                        
+                    </tr>                        
+                </tbody>                
+            </table>
+            <form name="eventCreationForm" novalidate ng-show="currentDummyEvent">
+                <div class="row">
+                    <div class="col-md-6">
+                        {{currentDummyEvent.reportDateDescription}}
+                        <input type="text" name="eventDate" class="form-control" ng-date ng-model="currentDummyEvent.eventDate" ng-required="true"/>
+                        <span ng-show="eventCreationForm.submitted && eventCreationForm.eventDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                    </div>
+                    <div class="col-md-6">
+                        {{'due_date'| translate}}
+                        <input type="text" name="dueDate" class="form-control" ng-date ng-model="currentDummyEvent.dueDate" />
+                        <span ng-show="eventCreationForm.submitted && eventCreationForm.dueDate.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                    </div>                        
+                </div>
+                <div class="row vertical-spacing">   
+                    <div class="col-md-6">
+                        <button type="button" class="btn btn-primary" ng-click="createEvent()">{{'create'| translate}}</button>
+                        <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="closeEventCreation()">{{'cancel'| translate}}</button>
+                    </div>                        
+                </div>
+            </form>            
+        </div>        
+        
+        <div ng-show="currentEvent && !showEventCreationDiv">
+            <hr>
+            <form name="dataEntryOuterForm" novalidate>                
+                <table class="table-borderless table-striped" ng-if='currentEvent'>
+                    <thead>
+                        <tr class="col-md-12">
+                            <th class="col-md-5">
+                                {{'data_element'| translate}}
+                            </th>
+                            <th class="col-md-5 align-center">
+                                {{'value'| translate}}
+                            </th>
+                            <th class="col-md-2 align-center" ng-if="allowProvidedElsewhereExists">
+                                {{'provided_elsewhere'| translate}}
+                            </th>
+                        </tr>
+                    </thead>
+                    <tr class="col-md-12" ng-repeat="prStDe in currentStage.programStageDataElements">
+                        <td class="col-md-5">
+                            {{prStDe.dataElement.name}}
+                        </td>
+                        <td class="col-md-5">
+                            <ng-form name="dataEntryInnerForm">
+                                <div ng-switch="prStDe.dataElement.type">
+                                    <div ng-switch-when="int">
+                                        <input type="number"
+                                               ng-class='getClass(prStDe.dataElement.id)'
+                                               ng-model="currentEvent[prStDe.dataElement.id]" 
+                                               ng-required={{prStDe.compulsory}}
+                                               ng-blur="saveDatavalue(prStDe)" 
+                                               name="foo"/>
+                                        <span ng-show="dataEntryOuterForm.submitted && dataEntryInnerForm.foo.$invalid" style="color:red;font-size:12px">{{'number_required' | translate}}</span>
+                                    </div>
+                                    <div ng-switch-when="string">                                        
+                                        <input type="text"
+                                               ng-class='getClass(prStDe.dataElement.id)'
+                                               ng-model="currentEvent[prStDe.dataElement.id]" 
+                                               ng-required={{prStDe.compulsory}} 
+                                               typeahead="option for option in prStDe.dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
+                                               typeahead-open-on-focus    
+                                               ng-blur="saveDatavalue(prStDe)" 
+                                               name="foo"/>
+                                    </div>
+                                    <div ng-switch-when="bool">
+                                        <select ng-class='getClass(prStDe.dataElement.id)'
+                                                ng-model="currentEvent[prStDe.dataElement.id]" 
+                                                ng-required={{prStDe.compulsory}} 
+                                                ng-change="saveDatavalue(prStDe)" 
+                                                name="foo">
+                                            <option value="">{{'please_select'| translate}}</option>                        
+                                            <option value="0">{{'no'| translate}}</option>
+                                            <option value="1">{{'yes'| translate}}</option>
+                                        </select>
+
+                                    </div>
+                                    <div ng-switch-when="date">
+                                        <input type="text" 
+                                               placeholder="yyyy-mm-dd" 
+                                               ng-date 
+                                               ng-class='getClass(prStDe.dataElement.id)'
+                                               ng-model="saveDatavalue(prStDe)" 
+                                               ng-required={{prStDe.compulsory}}  
+                                               blur-or-change="saveDatavalue(dhis2Event, eventGridColumn.id)"
+                                               name="foo"/>
+                                    </div>
+                                </div>
+                            </ng-form>                            
+                        </td>
+                        <td class="col-md-2" ng-if="allowProvidedElsewhereExists">                    
+                            <div class="align-center" ng-show="prStDe.allowProvidedElsewhere">
+                                <input type="checkbox" 
+                                       ng-model="currentEvent.providedElsewhere[prStDe.dataElement.id]"
+                                       ng-change="saveDatavalueLocation(prStDe)"/>
+                            </div>
+                        </td>
+                    </tr>
+                </table>
+            </form>
+        </div>
+        <div ng-show="!selectedEnrollment">
+            <div class="alert alert-warning">{{'not_yet_enrolled_data_entry'| translate}}</div> 
+        </div>
+    </div>
+</div>
+
+
+
+
+<!--<div class="panel panel-primary" ng-controller="DataEntryController">
+    <div class="panel-heading">
         {{dataentryWidget.title| translate}} 
         <span class="nav-pills" ng-show="selectedEnrollment && allowEventCreation">
-            | <a href ng-click="createNewEvent()" title="{{'create_new_event_repeatable'| translate}}"><span class="bold">{{'create_new_event'| translate}}</span></a>
+            | <a href ng-click="createNewEvent()" title="{{'create_new_event'| translate}}"><span class="bold">{{'create_new_event'| translate}}</span></a>
         </span>
         <span class="pull-right">
             <a class="small-horizonal-spacing" href ng-click="expandCollapse(dataentryWidget)">
@@ -156,4 +322,4 @@
             <div class="alert alert-warning">{{'not_yet_enrolled_data_entry'| translate}}</div> 
         </div>
     </div>
-</div>
\ No newline at end of file
+</div>-->
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-06-27 13:33:07 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-06-30 07:19:37 +0000
@@ -10,6 +10,7 @@
     "not_yet_enrolled_note": "Not yet enrolled. Note recording not possible.",
     "empty_notes": "Empty notes list.",
     "no_event_is_yet_created": "No event is available for data entry. Please create one from below.",
+    "event_creation": "Please create one from below.",
     "not_selected": "Not selected",
     "view_all": "[View all]",
     "list_all_entities": "List all entities",