|POST|Content-Type,Authorization|true
17 | *
18 | **/
19 | .factory('NodeResource', NodeResource);
20 |
21 | /**
22 | * Manually identify dependencies for minification-safe code
23 | *
24 | **/
25 | NodeResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'NodeResourceConstant', 'NodeChannel'];
26 |
27 | /** @ngInject */
28 | function NodeResource($http, BaseResource, DrupalApiConstant, NodeResourceConstant, NodeChannel) {
29 |
30 | //setup and return service
31 | var nodeResourceService = {
32 | //CRUD operations
33 | retrieve : retrieve,
34 | create : create,
35 | update : update,
36 | delete : _delete,
37 | index : index,
38 | //Actions
39 | files : files,
40 | comments : comments,
41 | attachFile : attachFile
42 | };
43 |
44 | return nodeResourceService;
45 |
46 | ////////////
47 |
48 | /**
49 | * retrieve
50 | *
51 | * Retrieve a node
52 | *
53 | * Method: GET
54 | * Url: http://drupal_instance/api_endpoint/node/{NID}
55 | *
56 | * @params {Object} data The requests data
57 | * @key {Integer} nid NID of the node to be loaded, required:true, source:path
58 | *
59 | * @return {Promise} A node object
60 | *
61 | **/
62 | function retrieve(data) {
63 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid;
64 | return BaseResource.retrieve( retrievePath,NodeChannel.pubRetrieveConfirmed, NodeChannel.pubRetrieveFailed);
65 | };
66 |
67 | /**
68 | * create
69 | *
70 | * Create a new node.
71 | * This function uses drupal_form_submit() and as such expects all input to match
72 | * the submitting form in question.
73 | *
74 | * Method: POST
75 | * Url: http://drupal_instance/api_endpoint/node
76 | *
77 | * @params {Object} data The data of the node to create, required:true, source:post body
78 | *
79 | *
80 | * @return {Promise} The node object of the newly created node.
81 | *
82 | **/
83 | function create(data) {
84 |
85 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath,
86 | createData = {
87 | node : data
88 | };
89 |
90 | return BaseResource.create( createData, createPath, NodeChannel.pubCreateConfirmed, NodeChannel.pubCreateFailed);
91 |
92 | };
93 |
94 | /**
95 | * update
96 | *
97 | * Update a node
98 | *
99 | * Method: PUT
100 | * Url: http://drupal_instance/api_endpoint/node/{NID}
101 | *
102 | * @params {Object} data The requests data
103 | * @key {Integer} nid Unique identifier for this node, required:true, source:path
104 | * @key {Array} data The node object with updated information, required:true, source:post body
105 | *
106 | * @return {Promise}
107 | *
108 | **/
109 | function update(data) {
110 |
111 | var updatePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid;
112 |
113 | delete data.nid;
114 | var updateData = { node: data };
115 |
116 |
117 | return BaseResource.update( updateData, updatePath, NodeChannel.pubUpdateConfirmed, NodeChannel.pubUpdateFailed);
118 |
119 | };
120 |
121 | /**
122 | * delete
123 | *
124 | * Delete a node
125 | *
126 | * Method: DELETE
127 | * Url: http://drupal_instance/api_endpoint/node/{NID}
128 | *
129 | * @params {Object} data the requests data
130 | * @key {Integer} nid The id of the node to delete, required:true, source:path
131 | *
132 | * @return {Promise}
133 | *
134 | **/
135 | function _delete(data) {
136 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid
137 | return BaseResource.delete(deletePath, NodeChannel.pubDeleteConfirmed, NodeChannel.pubDeleteFailed);
138 | };
139 |
140 | /**
141 | * index
142 | *
143 | * List all nodes
144 | *
145 | * Method: GET
146 | * Url: http://drupal_instance/api_endpoint/node
147 | *
148 | * @params {Object} data the requests data
149 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param
150 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param
151 | * @key {String} fields The fields to get., required:false, source:param
152 | * @key {Array} parameters Parameters, required:false, source:param
153 | *
154 | *
155 | * @return {Promise}
156 | *
157 | **/
158 | function index(data) {
159 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/';
160 | return BaseResource.index(data, indexPath, NodeChannel.pubIndexConfirmed, NodeChannel.pubIndexFailed);
161 | };
162 |
163 | /**
164 | * files
165 | *
166 | * This method returns files associated with a node.
167 | *
168 | * Method: GET
169 | * Url: http://drupal_instance/api_endpoint/node/files/{NID}/{FILE_CONTENTS}/{IMAGE_STYLES}
170 | *
171 | * @params {Object} data the requests data
172 | * @key {Integer} nid The nid of the node whose files we are getting, required:true, source:path
173 | * @key {Integer} file_contents To return file contents or not., required:false, source:path
174 | * @key {Integer} image_styles To return image styles or not., required:false, source:path
175 | *
176 | * @return {Promise}
177 | *
178 | **/
179 | function files(data) {
180 | var filesPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid + '/' + NodeResourceConstant.actions.files;
181 |
182 | //set file_contents value
183 | filesPath += '/'+( (data.file_contents)?1:0);
184 | //set image_styles value
185 | filesPath += '/'+( (data.image_styles)?1:0);
186 |
187 | var requestConfig = {
188 | url : filesPath,
189 | method : 'GET'
190 | }
191 |
192 | return BaseResource.request(requestConfig, NodeChannel.pubFilesConfirmed, NodeChannel.pubFilesFailed);
193 |
194 | };
195 |
196 | /**
197 | * comments
198 | *
199 | * This method returns the number of new comments on a given node.
200 | *
201 | * Method: GET
202 | * Url: http://drupal_instance/api_endpoint/node/comments/{NID}
203 | *
204 | * @params {Object} data the requests data
205 | * @key {Integer} nid The node id to load comments for., required:true, source:path
206 | * @key {Integer} count Number of comments to load., required:false, source:param
207 | * @key {Integer} offset If count is set to non-zero value, you can pass also non-zero value for start. For example to get comments from 5 to 15, pass count=10 and start=5., required:false, source:param
208 | *
209 | * @return {Promise}
210 | *
211 | **/
212 | function comments(data) {
213 |
214 | var commentsPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid + '/' + NodeResourceConstant.actions.comments,
215 | requestConfig = {
216 | url : commentsPath,
217 | method : 'GET'
218 | };
219 |
220 | if( data.count || data.count == 0 || data.offset || data.offset == 0 ) {
221 | commentsPath += '?';
222 | }
223 |
224 | //optional data
225 | if(data.count || data.count == 0) {
226 | commentsPath += 'count='+data.count+',';
227 | }
228 | //@TODO check if we need count set to non-zero to use offset value
229 | if(data.offset || data.offset == 0 ) {
230 | commentsPath += 'offset='+data.offset+',';
231 | }
232 |
233 | return BaseResource.request(requestConfig, NodeChannel.pubCommentsConfirmed, NodeChannel.pubCommentsFailed);
234 |
235 | };
236 |
237 | /**
238 | * attachFile
239 | *
240 | * This method returns the number of new comments on a given node.
241 | *
242 | * Method: POST
243 | * Url: http://drupal_instance/api_endpoint/node/attach_file/{NID}
244 | *
245 | * @params {Object} data the requests data
246 | * @key {Integer} nid The nid of the node to attach a file to, required:true, source:path
247 | * @key {Sting} field_name The file field name, required:true, source:post body
248 | * @key {Integer} attach Attach the file(s) to the node. If FALSE, this clears ALL files attached, and attaches the files, required:false, source:post body
249 | * @key {Array} field_values The extra field values, required:false, source:post body
250 | *
251 | * @return {Promise}
252 | *
253 | **/
254 | function attachFile(data) {
255 | //@TODO check how it works
256 |
257 | var attachFilePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + NodeResourceConstant.resourcePath + '/' + data.nid + '/' + NodeResourceConstant.actions.attachFile,
258 | requestConfig = {
259 | url : attachFilePath,
260 | method : 'POST ',
261 | data : {
262 | field_name : field_name,
263 | attach : data.attach,
264 | field_values : data.field_values
265 | }
266 | };
267 |
268 | return BaseResource.request(attachFilePath, NodeChannel.pubAttachFileConfirmed, NodeChannel.pubAttachFileFailed);
269 | };
270 |
271 |
272 | };
273 |
274 | })();
275 |
--------------------------------------------------------------------------------
/src/resources/node/node.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for NodeResourceModules
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var NodeResourceConstant = {
10 |
11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal
12 | resourcePath : 'node',
13 | //actions of user resource
14 | actions : {
15 | //following actions are defined over their request method (GET, POST, PUT, DELETE) so they are commented out
16 | //retrieve : 'retrieve',
17 | //create : 'create',
18 | //update : 'update',
19 | //delete : 'delete',
20 | //index : 'index',
21 | //
22 | files : 'files',
23 | comments : 'comments',
24 | attach_file : 'attach_file'
25 | }
26 |
27 | };
28 |
29 | /**
30 | * Node Constant Modules
31 | */
32 | angular
33 | .module('d7-services.resources.node.resourceConstant', [])
34 | .constant("NodeResourceConstant", NodeResourceConstant);
35 |
36 | })();
37 |
--------------------------------------------------------------------------------
/src/resources/resources.bundle.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | /**
5 | * @ngdoc object
6 | * @name d7-services.resources:Resources
7 | * @description
8 | * This Module bundles all modules related to drupals resources
9 | * @requires d7-services.resources.comment:CommentBundle
10 | * @requires d7-services.resources.definition:DefinitionBundle
11 | * @requires d7-services.resources.file:FileBundle
12 | * @requires d7-services.resources.geocoder:GoecoderBundle
13 | * @requires d7-services.resources.menu:MenuBundle
14 | * @requires d7-services.resources.node:NodeBundle
15 | * @requires d7-services.resources.system:System
16 | * @requires d7-services.resources.taxonomy_term:TaxonomyTermBundle
17 | * @requires d7-services.resources.taxonomy_vocabulary:TaxonomyVocabularyBundle
18 | * @requires d7-services.resources.user:UserBundle
19 | * @requires d7-services.resources.views:ViewsBundle
20 | *
21 | */
22 | angular
23 | .module('d7-services.resources', [
24 | 'd7-services.resources.comment',
25 | 'd7-services.resources.definition',
26 | 'd7-services.resources.file',
27 | 'd7-services.resources.geocoder',
28 | 'd7-services.resources.menu',
29 | 'd7-services.resources.node',
30 | 'd7-services.resources.system',
31 | 'd7-services.resources.taxonomy_term',
32 | 'd7-services.resources.taxonomy_vocabulary',
33 | 'd7-services.resources.user',
34 | 'd7-services.resources.views'
35 | ]);
36 |
37 | })();
--------------------------------------------------------------------------------
/src/resources/system/system.bundle.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | /**
5 | * @ngdoc object
6 | * @name d7-services.resources.system:System
7 | * @description
8 | * This Module bundles all modules related to drupal system resource
9 | * @requires d7-services.resources.system.resourceConstant:SystemResourceConstant
10 | * @requires d7-services.resources.system.resource:SystemResource
11 | * @requires d7-services.resources.system.channelConstant:SystemChannelConstant
12 | * @requires d7-services.resources.system.channel:SystemChannel
13 | */
14 | angular.module('d7-services.resources.system', [
15 | 'd7-services.resources.system.resourceConstant',
16 | 'd7-services.resources.system.resource',
17 | 'd7-services.resources.system.channelConstant',
18 | 'd7-services.resources.system.channel']);
19 | })();
--------------------------------------------------------------------------------
/src/resources/system/system.channelConstant.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | var SystemChannelConstant = {
5 | // Connect action
6 | connectConfirmed: 'event:drupal-system-connectConfirmed',
7 | connectFailed: 'event:drupal-system-connectFailed',
8 | // Get variable action
9 | getVariableConfirmed: 'event:drupal-system-getVariableConfirmed',
10 | getVariableFailed: 'event:drupal-system-getVariableFailed',
11 | // Set variable action
12 | setVariableConfirmed: 'event:drupal-system-setVariableConfirmed',
13 | setVariableFailed: 'event:drupal-system-setVariableFailed',
14 | // Del variable action
15 | delVariableConfirmed: 'event:drupal-system-delVariableConfirmed',
16 | delVariableFailed: 'event:drupal-system-delVariableFailed'
17 | };
18 |
19 | /**
20 | * @ngdoc object
21 | * @name d7-services.resources.system.channelConstant:SystemChannelConstant
22 | * @description
23 | * Constant for the System channel
24 | * @property {string} connectConfirmed - event name of connect confirm event
25 | * @property {string} connectFailed - event name of connect failed event
26 |
27 | * @property {string} getVariableConfirmed - event name of getVariable confirm event
28 | * @property {string} getVariableFailed - event name of getVariable failed event
29 |
30 | * @property {string} setVariableConfirmed - event name of setVariable confirm event
31 | * @property {string} setVariableFailed - event name of setVariable failed event
32 |
33 | * @property {string} delVariableConfirmed - event name of delVariable confirm event
34 | * @property {string} delVariableFailed - event name of delVariable failed event
35 | *
36 | * @example
37 | *
38 | * SystemChannelConstant is editable in config phase
39 | *
40 | * angular
41 | * .module('myModule', ['d7-services.resources.system'])
42 | * .config(function (SystemChannelConstant) {
43 | * SystemChannelConstant.connectConfirmed = 'MY_EVENT_NAME';
44 | * }
45 | *
46 | *
47 | * SystemChannelConstant injectable
48 | *
49 | * angular
50 | * .module('myModule', ['d7-services.resources.system'])
51 | * .controller(function (SystemChannelConstant) {
52 | * console.log(SystemChannelConstant.connectConfirmed);
53 | * }
54 | *
55 | */
56 | angular
57 | .module('d7-services.resources.system.channelConstant', [])
58 | .constant("SystemChannelConstant", SystemChannelConstant);
59 |
60 | })();
61 |
--------------------------------------------------------------------------------
/src/resources/system/system.resource.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | /**
5 | * @ngdoc service
6 | * @name d7-services.resources.system.resource:SystemResource
7 | * @description
8 | * This service mirrors the Drupal system resource of the services 3.x module.
9 | * To use this you have to set following line in your Drupal CORS module settings
10 | * @requires d7-services.resources.system.resourceConstant:SystemResourceConstant
11 | * @requires d7-services.resources.system.channelConstant:SystemChannelConstant
12 | * @requires d7-services.commons.baseResource:BaseResource
13 | * @requires d7-services.commons.configurations:DrupalApiConstant
14 | */
15 | angular
16 | .module('d7-services.resources.system.resource', ['d7-services.commons.configurations', 'd7-services.commons.baseResource', 'd7-services.resources.system.resourceConstant', 'd7-services.resources.system.channel'])
17 | .factory('SystemResource', SystemResource);
18 |
19 |
20 | SystemResource.$inject = ['DrupalApiConstant', 'BaseResource', 'SystemResourceConstant', 'SystemChannel'];
21 |
22 | /** @ngInject */
23 | function SystemResource(DrupalApiConstant, BaseResource, SystemResourceConstant, SystemChannel) {
24 |
25 | var systemResourceService = {
26 | connect: connect,
27 | get_variable: get_variable,
28 | set_variable: set_variable,
29 | del_variable: del_variable
30 | };
31 |
32 | return systemResourceService;
33 |
34 | ////////////
35 |
36 | /**
37 | * @ngdoc method
38 | * @name connect
39 | * @methodOf d7-services.resources.system.resource:SystemResource
40 | * @description
41 | * Returns the details of currently logged in user.
42 | *
43 | * Method: POST
44 | * Url: http://drupal_instance/api_endpoint/system/connect
45 | *
46 | * @returns {Promise} Object with session id, session name and a user object.
47 | *
48 | * @example
49 | *
50 | * performing a system connect request and handling data in promise callback
51 | *
52 | * angular
53 | * .module('myModule', ['d7-services.resources.system'])
54 | * .config(function (SystemResource) {
55 | * SystemResource.connect()
56 | * .then(
57 | * function(confirmData) {...},
58 | * function(failData) {...}
59 | * );
60 | * }
61 | *
62 | *
63 | * performing a system connect request and handling data in event callback
64 | *
65 | * angular
66 | * .module('myModule', ['d7-services.resources.system'])
67 | * .config(function ($scope, SystemResource, SystemChannel) {
68 | * SystemResource.connect();
69 | * //subscribe to confirm event
70 | * SystemChannel.subConnectConfirmed($scope, function(confirmData) {...});
71 | * //subscribe to fail event
72 | * SystemChannel.subConnectFailed($scope, function(failData) {...});
73 | * });
74 | *
75 | */
76 | function connect() {
77 |
78 | var connectPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + SystemResourceConstant.resourcePath + '/' + SystemResourceConstant.actions.connect,
79 | requestConfig = {
80 | method: 'POST',
81 | url: connectPath
82 | };
83 |
84 | return BaseResource.request(requestConfig, SystemChannel.pubConnectConfirmed, SystemChannel.pubConnectFailed);
85 |
86 | }
87 |
88 | /**
89 | * @ngdoc method
90 | * @name get_variable
91 | * @methodOf d7-services.resources.system.resource:SystemResource
92 | * @description
93 | * Returns a persistent variable.
94 | * Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.
95 | *
96 | * Method: POST
97 | * Url: http://drupal_instance/api_endpoint/system/get_variable
98 | *
99 | * @param {Object} data - The requests data
100 | * @param {String} data.name - The name of the variable to return, required:true, source:post body
101 | * @param {String} data._default - The default value to use if this variable has never been set, required:false, source:post body
102 | *
103 | * @returns {Promise} Object with session id, session name and a user object.
104 | *
105 | * @example
106 | *
107 | * performing a system get_variable request and handling data in promise callback
108 | *
109 | * angular
110 | * .module('myModule', ['d7-services.resources.system'])
111 | * .config(function (SystemResource) {
112 | * SystemResource.get_variable()
113 | * .then(
114 | * function(confirmData) {...},
115 | * function(failData) {...}
116 | * );
117 | * }
118 | *
119 | *
120 | * performing a system get_variable request and handling data in event callback
121 | *
122 | * angular
123 | * .module('myModule', ['d7-services.resources.system'])
124 | * .config(function ($scope, SystemResource, SystemChannel) {
125 | * SystemResource.get_variable();
126 | *
127 | * //subscribe to confirm event
128 | * SystemChannel.subGetVariableConfirmed($scope, function(confirmData) {...});
129 | * //subscribe to fail event
130 | * SystemChannel.subGetVariableFailed($scope, function(failData) {...});
131 | * });
132 | *
133 | *
134 | */
135 | function get_variable(data) {
136 |
137 | var getVariablePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + SystemResourceConstant.resourcePath + '/' + SystemResourceConstant.actions.get_variable,
138 | requestConfig = {
139 | method: 'POST',
140 | url: getVariablePath,
141 | data: {
142 | name: data.name
143 | }
144 | };
145 |
146 | if('default' in data) {
147 | requestConfig.data.default = data.default;
148 | }
149 |
150 | return BaseResource.request(requestConfig, SystemChannel.pubGetVariableConfirmed, SystemChannel.pubGetVariableFailed);
151 |
152 | }
153 |
154 | /**
155 | * @ngdoc method
156 | * @name set_variable
157 | * @methodOf d7-services.resources.system.resource:SystemResource
158 | * @description
159 | * Sets a persistent variable.
160 | * Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.
161 | *
162 | * The data object for this request looks something like this:
163 | * {
164 | * name : 'my_variable_name'
165 | * }
166 | *
167 | * Method: POST
168 | * Url: http://drupal_instance/api_endpoint/system/set_variable
169 | *
170 | * @param {Object} data - The requests data
171 | * @param {String} data.name - The name of the variable to set, required:true, source:post body
172 | * @param {String} data.value - The value to set. This can be any PHP data type; these functions take care of serialization as necessary, required:true, source:post body
173 | *
174 | * @returns {Promise} True if successful false if not
175 | *
176 | * @example
177 | *
178 | * performing a system set_variable request and handling data in promise callback
179 | *
180 | * angular
181 | * .module('myModule', ['d7-services.resources.system'])
182 | * .config(function (SystemResource) {
183 | * SystemResource.set_variable()
184 | * .then(
185 | * function(confirmData) {...},
186 | * function(failData) {...}
187 | * );
188 | * }
189 | *
190 | *
191 | * performing a system set_variable request and handling data in event callback
192 | *
193 | * angular
194 | * .module('myModule', ['d7-services.resources.system'])
195 | * .config(function ($scope, SystemResource, SystemChannel) {
196 | * SystemResource.set_variable({});
197 | *
198 | * //subscribe to confirm event
199 | * SystemChannel.subSetVariableConfirmed($scope, function(confirmData) {...});
200 | * //subscribe to fail event
201 | * SystemChannel.subSetVariableFailed($scope, function(failData) {...});
202 | * });
203 | *
204 | *
205 | */
206 | function set_variable(data) {
207 |
208 | var setVariablePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + SystemResourceConstant.resourcePath + '/' + SystemResourceConstant.actions.set_variable,
209 | requestConfig = {
210 | method: 'POST',
211 | url: setVariablePath,
212 | data: {
213 | name: data.name,
214 | value: data.value
215 | }
216 | };
217 |
218 | return BaseResource.request(requestConfig, SystemChannel.pubSetVariableConfirmed, SystemChannel.pubSetVariableFailed);
219 |
220 | }
221 |
222 | /**
223 | * @ngdoc method
224 | * @name del_variable
225 | * @methodOf d7-services.resources.system.resource:SystemResource
226 | * @description
227 | * Unsets a persistent variable.
228 | * Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.
229 | *
230 | * Method: POST
231 | * Url: http://drupal_instance/api_endpoint/system/del_variable
232 | *
233 | * @param {Object} data - The requests data
234 | * @param {String} data.name - The name of the variable to undefine, required:true, source:post body
235 | *
236 | *
237 | * @returns {Promise} True if successful false if not
238 | *
239 | * @example
240 | *
241 | * performing a system del_variable request and handling data in promise callback
242 | *
243 | * angular
244 | * .module('myModule', ['d7-services.resources.system'])
245 | * .config(function (SystemResource) {
246 | * SystemResource.del_variable({})
247 | * .then(
248 | * function(confirmData) {...},
249 | * function(failData) {...}
250 | * );
251 | * }
252 | *
253 | *
254 | * performing a system del_variable request and handling data in event callback
255 | *
256 | * angular
257 | * .module('myModule', ['d7-services.resources.system'])
258 | * .config(function ($scope, SystemResource, SystemChannel) {
259 | * SystemResource.del_variable({});
260 | *
261 | * //subscribe to confirm event
262 | * SystemChannel.subDelVariableConfirmed($scope, function(confirmData) {...});
263 | * //subscribe to fail event
264 | * SystemChannel.subDelVariableFailed($scope, function(failData) {...});
265 | * });
266 | *
267 | */
268 | function del_variable(data) {
269 |
270 | var delVariablePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + SystemResourceConstant.resourcePath + '/' + SystemResourceConstant.actions.del_variable,
271 | requestConfig = {
272 | method: 'POST',
273 | url: delVariablePath,
274 | data: {
275 | name: data.name
276 | }
277 | };
278 |
279 | return BaseResource.request(requestConfig, SystemChannel.pubDelVariableConfirmed, SystemChannel.pubDelVariableFailed);
280 |
281 | }
282 |
283 | }
284 |
285 | })();
--------------------------------------------------------------------------------
/src/resources/system/system.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;
2 | (function () {
3 | 'use strict';
4 |
5 | var SystemResourceConstant = {
6 | resourcePath: 'system',
7 | actions: {
8 | connect: 'connect',
9 | get_variable: 'get_variable',
10 | set_variable: 'set_variable',
11 | del_variable: 'del_variable'
12 | }
13 | };
14 |
15 | /**
16 | * @ngdoc object
17 | * @name d7-services.resources.system.resourceConstant:SystemResourceConstant
18 | * @description
19 | * Constant for the System resource
20 | * @property {string} resourcePath - This is the default alias of Drupal. If you set custom alisa override also this property.
21 | * @property {object} actions - Subpaths provided for this resource
22 | * @property {string} actions.connect - connect path
23 | * @property {string} actions.get_variable - get_variable path
24 | * @property {string} actions.del_variable - del_variable path
25 | *
26 | * @example
27 | *
28 | * SystemResourceConstant is editable in config phase
29 | *
30 | * angular
31 | * .module('myModule', ['d7-services.resources.system'])
32 | * .config(function (SystemResourceConstant) {
33 | * SystemResourceConstant.resourcePath = 'my/path';
34 | * }
35 | *
36 | *
37 | * SystemResourceConstant injectable
38 | *
39 | * angular
40 | * .module('myModule', ['d7-services.resources.system'])
41 | * .controller(function (SystemResourceConstant) {
42 | * console.log(SystemResourceConstant.resourcePath);
43 | * }
44 | *
45 | */
46 | angular
47 | .module('d7-services.resources.system.resourceConstant', [])
48 | .constant("SystemResourceConstant", SystemResourceConstant);
49 |
50 | })();
51 |
--------------------------------------------------------------------------------
/src/resources/taxonomy_term/taxonomy_term.bundle.js:
--------------------------------------------------------------------------------
1 | ;
2 | (function () {
3 | 'use strict';
4 |
5 | /**
6 | * @ngdoc object
7 | * @name d7-services.resources.taxonomy_term:TaxonomyTerm
8 | * @description
9 | * This Module bundles all modules related to drupal taxonomy_term resource
10 | * @requires d7-services.resources.taxonomy_term.resourceConstant:TaxonomyTermResourceConstant
11 | * @requires d7-services.resources.taxonomy_term.resource:TaxonomyTermResource
12 | * @requires d7-services.resources.taxonomy_term.channelConstant:TaxonomyTermChannelConstant
13 | * @requires d7-services.resources.taxonomy_term.channel:TaxonomyTermChannel
14 | */
15 | angular
16 | .module('d7-services.resources.taxonomy_term', [
17 | 'd7-services.resources.taxonomy_term.resourceConstant',
18 | 'd7-services.resources.taxonomy_term.resource',
19 | 'd7-services.resources.taxonomy_term.channelConstant',
20 | 'd7-services.resources.taxonomy_term.channel']);
21 | })();
--------------------------------------------------------------------------------
/src/resources/taxonomy_term/taxonomy_term.channelConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for TaxonomyTermChannel
6 | *
7 | * NOTE: if you want to change this constant do this in a config section of angular
8 | */
9 | var TaxonomyTermChannelConstant = {
10 | // Retrieve action
11 | retrieveConfirmed : 'event:drupal-taxonomy_term-retrieveConfirmed',
12 | retrieveFailed : 'event:drupal-taxonomy_term-retrieveFailed',
13 | // Create action
14 | createConfirmed : 'event:drupal-taxonomy_term-createConfirmed',
15 | createFailed : 'event:drupal-taxonomy_term-createFailed',
16 | // Update action
17 | updateConfirmed : 'event:drupal-taxonomy_term-updateConfirmed',
18 | updateFailed : 'event:drupal-taxonomy_term-updateFailed',
19 | // Delete action
20 | deleteConfirmed : 'event:drupal-taxonomy_term-deleteConfirmed',
21 | deleteFailed : 'event:drupal-taxonomy_term-deleteFailed',
22 | // Index action
23 | indexConfirmed : 'event:drupal-taxonomy_term-indexConfirmed',
24 | indexFailed : 'event:drupal-taxonomy_term-indexFailed',
25 | // SelectNodes action
26 | selectNodesConfirmed : 'event:drupal-taxonomy_term-selectNodesConfirmed',
27 | selectNodesFailed : 'event:drupal-taxonomy_term-selectNodesFailed',
28 |
29 | };
30 |
31 | /**
32 | * TaxonomyTerm Channel Constant
33 | */
34 | angular
35 | .module('d7-services.resources.taxonomy_term.channelConstant', [])
36 | .constant("TaxonomyTermChannelConstant", TaxonomyTermChannelConstant);
37 |
38 | })();
39 |
--------------------------------------------------------------------------------
/src/resources/taxonomy_term/taxonomy_term.resource.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * TaxonomyTerm Resource Modules
6 | *
7 | * see sourcecode in services/resources/taxonomy_term_resource.inc
8 | **/
9 | angular.module('d7-services.resources.taxonomy_term.resource', ['d7-services.commons.configurations', 'd7-services.resources.taxonomy_term.resourceConstant', 'd7-services.resources.taxonomy_term.channel', 'd7-services.commons.baseResource'])
10 |
11 | /**
12 | * TaxonomyTermResource
13 | *
14 | * This service mirrors the Drupal taxonomy_term resource of the services 3.x module.
15 | * To use this you have to set following line in your Drupal CORS module settings
16 | * your_api_endpoint/taxonomy_term/*||POST|Content-Type,Authorization|true
17 | *
18 | **/
19 | .factory('TaxonomyTermResource', TaxonomyTermResource);
20 |
21 | /**
22 | * Manually identify dependencies for minification-safe code
23 | *
24 | **/
25 | TaxonomyTermResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'TaxonomyTermResourceConstant', 'TaxonomyTermChannel'];
26 |
27 | /** @ngInject */
28 | function TaxonomyTermResource($http, BaseResource, DrupalApiConstant, TaxonomyTermResourceConstant, TaxonomyTermChannel) {
29 |
30 | //setup and return service
31 | var taxonomy_termResourceService = {
32 | //CRUD operations
33 | retrieve : retrieve,
34 | create : create,
35 | update : update,
36 | delete : _delete,
37 | index : index,
38 | //Actions
39 | selectNodes : selectNodes,
40 |
41 | };
42 |
43 | return taxonomy_termResourceService;
44 |
45 | ////////////
46 |
47 | /**
48 | * retrieve
49 | *
50 | * Retrieve a term
51 | *
52 | * Method: GET
53 | * Url: http://drupal_instance/api_endpoint/taxonomy_term/{TID}
54 | *
55 | * @params {Object} data The requests data
56 | * @key {Integer} tid TID of the taxonomy_term to get, required:true, source:path
57 | *
58 | * @return {Promise} A taxonomy_term object
59 | *
60 | **/
61 | function retrieve(data) {
62 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath + '/' + data.tid;
63 | return BaseResource.retrieve( retrievePath,TaxonomyTermChannel.pubRetrieveConfirmed, TaxonomyTermChannel.pubRetrieveFailed);
64 | };
65 |
66 | /**
67 | * create
68 | *
69 | * Create a term
70 | * This function uses drupal_form_submit() and as such expects all input to match
71 | * the submitting form in question.
72 | *
73 | * Method: POST
74 | * Url: http://drupal_instance/api_endpoint/taxonomy_term
75 | *
76 | * @params {Object} term The data of the taxonomy_term to create, required:true, source:post body
77 | *
78 | *
79 | * Roles can be passed in a roles property which is an associative
80 | * array formatted with '' => '', not including the authenticated taxonomy_term role, which is given by default.
81 | *
82 | * @return {Promise} The taxonomy_term object of the newly created taxonomy_term.
83 | *
84 | **/
85 | function create(term) {
86 |
87 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath;
88 |
89 | var createData = {
90 | term : term
91 | };
92 |
93 | return BaseResource.create( createData, createPath, TaxonomyTermChannel.pubCreateConfirmed, TaxonomyTermChannel.pubCreateFailed);
94 |
95 | };
96 |
97 | /**
98 | * update
99 | *
100 | * Update a term
101 | *
102 | * Method: PUT
103 | * Url: http://drupal_instance/api_endpoint/taxonomy_term/{TID}
104 | *
105 | * @params {Object} data The requests data
106 | * @key {Integer} tid The unique identifier for this taxonomy term., required:true, source:path
107 | * @key {Array} data The taxonomy term data to update, required:true, source:post body
108 | *
109 | * @return {Promise}
110 | *
111 | **/
112 | function update(data) {
113 |
114 | var updatePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath + '/' + data.tid;
115 |
116 | var updateData = {term : data};
117 |
118 | return BaseResource.update( updateData, updatePath, TaxonomyTermChannel.pubUpdateConfirmed, TaxonomyTermChannel.pubUpdateFailed);
119 |
120 | };
121 |
122 | /**
123 | * delete
124 | *
125 | * Delete the term
126 | *
127 | * Method: DELETE
128 | * Url: http://drupal_instance/api_endpoint/taxonomy_term/{TID}
129 | *
130 | * @params {Object} data the requests data
131 | * @key {Integer} tid The id of the taxonomy_term to delete, required:true, source:path
132 | *
133 | * @return {Promise}
134 | *
135 | **/
136 | function _delete(data) {
137 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath + '/' + data.tid
138 | return BaseResource.delete(deletePath, TaxonomyTermChannel.pubDeleteConfirmed, TaxonomyTermChannel.pubDeleteFailed);
139 | };
140 |
141 | /**
142 | * index
143 | *
144 | * List all taxonomy_terms
145 | *
146 | * Method: GET
147 | * Url: http://drupal_instance/api_endpoint/taxonomy_term
148 | *
149 | * @params {Object} data the requests data
150 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param
151 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param
152 | * @key {String} fields The fields to get., required:false, source:param
153 | * @key {Array} parameters Parameters, required:false, source:param
154 | *
155 | *
156 | * @return {Promise}
157 | *
158 | **/
159 | function index(data) {
160 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath + '/';
161 | return BaseResource.index(data, indexPath,TaxonomyTermChannel.pubIndexConfirmed, TaxonomyTermChannel.pubIndexFailed);
162 | };
163 |
164 | /**
165 | * selectNodes
166 | *
167 | * Returns all nodes with provided taxonomy id.
168 | *
169 | * Method: POST
170 | * Url: http://drupal_instance/api_endpoint/taxonomy_term/selectNodes
171 | *
172 | * @params {Object} data the requests data
173 | * @key {Integer} tid The vocabulary ids to retrieve, separated by comma., required:true, source:post body
174 | * @key {Integer} pager Whether the nodes are to be used with a pager (the case on most Drupal pages) or not (in an XML feed, for example)., required:false, source:post body
175 | * @key {String} limit Maximum number of nodes to find., required:false, source:post body
176 | * @key {Array} order The order clause for the query that retrieve the nodes., required:false, source:post body
177 | *
178 | *
179 | * @return {Promise}
180 | *
181 | **/
182 | function selectNodes(data) {
183 | var pathToSelectNodes = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyTermResourceConstant.resourcePath + '/' + TaxonomyTermResourceConstant.actions.selectNodes,
184 | requestConfig = {
185 | url : pathToSelectNodes,
186 | method : 'POST',
187 | data : data
188 | };
189 |
190 |
191 |
192 | return BaseResource.request(requestConfig,TaxonomyTermChannel.pubSelectNodesConfirmed, TaxonomyTermChannel.pubSelectNodesFailed);
193 |
194 | };
195 |
196 | };
197 |
198 | })();
--------------------------------------------------------------------------------
/src/resources/taxonomy_term/taxonomy_term.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for TaxonomyTermResourceModules
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var TaxonomyTermResourceConstant = {
10 |
11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal
12 | resourcePath : 'taxonomy_term',
13 | //actions of taxonomy_term resource
14 | actions : {
15 | //following actions are defined over their request method (GET, POST, PUT, DELETE) so they are commented out
16 | //retrieve : 'retrieve',
17 | //create : 'create',
18 | //update : 'update',
19 | //delete : 'delete',
20 | //index : 'index',
21 | //
22 | selectNodes : 'selectNodes',
23 | }
24 |
25 | };
26 |
27 | /**
28 | * TaxonomyTerm Constant Modules
29 | */
30 | angular
31 | .module('d7-services.resources.taxonomy_term.resourceConstant', [])
32 | .constant("TaxonomyTermResourceConstant", TaxonomyTermResourceConstant);
33 |
34 | })();
35 |
--------------------------------------------------------------------------------
/src/resources/taxonomy_vocabulary/taxonomy_vocabulary.bundle.js:
--------------------------------------------------------------------------------
1 | ;
2 | (function () {
3 | 'use strict';
4 |
5 | /**
6 | * @ngdoc object
7 | * @name d7-services.resources.taxonomy_vocabulary:TaxonomyVocabulary
8 | * @description
9 | * This Module bundles all modules related to drupal taxonomy_vocabulary resource
10 | * @requires d7-services.resources.taxonomy_vocabulary.resourceConstant:TaxonomyVocabularyResourceConstant
11 | * @requires d7-services.resources.taxonomy_vocabulary.resource:TaxonomyVocabularyResource
12 | * @requires d7-services.resources.taxonomy_vocabulary.channelConstant:TaxonomyVocabularyChannelConstant
13 | * @requires d7-services.resources.taxonomy_vocabulary.channel:TaxonomyVocabularyChannel
14 | */
15 | angular
16 | .module('d7-services.resources.taxonomy_vocabulary', [
17 | 'd7-services.resources.taxonomy_vocabulary.resourceConstant',
18 | 'd7-services.resources.taxonomy_vocabulary.resource',
19 | 'd7-services.resources.taxonomy_vocabulary.channelConstant',
20 | 'd7-services.resources.taxonomy_vocabulary.channel']);
21 | })();
--------------------------------------------------------------------------------
/src/resources/taxonomy_vocabulary/taxonomy_vocabulary.channelConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for TaxonomyVocabularyChannel
6 | *
7 | * NOTE: if you want to change this constant do this in a config section of angular
8 | */
9 | var TaxonomyVocabularyChannelConstant = {
10 | //CRUD
11 | // Retrieve operation
12 | retrieveConfirmed : 'event:drupal-taxonomy_vocabulary-retrieveConfirmed',
13 | retrieveFailed : 'event:drupal-taxonomy_vocabulary-retrieveFailed',
14 | // Create operation
15 | createConfirmed : 'event:drupal-taxonomy_vocabulary-createConfirmed',
16 | createFailed : 'event:drupal-taxonomy_vocabulary-createFailed',
17 | // Update operation
18 | updateConfirmed : 'event:drupal-taxonomy_vocabulary-updateConfirmed',
19 | updateFailed : 'event:drupal-taxonomy_vocabulary-updateFailed',
20 | // Delete operation
21 | deleteConfirmed : 'event:drupal-taxonomy_vocabulary-deleteConfirmed',
22 | deleteFailed : 'event:drupal-taxonomy_vocabulary-deleteFailed',
23 | // Index action
24 | indexConfirmed : 'event:drupal-taxonomy_vocabulary-indexConfirmed',
25 | indexFailed : 'event:drupal-taxonomy_vocabulary-indexFailed',
26 | // getTree action
27 | getTreeConfirmed : 'event:drupal-taxonomy_vocabulary-getTreeConfirmed',
28 | getTreeFailed : 'event:drupal-taxonomy_vocabulary-getTreeFailed',
29 | // retrieveByMachineName action
30 | retrieveByMachineNameConfirmed : 'event:drupal-taxonomy_vocabulary-retrieveByMachineNameConfirmed',
31 | retrieveByMachineNameFailed : 'event:drupal-taxonomy_vocabulary-retrieveByMachineNameFailed',
32 |
33 |
34 | };
35 |
36 | /**
37 | * TaxonomyVocabulary Channel Constant
38 | */
39 | angular
40 | .module('d7-services.resources.taxonomy_vocabulary.channelConstant', [])
41 | .constant("TaxonomyVocabularyChannelConstant", TaxonomyVocabularyChannelConstant);
42 |
43 | })();
44 |
--------------------------------------------------------------------------------
/src/resources/taxonomy_vocabulary/taxonomy_vocabulary.resource.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * TaxonomyVocabulary Resource Modules
6 | *
7 | * see sourcecode in services/resources/taxonomy_vocabulary_resource.inc
8 | **/
9 | angular.module('d7-services.resources.taxonomy_vocabulary.resource', ['d7-services.commons.configurations', 'd7-services.resources.taxonomy_vocabulary.resourceConstant', 'd7-services.resources.taxonomy_vocabulary.channel', 'd7-services.commons.baseResource'])
10 |
11 | /**
12 | * TaxonomyVocabularyResource
13 | *
14 | * This service mirrors the Drupal taxonomy_vocabulary resource of the services 3.x module.
15 | * To use this you have to set following line in your Drupal CORS module settings
16 | * your_api_endpoint/taxonomy_vocabulary/*||POST|Content-Type,Authorization|true
17 | *
18 | **/
19 | .factory('TaxonomyVocabularyResource', TaxonomyVocabularyResource);
20 |
21 | /**
22 | * Manually identify dependencies for minification-safe code
23 | *
24 | **/
25 | TaxonomyVocabularyResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'TaxonomyVocabularyResourceConstant', 'TaxonomyVocabularyChannel'];
26 |
27 | /** @ngInject */
28 | function TaxonomyVocabularyResource($http, BaseResource, DrupalApiConstant, TaxonomyVocabularyResourceConstant, TaxonomyVocabularyChannel) {
29 |
30 | //setup and return service
31 | var taxonomy_vocabularyResourceService = {
32 | //CRUD operations
33 | retrieve : retrieve,
34 | create : create,
35 | update : update,
36 | delete : _delete,
37 | index : index,
38 | //Actions
39 | getTree : getTree,
40 | retrieveByMachineName : retrieveByMachineName
41 |
42 | };
43 |
44 | return taxonomy_vocabularyResourceService;
45 |
46 | ////////////
47 |
48 | /**
49 | * retrieve
50 | *
51 | * Retrieve a taxonomy vocabulary
52 | *
53 | * Method: GET
54 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary/{TID}
55 | *
56 | * @params {Object} data The requests data
57 | * @key {Integer} tid The vid of the taxonomy vocabulary to get, required:true, source:path
58 | *
59 | * @return {Promise} A taxonomy_vocabulary object
60 | *
61 | **/
62 | function retrieve(data) {
63 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/' + data.vid;
64 | return BaseResource.retrieve( retrievePath,TaxonomyVocabularyChannel.pubRetrieveConfirmed, TaxonomyVocabularyChannel.pubRetrieveFailed);
65 | };
66 |
67 | /**
68 | * create
69 | *
70 | * Create a taxonomy vocabulary
71 | * This function uses drupal_form_submit() and as such expects all input to match
72 | * the submitting form in question.
73 | *
74 | * Method: POST
75 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary
76 | *
77 | * @params {Object} data The vid of the taxonomy vocabulary to get, required:true, source:post body
78 | *
79 | *
80 | * Roles can be passed in a roles property which is an associative
81 | * array formatted with '' => '', not including the authenticated taxonomy_vocabulary role, which is given by default.
82 | *
83 | * @return {Promise} The taxonomy_vocabulary object of the newly created taxonomy_vocabulary.
84 | *
85 | **/
86 | function create(data) {
87 |
88 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath;
89 |
90 | var createData = {
91 | vocabulary : data
92 | };
93 |
94 | return BaseResource.create( createData, createPath, TaxonomyVocabularyChannel.pubCreateConfirmed, TaxonomyVocabularyChannel.pubCreateFailed);
95 |
96 | };
97 |
98 | /**
99 | * update
100 | *
101 | * Update a taxonomy vocabulary
102 | *
103 | * Method: PUT
104 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary/{TID}
105 | *
106 | * @params {Object} data The requests data
107 | * @key {Integer} vid The unique identifier for this taxonomy vocabulary., required:true, source:path
108 | * @key {Array} vocabulary The taxonomy vocabulary data to update, required:true, source:post body
109 | *
110 | * @return {Promise}
111 | *
112 | **/
113 | function update(data) {
114 |
115 | var updatePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/' + data.vid;
116 |
117 | var updateData = {vocabulary : data};
118 |
119 | return BaseResource.update( updateData, updatePath, TaxonomyVocabularyChannel.pubUpdateConfirmed, TaxonomyVocabularyChannel.pubUpdateFailed);
120 |
121 | };
122 |
123 | /**
124 | * delete
125 | *
126 | * Delete a taxonomy vocabulary
127 | *
128 | * Method: DELETE
129 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary/{TID}
130 | *
131 | * @params {Object} data the requests data
132 | * @key {Integer} tid The id of the taxonomy vocabulary to delete, required:true, source:path
133 | *
134 | * @return {Promise}
135 | *
136 | **/
137 | function _delete(data) {
138 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/' + data.tid
139 | return BaseResource.delete(deletePath, TaxonomyVocabularyChannel.pubDeleteConfirmed, TaxonomyVocabularyChannel.pubDeleteFailed);
140 | };
141 |
142 | /**
143 | * index
144 | *
145 | * List all taxonomy vocabularies
146 | *
147 | * Method: GET
148 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary
149 | *
150 | * @params {Object} data the requests data
151 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param
152 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param
153 | * @key {String} fields The fields to get., required:false, source:param
154 | * @key {Array} parameters Parameters, required:false, source:param
155 | *
156 | *
157 | * @return {Promise}
158 | *
159 | **/
160 | function index(data) {
161 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/';
162 | return BaseResource.index(data, indexPath,TaxonomyVocabularyChannel.pubIndexConfirmed, TaxonomyVocabularyChannel.pubIndexFailed);
163 | };
164 |
165 | /**
166 | * getTree
167 | *
168 | * Returns a full list of taxonomy terms.
169 | *
170 | * Method: POST
171 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary/getTree
172 | *
173 | * @params {Object} data the requests data
174 | * @key {Integer} vid The vocabulary id to retrieve., separated by comma., required:true, source:post body
175 | * @key {Integer} parent The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary., required:false, source:post body
176 | * @key {Integer} maxdepth The number of levels of the tree to return. Leave NULL to return all levels., required:false, source:post body
177 | * @key {Integer} load_entities Whether the tree of terms should contain full term entity objects. If 1 (TRUE), a full entity load will occur on the term objects. Otherwise they are partial objects to save execution time and memory consumption. Defaults to 0 (FALSE)., required:false, source:post body
178 | *
179 | * @return {Promise}
180 | *
181 | **/
182 | function getTree(data) {
183 | var pathToGetTree = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/' + TaxonomyVocabularyResourceConstant.actions.getTree,
184 | requestConfig = {
185 | url : pathToGetTree,
186 | method : 'POST',
187 | data : data
188 | };
189 |
190 | return BaseResource.request(requestConfig,TaxonomyVocabularyChannel.pubGetTreeConfirmed, TaxonomyVocabularyChannel.pubGetTreeFailed);
191 |
192 | };
193 |
194 | /**
195 | * retrieveByMachineName
196 | *
197 | * Returns a vocabulary based on machine name.
198 | *
199 | * Method: POST
200 | * Url: http://drupal_instance/api_endpoint/taxonomy_vocabulary/retrieveByMachineName
201 | *
202 | * @params {Object} data the requests data
203 | * @key {String} vid The vocabulary id to retrieve., required:true, source:post body
204 | *
205 | * @return {Promise}
206 | *
207 | **/
208 | function retrieveByMachineName(data) {
209 | var pathToRetrieveByMachineName = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + TaxonomyVocabularyResourceConstant.resourcePath + '/' + TaxonomyVocabularyResourceConstant.actions.retrieveByMachineName,
210 | requestConfig = {
211 | url : pathToRetrieveByMachineName,
212 | method : 'POST',
213 | data : data
214 | };
215 |
216 | return BaseResource.request(requestConfig,TaxonomyVocabularyChannel.pubRetrieveByMachineNameConfirmed, TaxonomyVocabularyChannel.pubRetrieveByMachineNameFailed);
217 |
218 | };
219 |
220 | };
221 |
222 | })();
--------------------------------------------------------------------------------
/src/resources/taxonomy_vocabulary/taxonomy_vocabulary.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for TaxonomyVocabularyResourceModules
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var TaxonomyVocabularyResourceConstant = {
10 |
11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal
12 | resourcePath : 'taxonomy_vocabulary',
13 | //actions of taxonomy_vocabulary resource
14 | actions : {
15 | //following actions are defined over their request method (GET, POST, PUT, DELETE) so they are commented out
16 | //retrieve : 'retrieve',
17 | //create : 'create',
18 | //update : 'update',
19 | //delete : 'delete',
20 | //index : 'index',
21 | //
22 | getTree : 'getTree',
23 | retrieveByMachineName : 'retrieveByMachineName'
24 | }
25 |
26 | };
27 |
28 | /**
29 | * TaxonomyVocabulary Constant Modules
30 | */
31 | angular
32 | .module('d7-services.resources.taxonomy_vocabulary.resourceConstant', [])
33 | .constant("TaxonomyVocabularyResourceConstant", TaxonomyVocabularyResourceConstant);
34 |
35 | })();
36 |
--------------------------------------------------------------------------------
/src/resources/user/user.bundle.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | /**
5 | * @ngdoc object
6 | * @name d7-services.resources.user:User
7 | * @description
8 | * This Module bundles all modules related to drupal user resource
9 | * @requires d7-services.resources.user.resourceConstant:UserResourceConstant
10 | * @requires d7-services.resources.user.resource:UserResource
11 | * @requires d7-services.resources.user.channelConstant:UserChannelConstant
12 | * @requires d7-services.resources.user.channel:UserChannel
13 | */
14 | angular
15 | .module('d7-services.resources.user',
16 | ['d7-services.resources.user.resourceConstant',
17 | 'd7-services.resources.user.resource',
18 | 'd7-services.resources.user.channelConstant',
19 | 'd7-services.resources.user.channel']);
20 | })();
--------------------------------------------------------------------------------
/src/resources/user/user.channelConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for UserChannel
6 | *
7 | * NOTE: if you want to change this constant do this in a config section of angular
8 | */
9 | var UserChannelConstant = {
10 | // Retrieve action
11 | retrieveConfirmed : 'event:drupal-user-retrieveConfirmed',
12 | retrieveFailed : 'event:drupal-user-retrieveFailed',
13 | // Create action
14 | createConfirmed : 'event:drupal-user-createConfirmed',
15 | createFailed : 'event:drupal-user-createFailed',
16 | // Update action
17 | updateConfirmed : 'event:drupal-user-updateConfirmed',
18 | updateFailed : 'event:drupal-user-updateFailed',
19 | // Delete action
20 | deleteConfirmed : 'event:drupal-user-deleteConfirmed',
21 | deleteFailed : 'event:drupal-user-deleteFailed',
22 | // Index action
23 | indexConfirmed : 'event:drupal-user-indexConfirmed',
24 | indexFailed : 'event:drupal-user-indexFailed',
25 | //Request new password action
26 | requestNewPasswordConfirmed : 'event:drupal-user-requestNewPasswordConfirmed',
27 | requestNewPasswordFailed : 'event:drupal-user-requestNewPasswordFailed',
28 | //Cancel action
29 | cancelConfirmed : 'event:drupal-user-cancelConfirmed',
30 | cancelFailed : 'event:drupal-user-cancelFailed',
31 | //Password Reset
32 | passwordResetConfirmed : 'event:drupal-user-passwordResetConfirmed',
33 | passwordResetFailed : 'event:drupal-user-passwordResetFailed',
34 | //Resend Welcome Email
35 | resendWelcomeEmailConfirmed : 'event:drupal-user-resendWelcomeEmailConfirmed',
36 | resendWelcomeEmailFailed : 'event:drupal-user-resendWelcomeEmailFailed',
37 | // Token action
38 | tokenConfirmed : 'event:drupal-user-tokenConfirmed',
39 | tokenFailed : 'event:drupal-user-tokenFailed',
40 | // Register action
41 | registerConfirmed : 'event:drupal-user-registerConfirmed',
42 | registerFailed : 'event:drupal-user-registerFailed',
43 | // Login action
44 | loginConfirmed : 'event:drupal-user-loginConfirmed',
45 | loginFailed : 'event:drupal-user-loginFailed',
46 | // Logout action
47 | logoutConfirmed : 'event:drupal-user-logoutConfirmed',
48 | logoutFailed : 'event:drupal-user-logoutFailed'
49 |
50 | };
51 |
52 | /**
53 | * User Channel Constant
54 | */
55 | angular
56 | .module('d7-services.resources.user.channelConstant', [])
57 | .constant("UserChannelConstant", UserChannelConstant);
58 |
59 | })();
60 |
--------------------------------------------------------------------------------
/src/resources/user/user.resource.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * User Resource Modules
6 | *
7 | * see sourcecode in services/resources/user_resource.inc
8 | **/
9 | angular.module('d7-services.resources.user.resource', ['d7-services.commons.configurations', 'd7-services.resources.user.resourceConstant', 'd7-services.resources.user.channel', 'd7-services.commons.baseResource'])
10 |
11 | /**
12 | * UserResource
13 | *
14 | * This service mirrors the Drupal user resource of the services 3.x module.
15 | * To use this you have to set following line in your Drupal CORS module settings
16 | * your_api_endpoint/user/*||POST|Content-Type,Authorization|true
17 | *
18 | **/
19 | .factory('UserResource', UserResource);
20 |
21 | /**
22 | * Manually identify dependencies for minification-safe code
23 | *
24 | **/
25 | UserResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'UserResourceConstant', 'UserChannel'];
26 |
27 | /** @ngInject */
28 | function UserResource($http, BaseResource, DrupalApiConstant, UserResourceConstant, UserChannel) {
29 |
30 | //setup and return service
31 | var userResourceService = {
32 | //CRUD operations
33 | retrieve : retrieve,
34 | create : create,
35 | update : update,
36 | delete : _delete,
37 | index : index,
38 | //Actions
39 | token : token,
40 | register : register,
41 | resendWelcomeEmail : resendWelcomeEmail,
42 | cancel : cancel,
43 | login : login,
44 | logout : logout,
45 | passwordReset : passwordReset,
46 | requestNewPassword : requestNewPassword
47 |
48 | };
49 |
50 | return userResourceService;
51 |
52 | ////////////
53 |
54 | /**
55 | * retrieve
56 | *
57 | * Retrieve a user
58 | *
59 | * Method: GET
60 | * Url: http://drupal_instance/api_endpoint/user/{UID}
61 | *
62 | * @params {Object} data The requests data
63 | * @key {Integer} uid UID of the user to be loaded, required:true, source:path
64 | *
65 | * @return {Promise} A user object
66 | *
67 | **/
68 | function retrieve(data) {
69 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid;
70 | return BaseResource.retrieve( retrievePath,UserChannel.pubRetrieveConfirmed, UserChannel.pubRetrieveFailed);
71 | };
72 |
73 | /**
74 | * create
75 | *
76 | * Create a new user.
77 | * This function uses drupal_form_submit() and as such expects all input to match
78 | * the submitting form in question.
79 | *
80 | * Method: POST
81 | * Url: http://drupal_instance/api_endpoint/user
82 | *
83 | * @params {Object} data The accout of the user to create, required:true, source:post body
84 | *
85 | * The $account object should contain, at minimum, the following properties:
86 | * - {String} name The user name
87 | * - {String} mail The email address
88 | * - {String} pass The plain text unencrypted password
89 | *
90 | * These properties can be passed but are optional
91 | * - {Integer} status Value 0 for blocked, otherwise will be active by default
92 | * - {Integer} notify Value 1 to notify user of new account, will not notify by default
93 | *
94 | * Roles can be passed in a roles property which is an associative
95 | * array formatted with '' => '', not including the authenticated user role, which is given by default.
96 | *
97 | * @return {Promise} The user object of the newly created user.
98 | *
99 | **/
100 | function create(data) {
101 |
102 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath;
103 |
104 | var createdata = {
105 | name : data.name,
106 | pass : data.pass,
107 | mail : data.mail
108 | }
109 |
110 | //optional data
111 |
112 | if(data.status || data.status == 0) {
113 | createdata.status = (data.status)?1:0;
114 | }
115 |
116 | if(data.notify || data.notify == 0) {
117 | createdata.notify = (data.notify)?1:0;
118 | }
119 |
120 | if (data.roles) {
121 | createdata.roles = BaseResource.preparePostData(data.roles, 'array_of_values');
122 | }
123 |
124 | return BaseResource.create( createdata, createPath, UserChannel.pubCreateConfirmed, UserChannel.pubCreateFailed);
125 |
126 | };
127 |
128 | /**
129 | * update
130 | *
131 | * Update a user
132 | *
133 | * Method: PUT
134 | * Url: http://drupal_instance/api_endpoint/user/{UID}
135 | *
136 | * @params {Object} data The requests data
137 | * @key {Integer} uid Unique identifier for this user, required:true, source:path
138 | * @key {Array} data The user object with updated information, required:true, source:post body
139 | *
140 | * @return {Promise}
141 | *
142 | **/
143 | function update(data) {
144 |
145 | var updatePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid;
146 |
147 | delete data.uid;
148 | var updateData = data;
149 |
150 | return BaseResource.update( updateData, updatePath, UserChannel.pubUpdateConfirmed, UserChannel.pubUpdateFailed);
151 |
152 | };
153 |
154 | /**
155 | * delete
156 | *
157 | * Delete a user
158 | *
159 | * Method: DELETE
160 | * Url: http://drupal_instance/api_endpoint/user/{UID}
161 | *
162 | * @params {Object} data the requests data
163 | * @key {Integer} uid The id of the user to delete, required:true, source:path
164 | *
165 | * @return {Promise}
166 | *
167 | **/
168 | function _delete(data) {
169 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid
170 | return BaseResource.delete(deletePath, UserChannel.pubDeleteConfirmed, UserChannel.pubDeleteFailed);
171 | };
172 |
173 | /**
174 | * index
175 | *
176 | * List all users
177 | *
178 | * Method: GET
179 | * Url: http://drupal_instance/api_endpoint/user
180 | *
181 | * @params {Object} data the requests data
182 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param
183 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param
184 | * @key {String} fields The fields to get., required:false, source:param
185 | * @key {Array} parameters Parameters, required:false, source:param
186 | *
187 | *
188 | * @return {Promise}
189 | *
190 | **/
191 | function index(data) {
192 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/';
193 | return BaseResource.index(data, indexPath,UserChannel.pubIndexConfirmed, UserChannel.pubIndexFailed);
194 | };
195 |
196 | /**
197 | * register
198 | *
199 | * register a user
200 | *
201 | * Method: POST
202 | * Url: http://drupal_instance/api_endpoint/user/register
203 | *
204 | * @param {Object} data The user object, required:true, source:post body
205 | *
206 | * @return {Promise}
207 | *
208 | **/
209 | function register(data) {
210 | //undefined check
211 | data = (data)?data:{};
212 |
213 | var registerPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + UserResourceConstant.actions.register,
214 | requestConfig = {
215 | method: 'POST',
216 | url : registerPath,
217 | data : data
218 | };
219 |
220 | return BaseResource.request(requestConfig, UserChannel.pubRegisterConfirmed, UserChannel.pubRegisterFailed);
221 | };
222 |
223 |
224 | /**
225 | * resendWelcomeEmail
226 | *
227 | * Resend the welcome email of a user fetched by uid
228 | *
229 | * Method: POST
230 | * Url: http://drupal_instance/api_endpoint/user/resend_welcome_email
231 | *
232 | * @param {Object} data The user object, required:true, source:post body
233 | *
234 | * @return {Promise}
235 | *
236 | **/
237 | function resendWelcomeEmail(data) {
238 | //undefined check
239 | data = (data)?data:{};
240 |
241 | var resendWelcomeEmailPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid + '/' + UserResourceConstant.actions.resend_welcome_email,
242 | requestConfig = {
243 | method: 'POST',
244 | url : resendWelcomeEmailPath
245 | };
246 |
247 | return BaseResource.request(requestConfig, UserChannel.pubResendWelcomeEmailConfirmed, UserChannel.pubResendWelcomeEmailFailed);
248 | };
249 |
250 | /**
251 | * cancel
252 | *
253 | * Cancel a user
254 | *
255 | * Method: POST
256 | * Url: http://drupal_instance/api_endpoint/user/cancel
257 | *
258 | * @param {Object} data The user object, required:true, source:post body
259 | *
260 | * @return {Promise}
261 | *
262 | **/
263 | function cancel(data) {
264 | //undefined check
265 | data = (data)?data:{};
266 |
267 | var cancelPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid + '/' + UserResourceConstant.actions.cancel,
268 | requestConfig = {
269 | method: 'POST',
270 | url : cancelPath
271 | };
272 |
273 | return BaseResource.request(requestConfig, UserChannel.pubCancelConfirmed, UserChannel.pubCancelFailed);
274 | };
275 |
276 | /**
277 | * PasswordReset
278 | *
279 | * PasswordReset a user
280 | *
281 | * Method: POST
282 | * Url: http://drupal_instance/api_endpoint/user/password_reset
283 | *
284 | * @param {Object} data The user object, required:true, source:post body
285 | *
286 | * @return {Promise}
287 | *
288 | **/
289 | function passwordReset(data) {
290 | //undefined check
291 | data = (data)?data:{};
292 |
293 | var passwordResetPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid + '/' + UserResourceConstant.actions.password_reset,
294 | requestConfig = {
295 | method: 'POST',
296 | url : passwordResetPath
297 | };
298 |
299 | return BaseResource.request(requestConfig, UserChannel.pubPasswordResetConfirmed, UserChannel.pubPasswordResetFailed);
300 | };
301 |
302 | /**
303 | * requestNewPassword
304 | *
305 | * Request a new password, given a user name or e-mail address
306 | *
307 | * Method: POST
308 | * Url: http://drupal_instance/api_endpoint/user/request_new_password
309 | *
310 | * @param {Object} data The user object
311 | * @key {String} name A valid user name or e-mail address, required:true, source:post body
312 | *
313 | *
314 | * @return {Promise}
315 | *
316 | **/
317 | function requestNewPassword(data) {
318 | //undefined check
319 | data = (data)?data:{};
320 |
321 | var requestNewPasswordPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + data.uid + '/' + UserResourceConstant.actions.request_new_password,
322 | requestConfig = {
323 | method: 'POST',
324 | url : requestNewPasswordPath,
325 | data : {
326 | name : data.name
327 | }
328 | };
329 |
330 | return BaseResource.request(requestConfig, UserChannel.pubRequestNewPasswordConfirmed, UserChannel.pubRequestNewPasswordFailed);
331 | };
332 |
333 |
334 | /**
335 | * login
336 | *
337 | * Login a user for a new session
338 | *
339 | * Method: POST
340 | * Url: http://drupal_instance/api_endpoint/user/login
341 | *
342 | * @params {Object} data The requests data
343 | * @key {String} username A valid username, required:true, source:post body
344 | * @key {String} password A valid password, required:true, source:post body
345 | *
346 | * @return {Promise}
347 | *
348 | **/
349 | function login( data ) {
350 | //undefined check
351 | data = (data)?data:{};
352 |
353 | var pathToLogin = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + UserResourceConstant.actions.login,
354 | requestConfig = {
355 | url : pathToLogin,
356 | method :'POST',
357 | data : data
358 | };
359 |
360 | return BaseResource.request(requestConfig, UserChannel.pubLoginConfirmed, UserChannel.pubLoginFailed);
361 |
362 | };
363 |
364 | /**
365 | * logout
366 | *
367 | * Logout a user session
368 | *
369 | * Method: POST
370 | * Url: http://drupal_instance/api_endpoint/user/logout
371 | *
372 | * @return {Promise}
373 | *
374 | **/
375 | function logout() {
376 |
377 | var pathToLogout = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + UserResourceConstant.actions.logout,
378 | requestConfig = {
379 | url : pathToLogout,
380 | method : 'POST'
381 | };
382 |
383 | return BaseResource.request(requestConfig, UserChannel.pubLogoutConfirmed, UserChannel.pubLogoutFailed);
384 |
385 | };
386 |
387 | /**
388 | * token
389 | *
390 | * Returns the CSRF token of the current session.
391 | *
392 | * Method: POST
393 | * Url: http://drupal_instance/api_endpoint/user/token
394 | *
395 | * @return {Promise}
396 | *
397 | **/
398 | function token() {
399 | var pathToToken = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + UserResourceConstant.resourcePath + '/' + UserResourceConstant.actions.token,
400 | requestConfig = {
401 | url : pathToToken,
402 | method : 'POST'
403 | };
404 |
405 | return BaseResource.request(requestConfig,UserChannel.pubTokenConfirmed, UserChannel.pubTokenFailed);
406 |
407 | };
408 |
409 | };
410 |
411 | })();
--------------------------------------------------------------------------------
/src/resources/user/user.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for UserResourceModules
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var UserResourceConstant = {
10 |
11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal
12 | resourcePath : 'user',
13 | //actions of user resource
14 | actions : {
15 | //following actions are defined over their request method (GET, POST, PUT, DELETE) so they are commented out
16 | //retrieve : 'retrieve',
17 | //create : 'create',
18 | //update : 'update',
19 | //delete : 'delete',
20 | //index : 'index',
21 | //
22 | login : 'login',
23 | logout : 'logout',
24 | token : 'token',
25 | request_new_password : 'request_new_password',
26 | register : 'register',
27 | cancel : 'cancel',
28 | password_reset : 'password_reset',
29 | resend_welcome_email : 'resend_welcome_email'
30 | }
31 |
32 | };
33 |
34 | /**
35 | * User Constant Modules
36 | */
37 | angular
38 | .module('d7-services.resources.user.resourceConstant', [])
39 | .constant("UserResourceConstant", UserResourceConstant);
40 |
41 | })();
42 |
--------------------------------------------------------------------------------
/src/resources/views/views.bundle.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 | 'use strict';
3 |
4 | /**
5 | * @ngdoc object
6 | * @name d7-services.resources.views:Views
7 | * @description
8 | * This Module bundles all modules related to drupal views resource
9 | * @requires d7-services.resources.views.resourceConstant:ViewsResourceConstant
10 | * @requires d7-services.resources.views.resource:ViewsResource
11 | * @requires d7-services.resources.views.channelConstant:ViewsChannelConstant
12 | * @requires d7-services.resources.views.channel:ViewsChannel
13 | * @requires d7-services.resources.views.operatorsConstant:OperatorsConstant
14 | */
15 | angular.module('d7-services.resources.views',
16 | ['d7-services.resources.views.resourceConstant',
17 | 'd7-services.resources.views.resource',
18 | 'd7-services.resources.views.channelConstant',
19 | 'd7-services.resources.views.channel',
20 | 'd7-services.resources.views.operatorsConstant']);
21 | })();
22 |
--------------------------------------------------------------------------------
/src/resources/views/views.channel.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Views Channel Module
6 | */
7 | angular.module('d7-services.resources.views.channel', ['d7-services.commons.baseChannel', 'd7-services.resources.views.channelConstant'])
8 | .factory('ViewsChannel', ViewsChannel);
9 |
10 | /**
11 | * Manually identify dependencies for minification-safe code
12 | *
13 | **/
14 | ViewsChannel.$inject = [ 'BaseChannel', 'ViewsChannelConstant' ];
15 |
16 | /**
17 | * Notification channel for views resource
18 | **/
19 | /** @ngInject */
20 | function ViewsChannel(BaseChannel, ViewsChannelConstant) {
21 |
22 | //setup and return service
23 | var viewsChannelService = {
24 |
25 | pubRetrieveConfirmed : pubRetrieveConfirmed,
26 | subRetrieveConfirmed : subRetrieveConfirmed,
27 | pubRetrieveFailed : pubRetrieveFailed,
28 | subRetrieveFailed : subRetrieveFailed
29 |
30 | };
31 |
32 | return viewsChannelService;
33 |
34 | ////////////
35 |
36 | //Views retrieve request functions
37 |
38 | /**
39 | * pubRetrieveConfirmed
40 | *
41 | * Publish the ViewsRetrieveConfirmed event with giver args
42 | *
43 | * @param {Object} args The events arguments
44 | *
45 | *
46 | **/
47 | function pubRetrieveConfirmed(args) {
48 | BaseChannel.pubRootEmit(ViewsChannelConstant.retrieveConfirmed, args);
49 | };
50 |
51 | /**
52 | * subRetrieveConfirmed
53 | *
54 | * subscribe for the ViewsRetrieveConfirmed event
55 | *
56 | * @param {Object} _Scope The scope that calls the channels subRetrieveConfirmed function
57 | * @param {function} scopeHandler The callback handler for ViewsRetrieveConfirmed event
58 | *
59 | * @return {function} The unsubscribe function from the $rootScope.on() call
60 | *
61 | **/
62 | function subRetrieveConfirmed(_Scope, scopeHandler) {
63 | var unsubScopeHandler = BaseChannel.subRootEmit( ViewsChannelConstant.retrieveConfirmed, _Scope, scopeHandler);
64 | return unsubScopeHandler;
65 | };
66 |
67 | //###############
68 |
69 |
70 | /**
71 | * pubRetrieveConfirmed
72 | *
73 | * Publish the ViewsRetrieveConfirmed event with giver args
74 | *
75 | * @param {Object} args The events arguments
76 | *
77 | *
78 | **/
79 | function pubRetrieveFailed(args) {
80 | BaseChannel.pubRootEmit(ViewsChannelConstant.retrieveFailed, args);
81 | };
82 |
83 | /**
84 | * subRetrieveFailed
85 | *
86 | * subscribe for the ViewsRetrieveFailed event
87 | *
88 | * @param {Object} _Scope The scope that calls the channels subRetrieveFailed function
89 | * @param {function} scopeHandler The callback handler for ViewsRetrieveFailed event
90 | *
91 | * @return {function} The unsubscribe function from the $rootScope.on() call
92 | *
93 | **/
94 | function subRetrieveFailed(_Scope, scopeHandler) {
95 | var unsubScopeHandler = BaseChannel.subRootEmit( ViewsChannelConstant.retrieveFailed, _Scope, scopeHandler);
96 | return unsubScopeHandler;
97 | };
98 |
99 | //__________________________________________________________________________________________________________________
100 | };
101 |
102 | })();
--------------------------------------------------------------------------------
/src/resources/views/views.channelConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for ViewsChannel
6 | *
7 | * NOTE: if you want to change this constant do this in a config section of angular
8 | */
9 | var ViewsChannelConstant = {
10 | // Connect action
11 | retrieveConfirmed : 'event:drupal-views-retrieveConfirmed',
12 | retrieveFailed : 'event:drupal-views-retrieveFailed',
13 | };
14 |
15 | /**
16 | * Views Channel Constant
17 | */
18 | angular
19 | .module('d7-services.resources.views.channelConstant', [])
20 | .constant("ViewsChannelConstant", ViewsChannelConstant);
21 |
22 | })();
23 |
--------------------------------------------------------------------------------
/src/resources/views/views.operatorsConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for views request option names
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var ViewsOperatorsConstant = {
10 | sort_operators : {
11 | asc : "ASC",
12 | desc : "DESC"
13 | },
14 | filter_operators : {
15 | is_less_than : "<",
16 | is_less_than_or_equal_to : "<=",
17 | is_equal_to : "=",
18 | is_not_equal_to : "!=",
19 | is_greater_than_or_equal_to : ">=",
20 | is_greater_than : ">",
21 | is_between : "between",
22 | is_not_between : "not+between",
23 | regular_expression : "regular_expression"
24 | }
25 | };
26 |
27 | /**
28 | * Views Constant Modules
29 | */
30 | angular
31 | .module('d7-services.resources.views.operatorsConstant', [])
32 | .constant("ViewsOperatorsConstant", ViewsOperatorsConstant);
33 |
34 | })();
35 |
--------------------------------------------------------------------------------
/src/resources/views/views.resource.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Views Resource Modules
6 | *
7 | * see sourcecode in services/resources/views_resource.inc
8 | *
9 | **/
10 | angular.module('d7-services.resources.views.resource', ['d7-services.commons.configurations', 'd7-services.commons.baseResource', 'd7-services.resources.views.resourceConstant', 'd7-services.resources.views.channel'])
11 |
12 | /**
13 | * ViewsResource
14 | *
15 | * This service mirrors the Drupal views resource of the services 3.x module.
16 | * To use this you have to set following line in your Drupal CORS module settings
17 | *
18 | **/
19 | .factory('ViewsResource', ViewsResource);
20 |
21 | /**
22 | * Manually identify dependencies for minification-safe code
23 | *
24 | **/
25 | ViewsResource.$inject = ['$http', 'DrupalApiConstant', 'BaseResource', 'ViewsResourceConstant', 'ViewsChannel'];
26 |
27 | /** @ngInject */
28 | function ViewsResource($http, DrupalApiConstant, BaseResource, ViewsResourceConstant, ViewsChannel) {
29 |
30 | //setup and return service
31 | var viewsResourceService = {
32 | retrieve : retrieve
33 | };
34 |
35 | return viewsResourceService;
36 |
37 | ////////////
38 |
39 | /**
40 | * retrieve
41 | *
42 | * Retrieves a view.
43 | *
44 | * Method: GET
45 | * Url: http://drupal_instance/api_endpoint/views/{VIEW_NAME}
46 | *
47 | * @params {Object} data The requests data
48 | * @key {String} view_name The name of the view to get., required:true, source:path
49 | * @key {String} display_id The display ID of the view to get., required:false, source:param
50 | * @key {Array} args A list of arguments to pass to the view., required:false, source:param
51 | * @key {Integer} offset The number of the entry for the page begin with., required:false, source:param
52 | * @key {Integer} limit The total number of entries to list., required:false, source:param
53 | * @key {Boolean} format_output Whether to return the raw data results or style the results., required:false, source:param
54 | * @key {Array} exposed_sortss A list of sort options to pass to the view. These are defined by the exposed sorts on your view, required:false, source:param
55 | * @key {Array} exposed_filters A list of filters to pass to the view. These are defined by the exposed filters on your view, required:false, source:param
56 | *
57 | *
58 | * @return {Promise}
59 | *
60 | * Custom view settings
61 | * exposed filters:
62 | * create them in the view under "Filter criteria". Expose them for users. Under the more tab in "Configure filter criterion" in the field "Filter identifier" you can change the field name. Use it like => comment_count=4
63 | * order by : create them in the view under "Sort criteria". Expose it for users and use it like => sort_by=created&sort_order=ASC
64 | *
65 | *
66 | **/
67 | function retrieve(data){
68 | var _data = {};
69 |
70 | //we angular.merge "deep copy" because we don't want to change the views/controllers values
71 | angular.merge(_data, data);
72 |
73 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + ViewsResourceConstant.resourcePath + '/' + _data.view_name;
74 |
75 | delete _data.view_name;
76 |
77 | //prepare params
78 | var format = undefined,
79 | preparedParams = undefined,
80 | preparedParamsArray = [];
81 |
82 | var exposedFiltersFieldsWithOperators = [];
83 | //collect all exposed filters with operators
84 | if(_data.exposed_filters) {
85 | var fieldName = undefined;
86 | angular.forEach(_data.exposed_filters , function(value, key) {
87 | //if a key ends with _op
88 | if(key.substr(key.length - 3) == '_op') {
89 | fieldName = key.split('_op').shift();
90 | exposedFiltersFieldsWithOperators.push(fieldName);
91 | }
92 | });
93 | }
94 |
95 | //prepare exposed filters fields that have operators
96 | angular.forEach(_data.exposed_filters , function(value, key) {
97 | //if a key is in exposedFiltersFieldsWithOperators array
98 | if(exposedFiltersFieldsWithOperators.indexOf(key) > -1) {
99 | delete _data.exposed_filters[key];
100 | preparedParamsArray.push(BaseResource.prepareGetParams(value, key, 'array_key_value'));
101 | }
102 | });
103 |
104 | angular.forEach(_data.exposed_filters , function(value, key) {
105 | //used to place custom created params in url
106 | if(key === 'custom_string') {
107 | preparedParamsArray.push(value);
108 | delete _data.exposed_filters[key];
109 | }
110 | });
111 |
112 | angular.forEach(_data, function(value , key) {
113 | if(key === 'exposed_filters' || key === 'exposed_sorts') { format = 'json'; }
114 |
115 | preparedParams = BaseResource.prepareGetParams(value, key, format);
116 | if(preparedParams) {
117 | preparedParamsArray.push(preparedParams);
118 | }
119 |
120 | format = undefined;
121 | });
122 |
123 | if(preparedParamsArray.length > 0) {
124 | retrievePath += '?'+ preparedParamsArray.join('&');
125 | }
126 |
127 | return BaseResource.retrieve( retrievePath, ViewsChannel.pubRetrieveConfirmed, ViewsChannel.pubRetrieveFailed);
128 |
129 | };
130 |
131 | };
132 |
133 | })();
--------------------------------------------------------------------------------
/src/resources/views/views.resourceConstant.js:
--------------------------------------------------------------------------------
1 | ;(function() {
2 | 'use strict';
3 |
4 | /**
5 | * Constants for ViewsResourceModules
6 | *
7 | * NOTE: if you want to change this constant do this in your app.js config section
8 | */
9 | var ViewsResourceConstant = {
10 |
11 | // NOTE: This is the default alias aliases for your views resources defined in Drupal
12 | resourcePath : 'views',
13 | //actions of node resource
14 | actions : {
15 | //retrieve : 'retrieve'
16 | },
17 |
18 | };
19 |
20 | /**
21 | * Views Constant Modules
22 | */
23 | angular
24 | .module('d7-services.resources.views.resourceConstant', [])
25 | .constant("ViewsResourceConstant", ViewsResourceConstant);
26 |
27 | })();
28 |
--------------------------------------------------------------------------------