|
@@ -5,8 +5,8 @@
|
5
|
5
|
(function () {
|
6
|
6
|
'use strict';
|
7
|
7
|
angular.module('luticate2Utils')
|
8
|
|
- .factory('luWebApiCrudDataAccess', ['luWebApiDataAccess', '$q', 'luUtilsDataAccess',
|
9
|
|
- function (luWebApiDataAccess, $q, luUtilsDataAccess) {
|
|
8
|
+ .factory('luWebApiCrudDataAccess', ['luWebApiDataAccess', '$q', 'luUtilsDataAccess', 'luDataInitializer',
|
|
9
|
+ function (luWebApiDataAccess, $q, luUtilsDataAccess, luDataInitializer) {
|
10
|
10
|
|
11
|
11
|
var luWebApiCrudDataAccess = {};
|
12
|
12
|
|
|
@@ -16,6 +16,31 @@
|
16
|
16
|
DataAccess.OP_EDIT = 'OP_EDIT';
|
17
|
17
|
DataAccess.OP_ADD = 'OP_ADD';
|
18
|
18
|
|
|
19
|
+ DataAccess.TYPE_DBO = 'TYPE_DBO';
|
|
20
|
+ DataAccess.TYPE_MODEL = 'TYPE_MODEL';
|
|
21
|
+
|
|
22
|
+ DataAccess.defaultDbo = {
|
|
23
|
+ id: null,
|
|
24
|
+ createdAt: null,
|
|
25
|
+ updatedAt: null,
|
|
26
|
+ toString: function()
|
|
27
|
+ {
|
|
28
|
+ return this.id;
|
|
29
|
+ }
|
|
30
|
+ };
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+ DataAccess.modelInitializer = luDataInitializer.create(function(model, op)
|
|
34
|
+ {
|
|
35
|
+ return DataAccess.initModel(model, op);
|
|
36
|
+ });
|
|
37
|
+
|
|
38
|
+ DataAccess.dboInitializer = luDataInitializer.create(function(dbo, type)
|
|
39
|
+ {
|
|
40
|
+ return DataAccess.initDbo(dbo, type);
|
|
41
|
+ });
|
|
42
|
+
|
|
43
|
+
|
19
|
44
|
DataAccess._initModel = function(model, op)
|
20
|
45
|
{
|
21
|
46
|
if (model == null) {
|
|
@@ -35,65 +60,21 @@
|
35
|
60
|
return DataAccess._initModel(model, op);
|
36
|
61
|
};
|
37
|
62
|
|
38
|
|
- DataAccess.initListModel = function(list, op)
|
39
|
|
- {
|
40
|
|
- var d = [];
|
41
|
|
- for (var i = 0; i < list.length; ++i) {
|
42
|
|
- d.push(DataAccess.initModel(list[i], op));
|
43
|
|
- }
|
44
|
|
- return d;
|
45
|
|
- };
|
46
|
63
|
|
47
|
|
- DataAccess.initPaginatedModel = function(data, op)
|
|
64
|
+ DataAccess._initDbo = function(model, type)
|
48
|
65
|
{
|
49
|
|
- var d = {
|
50
|
|
- count: data.count,
|
51
|
|
- data: DataAccess.initListModel(data.data, op)
|
52
|
|
- };
|
53
|
|
- return d;
|
54
|
|
- };
|
55
|
|
-
|
56
|
|
- DataAccess.thenInitModel = function(promise, op)
|
57
|
|
- {
|
58
|
|
- var deferred = $q.defer();
|
59
|
|
- promise.then(function(data)
|
60
|
|
- {
|
61
|
|
- deferred.resolve(DataAccess.initModel(data, op));
|
62
|
|
- }, deferred.reject);
|
63
|
|
- return deferred.promise;
|
64
|
|
- };
|
65
|
|
-
|
66
|
|
- DataAccess.thenInitListModel = function(promise, op)
|
67
|
|
- {
|
68
|
|
- var deferred = $q.defer();
|
69
|
|
- promise.then(function(data)
|
70
|
|
- {
|
71
|
|
- deferred.resolve(DataAccess.initListModel(data, op));
|
72
|
|
- }, deferred.reject);
|
73
|
|
- return deferred.promise;
|
|
66
|
+ if (model == null) {
|
|
67
|
+ return null;
|
|
68
|
+ }
|
|
69
|
+ var dbo = DataAccess.extendDeep({}, DataAccess.defaultDbo, model);
|
|
70
|
+ dbo.createdAt = luUtilsDataAccess.stringToMomentDateTime(dbo.createdAt);
|
|
71
|
+ dbo.updatedAt = luUtilsDataAccess.stringToMomentDateTime(dbo.updatedAt);
|
|
72
|
+ return dbo;
|
74
|
73
|
};
|
75
|
74
|
|
76
|
|
- DataAccess.thenInitPaginatedModel = function(promise, op)
|
|
75
|
+ DataAccess.initDbo = function(model, type)
|
77
|
76
|
{
|
78
|
|
- var deferred = $q.defer();
|
79
|
|
- promise.then(function(data)
|
80
|
|
- {
|
81
|
|
- deferred.resolve(DataAccess.initPaginatedModel(data, op));
|
82
|
|
- }, deferred.reject);
|
83
|
|
- return deferred.promise;
|
84
|
|
- };
|
85
|
|
-
|
86
|
|
-
|
87
|
|
-
|
88
|
|
-
|
89
|
|
- DataAccess.defaultDbo = {
|
90
|
|
- id: null,
|
91
|
|
- createdAt: null,
|
92
|
|
- updatedAt: null,
|
93
|
|
- toString: function()
|
94
|
|
- {
|
95
|
|
- return this.id;
|
96
|
|
- }
|
|
77
|
+ return DataAccess._initDbo(model, type);
|
97
|
78
|
};
|
98
|
79
|
|
99
|
80
|
DataAccess.extendDeep = function extendDeep(dst) {
|
|
@@ -110,98 +91,34 @@
|
110
|
91
|
});
|
111
|
92
|
return dst;
|
112
|
93
|
};
|
113
|
|
-
|
114
|
|
- DataAccess._initDbo = function(model)
|
115
|
|
- {
|
116
|
|
- if (model == null) {
|
117
|
|
- return null;
|
118
|
|
- }
|
119
|
|
- var dbo = DataAccess.extendDeep({}, DataAccess.defaultDbo, model);
|
120
|
|
- dbo.createdAt = luUtilsDataAccess.stringToMomentDateTime(dbo.createdAt);
|
121
|
|
- dbo.updatedAt = luUtilsDataAccess.stringToMomentDateTime(dbo.updatedAt);
|
122
|
|
- return dbo;
|
123
|
|
- };
|
124
|
|
-
|
125
|
|
- DataAccess.initDbo = function(model)
|
126
|
|
- {
|
127
|
|
- return DataAccess._initDbo(model);
|
128
|
|
- };
|
129
|
|
-
|
130
|
|
- DataAccess.initListDbo = function(list)
|
131
|
|
- {
|
132
|
|
- var d = [];
|
133
|
|
- for (var i = 0; i < list.length; ++i) {
|
134
|
|
- d.push(DataAccess.initDbo(list[i]));
|
135
|
|
- }
|
136
|
|
- return d;
|
137
|
|
- };
|
138
|
|
-
|
139
|
|
- DataAccess.initPaginatedDbo = function(data)
|
140
|
|
- {
|
141
|
|
- var d = {
|
142
|
|
- count: data.count,
|
143
|
|
- data: DataAccess.initListDbo(data.data)
|
144
|
|
- };
|
145
|
|
- return d;
|
146
|
|
- };
|
147
|
|
-
|
148
|
|
- DataAccess.thenInitDbo = function(promise)
|
149
|
|
- {
|
150
|
|
- var deferred = $q.defer();
|
151
|
|
- promise.then(function(data)
|
152
|
|
- {
|
153
|
|
- deferred.resolve(DataAccess.initDbo(data));
|
154
|
|
- }, deferred.reject);
|
155
|
|
- return deferred.promise;
|
156
|
|
- };
|
157
|
|
-
|
158
|
|
- DataAccess.thenInitListDbo = function(promise)
|
159
|
|
- {
|
160
|
|
- var deferred = $q.defer();
|
161
|
|
- promise.then(function(data)
|
162
|
|
- {
|
163
|
|
- deferred.resolve(DataAccess.initListDbo(data));
|
164
|
|
- }, deferred.reject);
|
165
|
|
- return deferred.promise;
|
166
|
|
- };
|
167
|
|
-
|
168
|
|
- DataAccess.thenInitPaginatedDbo = function(promise)
|
169
|
|
- {
|
170
|
|
- var deferred = $q.defer();
|
171
|
|
- promise.then(function(data)
|
172
|
|
- {
|
173
|
|
- deferred.resolve(DataAccess.initPaginatedDbo(data));
|
174
|
|
- }, deferred.reject);
|
175
|
|
- return deferred.promise;
|
176
|
|
- };
|
177
|
94
|
|
178
|
95
|
|
179
|
96
|
|
180
|
97
|
DataAccess.getSingleById = function (id, luBusyGroups) {
|
181
|
|
- return DataAccess.thenInitDbo(DataAccess.get(id, null, luBusyGroups));
|
|
98
|
+ return DataAccess.dboInitializer.thenInitData(DataAccess.get(id, null, luBusyGroups), DataAccess.TYPE_MODEL);
|
182
|
99
|
};
|
183
|
100
|
|
184
|
101
|
DataAccess.getMultiple = function (orderBy, filter, page, perPage, luBusyGroups) {
|
185
|
|
- return DataAccess.thenInitPaginatedDbo(DataAccess.get('', {
|
|
102
|
+ return DataAccess.dboInitializer.thenInitPaginatedData(DataAccess.get('', {
|
186
|
103
|
orderBy: orderBy,
|
187
|
104
|
filter: filter,
|
188
|
105
|
page: page,
|
189
|
106
|
perPage: perPage
|
190
|
|
- }, luBusyGroups));
|
|
107
|
+ }, luBusyGroups), DataAccess.TYPE_MODEL);
|
191
|
108
|
};
|
192
|
109
|
|
193
|
110
|
DataAccess.addDbo = function(data, luBusyGroups) {
|
194
|
|
- var model = DataAccess.initModel(data, DataAccess.OP_ADD);
|
195
|
|
- return DataAccess.thenInitDbo(DataAccess.post('', null, model, luBusyGroups));
|
|
111
|
+ var model = DataAccess.modelInitializer.initData(data, DataAccess.OP_ADD);
|
|
112
|
+ return DataAccess.dboInitializer.thenInitData(DataAccess.post('', null, model, luBusyGroups), DataAccess.TYPE_MODEL);
|
196
|
113
|
};
|
197
|
114
|
|
198
|
115
|
DataAccess.editSingleByIdDbo = function(id, data, luBusyGroups) {
|
199
|
|
- var model = DataAccess.initModel(data, DataAccess.OP_EDIT);
|
200
|
|
- return DataAccess.thenInitDbo(DataAccess.post(id, null, model, luBusyGroups));
|
|
116
|
+ var model = DataAccess.modelInitializer.initData(data, DataAccess.OP_EDIT);
|
|
117
|
+ return DataAccess.dboInitializer.thenInitData(DataAccess.post(id, null, model, luBusyGroups), DataAccess.TYPE_MODEL);
|
201
|
118
|
};
|
202
|
119
|
|
203
|
120
|
DataAccess.deleteDbo = function(id, luBusyGroups) {
|
204
|
|
- return DataAccess.thenInitDbo(DataAccess.delete(id, null, null, luBusyGroups));
|
|
121
|
+ return DataAccess.dboInitializer.thenInitData(DataAccess.delete(id, null, null, luBusyGroups), DataAccess.TYPE_MODEL);
|
205
|
122
|
};
|
206
|
123
|
|
207
|
124
|
return DataAccess;
|