Skip to content

Commit f28e7dc

Browse files
Merge pull request #12 from dreamfactorysoftware/develop
Wrap post and put requests data in resource
2 parents 554d905 + 446bba6 commit f28e7dc

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ angular.module('your-app', [ 'ngResource' ])
135135
'$resource',
136136

137137
function ($resource) {
138-
return $resource('/api/v2/_table/Model', {
138+
return $resource('/api/v2/_table/Model', {}, {
139139
query: {
140140
method: 'GET',
141141
isArray: false // true if response is an array

add_angular.dfpkg

166 Bytes
Binary file not shown.

add_angular.zip

166 Bytes
Binary file not shown.

add_angular/app/app.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ angular.module('addressbook', [
1212

1313
])
1414

15-
.constant('INSTANCE_URL', '')
15+
.constant('INSTANCE_URL', 'https://dreamfactory:8888')
1616

17-
.constant('APP_API_KEY', 'b6b16dab500f8c9649e365410200a09ad30dc2b3a202f56611d9f6e98f7729c0')
17+
.constant('APP_API_KEY', '0c7b9f992741c6119c1614557615490080e8187199db589d33d0d35127bcb74a')
1818

1919
.run([
2020
'$cookies', 'APP_API_KEY', '$http', '$rootScope', '$window',
@@ -68,18 +68,31 @@ angular.module('addressbook', [
6868

6969
request: function (config) {
7070

71+
var ignoreWrapping = false;
72+
73+
if (config.url.indexOf ('/user/register') > -1 || config.url.indexOf ('/user/session') > -1) {
74+
ignoreWrapping = true;
75+
}
76+
7177
// Append instance url before every api call
7278
if (config.url.indexOf('/api/v2') > -1) {
7379
config.url = INSTANCE_URL + config.url;
80+
81+
if ((config.method == 'POST' || config.method == 'PUT' || config.method == 'PATCH') && !ignoreWrapping) {
82+
var data;
83+
if (Array.isArray(config.data)) {
84+
config.data = { resource: config.data };
85+
} else {
86+
config.data = { resource: [config.data] };
87+
}
88+
}
7489
};
7590

7691
// delete x-dreamfactory-session-token header if login
7792
if (config.method.toLowerCase() === 'post' && config.url.indexOf('/api/v2/user/session') > -1) {
7893
delete config.headers['X-DreamFactory-Session-Token'];
7994
}
8095

81-
console.log(config);
82-
8396
return config;
8497
},
8598

add_angular/app/contact-info/contact-info.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ angular.module('contact-info', [
6969

7070

7171
$scope.addEditContactInfo = function (ev, item) {
72+
console.log('Contact info')
7273
$mdDialog.show({
7374
controller: 'ContactInfoUpdateCtrl',
7475
templateUrl: 'app/contact-info/contact-info-add-edit.html',
7576
parent: angular.element(document.body),
7677
targetEvent: ev,
7778
locals: {
78-
contactInfo: item || { contact_id: $route.current.params.id, id: '' }
79+
contactInfo: item || { contact_id: $route.current.params.id }
7980
}
8081
}).then(function () {
8182
$scope.loadData();
@@ -93,6 +94,9 @@ angular.module('contact-info', [
9394
function ($mdScope, $mdDialog, ContactInfo, contactInfo, $mdToast) {
9495
$mdScope.contactInfo = angular.copy(contactInfo);
9596
$mdScope.info_types = [ 'home', 'work', 'mobile' ];
97+
if ($mdScope.contactInfo.id === '') {
98+
delete $mdScope.contactInfo;
99+
}
96100

97101
$mdScope.submit = function () {
98102
if (!$mdScope.contactInfo.id) {

add_angular/app/contacts/contacts.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ angular.module('contacts', [
2929
controller : 'ContactsItemCtrl',
3030
resolve : {
3131
contact: function () {
32-
return { id: null };
32+
return { };
3333
},
3434
groups: function (Groups) {
3535
return Groups.query().$promise;
@@ -201,7 +201,7 @@ angular.module('contacts', [
201201
parent: angular.element(document.body),
202202
targetEvent: ev,
203203
locals: {
204-
contactInfo: item || { contact_id: $route.current.params.id, id: '' }
204+
contactInfo: item || { contact_id: $route.current.params.id }
205205
}
206206
}).then(function () {
207207
$scope.loadData();

add_angular/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h3>
6868
<md-divider></md-divider>
6969
</div>
7070

71-
<h5 flex="" class="sticky-bottom">Angular Addressbook v1.0.2</h5>
71+
<h5 flex="" class="sticky-bottom">Angular Addressbook v1.0.4</h5>
7272
</md-content>
7373
</md-sidenav>
7474

0 commit comments

Comments
 (0)