← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21560: tracker/event-capture: moved file upload/download service and directive to web-commons-resources

 

------------------------------------------------------------
revno: 21560
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2016-01-02 09:44:30 +0100
message:
  tracker/event-capture: moved file upload/download service and directive to web-commons-resources
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.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-event-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2015-12-30 12:59:32 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2016-01-02 08:44:30 +0000
@@ -4,88 +4,5 @@
 
 /* Directives */
 
-var eventCaptureDirectives = angular.module('eventCaptureDirectives', [])
-
-.directive('d2FileInput', function(DHIS2EventService, DHIS2EventFactory, FileService, DialogService){
-    
-    return {
-        restrict: "A",
-        scope: {
-            d2FileInputList: '=',
-            d2FileInput: '=',
-            d2FileInputName: '=',
-            d2FileInputCurrentName: '=',
-            d2FileInputPs: '='
-        },
-        link: function (scope, element, attrs) {
-            
-            var de = attrs.inputFieldId;
-            
-            var updateModel = function () {
-                
-                var update = scope.d2FileInput.eventDate ? true : false;
-                
-                FileService.upload(element[0].files[0]).then(function(data){
-                    
-                    if(data && data.status === 'OK' && data.response && data.response.fileResource && data.response.fileResource.id && data.response.fileResource.name){
-                                            
-                        scope.d2FileInput[de] = data.response.fileResource.id;   
-                        scope.d2FileInputCurrentName[de] = data.response.fileResource.name;
-                        if( update ){                            
-                            if(!scope.d2FileInputName[scope.d2FileInput.event]){
-                                scope.d2FileInputName[scope.d2FileInput.event] = [];
-                            }                            
-                            scope.d2FileInputName[scope.d2FileInput.event][de] = data.response.fileResource.name;
-                            
-                            var updatedSingleValueEvent = {event: scope.d2FileInput.event, dataValues: [{value: data.response.fileResource.id, dataElement:  de}]};
-                            var updatedFullValueEvent = DHIS2EventService.reconstructEvent(scope.d2FileInput, scope.d2FileInputPs.programStageDataElements);
-                            DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){
-                                scope.d2FileInputList = DHIS2EventService.refreshList(scope.d2FileInputList, scope.d2FileInput);
-                            });
-                        }
-                    }
-                    else{
-                        var dialogOptions = {
-                            headerText: 'error',
-                            bodyText: 'file_upload_failed'
-                        };		
-                        DialogService.showDialog({}, dialogOptions);
-                    }
-                    
-                });                 
-            };             
-            element.bind('change', updateModel);            
-        }
-    };    
-})
-
-.directive('d2FileInputDelete', function($parse, $timeout, FileService, DialogService){
-    
-    return {
-        restrict: "A",
-        link: function (scope, element, attrs) {
-            var valueGetter = $parse(attrs.d2FileInputDelete);
-            var nameGetter = $parse(attrs.d2FileInputName);
-            var nameSetter = nameGetter.assign;
-            
-            if(valueGetter(scope)) {
-                FileService.get(valueGetter(scope)).then(function(data){
-                    if(data && data.name && data.id){
-                        $timeout(function(){
-                            nameSetter(scope, data.name);
-                            scope.$apply();
-                        });
-                    }
-                    else{
-                        var dialogOptions = {
-                            headerText: 'error',
-                            bodyText: 'file_missing'
-                        };		
-                        DialogService.showDialog({}, dialogOptions);
-                    }                    
-                });                 
-            }
-        }
-    };    
-});
+var eventCaptureDirectives = angular.module('eventCaptureDirectives', []);
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2015-12-30 12:59:32 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2016-01-02 08:44:30 +0000
@@ -17,40 +17,6 @@
     };
 })
 
-/* Service for uploading/downloading file */
-.service('FileService', function ($http) {
-
-    return {
-        get: function (uid) {
-            var promise = $http.get('../api/fileResources/' + uid).then(function (response) {
-                return response.data;
-            });
-            return promise;
-        },
-        delete: function (uid) {
-            var promise = $http.get('../api/fileResources/' + uid).then(function (response) {
-                return response.data;
-            });
-            return promise;
-        },
-        download: function (fileName) {
-            var promise = $http.get(fileName).then(function (response) {
-                return response.data;
-            });
-            return promise;
-        },
-        upload: function(file){
-            var formData = new FormData();
-            formData.append('file', file);
-            var headers = {transformRequest: angular.identity, headers: {'Content-Type': undefined}};
-            var promise = $http.post('../api/fileResources', formData, headers).then(function(response){
-                return response.data;
-            });
-            return promise;
-        }
-    };
-})
-
 .factory('OfflineECStorageService', function($http, $q, $rootScope, ECStorageService){
     return {        
         hasLocalData: function() {

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js	2015-12-03 11:30:42 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.directives.js	2016-01-02 08:44:30 +0000
@@ -297,4 +297,87 @@
                     });
         }
     };
