-
-
+
+
@@ -81,6 +81,8 @@
+
+
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/app.js 2014-05-14 13:04:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/app.js 2014-06-06 13:35:06 +0000
@@ -16,6 +16,8 @@
.value('DHIS2URL', '..')
+
+
.config(function($httpProvider, $routeProvider, $translateProvider) {
$httpProvider.defaults.useXDomain = true;
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-05-28 15:31:32 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-06-06 13:35:06 +0000
@@ -50,9 +50,7 @@
$scope.showRegistrationDiv = false;
//watch for selection of org unit from tree
- $scope.$watch('selectedOrgUnit', function() {
-
- $scope.attributes = AttributesFactory.getWithoutProgram();
+ $scope.$watch('selectedOrgUnit', function() {
if( angular.isObject($scope.selectedOrgUnit)){
@@ -63,9 +61,13 @@
//apply translation - by now user's profile is fetched from server.
TranslationService.translate();
- $scope.loadPrograms($scope.selectedOrgUnit);
- $scope.search($scope.searchMode.listAll);
-
+
+ $scope.loadPrograms($scope.selectedOrgUnit);
+
+ AttributesFactory.getWithoutProgram().then(function(atts){
+ $scope.attributes = atts;
+ $scope.search($scope.searchMode.listAll);
+ });
}
});
@@ -78,39 +80,41 @@
if (angular.isObject($scope.selectedOrgUnit)) {
- $scope.programs = [];
-
- var programs = ProgramFactory.getAll();
-
- if( programs && programs != 'undefined' ){
- angular.forEach(programs, function(program){
- if(angular.isObject(program)){
- if(program.organisationUnits.hasOwnProperty(orgUnit.id)){
- $scope.programs.push(program);
- }
+ ProgramFactory.getAll().then(function(programs){
+ $scope.programs = [];
+ angular.forEach(programs, function(program){
+ if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id)){
+ $scope.programs.push(program);
}
- });
+ });
- if( !angular.isUndefined($scope.programs)){
- if($scope.programs.length === 1){
- $scope.selectedProgram = $scope.programs[0];
- $scope.pr = $scope.selectedProgram;
- $scope.attributes = AttributesFactory.getByProgram($scope.selectedProgram);
- }
- }
- }
+ if(angular.isObject($scope.programs) && $scope.programs.length === 1){
+ $scope.selectedProgram = $scope.programs[0];
+
+ AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
+ $scope.attributes = atts;
+ $scope.generateGridColumns($scope.attributes);
+ });
+ }
+ });
}
};
$scope.getProgramAttributes = function(program, doSearch){
$scope.trackedEntityList = null;
$scope.selectedProgram = program;
-
+
if($scope.selectedProgram){
- $scope.attributes = AttributesFactory.getByProgram($scope.selectedProgram);
+ AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
+ $scope.attributes = atts;
+ $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+ });
}
else{
- $scope.attributes = AttributesFactory.getWithoutProgram();
+ AttributesFactory.getWithoutProgram().then(function(atts){
+ $scope.attributes = atts;
+ $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+ });
}
if(doSearch){
@@ -119,7 +123,7 @@
};
$scope.search = function(mode){
-
+
$scope.emptySearchText = false;
$scope.emptySearchAttribute = false;
$scope.showSearchDiv = false;
@@ -157,7 +161,7 @@
else if( mode === $scope.searchMode.listAll ){
$scope.showTrackedEntityDiv = true;
}
-
+
$scope.gridColumns = $scope.generateGridColumns($scope.attributes);
//get events for the specified parameters
@@ -172,7 +176,7 @@
//generate grid columns from teilist attributes
$scope.generateGridColumns = function(attributes){
- var columns = angular.copy(attributes);
+ var columns = attributes ? angular.copy(attributes) : [];
//also add extra columns which are not part of attributes (orgunit for example)
columns.push({id: 'orgUnitName', name: 'Organisation unit', type: 'string', displayInListNoProgram: false});
@@ -251,7 +255,7 @@
});
};
- $scope.showDashboard = function(currentEntity){
+ $scope.showDashboard = function(currentEntity){
$location.path('/dashboard').search({selectedEntityId: currentEntity.id,
selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id: null});
};
@@ -297,7 +301,8 @@
$modal,
$timeout,
storage,
- TEIService,
+ TEIService,
+ ProgramFactory,
CurrentSelection,
TranslationService) {
@@ -306,7 +311,7 @@
//dashboard items
$rootScope.dashboardWidgets = {bigger: [], smaller: []};
- $rootScope.enrollmentWidget = {title: 'enrollment', view: "components/enrollment/enrollment.html", show: true};
+ $rootScope.enrollmentWidget = {title: 'program', view: "components/enrollment/enrollment.html", show: true};
$rootScope.dataentryWidget = {title: 'dataentry', view: "components/dataentry/dataentry.html", show: true};
$rootScope.selectedWidget = {title: 'current_selections', view: "components/selected/selected.html", show: false};
$rootScope.profileWidget = {title: 'profile', view: "components/profile/profile.html", show: true};
@@ -327,24 +332,30 @@
$scope.selectedEntityId = ($location.search()).selectedEntityId;
$scope.selectedProgramId = ($location.search()).selectedProgramId;
$scope.selectedOrgUnit = storage.get('SELECTED_OU');
-
- if($scope.selectedProgramId && storage.get($scope.selectedProgramId)){
- $scope.selectedProgram = storage.get($scope.selectedProgramId);
- }
- else{
- $scope.selectedProgram = null;
- }
if( $scope.selectedEntityId ){
-
+
//Fetch the selected entity
- TEIService.get($scope.selectedEntityId).then(function(data){
- CurrentSelection.set({tei: data, pr: $scope.selectedProgram ? $scope.selectedProgram.id : null});
-
- //broadcast selected entity for dashboard controllers
- $timeout(function() {
- $rootScope.$broadcast('selectedEntity', {});
- }, 100);
+ TEIService.get($scope.selectedEntityId).then(function(data){
+
+ if($scope.selectedProgramId){
+ ProgramFactory.get($scope.selectedProgramId).then(function(program){
+ $scope.selectedProgram = program;
+
+ //broadcast selected items for dashboard controllers
+ CurrentSelection.set({tei: data, pr: $scope.selectedProgram});
+ $timeout(function() {
+ $rootScope.$broadcast('selectedEntity', {});
+ }, 100);
+ });
+ }
+ else{
+ //broadcast selected items for dashboard controllers
+ CurrentSelection.set({tei: data, pr: ''});
+ $timeout(function() {
+ $rootScope.$broadcast('selectedEntity', {});
+ }, 100);
+ }
});
}
@@ -372,15 +383,6 @@
};
})
-//Controller for the profile section
-
-
-//Controller for the enrollment section
-
-
-//Controller for the data entry section
-
-
//Controller for the dashboard widgets
.controller('DashboardWidgetsController',
function($scope,
@@ -394,15 +396,6 @@
};
})
-//Controller for the relationship section
-
-
-//Controller for the notes section
-
-
-//Controller for the selected section
-
-
//Controller for the header section
.controller('HeaderController',
function($scope,
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js 2014-05-27 12:38:36 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js 2014-06-06 13:35:06 +0000
@@ -23,6 +23,49 @@
restrict: 'A',
link: function(scope, element, attrs){
+ //when tree has loaded, get selected orgunit - if there is any - and inform angular
+ $(function() {
+
+ var adapters = [];
+ var partial_adapters = [];
+
+ if( dhis2.ou.memoryOnly ) {
+ adapters = [ dhis2.storage.InMemoryAdapter ];
+ partial_adapters = [ dhis2.storage.InMemoryAdapter ];
+ } else {
+ adapters = [ dhis2.storage.IndexedDBAdapter, dhis2.storage.DomLocalStorageAdapter, dhis2.storage.InMemoryAdapter ];
+ partial_adapters = [ dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter ];
+ }
+
+ dhis2.ou.store = new dhis2.storage.Store({
+ name: OU_STORE_NAME,
+ objectStores: [
+ {
+ name: OU_KEY,
+ adapters: adapters
+ },
+ {
+ name: OU_PARTIAL_KEY,
+ adapters: partial_adapters
+ }
+ ]
+ });
+
+ dhis2.ou.store.open().done( function() {
+ selection.load();
+ $( "#orgUnitTree" ).one( "ouwtLoaded", function() {
+ var selected = selection.getSelected()[0];
+ selection.getOrganisationUnit(selected).done(function(data){
+ if( data ){
+ scope.selectedOrgUnit = {id: selected, name: data[selected].n};
+ scope.$apply();
+ }
+ });
+ });
+
+ });
+ });
+
//listen to user selection, and inform angular
selection.setListenerFunction( organisationUnitSelected );
selection.responseReceived();
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-05-28 15:20:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-06-06 13:35:06 +0000
@@ -4,6 +4,17 @@
var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResource'])
+
+.factory('StorageService', function(){
+ var store = new dhis2.storage.Store({
+ name: "dhis2tc",
+ adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
+ objectStores: ['trackerCapturePrograms', 'programStages', 'trackedEntities','attributes','optionSets']
+ });
+ return{
+ currentStore: store
+ };
+})
/* factory for loading logged in user profiles from DHIS2 */
.factory('CurrentUserProfile', function($http) {
@@ -22,71 +33,88 @@
})
/* Factory to fetch programs */
-.factory('ProgramFactory', function($http, storage) {
-
- var programUid, programPromise;
- var programs, programsPromise;
- var program;
+.factory('ProgramFactory', function($q, $rootScope, StorageService, ProgramStageFactory) {
return {
-
+ getAll: function(){
+
+ var def = $q.defer();
+
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.getAll('trackerCapturePrograms').done(function(programs){
+ $rootScope.$apply(function(){
+ def.resolve(programs);
+ });
+ });
+ });
+
+ return def.promise;
+ },
get: function(uid){
- if( programUid !== uid ){
- programPromise = $http.get( '../api/programs/' + uid + '.json?viewClass=detailed&paging=false').then(function(response){
- programUid = response.data.id;
- program = response.data;
- return program;
- });
- }
- return programPromise;
- },
-
- getMine: function(type){
- if( !programsPromise ){
- programsPromise = $http.get( '../api/me/programs?includeDescendants=true&type='+type).then(function(response){
- programs = response.data;
- return programs;
- });
- }
- return programsPromise;
- },
-
- getEventProgramsByOrgUnit: function(orgUnit, type){
-
- var promise = $http.get( '../api/programs.json?orgUnit=' + orgUnit + '&type=' + type ).then(function(response){
- programs = response.data;
- return programs;
- });
- return promise;
- },
- getAll: function(){
- var programs = [];
- angular.forEach(storage.get('TRACKER_PROGRAMS'), function(p){
- programs.push(storage.get(p.id));
- });
- return programs;
+
+ var def = $q.defer();
+
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.get('trackerCapturePrograms', uid).done(function(pr){
+ $rootScope.$apply(function(){
+ def.resolve(pr);
+ });
+ });
+ });
+ return def.promise;
}
};
})
/* Factory to fetch programStages */
-.factory('ProgramStageFactory', function($http, storage) {
+.factory('ProgramStageFactory', function($q, $rootScope, StorageService) {
- var programStage, promise;
return {
- get: function(uid){
- if( programStage !== uid ){
- promise = $http.get( '../api/programStages/' + uid + '.json?viewClass=detailed&paging=false').then(function(response){
- programStage = response.data.id;
-
- //store locally - might need them for event data values
- angular.forEach(response.data.programStageDataElements, function(prStDe){
- storage.set(prStDe.dataElement.id, prStDe);
- });
-
- return response.data;
+ get: function(uid){
+ var def = $q.defer();
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.get('programStages', uid).done(function(pst){
+ angular.forEach(pst.programStageDataElements, function(pstDe){
+ if(pstDe.dataElement.optionSet){
+ StorageService.currentStore.get('optionSets', pstDe.dataElement.optionSet.id).done(function(optionSet){
+ pstDe.dataElement.optionSet = optionSet;
+ });
+ }
+ });
+ $rootScope.$apply(function(){
+ def.resolve(pst);
+ });
});
- }
- return promise;
+ });
+ return def.promise;
+ },
+ getByProgram: function(program){
+ var def = $q.defer();
+ var stageIds = [];
+ var programStages = [];
+ angular.forEach(program.programStages, function(stage){
+ stageIds.push(stage.id);
+ });
+
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.getAll('programStages').done(function(stages){
+ angular.forEach(stages, function(stage){
+ if(stageIds.indexOf(stage.id) !== -1){
+ angular.forEach(stage.programStageDataElements, function(pstDe){
+ if(pstDe.dataElement.optionSet){
+ StorageService.currentStore.get('optionSets', pstDe.dataElement.optionSet.id).done(function(optionSet){
+ pstDe.dataElement.optionSet = optionSet;
+ });
+ }
+ });
+ programStages.push(stage);
+ }
+ });
+ $rootScope.$apply(function(){
+ def.resolve(programStages);
+ });
+ });
+ });
+ return def.promise;
}
};
})
@@ -159,6 +187,26 @@
})
/* Service for getting tracked entity instances */
+.factory('TEService', function(StorageService, $q, $rootScope) {
+
+ return {
+
+ getAll: function(){
+ var def = $q.defer();
+
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.getAll('trackedEntities').done(function(entities){
+ $rootScope.$apply(function(){
+ def.resolve(entities);
+ });
+ });
+ });
+ return def.promise;
+ }
+ };
+})
+
+/* Service for getting tracked entity instances */
.factory('TEIService', function($http, $filter, EntityService) {
var promise;
@@ -241,84 +289,85 @@
})
/* Factory for getting tracked entity attributes */
-.factory('AttributesFactory', function(storage) {
-
+.factory('AttributesFactory', function($q, $rootScope, StorageService) {
+
return {
- getAll: function(){
- return storage.get('ATTRIBUTES');
+ getAll: function(){
+
+ var def = $q.defer();
+
+ StorageService.currentStore.open().done(function(){
+ StorageService.currentStore.getAll('attributes').done(function(attributes){
+ angular.forEach(attributes, function(att){
+ if(att.optionSet){
+ StorageService.currentStore.get('optionSets', att.optionSet.id).done(function(optionSet){
+ att.optionSet = optionSet;
+ });
+ }
+ $rootScope.$apply(function(){
+ def.resolve(attributes);
+ });
+ });
+ });
+ });
+ return def.promise;
},
getByProgram: function(program){
- if(program){
- var attributes = [];
- var programAttributes = [];
+ var attributes = [];
+ var programAttributes = [];
- angular.forEach(this.getAll(), function(attribute){
+ var def = $q.defer();
+ this.getAll().then(function(atts){
+ angular.forEach(atts, function(attribute){
attributes[attribute.id] = attribute;
});
angular.forEach(program.programTrackedEntityAttributes, function(pAttribute){
- programAttributes.push(attributes[pAttribute.attribute.id]);
- });
+ programAttributes.push(attributes[pAttribute.trackedEntityAttribute.id]);
+ });
- return programAttributes;
- }
- return this.getWithoutProgram();
- },
- getWithoutProgram: function(){
- var attributes = [];
-
- angular.forEach(this.getAll(), function(attribute) {
- if (attribute.displayInListNoProgram) {
- attributes.push(attribute);
- }
- });
-
- return attributes;
- },
- convertListingForToQuery: function(){
- var param = '';
- angular.forEach(this.getForListing(), function(attribute) {
- param += '&' + 'attribute=' + attribute.id;
+ def.resolve(programAttributes);
});
+ return def.promise;
+ },
+ getWithoutProgram: function(){
- return param;
- },
+ var def = $q.defer();
+ this.getAll().then(function(atts){
+ var attributes = [];
+ angular.forEach(atts, function(attribute){
+ if (attribute.displayInListNoProgram) {
+ attributes.push(attribute);
+ }
+ });
+ def.resolve(attributes);
+ });
+ return def.promise;
+ },
getMissingAttributesForEnrollment: function(tei, program){
- var programAttributes = this.getByProgram(program);
- var existingAttributes = tei.attributes;
- var missingAttributes = [];
- for(var i=0; i