dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35852
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18367: tracker-capture: depending on setting, provide new event creation dialog when completing an event
------------------------------------------------------------
revno: 18367
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-20 16:06:35 +0100
message:
tracker-capture: depending on setting, provide new event creation dialog when completing an event
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/dataentry/dataentry.html
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/scripts/services.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.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 2015-02-20 12:08:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-02-20 15:06:35 +0000
@@ -49,7 +49,6 @@
$scope.allowEventCreation = false;
$scope.repeatableStages = [];
- $scope.dhis2Events = [];
$scope.eventsByStage = [];
$scope.programStages = [];
@@ -79,7 +78,6 @@
$scope.getEvents = function(){
DHIS2EventFactory.getEventsByProgram($scope.selectedEntity.trackedEntityInstance, $scope.selectedProgram.id).then(function(events){
- $scope.dhis2Events = [];
if(angular.isObject(events)){
angular.forEach(events, function(dhis2Event){
if(dhis2Event.enrollment === $scope.selectedEnrollment.enrollment && dhis2Event.orgUnit){
@@ -110,91 +108,40 @@
$scope.currentEvent = dhis2Event;
$scope.showDataEntry($scope.currentEvent, true);
}
-
- $scope.dhis2Events.push(dhis2Event);
$scope.eventsByStage[dhis2Event.programStage].push(dhis2Event);
}
}
});
}
-
- $scope.dhis2Events = orderByFilter($scope.dhis2Events, '-sortingDate');
- $scope.dummyEventsByStage = checkForEventCreation($scope.dhis2Events, $scope.selectedProgram);
sortEventsByStage();
});
};
- var checkForEventCreation = function(availableEvents, program){
-
- var dummyEvents = [];
- if($scope.selectedEnrollment.status === 'ACTIVE'){
- if(!angular.isObject(availableEvents)){
- angular.forEach($scope.selectedProgram.programStages, function(ps){
- var programStage = $scope.selectedProgramWithStage[ps.id];
- var dummyEvent = EventUtils.createDummyEvent(availableEvents, programStage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
- dummyEvents.push(dummyEvent);
- });
-
- dummyEvents = orderByFilter(dummyEvents, '-eventDate');
-
- if(dummyEvents){
- $scope.allowEventCreation = true;
- }
-
- return dummyEvents;
- }
- else{
- var eventsPerStage = [];
- angular.forEach(availableEvents, function(event){
- if(eventsPerStage[event.programStage]){
- eventsPerStage[event.programStage].push(event);
- }
- else{
- eventsPerStage[event.programStage] = [];
- eventsPerStage[event.programStage].push(event);
- }
- });
-
- angular.forEach(program.programStages, function(ps){
- var stage = $scope.selectedProgramWithStage[ps.id];
- if(!eventsPerStage[stage.id]){
- $scope.allowEventCreation = true;
- var dummyEvent = EventUtils.createDummyEvent(availableEvents, stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
- dummyEvents.push(dummyEvent);
- }
- else{
- if(stage.repeatable){
- var stageNeedsEvent = true;
- for(var j=0; j<eventsPerStage[stage.id].length && stageNeedsEvent; j++){
- if(!eventsPerStage[stage.id][j].eventDate){
- stageNeedsEvent = false;
- }
- }
-
- if(stageNeedsEvent){
- $scope.allowEventCreation = true;
- var dummyEvent = EventUtils.createDummyEvent(availableEvents, stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
- dummyEvents.push(dummyEvent);
- }
- }
- }
- });
- }
- }
-
- var dummyEventsByStage = [];
- angular.forEach(dummyEvents, function(ev){
- dummyEventsByStage[ev.programStage] = ev;
- });
-
- return dummyEventsByStage;
- };
-
$scope.enableRescheduling = function(){
$scope.schedulingEnabled = !$scope.schedulingEnabled;
};
- $scope.showCreateEvent = function(dummyEvent, stage){
+ $scope.stageNeedsEvent = function(stage){
+
+ if($scope.eventsByStage[stage.id].length < 1){
+ return true;
+ }
+
+ if(stage.repeatable){
+ for(var j=0; j<$scope.eventsByStage[stage.id].length; j++){
+ if(!$scope.eventsByStage[stage.id][j].eventDate){
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ };
+
+ $scope.showCreateEvent = function(stage){
+
+ var dummyEvent = EventUtils.createDummyEvent($scope.eventsByStage[stage.id], stage, $scope.selectedOrgUnit, $scope.selectedEnrollment);
+
var modalInstance = $modal.open({
templateUrl: 'components/dataentry/new-event.html',
controller: 'EventCreationController',
@@ -227,14 +174,6 @@
newEvent.coordinate = {};
}
- if(!angular.isObject($scope.dhis2Events)){
- $scope.dhis2Events = [newEvent];
- }
- else{
- $scope.dhis2Events.splice(0,0,newEvent);
- }
-
- $scope.dummyEventsByStage = checkForEventCreation($scope.dhis2Events, $scope.selectedProgram);
$scope.eventsByStage[newEvent.programStage].push(newEvent);
$scope.showDataEntry(newEvent, false);
}
@@ -599,14 +538,12 @@
else{//complete event
$scope.currentEvent.status = 'COMPLETED';
}
- var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);
- var continueLoop = true;
- for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
- if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
- $scope.dhis2Events[i].statusColor = statusColor;
- continueLoop = false;
- }
- }
+
+ setStatusColor();
+
+ if($scope.currentEvent.status === 'COMPLETED' && $scope.currentStage.allowGenerateNextVisit){
+ $scope.showCreateEvent($scope.currentStage);
+ }
});
});
};
@@ -644,18 +581,24 @@
else{//complete event
$scope.currentEvent.status = 'SKIPPED';
}
- var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);
- var continueLoop = true;
- for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
- if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
- $scope.dhis2Events[i].statusColor = statusColor;
- continueLoop = false;
- }
- }
+
+ setStatusColor();
});
});
};
+ var setStatusColor = function(){
+ var statusColor = EventUtils.getEventStatusColor($scope.currentEvent);
+ var continueLoop = true;
+ for(var i=0; i< $scope.eventsByStage[$scope.currentEvent.programStage].length && continueLoop; i++){
+ if($scope.eventsByStage[$scope.currentEvent.programStage][i].event === $scope.currentEvent.event ){
+ $scope.eventsByStage[$scope.currentEvent.programStage][i].statusColor = statusColor;
+ $scope.currentEvent.statusColor = statusColor;
+ continueLoop = false;
+ }
+ }
+ };
+
$scope.validateEvent = function(){};
$scope.deleteEvent = function(){
@@ -672,16 +615,6 @@
DHIS2EventFactory.delete($scope.currentEvent).then(function(data){
var continueLoop = true, index = -1;
- for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
- if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
- $scope.dhis2Events[i] = $scope.currentEvent;
- continueLoop = false;
- index = i;
- }
- }
- $scope.dhis2Events.splice(index,1);
-
- continueLoop = true, index = -1;
for(var i=0; i< $scope.eventsByStage[$scope.currentEvent.programStage].length && continueLoop; i++){
if($scope.eventsByStage[$scope.currentEvent.programStage][i].event === $scope.currentEvent.event ){
$scope.eventsByStage[$scope.currentEvent.programStage][i] = $scope.currentEvent;
@@ -690,12 +623,7 @@
}
}
$scope.eventsByStage[$scope.currentEvent.programStage].splice(index,1);
-
$scope.currentEvent = null;
- if($scope.dhis2Events.length < 1){
- $scope.dhis2Events = '';
- }
- $scope.dummyEventsByStage = checkForEventCreation($scope.dhis2Events, $scope.selectedProgram);
});
});
};
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html 2015-02-20 12:08:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html 2015-02-20 15:06:35 +0000
@@ -33,8 +33,8 @@
<!-- event add/filter icon begins -->
<span class='pull-right'>
- <span ng-if="dummyEventsByStage[stage.id]">
- <a href title="{{'create_new_event'| translate}}" ng-click="showCreateEvent(dummyEventsByStage[stage.id])"><i class="fa fa-plus"></i></a>
+ <span ng-if="stageNeedsEvent(stage)">
+ <a href title="{{'create_new_event'| translate}}" ng-click="showCreateEvent(stage)"><i class="fa fa-plus"></i></a>
</span>
<span class="small-horizonal-spacing" ng-if="eventsByStage[stage.id].length > 1">
<a href title="{{'filter'| translate}}"><i class="fa fa-search"></i></a>
=== 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 2015-02-19 15:42:18 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-02-20 15:06:35 +0000
@@ -310,7 +310,7 @@
program: program.id,
programStage: stage.id,
orgUnit: orgUnit.id,
- dueDate: DateUtils.formatFromUserToApi( EventUtils.getEventDueDate(dhis2Events.events, stage, enrollment) ),
+ dueDate: DateUtils.formatFromUserToApi( EventUtils.getEventDueDate(null, stage, enrollment) ),
status: 'SCHEDULE'
};
=== 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 2015-02-20 12:08:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-02-20 15:06:35 +0000
@@ -1268,9 +1268,9 @@
.service('EventUtils', function(DateUtils, CalendarService, OptionSetService, OrgUnitService, $filter, orderByFilter){
return {
- createDummyEvent: function(events, programStage, orgUnit, enrollment){
+ createDummyEvent: function(eventsPerStage, programStage, orgUnit, enrollment){
var today = DateUtils.getToday();
- var dueDate = this.getEventDueDate(events, programStage, enrollment);
+ var dueDate = this.getEventDueDate(eventsPerStage, programStage, enrollment);
var dummyEvent = {programStage: programStage.id,
orgUnit: orgUnit.id,
orgUnitName: orgUnit.name,
@@ -1317,7 +1317,7 @@
}
}
},
- getEventDueDate: function(events, programStage, enrollment){
+ getEventDueDate: function(eventsPerStage, programStage, enrollment){
var referenceDate = enrollment.dateOfIncident ? enrollment.dateOfIncident : enrollment.dateOfEnrollment,
offset = programStage.minDaysFromStart,
calendarSetting = CalendarService.getSetting();
@@ -1327,12 +1327,12 @@
}
if(programStage.repeatable){
- var eventsPerStage = [];
+ /*var eventsPerStage = [];
angular.forEach(events, function(event){
if(event.programStage === programStage.id){
eventsPerStage.push(event);
}
- });
+ });*/
if(eventsPerStage.length > 0){
eventsPerStage = orderByFilter(eventsPerStage, '-eventDate');
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js 2015-02-13 14:35:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js 2015-02-20 15:06:35 +0000
@@ -528,7 +528,7 @@
return $.ajax( {
url: '../api/programStages.json',
type: 'GET',
- data: 'filter=id:eq:' + id +'&fields=id,name,sortOrder,version,dataEntryForm,captureCoordinates,blockEntryForm,autoGenerateEvent,generatedByEnrollmentDate,reportDateDescription,minDaysFromStart,repeatable,openAfterEnrollment,standardInterval,reportDateToUse,programStageSections[id,name,programStageDataElements[dataElement[id]]],programStageDataElements[displayInReports,allowProvidedElsewhere,allowFutureDate,compulsory,dataElement[id,code,name,formName,type,optionSet[id]]]'
+ data: 'filter=id:eq:' + id +'&fields=id,name,sortOrder,version,dataEntryForm,captureCoordinates,blockEntryForm,autoGenerateEvent,allowGenerateNextVisit,generatedByEnrollmentDate,reportDateDescription,minDaysFromStart,repeatable,openAfterEnrollment,standardInterval,reportDateToUse,programStageSections[id,name,programStageDataElements[dataElement[id]]],programStageDataElements[displayInReports,allowProvidedElsewhere,allowFutureDate,compulsory,dataElement[id,code,name,formName,type,optionSet[id]]]'
}).done( function( response ){
_.each( _.values( response.programStages ), function( programStage ) {
dhis2.tc.store.set( 'programStages', programStage );