Selaa lähdekoodia

send image to server

develop
Robin Thoni 8 vuotta sitten
vanhempi
commit
02abe0d793

+ 22
- 2
public/app/controllers/upload.controller.js Näytä tiedosto

@@ -1,6 +1,6 @@
1 1
 angular.module('app')
2
-    .controller('UploadController', ['$scope', '$state', '$mdDialog',
3
-        function($scope, $state, $mdDialog) {
2
+    .controller('UploadController', ['$scope', '$state', '$mdDialog', 'EffectsBusiness',
3
+        function($scope, $state, $mdDialog, EffectsBusiness) {
4 4
 
5 5
             $scope.image = null;
6 6
 
@@ -30,4 +30,24 @@ angular.module('app')
30 30
             {
31 31
                 $scope.input.click();
32 32
             };
33
+            
34
+            $scope.applyEffect = function(effect, data)
35
+            {
36
+                EffectsBusiness.apply({
37
+                    effect: effect,
38
+                    image: $scope.image.content,
39
+                    data: data
40
+                }).then(function(data)
41
+                {
42
+                    $scope.image.content = data.image;
43
+                }, function (error)
44
+                {
45
+                    console.log(error);
46
+                });
47
+            };
48
+
49
+            $scope.test = function()
50
+            {
51
+                $scope.applyEffect("BlackAndWhite", null);
52
+            };
33 53
     }]);

+ 2
- 0
public/app/index.html Näytä tiedosto

@@ -58,6 +58,8 @@
58 58
 
59 59
     <!-- SDK -->
60 60
     <script src="../sdk/sdk.js"></script>
61
+    <script src="../sdk/DataAccess/effects.js"></script>
62
+    <script src="../sdk/Business/effects.js"></script>
61 63
 
62 64
     <!-- Directives -->
63 65
     <script src="controllers/directives/dropzone.controller.js"></script>

+ 1
- 0
public/app/views/upload.html Näytä tiedosto

@@ -7,5 +7,6 @@
7 7
             Drag a file here or <a href="" ng-click="pickFile()">pick one</a>
8 8
         </p>
9 9
     </div>
10
+    <button type="button" ng-click="test()" >Test.</button>
10 11
     <input type="file" class="hidden-input" id="filePicker">
11 12
 </div>

+ 27
- 0
public/sdk/Business/effects.js Näytä tiedosto

@@ -0,0 +1,27 @@
1
+/**
2
+ * Created by robin on 4/22/16.
3
+ */
4
+
5
+(function()
6
+{
7
+    angular.module("appSdk").factory("EffectsBusiness", ['EffectsDataAccess', '$q', function (EffectsDataAccess, $q) {
8
+        var Business = {};
9
+
10
+        Business.apply = function(data, promise)
11
+        {
12
+            var defer = $q.defer();
13
+
14
+            data.image = btoa(data.image);
15
+
16
+            EffectsDataAccess.apply(data, promise).then(function(data)
17
+            {
18
+                data.image = atob(data.image);
19
+                defer.resolve(data);
20
+            }, defer.reject);
21
+
22
+            return defer.promise;
23
+        };
24
+        
25
+        return Business;
26
+    }])
27
+})();

+ 19
- 0
public/sdk/DataAccess/effects.js Näytä tiedosto

@@ -0,0 +1,19 @@
1
+/**
2
+ * Created by robin on 4/22/16.
3
+ */
4
+
5
+(function()
6
+{
7
+    angular.module("appSdk").factory("EffectsDataAccess", ['luticateRequest', function (luticateRequest) {
8
+        var DataAccess = {};
9
+
10
+        var entry_point = "/api/effects/";
11
+
12
+        DataAccess.apply = function(data, promise)
13
+        {
14
+            return luticateRequest.post(entry_point + data.effect + "/apply", {data: JSON.stringify(data)}, promise);
15
+        };
16
+        
17
+        return DataAccess;
18
+    }])
19
+})();

+ 19
- 0
public/sdk/DataAccess/images.js Näytä tiedosto

@@ -0,0 +1,19 @@
1
+/**
2
+ * Created by robin on 4/22/16.
3
+ */
4
+
5
+(function()
6
+{
7
+    angular.module("appSdk").factory("ImagesDataAccess", ['luticateRequest', function (luticateRequest) {
8
+        var DataAccess = {};
9
+
10
+        var entry_point = "/api/images/";
11
+
12
+        DataAccess.getAll = function(data, promise)
13
+        {
14
+            return luticateRequest.get(entry_point, data, promise);
15
+        };
16
+
17
+        return DataAccess;
18
+    }])
19
+})();

Loading…
Peruuta
Tallenna