+})
+
+.directive('d2FileInput', function(DHIS2EventService, DHIS2EventFactory, FileService, DialogService){
+    
+    return {
+        restrict: "A",
+        scope: {
+            d2FileInputList: '=',
+            d2FileInput: '=',
+            d2FileInputName: '=',
+            d2FileInputCurrentName: '=',
+            d2FileInputPs: '='
+        },
+        link: function (scope, element, attrs) {
+            
+            var de = attrs.inputFieldId;
+            
+            var updateModel = function () {
+                
+                var update = scope.d2FileInput.event &&  scope.d2FileInput.event !== 'SINGLE_EVENT' ? true : false;
+                
+                FileService.upload(element[0].files[0]).then(function(data){
+                    
+                    if(data && data.status === 'OK' && data.response && data.response.fileResource && data.response.fileResource.id && data.response.fileResource.name){
+                                            
+                        scope.d2FileInput[de] = data.response.fileResource.id;   
+                        scope.d2FileInputCurrentName[de] = data.response.fileResource.name;
+                        if( update ){                            
+                            if(!scope.d2FileInputName[scope.d2FileInput.event]){
+                                scope.d2FileInputName[scope.d2FileInput.event] = [];
+                            }                            
+                            scope.d2FileInputName[scope.d2FileInput.event][de] = data.response.fileResource.name;
+                            
+                            var updatedSingleValueEvent = {event: scope.d2FileInput.event, dataValues: [{value: data.response.fileResource.id, dataElement:  de}]};
+                            var updatedFullValueEvent = DHIS2EventService.reconstructEvent(scope.d2FileInput, scope.d2FileInputPs.programStageDataElements);
+                            DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){
+                                scope.d2FileInputList = DHIS2EventService.refreshList(scope.d2FileInputList, scope.d2FileInput);
+                            });
+                        }
+                    }
+                    else{
+                        var dialogOptions = {
+                            headerText: 'error',
+                            bodyText: 'file_upload_failed'
+                        };		
+                        DialogService.showDialog({}, dialogOptions);
+                    }
+                    
+                });                 
+            };             
+            element.bind('change', updateModel);            
+        }
+    };    
+})
+
+.directive('d2FileInputDelete', function($parse, $timeout, FileService, DialogService){
+    
+    return {
+        restrict: "A",
+        link: function (scope, element, attrs) {
+            var valueGetter = $parse(attrs.d2FileInputDelete);
+            var nameGetter = $parse(attrs.d2FileInputName);
+            var nameSetter = nameGetter.assign;
+            
+            if(valueGetter(scope)) {
+                FileService.get(valueGetter(scope)).then(function(data){
+                    if(data && data.name && data.id){
+                        $timeout(function(){
+                            nameSetter(scope, data.name);
+                            scope.$apply();
+                        });
+                    }
+                    else{
+                        var dialogOptions = {
+                            headerText: 'error',
+                            bodyText: 'file_missing'
+                        };		
+                        DialogService.showDialog({}, dialogOptions);
+                    }                    
+                });                 
+            }
+        }
+    };    
 });

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-12-30 12:59:32 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2016-01-02 08:44:30 +0000
@@ -881,6 +881,40 @@
     };
 })
 
+/* Service for uploading/downloading file */
+.service('FileService', function ($http) {
+
+    return {
+        get: function (uid) {
+            var promise = $http.get('../api/fileResources/' + uid).then(function (response) {
+                return response.data;
+            });
+            return promise;
+        },
+        delete: function (uid) {
+            var promise = $http.get('../api/fileResources/' + uid).then(function (response) {
+                return response.data;
+            });
+            return promise;
+        },
+        download: function (fileName) {
+            var promise = $http.get(fileName).then(function (response) {
+                return response.data;
+            });
+            return promise;
+        },
+        upload: function(file){
+            var formData = new FormData();
+            formData.append('file', file);
+            var headers = {transformRequest: angular.identity, headers: {'Content-Type': undefined}};
+            var promise = $http.post('../api/fileResources', formData, headers).then(function(response){
+                return response.data;
+            });
+            return promise;
+        }
+    };
+})
+
 /* service for building variables based on the data in users fields */
 .service('VariableService', function(DateUtils,$filter,$log){
     var processSingleValue = function(processedValue,valueType){