dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38016
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19420: minor refactoring in tracker-capture - program rule actions now come as part of the program rule
------------------------------------------------------------
revno: 19420
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-16 14:17:07 +0200
message:
minor refactoring in tracker-capture - program rule actions now come as part of the program rule
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.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-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-06-16 11:21:02 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2015-06-16 12:17:07 +0000
@@ -487,7 +487,7 @@
function getProgramRules( programRules )
{
- return getD2Objects( programRules, 'programRules', '../api/programRules', 'fields=id,name,condition,description,program[id],programRuleActions[id,content,programRuleActionType,programStageSection[id,name],dataElement[id]]');
+ return getD2Objects( programRules, 'programRules', '../api/programRules', 'fields=id,name,condition,description,program[id],programStage[id],priority,programRuleActions[id,content,location,data,programRuleActionType,programStageSection[id],dataElement[id]]');
}
function getMetaProgramRuleVariables( programs )
=== 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-06-16 11:22:51 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-06-16 12:17:07 +0000
@@ -10,7 +10,7 @@
var store = new dhis2.storage.Store({
name: "dhis2tc",
adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
- objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations', 'ouLevels', 'programRuleVariables', 'programRules', 'programRuleActions']
+ objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations', 'ouLevels', 'programRuleVariables', 'programRules']
});
return{
currentStore: store
@@ -1086,34 +1086,21 @@
var def = $q.defer();
TCStorageService.currentStore.open().done(function(){
- TCStorageService.currentStore.getAll('programRules').done(function(rules){
- TCStorageService.currentStore.getAll('programRuleActions').done(function(actions){
- //The hash will serve as a direct-lookup for linking the actions to rules later.
- var programRulesHash = {};
- //The array will ultimately be returned to the caller.
- var programRulesArray = [];
- //Loop through and add the rules belonging to this program and program stage
- angular.forEach(rules, function(rule){
- if(rule.program.id == programUid) {
- if(!rule.programStage || !rule.programStage.id || rule.programStage.id == programStageUid) {
- rule.actions = [];
- programRulesHash[rule.id] = rule;
- programRulesArray.push(rule);
- }
- }
- });
-
- //Loop through and attach all actions to the correct rules:
- angular.forEach(actions, function(action){
- if(programRulesHash[action.programRule.id])
- {
- programRulesHash[action.programRule.id].actions.push(action);
- }
- });
-
- $rootScope.$apply(function(){
- def.resolve(programRulesArray);
- });
+ TCStorageService.currentStore.getAll('programRules').done(function(rules){
+ //The array will ultimately be returned to the caller.
+ var programRulesArray = [];
+ //Loop through and add the rules belonging to this program and program stage
+ angular.forEach(rules, function(rule){
+ if(rule.program.id == programUid) {
+ if(!rule.programStage || !rule.programStage.id || rule.programStage.id == programStageUid) {
+ rule.actions = [];
+ programRulesArray.push(rule);
+ }
+ }
+ });
+
+ $rootScope.$apply(function(){
+ def.resolve(programRulesArray);
});
});
});
=== 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-06-14 09:28:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js 2015-06-16 12:17:07 +0000
@@ -29,7 +29,7 @@
dhis2.tc.store = new dhis2.storage.Store({
name: 'dhis2tc',
adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
- objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations', 'ouLevels', 'programRuleVariables', 'programRules', 'programRuleActions']
+ objectStores: ['programs', 'programStages', 'trackedEntities', 'trackedEntityForms', 'attributes', 'relationshipTypes', 'optionSets', 'programValidations', 'ouLevels', 'programRuleVariables', 'programRules']
});
(function($) {
@@ -145,8 +145,6 @@
promise = promise.then( getProgramRuleVariables );
promise = promise.then( getMetaProgramRules );
promise = promise.then( getProgramRules );
- promise = promise.then( getMetaProgramRuleActions );
- promise = promise.then( getProgramRuleActions );
promise = promise.then( getMetaProgramValidations );
promise = promise.then( getProgramValidations );
promise = promise.then( getTrackedEntityForms );
@@ -496,115 +494,6 @@
};
}
-function getMetaProgramRuleActions( data )
-{
- if( !data ){
- return;
- }
-
- var def = $.Deferred();
-
- var programRuleIds = [];
- _.each( _.values( data.programRules ), function ( programRule ) {
- if( programRule.id ) {
- programRuleIds.push( programRule.id );
- }
- });
-
- $.ajax({
- url: '../api/programRuleActions.json',
- type: 'GET',
- data:'paging=false&fields=id,programRule[id]'
- }).done( function(response) {
- var programRuleActions = [];
- _.each( _.values( response.programRuleActions ), function ( programRuleAction ) {
- if( programRuleAction &&
- programRuleAction.id &&
- programRuleAction.programRule &&
- programRuleAction.programRule.id &&
- programRuleIds.indexOf( programRuleAction.programRule.id ) !== -1) {
-
- programRuleActions.push( programRuleAction );
- }
- });
-
- def.resolve( {programRuleActions: programRuleActions, programs: data.programs} );
-
- }).fail(function(){
- def.resolve( null );
- });
-
- return def.promise();
-}
-
-function getProgramRuleActions( data )
-{
- if( !data || !data.programRuleActions ){
- return;
- }
-
- var mainDef = $.Deferred();
- var mainPromise = mainDef.promise();
-
- var def = $.Deferred();
- var promise = def.promise();
-
- var builder = $.Deferred();
- var build = builder.promise();
-
- _.each( _.values( data.programRuleActions ), function ( programRuleAction ) {
- build = build.then(function() {
- var d = $.Deferred();
- var p = d.promise();
- dhis2.tc.store.get('programRuleActions', programRuleAction.id).done(function(obj) {
- if(!obj) {
- promise = promise.then( getProgramRuleAction( programRuleAction.id ) );
- }
- d.resolve();
- });
-
- return p;
- });
- });
-
- build.done(function() {
- def.resolve();
-
- promise = promise.done( function () {
- mainDef.resolve( data.programs );
- } );
- }).fail(function(){
- mainDef.resolve( null );
- });
-
- builder.resolve();
-
- return mainPromise;
-}
-
-function getProgramRuleAction( id )
-{
- return function() {
- return $.ajax( {
- url: '../api/programRuleActions.json',
- type: 'GET',
- data: 'paging=false&filter=id:eq:' + id +'&fields=id,programRule[id],programRuleActionType,dataElement[id],location,content,data,'
- }).done( function( response ){
-
- _.each( _.values( response.programRuleActions ), function ( programRuleAction ) {
-
- if( programRuleAction &&
- programRuleAction.id &&
- programRuleAction.programRule &&
- programRuleAction.programRule.id ) {
-
- dhis2.tc.store.set( 'programRuleActions', programRuleAction );
- }
- });
- });
- };
-}
-
function getMetaProgramRuleVariables( programs )
{
if( !programs ){
@@ -808,7 +697,7 @@
return $.ajax( {
url: '../api/programRules.json',
type: 'GET',
- data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,description,condition,program[id],programstage[id],priority'
+ data: 'paging=false&filter=id:eq:' + id +'&fields=id,name,description,condition,program[id],programstage[id],priority,programRulesAction[id,content,location,data,programRuleActionType,programStageSection[id,name],dataElement[id]]'
}).done( function( response ){
_.each( _.values( response.programRules ), function ( programRule ) {