Pārlūkot izejas kodu

crud dataaccess; crud business; request

tags/v0.1.1
Robin Thoni 8 gadus atpakaļ
vecāks
revīzija
12a4517637

+ 1
- 1
Gruntfile.js Parādīt failu

@@ -9,7 +9,7 @@ module.exports = function(grunt) {
9 9
             demo: {
10 10
                 files: {
11 11
                     'dist/luticate-utils.min.js': [
12
-                        'src/luticateutils.js',
12
+                        'src/luticate2-utils.js',
13 13
                         'src/**/*.js'
14 14
                     ]
15 15
                 }

+ 1
- 1
dist/luticate-utils.min.js Parādīt failu

@@ -1 +1 @@
1
-!function(){angular.module("luticate2-utils",[])}(),function(){"use strict";angular.module("luticateUtils").factory("luPromise",[function(){var a={};return a.promises={},a.loaders=[],a.errors=[],a.STATUS_RUNNING=0,a.STATUS_RESOLVED=1,a.STATUS_REJECTED=2,a.build=function(b){a[b]={};for(var c in a.promises)if(a.promises.hasOwnProperty(c)){var d=a.promises[c];d[b].forEach(function(c){null==a[b][c]&&(a[b][c]=[]),a[b][c].push(d)})}},a.newPromise=function(a,b,c,d){return{id:a,groups:b,loaderGroups:c,errorGroups:d}},a.initPromise=function(b){var c={loaders:[],errors:[],status:a.STATUS_RUNNING,id:b.id};b.groups instanceof Array?b.groups.forEach(function(a){c.loaders.push(a),c.errors.push(a)}):"string"==typeof b.groups&&(c.loaders.push(b.groups),c.errors.push(b.groups)),b.loaderGroups instanceof Array?b.loaderGroups.forEach(function(a){c.loaders.push(a)}):"string"==typeof b.loaderGroups&&c.loaders.push(b.loaderGroups),b.errorGroups instanceof Array?b.errorGroups.forEach(function(a){c.errors.push(a)}):"string"==typeof b.errorGroups&&c.errors.push(b.errorGroups),a.promises[b.id]=c,a.build("loaders"),a.build("errors")},a.getLoadersGroup=function(b){return null==a.loaders[b]?null:a.loaders[b]},a.getErrorsGroup=function(b){return null==a.errors[b]?null:a.errors[b]},a.reject=function(b,c){a.promises[b.id].status=a.STATUS_REJECTED,a.promises[b.id].value=c},a.resolve=function(b,c){a.promises[b.id].status=a.STATUS_RESOLVED,a.promises[b.id].value=c},a}])}(),function(){"use strict";angular.module("luticateUtils").factory("luRequest",["$q","$http","luPromise",function(a,b,c){function d(a,b,d,e){var f={Data:b,Status:d};a.reject(f),null!=e&&c.reject(e,f)}function e(a,b,d){a.resolve(b),null!=d&&c.resolve(d,b)}var f={};return f.get=function(a,b,c){return f.request(a,"GET",b,null,c)},f.post=function(a,b,c,d){return f.request(a,"POST",b,c,d)},f.put=function(a,b,c,d){return f.request(a,"PUT",b,c,d)},f["delete"]=function(a,b,c,d){return f.request(a,"DELETE",b,c,d)},f.request=function(f,g,h,i,j){null!=j&&c.initPromise(j);var k=a.defer();f=f.replace(/\/+$/,"");var l={url:f,method:g,params:h,data:null==i?null:$.param(i),headers:{"Content-Type":"application/x-www-form-urlencoded"}};return b(l).success(function(a,b){if(null==a||null!=a.Message){var c=null==a?"Failed to parse response":a.Message;d(k,c,b,j)}else e(k,a.Data,j)}).error(function(a,b){if(null==a||null!=a.Message){var c=null==a?"Failed to parse response":a.Message;d(k,c,b,j)}else d(k,a,b,j)}),k.promise},f}])}();
1
+!function(){angular.module("luticate2Utils",[])}(),function(){"use strict";angular.module("luticate2Utils").factory("luBusiness",[function(){var a={};return a.create=function(){var a={};return a},a}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luBusyBusiness",[function(){var a={};return a.promises={},a.loaders=[],a.errors=[],a.STATUS_RUNNING=0,a.STATUS_RESOLVED=1,a.STATUS_REJECTED=2,a.build=function(b){a[b]={};for(var c in a.promises)if(a.promises.hasOwnProperty(c)){var d=a.promises[c];d[b].forEach(function(c){null==a[b][c]&&(a[b][c]=[]),a[b][c].push(d)})}},a.newPromise=function(a,b,c,d){return{id:a,groups:b,loaderGroups:c,errorGroups:d}},a.initLuBusy=function(b){var c={loaders:[],errors:[],status:a.STATUS_RUNNING,id:b.id};b.groups instanceof Array?b.groups.forEach(function(a){c.loaders.push(a),c.errors.push(a)}):"string"==typeof b.groups&&(c.loaders.push(b.groups),c.errors.push(b.groups)),b.loaderGroups instanceof Array?b.loaderGroups.forEach(function(a){c.loaders.push(a)}):"string"==typeof b.loaderGroups&&c.loaders.push(b.loaderGroups),b.errorGroups instanceof Array?b.errorGroups.forEach(function(a){c.errors.push(a)}):"string"==typeof b.errorGroups&&c.errors.push(b.errorGroups),a.promises[b.id]=c,a.build("loaders"),a.build("errors")},a.getLoadersGroup=function(b){return null==a.loaders[b]?null:a.loaders[b]},a.getErrorsGroup=function(b){return null==a.errors[b]?null:a.errors[b]},a.reject=function(b,c){a.promises[b.id].status=a.STATUS_REJECTED,a.promises[b.id].value=c},a.resolve=function(b){a.promises[b.id].status=a.STATUS_RESOLVED,a.promises[b.id].value=null},a}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luWebApiCrudBusiness",["luBusiness","luWebApiDataAccess",function(a,b){var c={};return c.create=function(b){var c=a.create();return c.dataAccess=b,c.getSingleById=function(a,b){return c.dataAccess.getSingleById(a,b)},c.getMultiple=function(a,b,d,e){return c.dataAccess.getMultiple(a,b,d,e)},c.addDbo=function(a,b){return c.dataAccess.addDbo(a,b)},c.editSingleByIdDbo=function(a,b,d){return c.dataAccess.editSingleByIdDbo(a,b,d)},c.deleteDbo=function(a,b){return c.dataAccess.deleteDbo(a,b)},c},c}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luDataAccess",[function(){var a={};return a.create=function(){var a={};return a},a}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luRequest",["$q","$http","luBusyBusiness",function(a,b,c){function d(a,b,d,e){var f={data:b,status:d};a.reject(f),null!=e&&c.reject(e,f)}function e(a,b,d){a.resolve(b),null!=d&&c.resolve(d)}var f={};return f.get=function(a,b,c){return f.request(a,"GET",b,null,c)},f.post=function(a,b,c,d){return f.request(a,"POST",b,c,d)},f.put=function(a,b,c,d){return f.request(a,"PUT",b,c,d)},f["delete"]=function(a,b,c,d){return f.request(a,"DELETE",b,c,d)},f.request=function(f,g,h,i,j){null!=j&&c.initLuBusy(j);var k=a.defer();f=f.replace(/\/+$/,"");var l={url:f,method:g,params:h,data:i,headers:{"Content-Type":"application/json"}};return b(l).then(function(a){var b=a.data,c=a.status;null==b?d(k,"Failed to parse response",c,j):null!=b.message?d(k,b.message,c,j):e(k,b.data,j)},function(a){var b=a.data,c=a.status;null==b?d(k,"Failed to parse response",c,j):null!=b.message?d(k,b.message,c,j):d(k,b,c,j)}),k.promise},f}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luWebApiCrudDataAccess",["luWebApiDataAccess",function(a){var b={};return b.create=function(b){var c=a.create(b);return c.getSingleById=function(a,b){return c.get(a,null,b)},c.getMultiple=function(a,b,d,e){return c.get("",{orderBy:a,page:b,perPage:d},e)},c.addDbo=function(a,b){return c.post("",null,a,b)},c.editSingleByIdDbo=function(a,b,d){return c.post(a,null,b,d)},c.deleteDbo=function(a,b){return c["delete"](a,null,null,b)},c},b}])}(),function(){"use strict";angular.module("luticate2Utils").factory("luWebApiDataAccess",["luDataAccess","luRequest",function(a,b){var c={};return c.create=function(c){var d=a.create();return d.entry_point=c,"/"!==d.entry_point.substr(-1)&&(d.entry_point+="/"),d.get=function(a,c,e){return b.get(d.entry_point+a,c,e)},d.post=function(a,c,e,f){return b.post(d.entry_point+a,c,e,f)},d.put=function(a,c,e,f){return b.put(d.entry_point+a,c,e,f)},d["delete"]=function(a,c,e,f){return b["delete"](d.entry_point+a,c,e,f)},d},c}])}();

+ 21
- 0
src/Business/lu-business.js Parādīt failu

@@ -0,0 +1,21 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luBusiness', [function () {
9
+
10
+            var luBusiness = {};
11
+
12
+            luBusiness.create = function () {
13
+                var Business = {};
14
+
15
+                return Business;
16
+            };
17
+
18
+            return luBusiness;
19
+
20
+        }]);
21
+})();

+ 2
- 2
src/Business/lu-busy-business.js Parādīt failu

@@ -103,9 +103,9 @@
103 103
                 luBusyBusiness.promises[promise.id].value = error;
104 104
             };
105 105
 
106
-            luBusyBusiness.resolve = function(promise, data) {
106
+            luBusyBusiness.resolve = function(promise) {
107 107
                 luBusyBusiness.promises[promise.id].status = luBusyBusiness.STATUS_RESOLVED;
108
-                luBusyBusiness.promises[promise.id].value = data;
108
+                luBusyBusiness.promises[promise.id].value = null;
109 109
             };
110 110
 
111 111
             return luBusyBusiness;

+ 43
- 0
src/Business/lu-webapi-crud-business.js Parādīt failu

@@ -0,0 +1,43 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luWebApiCrudBusiness', ['luBusiness', 'luWebApiDataAccess', function (luBusiness, luWebApiDataAccess) {
9
+
10
+            var luWebApiCrudBusiness = {};
11
+
12
+            luWebApiCrudBusiness.create = function (dataAccess) {
13
+                var Business = luBusiness.create();
14
+
15
+                Business.dataAccess = dataAccess;
16
+
17
+                Business.getSingleById = function (id, luBusyDbo) {
18
+                    return Business.dataAccess.getSingleById(id, luBusyDbo);
19
+                };
20
+
21
+                Business.getMultiple = function (orderBy, page, perPage, luBusyDbo) {
22
+                    return Business.dataAccess.getMultiple(orderBy, page, perPage, luBusyDbo);
23
+                };
24
+
25
+                Business.addDbo = function(data, luBusyDbo) {
26
+                    return Business.dataAccess.addDbo(data, luBusyDbo);
27
+                };
28
+
29
+                Business.editSingleByIdDbo = function(id, data, luBusyDbo) {
30
+                    return Business.dataAccess.editSingleByIdDbo(id, data, luBusyDbo);
31
+                };
32
+
33
+                Business.deleteDbo = function(id, luBusyDbo) {
34
+                    return Business.dataAccess.deleteDbo(id, luBusyDbo);
35
+                };
36
+
37
+                return Business;
38
+            };
39
+
40
+            return luWebApiCrudBusiness;
41
+
42
+        }]);
43
+})();

+ 4
- 29
src/DataAccess/lu-dataaccess.js Parādīt failu

@@ -5,39 +5,14 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticate2Utils')
8
-        .factory('luDataAccess', ['$q', 'luRequest', function ($q, luRequest) {
8
+        .factory('luDataAccess', [function () {
9 9
 
10 10
             var luDataAccess = {};
11 11
 
12
-            luDataAccess.create = function (entry_point) {
13
-                var da = {};
12
+            luDataAccess.create = function () {
13
+                var DataAccess = {};
14 14
 
15
-                da.entry_point = entry_point;
16
-                if (da.entry_point.substr(-1) !== '/') {
17
-                    da.entry_point += '/';
18
-                }
19
-
20
-                da.get = function(url, dataGet, promise)
21
-                {
22
-                    return luRequest.get(da.entry_point + url, dataGet, promise);
23
-                };
24
-
25
-                da.post = function(url, dataGet, dataPost, promise)
26
-                {
27
-                    return luRequest.post(da.entry_point + url, dataGet, dataPost, promise);
28
-                };
29
-
30
-                da.put = function(url, dataGet, dataPost, promise)
31
-                {
32
-                    return luRequest.put(da.entry_point + url, dataGet, dataPost, promise);
33
-                };
34
-
35
-                da.delete = function(url, dataGet, dataPost, promise)
36
-                {
37
-                    return luRequest.delete(da.entry_point + url, dataGet, dataPost, promise);
38
-                };
39
-
40
-                return da;
15
+                return DataAccess;
41 16
             };
42 17
 
43 18
             return luDataAccess;

+ 21
- 14
src/DataAccess/lu-request.js Parādīt failu

@@ -32,8 +32,8 @@
32 32
             function reject(deferred, data, status, luBusyDbo)
33 33
             {
34 34
                 var obj = {
35
-                    Data: data,
36
-                    Status: status
35
+                    data: data,
36
+                    status: status
37 37
                 };
38 38
                 deferred.reject(obj);
39 39
                 if (luBusyDbo != null) {
@@ -45,7 +45,7 @@
45 45
             {
46 46
                 deferred.resolve(data);
47 47
                 if (luBusyDbo != null) {
48
-                    luBusyBusiness.resolve(luBusyDbo, data);
48
+                    luBusyBusiness.resolve(luBusyDbo);
49 49
                 }
50 50
             }
51 51
 
@@ -62,26 +62,33 @@
62 62
                     url: url,
63 63
                     method: method,
64 64
                     params: dataGet,
65
-                    data: dataPost == null ? null : $.param(dataPost),
65
+                    data: dataPost,
66 66
                     headers: {
67 67
                         'Content-Type': "application/json"
68 68
                     }
69 69
                 };
70 70
 
71 71
                 $http(params)
72
-                    .success(function (result, status) {
73
-                        if (result == null || result.Message != null) {
74
-                            var message = result == null ? "Failed to parse response" : result.Message;
75
-                            reject(deferred, message, status, luBusyDbo);
72
+                    .then(function (response) {
73
+                        var result = response.data;
74
+                        var status = response.status;
75
+                        if (result == null) {
76
+                            reject(deferred, "Failed to parse response", status, luBusyDbo);
77
+                        }
78
+                        else if (result.message != null) {
79
+                            reject(deferred, result.message, status, luBusyDbo);
76 80
                         }
77 81
                         else {
78
-                            resolve(deferred, result.Data, luBusyDbo);
82
+                            resolve(deferred, result.data, luBusyDbo);
83
+                        }
84
+                    }, function (response) {
85
+                        var result = response.data;
86
+                        var status = response.status;
87
+                        if (result == null) {
88
+                            reject(deferred, "Failed to parse response", status, luBusyDbo);
79 89
                         }
80
-                    })
81
-                    .error(function (result, status) {
82
-                        if (result == null || result.Message != null) {
83
-                            var message = result == null ? "Failed to parse response" : result.Message;
84
-                            reject(deferred, message, status, luBusyDbo);
90
+                        else if (result.message != null) {
91
+                            reject(deferred, result.message, status, luBusyDbo);
85 92
                         }
86 93
                         else {
87 94
                             reject(deferred, result, status, luBusyDbo);

+ 45
- 0
src/DataAccess/lu-webapi-crud-dataaccess.js Parādīt failu

@@ -0,0 +1,45 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luWebApiCrudDataAccess', ['luWebApiDataAccess', function (luWebApiDataAccess) {
9
+
10
+            var luWebApiCrudDataAccess = {};
11
+
12
+            luWebApiCrudDataAccess.create = function (entry_point) {
13
+                var DataAccess = luWebApiDataAccess.create(entry_point);
14
+
15
+                DataAccess.getSingleById = function (id, luBusyDbo) {
16
+                    return DataAccess.get(id, null, luBusyDbo);
17
+                };
18
+
19
+                DataAccess.getMultiple = function (orderBy, page, perPage, luBusyDbo) {
20
+                    return DataAccess.get('', {
21
+                        orderBy: orderBy,
22
+                        page: page,
23
+                        perPage: perPage
24
+                    }, luBusyDbo);
25
+                };
26
+
27
+                DataAccess.addDbo = function(data, luBusyDbo) {
28
+                    return DataAccess.post('', null, data, luBusyDbo);
29
+                };
30
+
31
+                DataAccess.editSingleByIdDbo = function(id, data, luBusyDbo) {
32
+                    return DataAccess.post(id, null, data, luBusyDbo);
33
+                };
34
+
35
+                DataAccess.deleteDbo = function(id, luBusyDbo) {
36
+                    return DataAccess.delete(id, null, null, luBusyDbo);
37
+                };
38
+
39
+                return DataAccess;
40
+            };
41
+
42
+            return luWebApiCrudDataAccess;
43
+
44
+        }]);
45
+})();

+ 46
- 0
src/DataAccess/lu-webapi-dataaccess.js Parādīt failu

@@ -0,0 +1,46 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luWebApiDataAccess', ['luDataAccess', 'luRequest', function (luDataAccess, luRequest) {
9
+
10
+            var luWebApiDataAccess = {};
11
+
12
+            luWebApiDataAccess.create = function (entry_point) {
13
+                var DataAccess = luDataAccess.create();
14
+
15
+                DataAccess.entry_point = entry_point;
16
+                if (DataAccess.entry_point.substr(-1) !== '/') {
17
+                    DataAccess.entry_point += '/';
18
+                }
19
+
20
+                DataAccess.get = function(url, dataGet, luBusyDbo)
21
+                {
22
+                    return luRequest.get(DataAccess.entry_point + url, dataGet, luBusyDbo);
23
+                };
24
+
25
+                DataAccess.post = function(url, dataGet, dataPost, luBusyDbo)
26
+                {
27
+                    return luRequest.post(DataAccess.entry_point + url, dataGet, dataPost, luBusyDbo);
28
+                };
29
+
30
+                DataAccess.put = function(url, dataGet, dataPost, luBusyDbo)
31
+                {
32
+                    return luRequest.put(DataAccess.entry_point + url, dataGet, dataPost, luBusyDbo);
33
+                };
34
+
35
+                DataAccess.delete = function(url, dataGet, dataPost, luBusyDbo)
36
+                {
37
+                    return luRequest.delete(DataAccess.entry_point + url, dataGet, dataPost, luBusyDbo);
38
+                };
39
+
40
+                return DataAccess;
41
+            };
42
+
43
+            return luWebApiDataAccess;
44
+
45
+        }]);
46
+})();

Notiek ielāde…
Atcelt
Saglabāt