├── .gitignore ├── README.md ├── bower.json ├── dist ├── maps │ └── ng-drupal-7-services.js.map └── ng-drupal-7-services.js ├── docs └── .gitkeep ├── gulp ├── config.js └── tasks │ ├── build.js │ ├── helper.js │ ├── jsdocs.js │ └── version.js ├── gulpfile.js ├── package.json └── src ├── commons ├── authentication │ ├── authentication.bundle.js │ ├── authentication.channel.js │ ├── authentication.channelConstant.js │ ├── authentication.httpIntercepter.js │ ├── authentication.service.js │ └── authentication.serviceConstant.js ├── commons.baseChannel.js ├── commons.baseResource.js ├── commons.bundle.js ├── commons.drupalApiConfig.js ├── commons.helperService.js ├── directives │ ├── directives.bundle.js │ └── directives.toggleByAccessLevel.js └── http │ ├── http.bundle.js │ ├── http.configurations.js │ └── http.requestAcceptIntercepter.js ├── ng-drupal-7-services.js └── resources ├── comment ├── comment.bundle.js ├── comment.channel.js ├── comment.channelConstant.js ├── comment.resource.js └── comment.resourceConstant.js ├── definition ├── definition.bundle.js ├── definition.channel.js ├── definition.channelConstant.js ├── definition.resource.js └── definition.resourceConstant.js ├── file ├── file.bundle.js ├── file.channel.js ├── file.channelConstant.js ├── file.resource.js └── file.resourceConstant.js ├── geocoder ├── geocoder.bundle.js ├── geocoder.channel.js ├── geocoder.channelConstant.js ├── geocoder.helperConstants.js ├── geocoder.resource.js └── geocoder.resourceConstant.js ├── menu ├── menu.bundle.js ├── menu.channel.js ├── menu.channelConstant.js ├── menu.resource.js └── menu.resourceConstant.js ├── node ├── node.bundle.js ├── node.channel.js ├── node.channelConstant.js ├── node.resource.js └── node.resourceConstant.js ├── resources.bundle.js ├── system ├── system.bundle.js ├── system.channel.js ├── system.channelConstant.js ├── system.resource.js └── system.resourceConstant.js ├── taxonomy_term ├── taxonomy_term.bundle.js ├── taxonomy_term.channel.js ├── taxonomy_term.channelConstant.js ├── taxonomy_term.resource.js └── taxonomy_term.resourceConstant.js ├── taxonomy_vocabulary ├── taxonomy_vocabulary.bundle.js ├── taxonomy_vocabulary.channel.js ├── taxonomy_vocabulary.channelConstant.js ├── taxonomy_vocabulary.resource.js └── taxonomy_vocabulary.resourceConstant.js ├── user ├── user.bundle.js ├── user.channel.js ├── user.channelConstant.js ├── user.resource.js └── user.resourceConstant.js └── views ├── views.bundle.js ├── views.channel.js ├── views.channelConstant.js ├── views.operatorsConstant.js ├── views.resource.js └── views.resourceConstant.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | /node_modules 3 | /bower_components 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular/Ionic Drupal7 Services 2 | #### Well structured angular modules mimic the architecture of [Drupal Services 3.x](https://www.drupal.org/project/services) 3 | 4 | [![Bower version](https://badge.fury.io/bo/ng-drupal-7-services.svg)](https://badge.fury.io/bo/ng-drupal-7-services) 5 | [![npm version](https://badge.fury.io/js/ng-drupal-7-services.svg)](https://badge.fury.io/js/ng-drupal-7-services) 6 | [![Package Quality](http://npm.packagequality.com/shield/ng-drupal-7-services.svg)](http://packagequality.com/#?package=ng-drupal-7-services) 7 | 8 | Angular Drupal7 Services is a REST client for AngularJS, which allows you to user predefined functions when communication with Drupal's api endpoints. 9 | Unlike the other project focusing on the same topic, Angular Drupal7 Services is precisely organized around the [Drupal Services 3.x](https://www.drupal.org/project/services) architecture and naming conventions. 10 | 11 | It optionally provides events next to the common used promise approach. 12 | 13 | A full set of Drupal's resources is available, and all basic workflow's depending to authentication or helpers for CRUD operations are also provided as a set of extra modules. 14 | 15 | ##DEMOS 16 | Check out the [Drupal-API-Explorer](https://github.com/BioPhoton/ng-drupal-services-tests-with-ng) for a full demo 17 | Or check out the sample implementation for [Ionic-Headless-Drupal](https://github.com/BioPhoton/Ionic-Angular-Headless-Drupal-Demo) 18 | 19 | 20 | ## Get Started 21 | 22 | **(1)** Get Angular Drupal7 Services: 23 | - clone & build this repository 24 | - [download as .zip](https://github.com/BioPhoton/ng-drupal-7-services/archive/master.zip) 25 | - or via **[npm](https://www.npmjs.org/)**: by running `$ npm install ng-drupal-7-services` from your console 26 | - or via **[Bower](http://bower.io/)**: by running `$ bower install ng-drupal-7-services` from your console 27 | 28 | **(2)** Include `ng-drupal-7-services.js` in your `index.html`. 29 | 30 | **(3)** Add `'d7-services'` to your main module's list of dependencies 31 | 32 | 33 | ## [API Documentation](http://www.drupalionic.org/docs) (!!!in progress!!!) 34 | 35 | ## Quickstart 36 | 37 | **(1)** Insert the ```ng-drupal-7-services.js``` bundle into your ```index.html``` file. 38 | 39 | ```html 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 57 | ... 58 | 59 | 60 | ... 61 | 62 | 63 | ``` 64 | 65 | **(2)** Using the services. 66 | 67 | ```javascript 68 | angular 69 | angular.module('myApp') 70 | .controller('NodeController', ['NodeResource', 'NodeChannel', function(NodeResource, NodeChannel){ 71 | 72 | //fire request 73 | var retrievePromis = NodeResource.retrieve({nid:1}); 74 | 75 | //using promise.then callbacks 76 | retrievePromis.then(function(data) { ... },function(error) { ... }); 77 | 78 | //subscribing to events 79 | //This could happen in another directive/controller too 80 | NodeChannel.subRetrieveConfirmed($scope, function(data){ ... }); 81 | NodeChannel.subRetrieveFailed($scope, function(error){ ... }); 82 | 83 | }]); 84 | ``` 85 | 86 | ##Configuration 87 | Basically all configurable options are wrapped in an angular constant. 88 | IF you changed any of Drupal's default settings adopt the constants in DrupalApiConstant in Angular's config phase as shown above. 89 | Find all available options in the [API Documentation](http://www.drupalionic.org/docs) under Commons/DrupalApiConstant. 90 | ```javascript 91 | angular.module('myApp', ['d7-services']) 92 | .config(function configFunction(DrupalApiConstant) { 93 | ... 94 | //your changes here 95 | ... 96 | }); 97 | ``` 98 | 99 | ##Supported Drupal Modules 100 | Here is a list of supported Drupal services 3.x modules: 101 | - [x] [Services](https://www.drupal.org/project/services) **7 Resources** | **51 Requests** 102 | - [x] [Services Views](https://www.drupal.org/project/services_view) **1 Resources** | **1 Requests** 103 | - [x] [Services Menu](https://www.drupal.org/project/services_menu) **1 Resources** | **1 Requests** 104 | - [ ] [Services Search](https://www.drupal.org/project/services_search) **2 Resources** | **2 Requests** 105 | - [ ] [Services Entity](https://www.drupal.org/project/services_entity) **6 Resources** | **47 Requests** 106 | - [x] [Services Definitions](https://www.drupal.org/project/services_tools) **1 Resources** | **1 Requests** 107 | - [x] [Geocoder](https://www.drupal.org/project/geocoder) **1 Resources** | **2 Requests** 108 | 109 | ##Extra Resources 110 | Following extramodules are provided for simplifing authentication routing and viewcomposition 111 | - [x] Authentication **authenticaion workflows and helper functions** 112 | - [x] AccessControl **handle access for routing and actions** 113 | - [x] Directives **show hide elements by role or accesslevel** 114 | 115 | 116 | - **Drupal Services** 117 | - Comment Resource 118 | - Retrieve 119 | - Create 120 | - Update 121 | - Delete 122 | - Index 123 | - CountAll 124 | - CountNew 125 | - Retrieve 126 | - File Resource 127 | - Retrieve 128 | - Create 129 | - Delete 130 | - Index 131 | - Create_raw 132 | - Node Resource 133 | - Retrieve 134 | - Create 135 | - Update 136 | - Delete 137 | - Index 138 | - Files 139 | - Comments 140 | - Attach_file 141 | - System Resource 142 | - Connect 143 | - Get_variable 144 | - Set_variable 145 | - Del_variable 146 | - TaxonomyTerm Resource 147 | - Retrieve 148 | - Create 149 | - Update 150 | - Delete 151 | - Index 152 | - SelectNodes 153 | - TaxonomyVocabulary Resource 154 | - Retrieve 155 | - Create 156 | - Update 157 | - Delete 158 | - Index 159 | - GetTree 160 | - User Resource 161 | - Retrieve 162 | - Create 163 | - Update 164 | - Delete 165 | - Index 166 | - Login 167 | - Logout 168 | - Token 169 | - Request_new_password 170 | - Register 171 | - Cancel 172 | - Password_reset 173 | - Resend_welcome_email 174 | 175 | - **Drupal Services Views** 176 | - Views Resource 177 | - Retrieve 178 | 179 | - **Drupal Geocoder** 180 | -Views Geocoder 181 | - Retrieve 182 | - Index 183 | 184 | - **Drupal Services Menu** 185 | - Menu Resource 186 | - Retrieve 187 | 188 | - **Drupal Services Definition** 189 | - Definition Resource 190 | - Index 191 | 192 | - **Extra Resources** 193 | - Authentication service 194 | - storeTokenData 195 | - deleteTokenData 196 | - refreshToken 197 | - storeSessionData 198 | - deleteSessionData 199 | - getConnectionState 200 | - setConnectionState 201 | - getCurrentUser 202 | - setCurrentUser 203 | - refreshConnection 204 | - getLastConnectTime 205 | 206 | # Extra Services 207 | ##AccessControl 208 | - roles 209 | - accessLevels 210 | - authorize 211 | 212 | ### Directives 213 | - accessLevel => show hide elem based on role and acessLevel 214 | 215 | ## Setup for Drupal 216 | - Start with a fresh Drupal7 installation. 217 | 218 | ###Services 219 | - install [Drupal Services](https://www.drupal.org/project/services) 220 | - Go to admin/structure/services/add and create a new endpoint with following settings: 221 | - machine name: api 222 | - server: REST 223 | - path: api 224 | - debug: unchecked 225 | - session authentication: checked 226 | - Then click the edit resources link and open the resources tab. 227 | Now every resource you like by check box. 228 | - Then click Save 229 | - Click the Server tab 230 | - For Response formatters check following: 231 | - json 232 | - For Request parsing check following: 233 | - application/json 234 | - application/x-www-form-urlencoded 235 | - multipart/form-data (for file upload) 236 | - text/xml 237 | - Click Save. 238 | - Flush all of Drupal's caches. 239 | 240 | ###Setup for CORS 241 | - install [CORS](https://www.drupal.org/project/cors) 242 | - Go to admin/config/services/cors and paste following into the textarea 243 | 244 | `api/v1*||POST,PUT,GET,DELETE|Content-Type,Authorization,X-CSRF-TOKEN|true` 245 | 246 | #Links 247 | Testing resources on a test server => https://www.drupal.org/node/1447020 248 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-drupal-7-services", 3 | "version": "2.2.8", 4 | "homepage": "https://github.com/BioPhoton/ng-drupal-7-services", 5 | "license": "MIT", 6 | "authors": [ 7 | "Michael Hladky " 8 | ], 9 | "description": "Well structured AngularJS modules mimic the architecture of Drupal Services 3.x. for your next AngularJS / Ionic - Drupal Headless / Decoupled project", 10 | "keywords": [ 11 | "Drupal", 12 | "Headless", 13 | "Decoupled", 14 | "Angular", 15 | "Angularjs", 16 | "ng", 17 | "NG", 18 | "Ionic", 19 | "API", 20 | "REST", 21 | "http", 22 | "Services3", 23 | "Client", 24 | "Resource", 25 | "Endpoint" 26 | ], 27 | "main": "dist/ng-drupal-7-services.js", 28 | "ignore": [ 29 | "node_modules/", 30 | "bower_components/", 31 | "gulp/", 32 | "gulp.js", 33 | "docs/", 34 | "test", 35 | "tests", 36 | "package.json", 37 | "gulpfile.js", 38 | "bundle.config.js" 39 | ], 40 | "dependencies": { 41 | "ngstorage": "~0.3.9", 42 | "angular-cookies": "~1.4.5" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /docs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BioPhoton/ng-drupal-7-services/82b0c8a72ee9771c9d261b0f3d361243c4594300/docs/.gitkeep -------------------------------------------------------------------------------- /gulp/config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains the variables used in other gulp files 3 | * which defines tasks 4 | */ 5 | 'use strict'; 6 | 7 | module.exports = (function() { 8 | 9 | //dir paths 10 | var root = './', 11 | srcFolder = root+'src/', 12 | 13 | buildFolder = root+'dist/', 14 | packageName = 'ng-drupal-7-services.js', 15 | 16 | docsFolder = root+'docs/'; 17 | 18 | var config = { 19 | root : root, 20 | srcFolder : srcFolder, 21 | ngdoc : { 22 | docsFolder : docsFolder 23 | }, 24 | build : { 25 | buildFolder: buildFolder, 26 | packageName : packageName 27 | } 28 | }; 29 | 30 | return config; 31 | 32 | //////////////// 33 | 34 | })(); 35 | -------------------------------------------------------------------------------- /gulp/tasks/build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var helper = require('./helper'); 5 | var $ = require('gulp-load-plugins')(); 6 | 7 | var config = require('../config'); 8 | 9 | var defaultConfig = { 10 | srcFolder : config.srcFolder, 11 | }; 12 | 13 | //////////////// 14 | 15 | 16 | /** 17 | * Overrides 18 | * 19 | * config.build {[see defaultConfig here]} 20 | * 21 | **/ 22 | var buildConfig = defaultConfig; 23 | 24 | if('build' in config) { 25 | buildConfig = helper.arrayConcatExtend(defaultConfig, config.build); 26 | } 27 | 28 | //__________________________________________________________________________________________________ 29 | 30 | 31 | //////////////////////// 32 | 33 | 34 | gulp.task('optimize:js',['clean-build'], function(done) { 35 | 36 | return gulp.src(buildConfig.srcFolder+'**/*.js') 37 | .pipe($.sourcemaps.init()) 38 | // getBundleName creates a cache busting name 39 | .pipe($.concat(buildConfig.packageName)) 40 | .pipe($.uglify()) 41 | .pipe($.sourcemaps.write('./maps')) 42 | .pipe(gulp.dest(buildConfig.buildFolder)) 43 | .on('error', function(error) { 44 | console.log(error); 45 | }); 46 | 47 | }); 48 | 49 | /** 50 | * Remove all fonts from the build folder 51 | * @param {Function} done - callback when complete 52 | */ 53 | gulp.task('clean-build', function(done) { 54 | return helper.clean(buildConfig.buildFolder + '**/*.*', done); 55 | }); 56 | 57 | 58 | -------------------------------------------------------------------------------- /gulp/tasks/helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = (function() { 4 | var gulp = require('gulp'); 5 | var del = require('del'); 6 | var notify = require('gulp-notify'); 7 | var extendify = require('extendify'); 8 | var merge = require('merge-stream'); 9 | var cheerio = require('gulp-cheerio'); 10 | var browserSync = require('browser-sync').create(); 11 | var $ = require('gulp-load-plugins')(); 12 | 13 | 14 | var arrayMergeExtend = extendify({ 15 | inPlace: false, 16 | isDeep: true 17 | }), 18 | arrayReplaceExtend = extendify({ 19 | inPlace: false, 20 | isDeep: true, 21 | arrays : 'replace' 22 | }), 23 | arrayConcatExtend = extendify({ 24 | inPlace: false, 25 | isDeep: true, 26 | arrays : 'concat' 27 | }); 28 | 29 | var helper = { 30 | arrayMergeExtend : arrayMergeExtend, 31 | arrayReplaceExtend : arrayReplaceExtend, 32 | arrayConcatExtend : arrayConcatExtend, 33 | log : log, 34 | bulkCopy : bulkCopy, 35 | htmlEdit : htmlEdit, 36 | clean :clean, 37 | watch : watch, 38 | startBrowserSync : startBrowserSync, 39 | inject : inject, 40 | errorHandler : errorhandler, 41 | orderSrc : orderSrc, 42 | bytediffFormatter : bytediffFormatter 43 | }; 44 | 45 | return helper; 46 | 47 | /** 48 | * Log a message or series of messages using chalk's blue color. 49 | * Can pass in a string, object or array. 50 | */ 51 | function log(msg) { 52 | if (typeof(msg) === 'object') { 53 | for (var item in msg) { 54 | if (msg.hasOwnProperty(item)) { 55 | $.util.log($.util.colors.lightblue(msg[item])); 56 | } 57 | } 58 | } else { 59 | $.util.log($.util.colors.blue(msg)); 60 | } 61 | } 62 | 63 | /**/ 64 | function bulkCopy(copyArray, done) { 65 | log('Performing bulk copy: ' + $.util.colors.blue(copyArray.length) + ' tasks'); 66 | var merged = merge(); 67 | 68 | for(var i = 0; i<=copyArray.length-1; i++) { 69 | log('copy '+ ((copyArray[i].name)?copyArray[i].name:'') +' files from '+ copyArray[i].src +' to '+ copyArray[i].dest); 70 | var move = gulp.src(copyArray[i].src) 71 | .pipe(gulp.dest(copyArray[i].dest)); 72 | 73 | merged.add(move); 74 | } 75 | 76 | return merged; 77 | } 78 | 79 | 80 | function htmlEdit(src,dest,callback,done) { 81 | return gulp.src(src) 82 | .pipe(cheerio(function ($, file, done) { 83 | callback($); 84 | done(); 85 | })) 86 | .pipe(gulp.dest(dest)); 87 | } 88 | 89 | 90 | /** 91 | * Delete all files in a given path 92 | * @param {Array} path - array of paths to delete 93 | * @param {Function} done - callback when complete 94 | */ 95 | function clean(path, done) { 96 | log('Cleaning: ' + $.util.colors.blue(path)); 97 | return del(path, done); 98 | } 99 | 100 | 101 | function watch(src, tasks) { 102 | log('watch: ' + $.util.colors.blue(src)); 103 | return gulp.watch(src, tasks); 104 | } 105 | 106 | /** 107 | * Start BrowserSync 108 | */ 109 | function startBrowserSync(baseDir, options) { 110 | 111 | baseDir = (baseDir)?baseDir:'./src'; 112 | 113 | var options = { 114 | port: 8010, 115 | server: { 116 | baseDir: baseDir 117 | }, 118 | reloadDelay: 1000 119 | } ; 120 | 121 | log('Starting BrowserSync on port ' + options.port); 122 | 123 | browserSync.init(options); 124 | 125 | } 126 | 127 | /** 128 | * Inject files in a sorted sequence at a specified inject label 129 | * @param {Array} src glob pattern for source files 130 | * @param {String} label The label name 131 | * @param {Array} order glob pattern for sort order of the files 132 | * @returns {Stream} The stream 133 | */ 134 | function inject(src, label, order) { 135 | var options = { read: false, relative : true}; 136 | if (label) { 137 | options.name = 'inject:' + label; 138 | } 139 | 140 | return $.inject(orderSrc(src, order), options); 141 | } 142 | 143 | function errorhandler(title) { 144 | 145 | return notify.onError({ 146 | title: title + ' error(s)', 147 | message: '<%= error.message %>' 148 | }); 149 | } 150 | 151 | 152 | /** 153 | * Order a stream 154 | * @param {Stream} src The gulp.src stream 155 | * @param {Array} order Glob array pattern 156 | * @returns {Stream} The ordered stream 157 | * 158 | * 159 | */ 160 | function orderSrc (src, order) { 161 | //order = order || ['**\/*']; 162 | return gulp 163 | .src(src) 164 | .pipe($.if(order, $.order(order))); 165 | } 166 | 167 | /** 168 | * Formatter for bytediff to display the size changes after processing 169 | * @param {Object} data - byte data 170 | * @return {String} Difference in bytes, formatted 171 | */ 172 | function bytediffFormatter(data) { 173 | var difference = (data.savings > 0) ? ' smaller.' : ' larger.'; 174 | return data.fileName + ' went from ' 175 | + (data.startSize / 1000).toFixed(2) + ' kB to ' 176 | + (data.endSize / 1000).toFixed(2) + ' kB and is ' 177 | + formatPercent(1 - data.percent, 2) + '%' + difference; 178 | } 179 | 180 | /** 181 | * Format a number as a percentage 182 | * @param {Number} num Number to format as a percent 183 | * @param {Number} precision Precision of the decimal 184 | * @return {String} Formatted perentage 185 | */ 186 | function formatPercent(num, precision) { 187 | return (num * 100).toFixed(precision); 188 | } 189 | 190 | })(); 191 | -------------------------------------------------------------------------------- /gulp/tasks/jsdocs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var args = require('yargs').argv; 5 | var helper = require('./helper'); 6 | var gulpDocs = require('gulp-ngdocs'); 7 | var $ = require('gulp-load-plugins')(); 8 | 9 | 10 | var config = require('../config'), 11 | srcFolder = config.srcFolder, 12 | desFolder = './docs'; 13 | 14 | var defaultConfig = { 15 | srcFolder :srcFolder, 16 | desFolder : desFolder, 17 | options : { 18 | //scripts: [docsConfig.srcFolder+'**/*.js'], 19 | //html5Mode: true, 20 | //startPage: '/api', 21 | //title: "My Awesome Docs", 22 | //image: "path/to/my/image.png", 23 | //imageLink: "http://my-domain.com", 24 | //titleLink: "/api" 25 | } 26 | }; 27 | 28 | //////////////// 29 | 30 | 31 | /** 32 | * Overrides 33 | * 34 | * config.inject {[see defaultConfig here]} 35 | * 36 | **/ 37 | var jsDocConfig = defaultConfig; 38 | 39 | if('ngdoc' in config) { 40 | jsDocConfig = helper.arrayConcatExtend(defaultConfig, config.ngdoc); 41 | } 42 | 43 | //__________________________________________________________________________________________________ 44 | 45 | 46 | //////////////// 47 | 48 | gulp.task('ngdocs', [], function () { 49 | 50 | return gulp.src(jsDocConfig.srcFolder + '**/*.js') 51 | .pipe(gulpDocs.process(jsDocConfig.options)) 52 | .pipe(gulp.dest(jsDocConfig.desFolder)); 53 | }); 54 | 55 | gulp.task('serve-ngdocs',['ngdocs'], function (done) { 56 | helper.startBrowserSync(jsDocConfig.desFolder); 57 | }); -------------------------------------------------------------------------------- /gulp/tasks/version.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'), 4 | args = require('yargs').argv, 5 | helper = require('./helper'), 6 | $ = require('gulp-load-plugins')(); 7 | 8 | var config = require('../config'); 9 | 10 | var defaultConfig = { 11 | root : config.root, 12 | packages : [ 13 | './package.json', 14 | './bower.json', 15 | //'./manifest.json' 16 | ] 17 | }; 18 | 19 | ////////////////// 20 | 21 | 22 | var versionConfig = defaultConfig; 23 | 24 | /** 25 | * Overrides 26 | * 27 | * config.styles {[see defaultConfig here]} 28 | * 29 | **/ 30 | 31 | if('versionConfig' in config) { 32 | versionConfig = helper.arrayConcatExtend(defaultConfig, config.versionConfig); 33 | } 34 | 35 | //__________________________________________________________________________________________________ 36 | 37 | /** 38 | * Bump the version 39 | * --type=pre will bump the prerelease version *.*.*-x 40 | * --type=patch or no flag will bump the patch version *.*.x 41 | * --type=minor will bump the minor version *.x.* 42 | * --type=major will bump the major version x.*.* 43 | * --version=1.2.3 will bump to a specific version and ignore other flags 44 | */ 45 | gulp.task('bump', function(done) { 46 | var msg = 'Bumping versions ', 47 | type = args.type, 48 | version = args.version, 49 | options = {}; 50 | 51 | if (version) { 52 | options.version = version; 53 | msg += 'to ' + version; 54 | } else { 55 | if(type != undefined) { 56 | options.type = type; 57 | msg += 'for a ' + type; 58 | } 59 | else { 60 | helper.log('No param to bump version to. Task stopped!'); 61 | return; 62 | } 63 | } 64 | 65 | helper.log(msg); 66 | 67 | return gulp 68 | .src(versionConfig.packages) 69 | .pipe($.print()) 70 | .pipe($.bump(options)) 71 | .pipe(gulp.dest(versionConfig.root), done); 72 | }); -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /*Gulp modules 2 | * */ 3 | 4 | /* jshint node: true */ 5 | /** 6 | * Welcome to your gulpfile! 7 | * The gulp tasks are splitted in several files in the gulp directory 8 | * because putting all here was really too long 9 | */ 10 | 11 | 'use strict'; 12 | 13 | var gulp = require('gulp'); 14 | 15 | 16 | 17 | var wrench = require('wrench'); 18 | var $ = require('gulp-load-plugins')(); 19 | 20 | /** 21 | * This will load all js or coffee files in the gulp directory 22 | * in order to load all gulp tasks 23 | */ 24 | wrench.readdirSyncRecursive('./gulp/tasks').filter(function(file) { 25 | return (/\.(js|coffee)$/i).test(file); 26 | }).map(function(file) { 27 | require('./gulp/tasks/' + file); 28 | }); 29 | 30 | /** 31 | * List the available gulp tasks 32 | */ 33 | gulp.task('help', $.taskListing); 34 | gulp.task('default', ['help']); 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-drupal-7-services", 3 | "repository": { 4 | "type": "git", 5 | "url": "https://github.com/BioPhoton/ng-drupal-7-services" 6 | }, 7 | "version": "2.2.8", 8 | "license": "MIT", 9 | "author": "Michael Hladky ", 10 | "description": "Well structured AngularJS modules mimic the architecture of Drupal Services 3.x. for your next AngularJS / Ionic Drupal Headless / Decoupled project", 11 | "keywords": [ 12 | "Drupal", 13 | "Headless", 14 | "Decoupled", 15 | "Angular", 16 | "Angularjs", 17 | "ng", 18 | "NG", 19 | "Ionic", 20 | "API", 21 | "REST", 22 | "http", 23 | "Services3", 24 | "Client", 25 | "Resource", 26 | "Endpoint" 27 | ], 28 | "bugs": { 29 | "url": "https://github.com/BioPhoton/ng-drupal-7-services/issues" 30 | }, 31 | "dependencies": { 32 | "angular-cookies": "~1.4.5", 33 | "ngstorage": "~0.3.9" 34 | }, 35 | "devDependencies": { 36 | "browser-sync": "^2.11.1", 37 | "del": "^2.2.0", 38 | "extendify": "^1.0.0", 39 | "gulp": "^3.9.0", 40 | "gulp-bump": "^1.0.0", 41 | "gulp-cheerio": "^0.6.2", 42 | "gulp-concat": "^2.6.0", 43 | "gulp-load-plugins": "^1.2.0", 44 | "gulp-ngdocs": "^0.2.13", 45 | "gulp-notify": "^2.2.0", 46 | "gulp-print": "^2.0.1", 47 | "gulp-sourcemaps": "^1.6.0", 48 | "gulp-uglify": "^1.5.3", 49 | "gulp-util": "^3.0.7", 50 | "merge-stream": "^1.0.0", 51 | "wrench": "^1.5.8", 52 | "yargs": "^4.2.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/commons/authentication/authentication.bundle.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc object 6 | * @name d7-services.commons.authentication:Authentication 7 | * @description 8 | * This module bundles all modules related to drupal authentication resource 9 | * @requires d7-services.commons.authentication.serviceConstant:AuthenticationServiceConstant 10 | * @requires d7-services.commons.authentication.service:AuthenticationService 11 | * @requires d7-services.commons.authentication.channelConstant:AuthenticationChannelConstant 12 | * @requires d7-services.commons.authentication.channel:AuthenticationChannel 13 | * @requires d7-services.commons.authentication.httpIntercepter:AuthenticationHttpIntercepter 14 | */ 15 | angular 16 | .module('d7-services.commons.authentication', [ 17 | 'd7-services.commons.authentication.serviceConstant', 18 | 'd7-services.commons.authentication.channel', 19 | 'd7-services.commons.authentication.channelConstant', 20 | 'd7-services.commons.authentication.httpIntercepter', 21 | 'd7-services.commons.authentication.service']); 22 | 23 | })(); -------------------------------------------------------------------------------- /src/commons/authentication/authentication.channelConstant.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for AuthenticationChannel 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | **/ 9 | var AuthenticationChannelConstant = { 10 | 11 | loginConfirmed : 'event:drupal-authService-loginConfirmed', 12 | loginFailed : 'event:drupal-authService-loginFailed', 13 | 14 | logoutConfirmed : 'event:drupal-authService-logoutConfirmed', 15 | logoutFailed : 'event:drupal-authService-logoutFailed', 16 | 17 | refreshConnectionConfirmed : 'event:drupal-authService-refreshConnectionConfirmed', 18 | refreshConnectionFailed : 'event:drupal-authService-refreshConnectionFailed', 19 | 20 | tryConnectConfirmed : 'event:drupal-authService-tryConnectConfirmed', 21 | tryConnectFailed : 'event:drupal-authService-tryConnectFailed', 22 | 23 | connectionStateUpdated : 'event:drupal-authService-connectionStateUpdated', 24 | 25 | currentUserUpdated : 'event:drupal-authService-currentUserUpdated' 26 | 27 | }; 28 | 29 | /** 30 | * API authentication channel constant 31 | */ 32 | angular 33 | .module('d7-services.commons.authentication.channelConstant', []) 34 | .constant("AuthenticationChannelConstant", AuthenticationChannelConstant); 35 | 36 | })(); -------------------------------------------------------------------------------- /src/commons/authentication/authentication.httpIntercepter.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | 5 | /** 6 | * Drupal request intercepter Module for the requests Accept attribute 7 | */ 8 | angular.module('d7-services.commons.authentication.httpIntercepter', ['d7-services.commons.authentication.service']) 9 | .factory('AuthenticationHttpInterceptor', AuthenticationHttpInterceptor); 10 | 11 | /** 12 | * Manually identify dependencies for minification-safe code 13 | * 14 | **/ 15 | AuthenticationHttpInterceptor.$inject = [ '$injector']; 16 | 17 | /** 18 | * HTTP Intercepter for Accept attribute of HTTP-Requests 19 | **/ 20 | /** @ngInject */ 21 | function AuthenticationHttpInterceptor($injector) { 22 | 23 | //setup and return service 24 | var intercepter = { 25 | request : doRequestCongiguration, 26 | }; 27 | 28 | return intercepter; 29 | 30 | //////////// 31 | 32 | //request function 33 | 34 | /** 35 | * request 36 | * 37 | * Intercepts a request and sets the Accept attribute 38 | * 39 | * @param {Object} config The requests config object 40 | * 41 | * @return {Object} The edited config object 42 | * 43 | **/ 44 | function doRequestCongiguration (config) { 45 | var tokenHeaders = null; 46 | 47 | // Need to manually retrieve dependencies with $injector.invoke 48 | // because Authentication depends on $http, which doesn't exist during the 49 | // configuration phase (when we are setting up interceptors). 50 | // Using $injector.invoke ensures that we are provided with the 51 | // dependencies after they have been created. 52 | $injector.invoke(['AuthenticationService', function (AuthenticationService) { 53 | tokenHeaders = AuthenticationService.getAuthenticationHeaders(); 54 | 55 | }]); 56 | 57 | //add headers___________________________________________________________________ 58 | 59 | //add Authorisation and X-CSRF-TOKEN if given 60 | if (tokenHeaders) { 61 | angular.extend(config.headers, tokenHeaders); 62 | } 63 | 64 | //add flags_____________________________________________________________________ 65 | 66 | //add withCredentials to every request 67 | //needed because we send cookies in our request headers 68 | config.withCredentials = true; 69 | 70 | return config; 71 | }; 72 | 73 | }; 74 | 75 | })(); -------------------------------------------------------------------------------- /src/commons/authentication/authentication.service.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Drupal API authentication service 6 | **/ 7 | angular.module('d7-services.commons.authentication.service', 8 | [ 'd7-services.commons.configurations' 9 | ,'d7-services.commons.authentication.serviceConstant' 10 | ,'d7-services.commons.authentication.channel' 11 | ,'d7-services.resources.system.resource' 12 | ,'d7-services.resources.user.resource' 13 | ,'ngCookies' 14 | ]) 15 | 16 | /** 17 | * AuthenticationService 18 | * 19 | * This service mirrors the Drupal system resource of the services 3.x module. 20 | * To use this you have to set following line in your Drupal CORS module settings 21 | * your_api_endpoint/system/*||POST|Content-Type,Authorization|true 22 | * 23 | **/ 24 | .factory('AuthenticationService', AuthenticationService); 25 | 26 | /** 27 | * Manually identify dependencies for minification-safe code 28 | * 29 | **/ 30 | AuthenticationService.$inject = ['$rootScope', 'DrupalApiConstant', 'AuthenticationServiceConstant', 'AuthenticationChannel', 'SystemResource', 'UserResource', '$cookies', '$http', '$q']; 31 | 32 | /** 33 | * ApiAuthService 34 | * 35 | * This service mirrors the Drupal system resource of the services 3.x module. 36 | * To use this you have to set following line in your Drupal CORS module settings 37 | * your_api_endpoint/system/*||POST|Content-Type,Authorization|true 38 | * 39 | **/ 40 | /** @ngInject */ 41 | function AuthenticationService( $rootScope, DrupalApiConstant, AuthenticationServiceConstant, AuthenticationChannel, SystemResource, UserResource, $cookies, $http, $q ) { 42 | 43 | //we set this to undefined because we wan't to detect the first connection check 44 | var userIsConected, 45 | currentUser = AuthenticationServiceConstant.anonymousUser, 46 | // time of last successful connection in ms 47 | lastConnectTime = 0, 48 | //auth token rendered as Authentication headers 49 | authenticationHeaders, 50 | //session data 51 | sessid = null, 52 | session_name = null, 53 | sessionCookieOptions = { 54 | domain : DrupalApiConstant.drupal_instance, 55 | path : '/', 56 | //secure : false, 57 | //expires : DrupalApiConstant.session_expiration_time, 58 | //expirationUnit : DrupalApiConstant.session_expiration_unite, 59 | }; 60 | 61 | //setup and return service 62 | var authenticationService = { 63 | isUser : isUser, 64 | isAuthorized : isAuthorized, 65 | login : login, 66 | logout : logout, 67 | refreshConnection : refreshConnection, 68 | getLastConnectTime : getLastConnectTime, 69 | getConnectionState : getConnectionState, 70 | getAuthenticationHeaders : getAuthenticationHeaders, 71 | getCurrentUser : getCurrentUser 72 | }; 73 | 74 | return authenticationService; 75 | 76 | //////////// 77 | 78 | /** 79 | * isUser 80 | * 81 | * @param {Object} user or uid The user objcet or uid 82 | * 83 | * @returns {Boolean} true if uid is equal false if not 84 | * 85 | */ 86 | function isUser(userOrUid) { 87 | 88 | var currentUser = getCurrentUser(); 89 | 90 | if(angular.isObject(userOrUid)) { 91 | if(userOrUid.uid == currentUser.uid) { 92 | return true; 93 | } 94 | return false; 95 | } 96 | 97 | 98 | if(userOrUid == currentUser.uid) { 99 | return true; 100 | } 101 | 102 | return false; 103 | }; 104 | 105 | /** 106 | * isAuthorized 107 | * 108 | * @param {Object} accessLevel The access level to check for 109 | * @param {Object} roles The role to check with. If roles is not gives the users roles will be taken 110 | * 111 | * @returns {Boolean} true if authorized false if not 112 | * 113 | */ 114 | function isAuthorized(accessLevelRoles, userRoles) { 115 | var isGranted = false, 116 | currentUser = getCurrentUser(); 117 | 118 | if(userRoles === undefined ) { 119 | userRoles = currentUser.roles; 120 | } 121 | 122 | //check by accessLevel and optional given roles 123 | if(accessLevelRoles == '*') { return true; } 124 | 125 | if(!angular.isArray(accessLevelRoles)) { 126 | return false; 127 | } 128 | 129 | for (var i = 0; i < accessLevelRoles.length; i++) { 130 | for (var prop in userRoles) { 131 | if(accessLevelRoles[i][prop] === userRoles[prop]) { 132 | return true; 133 | } 134 | } 135 | } 136 | 137 | return false; 138 | }; 139 | 140 | /** 141 | * login 142 | * 143 | * Uses the login request of the user resource and saves session data on success 144 | * 145 | **/ 146 | function login(loginData) { 147 | 148 | return UserResource 149 | .login(loginData) 150 | .success(function (responseData, status, headers, config) { 151 | setAuthenticationHeaders(responseData.token); 152 | 153 | setLastConnectTime(Date.now()); 154 | setConnectionState((responseData.user.uid === 0)?false:true) 155 | setCookies(responseData.sessid, responseData.session_name); 156 | setCurrentUser(responseData.user); 157 | 158 | AuthenticationChannel.pubLoginConfirmed(responseData); 159 | }) 160 | .error(function (responseError, status, headers, config) { 161 | AuthenticationChannel.pubLoginFailed(responseError); 162 | }); 163 | 164 | }; 165 | 166 | /** 167 | * logout 168 | * 169 | * Uses the logout request of the user resource and deletes session data on success 170 | * 171 | * @return {Promise} requests promise 172 | **/ 173 | function logout() { 174 | 175 | return UserResource 176 | .logout() 177 | .success(function (responseData, status, headers, config) { 178 | delAuthenticationHeaders(); 179 | delCookies(); 180 | setConnectionState(false); 181 | setCurrentUser(AuthenticationServiceConstant.anonymousUser); 182 | 183 | AuthenticationChannel.pubLogoutConfirmed(responseData); 184 | }) 185 | .error(function (responseError, status, headers, config) { 186 | AuthenticationChannel.pubLogoutFailed(responseError); 187 | }); 188 | 189 | }; 190 | 191 | /** 192 | * refreshConnection 193 | * 194 | * @TODO write doc 195 | * 196 | * @return {Promise} with new token 197 | * 198 | **/ 199 | function refreshConnection() { 200 | var defer = $q.defer(); 201 | 202 | //check token 203 | refreshTokenFromServer() 204 | .then( 205 | function(response) { 206 | //check connection 207 | return tryConnect() 208 | .success(function(responseData, status, headers, config) { 209 | AuthenticationChannel.pubRefreshConnectionConfirmed(responseData); 210 | defer.resolve(responseData.data); 211 | }) 212 | } 213 | ) 214 | .catch( 215 | function(responseError) { 216 | console.log('error', responseError); 217 | AuthenticationChannel.pubRefreshConnectionFailed(responseError); 218 | //offline fix 219 | setLastConnectTime(1); 220 | defer.resolve(responseError); 221 | } 222 | ); 223 | 224 | return defer.promise; 225 | 226 | }; 227 | 228 | /** 229 | * tryConnect 230 | * 231 | * @TODO write doc 232 | * 233 | * @returns 234 | */ 235 | function tryConnect() { 236 | 237 | return SystemResource 238 | .connect() 239 | .success( function (responseData, status, headers, config) { 240 | setLastConnectTime(Date.now()); 241 | setCookies(responseData.sessid, responseData.session_name); 242 | setConnectionState((responseData.user.uid === 0)?false:true) 243 | setCurrentUser(responseData.user); 244 | 245 | AuthenticationChannel.pubTryConnectConfirmed(responseData); 246 | }) 247 | .error(function(responseError, status, headers, config) { 248 | AuthenticationChannel.pubTryConnectFailed(responseError); 249 | }); 250 | 251 | } 252 | 253 | /** 254 | * refreshTokenFromServer 255 | * 256 | * request a new token from server => api_endpoint/user/token 257 | * 258 | * @return {Promise} with new token 259 | * 260 | **/ 261 | function refreshTokenFromServer() { 262 | 263 | return UserResource 264 | .token() 265 | .success(function(responseData, status, headers, config) { 266 | setAuthenticationHeaders(responseData.token); 267 | }) 268 | .error(function(responseError) { 269 | // 270 | }); 271 | 272 | }; 273 | 274 | 275 | /** 276 | * getCurrentUser 277 | * 278 | * Returns the current authenticated user 279 | * 280 | * @return {Object} user as JSON 281 | * 282 | **/ 283 | function getCurrentUser() { return currentUser; }; 284 | 285 | /** 286 | * setCurrentUser 287 | * 288 | * Sets the current loggend in user 289 | * 290 | **/ 291 | function setCurrentUser(newUser) { 292 | if(currentUser != newUser) { 293 | currentUser = newUser; 294 | AuthenticationChannel.pubCurrentUserUpdated(newUser); 295 | } 296 | }; 297 | 298 | /** 299 | * getConnectionState 300 | * 301 | * Returns the current state of connection 302 | * 303 | * @return {Boolean} userIsConected 304 | * 305 | **/ 306 | function getConnectionState() { return (userIsConected)?true:false; }; 307 | 308 | /** 309 | * setConnectionState 310 | * 311 | * Sets the current state of connection as boolean 312 | * 313 | **/ 314 | function setConnectionState(newState) { 315 | newState = (newState)?true:false; 316 | 317 | if(newState !== userIsConected) { 318 | userIsConected = newState; 319 | AuthenticationChannel.pubConnectionStateUpdated(userIsConected); 320 | } 321 | }; 322 | 323 | /** 324 | * getAuthenticationHeaders 325 | * 326 | * Returns the saved authentication header obj 327 | * 328 | * @return {Object} authentication header 329 | * 330 | **/ 331 | function getAuthenticationHeaders() { return authenticationHeaders; }; 332 | 333 | 334 | /** 335 | * setAuthenticationHeaders 336 | * 337 | * Sets the authentication header as obj if different from actual value. 338 | * After this action the commons.authentication.AuthenticationHeaderInterceptor add's Authorisation and X-CSRF-Token headers to request 339 | * 340 | * @param {String} X-CSRF-TOKEN value 341 | * 342 | **/ 343 | function setAuthenticationHeaders(newToken) { 344 | 345 | var newData = { 346 | 'Authorization' : newToken, 347 | 'X-CSRF-TOKEN' : newToken 348 | }; 349 | 350 | //if header data exist check if they are different. 351 | //if they are different set them 352 | if(authenticationHeaders) { 353 | if(authenticationHeaders.Authorization != newToken) { 354 | authenticationHeaders = newData; 355 | } 356 | } 357 | //if header data not exist set them 358 | else { 359 | authenticationHeaders = newData; 360 | } 361 | 362 | }; 363 | 364 | /** 365 | * delAuthenticationHeaders 366 | * 367 | * Deletes the authentication headers from service 368 | * After this action the http intercepter will not add Authorisation and X-CSRF-Token headers to request 369 | * 370 | **/ 371 | function delAuthenticationHeaders() { 372 | authenticationHeaders = null; 373 | }; 374 | 375 | /** 376 | * getCookies 377 | * 378 | * Returns the saved cookie data 379 | * 380 | * @return {String} cookie data 381 | * 382 | **/ 383 | function getCookies() { 384 | return session_name+"="+sessid; 385 | }; 386 | 387 | /** 388 | * setCookies 389 | * 390 | * Saves the session id and name in service and cookies 391 | * 392 | * 393 | **/ 394 | function setCookies(newSessid, newSession_name) { 395 | //save data in service 396 | sessid = newSessid; 397 | session_name = newSession_name; 398 | 399 | //store session cookies 400 | //$cookies[data.session_name] = data.sessid; 401 | $cookies.put(newSession_name, newSessid, sessionCookieOptions); 402 | }; 403 | 404 | /** 405 | * delCookies 406 | * 407 | * Deletes the cookie from service and cookies 408 | * 409 | **/ 410 | function delCookies() { 411 | //delete data in service 412 | sessid = null; 413 | session_name = null; 414 | 415 | //delete session cookies 416 | $cookies.remove(session_name, sessionCookieOptions.path); 417 | }; 418 | 419 | /** 420 | * getLastConnectTime 421 | * 422 | * Returns the time of last successful connection in ms 423 | * 424 | * @return time in ms 425 | * 426 | **/ 427 | function getLastConnectTime() { return lastConnectTime; }; 428 | 429 | /** 430 | * setLastConnectTime 431 | * 432 | * Sets the time of last successful connection in ms 433 | * 434 | **/ 435 | function setLastConnectTime(newTimeInMs) { 436 | var newTimeInMs = parseInt(newTimeInMs); 437 | if(newTimeInMs === NaN || newTimeInMs < 0) return; 438 | lastConnectTime = newTimeInMs; 439 | }; 440 | 441 | 442 | }; 443 | 444 | })(); 445 | -------------------------------------------------------------------------------- /src/commons/authentication/authentication.serviceConstant.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for authenticationService 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | **/ 9 | 10 | //setup constant 11 | 12 | //default roles 13 | var anonymous_user = { 14 | 'id' : 1, 15 | 'role' : "anonymous user" 16 | }, 17 | authenticated_user = { 18 | 'id' : 2, 19 | 'role' : "authenticated user" 20 | }, 21 | administrator = { 22 | 'id' : 3, 23 | 'role' : "administrator" 24 | }; 25 | //default access levels 26 | var publicLevel = "*", 27 | anonLevel = {}, 28 | userLevel = {}, 29 | adminLevel = {}; 30 | 31 | anonLevel[anonymous_user.id] = anonymous_user.role; 32 | userLevel[authenticated_user.id] = authenticated_user.role; 33 | adminLevel[administrator.id ] = administrator.role; 34 | 35 | var AuthenticationServiceConstant = { 36 | //the drupals guest user obj 37 | anonymousUser : { 38 | "uid" : 0, 39 | "roles" : {}, 40 | "cache" : 0, 41 | "timestamp" : Date.now() 42 | }, 43 | //default drupal roles key is role id 44 | roles : {}, 45 | //default access levels 46 | //here you can grand access for role groups 47 | accessLevels : { 48 | 'public' : publicLevel, 49 | 'anon': [anonLevel], 50 | 'user' : [userLevel], 51 | 'admin': [adminLevel] 52 | } 53 | }; 54 | 55 | AuthenticationServiceConstant.anonymousUser.roles[anonymous_user.id] = anonymous_user.role; 56 | 57 | AuthenticationServiceConstant.roles[anonymous_user.id] = anonymous_user.role; 58 | AuthenticationServiceConstant.roles[authenticated_user.id] = authenticated_user.role; 59 | AuthenticationServiceConstant.roles[administrator.id] = administrator.role; 60 | 61 | /** 62 | * API authentication service constant 63 | **/ 64 | angular 65 | .module('d7-services.commons.authentication.serviceConstant', []) 66 | .constant("AuthenticationServiceConstant", AuthenticationServiceConstant); 67 | 68 | })(); -------------------------------------------------------------------------------- /src/commons/commons.baseChannel.js: -------------------------------------------------------------------------------- 1 | ;(function () { 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * @ngdoc service 7 | * @name d7-services.commons.baseChannel:BaseChannel 8 | * @description 9 | * An abstract notification channel. 10 | * This service enables you to publish and subscribe data over events in a very fast and efficient way. 11 | * @see {@link http://slides.com/michael_hladky/event-channel#/|Reacting to changes in AngularJS} 12 | */ 13 | angular.module('d7-services.commons.baseChannel', []) 14 | .factory('BaseChannel', BaseChannel); 15 | 16 | BaseChannel.$inject = ['$rootScope']; 17 | 18 | /** @ngInject */ 19 | function BaseChannel($rootScope) { 20 | 21 | var baseChannelService = { 22 | pubRootEmit: pubRootEmit, 23 | subRootEmit: subRootEmit 24 | }; 25 | 26 | return baseChannelService; 27 | 28 | //////////// 29 | 30 | /** 31 | * @ngdoc method 32 | * @name subRootEmit 33 | * @methodOf d7-services.commons.baseChannel:BaseChannel 34 | * @description 35 | * subscribe for an event published over $rootScope.$emit(event, args) 36 | * 37 | * @param {String} eventName - The events name 38 | * @param {Object} _Scope - The scope that calls the channels subscribe function 39 | * @param {function} scopeHandler - The callback handler normally defined in the $scopes controller or directive or service 40 | * @param {function} mapArgs - A mapper function to customize the given event arguments 41 | * 42 | * @return {function} The unsubscribe function from the $rootScope.on() call 43 | * 44 | * @example 45 | * 46 | * subscribe to an event 47 | *
 48 |      * angular
 49 |      *  .module('myModule', ['d7-services.commons.d7-services.commons.baseChannel'])
 50 |      *  .controller('myController',function ($scope,BaseChannel) {
 51 |      *    var unsubscribeHandler = BaseChannel.subRootEmit('MY_EVENT', $scope, function(args) {...}, function(args){return args;});
 52 |      * }
 53 |      * 
54 | * 55 | */ 56 | function subRootEmit(eventName, _Scope, scopeHandler, mapArgs) { 57 | 58 | //subscribe with rootScope to event and cache unsubscribe function 59 | var unsubScopeHandler = $rootScope.$on(eventName, function (event, args) { 60 | if (typeof mapArgs === 'function') { 61 | scopeHandler(mapArgs(args)); 62 | } else { 63 | scopeHandler(args); 64 | } 65 | 66 | }); 67 | 68 | //unsubscribe rootScope listener after scope destruction 69 | _Scope.$on('$destroy', function () { 70 | unsubScopeHandler(); 71 | }); 72 | 73 | //return he unsubscribe function from the $rootScope.on() call 74 | return unsubScopeHandler; 75 | } 76 | 77 | /** 78 | * @ngdoc method 79 | * @name pubRootEmit 80 | * @methodOf d7-services.commons.baseChannel:BaseChannel 81 | * @description 82 | * publish an event only to $rootScope using $rootScope.$emit 83 | * 84 | * @param {String} eventName The events name 85 | * @param {object} args The events arguments 86 | * 87 | * @example 88 | * 89 | * publish data with event 90 | *
 91 |      * angular
 92 |      *  .module('myModule', ['d7-services.commons.d7-services.commons.baseChannel'])
 93 |      *  .controller('myController', function ($scope,BaseChannel) {
 94 |      *    BaseChannel.pubRootEmit('MY_EVENT', {my:'args'});
 95 |      * }
 96 |      * 
97 | * 98 | */ 99 | function pubRootEmit(eventName, args) { 100 | $rootScope.$emit(eventName, args); 101 | } 102 | 103 | } 104 | 105 | })(); -------------------------------------------------------------------------------- /src/commons/commons.bundle.js: -------------------------------------------------------------------------------- 1 | ;(function () { 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * @ngdoc object 7 | * @name d7-services.commons:Commons 8 | * @description 9 | * This module bundles all modules related to the commons modules 10 | * @requires d7-services.commons.authentication:AuthenticationBundle 11 | * @requires d7-services.commons.http:HttpBundle 12 | * @requires d7-services.commons.directives:DirectivesBundle 13 | * @requires d7-services.commons.baseChannel:BaseChannel 14 | * @requires d7-services.commons.baseResource:BaseResource 15 | * @requires d7-services.commons.configurations:DrupalApiConstant 16 | * @requires d7-services.helperService.http:DrupalHelperService 17 | */ 18 | angular.module('d7-services.commons', [ 19 | 'd7-services.commons.authentication', 20 | 'd7-services.commons.http', 21 | 'd7-services.commons.directives', 22 | 'd7-services.commons.baseChannel', 23 | 'd7-services.commons.baseResource', 24 | 'd7-services.commons.configurations', 25 | 'd7-services.commons.helperService']); 26 | 27 | })(); -------------------------------------------------------------------------------- /src/commons/commons.drupalApiConfig.js: -------------------------------------------------------------------------------- 1 | ;(function () { 2 | "use strict"; 3 | 4 | var DrupalApiConstant = { 5 | // api 6 | drupal_instance: "http://your.site.name/", 7 | api_endpoint: "api/", 8 | responseFormat: "application/json", 9 | // - bencode: The encoding used by the BitTorrent file sharing system. 10 | // - json => JavaScript Object Notation 11 | // - jsonp: JSON with padding 12 | // - php: Responses are encoded using the data format emitted by PHPs "serialize()" function 13 | // - rss 14 | // - xml 15 | // - yaml 16 | 17 | // By default, Drupal is configured with a session expiration time of 2000000 seconds which is 23 day 3 hr. 33 min. 20 sec 18 | // To customize this install the session expire module => https://www.drupal.org/project/session_expire 19 | // And also set same value here 20 | session_expiration_time: 2000000, 21 | session_expiration_unite: "seconds", 22 | // paths 23 | publicFilePath: "public/", 24 | privateFilePath: "private/", 25 | filesPath: "sites/default/files/", 26 | imageStylesPath: "styles/", 27 | // Drupal's predefined image styles 28 | imageStyles: { 29 | large: "large", 30 | medium: "medium", 31 | thumbnail: "thumbnail" 32 | }, 33 | // 34 | LANGUAGE_NONE: "und" 35 | }; 36 | 37 | /** 38 | * @ngdoc object 39 | * @name d7-services.commons.configurations:DrupalApiConstant 40 | * @description 41 | * Constant for the d7-services module. Holds general options, request relevant data, defaults, filter options, imagestyles and so on. 42 | * 43 | * @property {string} drupal_instance - The sites domain 44 | * @property {string} api_endpoint - The path to the services 45 | * @property {string} responseFormat - Response format of a request. @see {@link https://www.drupal.org/node/1699450|Services response formatters and request parsing} 46 | * @property {Integer} session_expiration_time - The sessions lifetime. By default, Drupal is configured with a session expiration time of 2000000 seconds which is 23 day 3 hr. 33 min. 20 sec. 47 | * @property {string} session_expiration_unite - Session Expriation untis (Default is seconds because Drupals default time is in seconds) 48 | * @property {string} publicFilePath - path to public folder 49 | * @property {string} privateFilePath - path to private folder 50 | * @property {Object} imageStyles - Drupals default image styles 51 | * @property {string} imageStyles.large - Large image style name 52 | * @property {string} imageStyles.medium - Medium image style name 53 | * @property {string} imageStyles.thumbnail - Thumbnail image style name 54 | * @property {string} LANGUAGE_NONE - default language 55 | * 56 | * @example 57 | * 58 | * DrupalApiConstant is editable in config phase 59 | *
 60 |      * angular
 61 |      *  .module("myModule", ["d7-services.commons"])
 62 |      *  .config(function (DrupalApiConstant) {
 63 |      *  
 64 |      *  //Define your drupal instance.
 65 |      *  DrupalApiConstant.drupal_instance = 'http://your.projects.domain/';
 66 |      *
 67 |      *  //Override the path to your api.
 68 |      *  //This path is defined in "Edit Resource" under tab "Edit".
 69 |      *  DrupalApiConstant.api_endpoint += 'v1/'; // results in "api/v1/";
 70 |      *
 71 |      *  //Override the default response format. (json,jsonp,php,rss,xml,yaml,...)
 72 |      *  //Find a list of profided fromats in "Edit Resource" under tab "Server".
 73 |      *  DrupalApiConstant.responseFormat = "application/json";
 74 |      *
 75 |      *  //Override the default public and private folders
 76 |      *  DrupalApiConstant.publicFilePath = "new_public/";
 77 |      *  DrupalApiConstant.privateFilePath = "new_private/";
 78 |      *
 79 |      *  //Override the Drupals default path to files.
 80 |      *  DrupalApiConstant.filesPath = "sites/default/my_files/";
 81 |      *
 82 |      *  //Override the Drupals default image styles path.
 83 |      *  DrupalApiConstant.imageStylesPath = "my_styles/";
 84 |      *
 85 |      *  //Override the default image styles and add custom once.
 86 |      *  DrupalApiConstant.imageStyles.large = 'modified_large';
 87 |      *  DrupalApiConstant.imageStyles.new_style = 'new_style_name';
 88 |      *
 89 |      *  //Override the default language.
 90 |      *  DrupalApiConstant.LANGUAGE_NONE = 'und';
 91 |      * }
 92 |      * 
93 | */ 94 | angular 95 | .module("d7-services.commons.configurations", []) 96 | .constant("DrupalApiConstant", DrupalApiConstant); 97 | 98 | 99 | })(); 100 | -------------------------------------------------------------------------------- /src/commons/commons.helperService.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc service 6 | * @name d7-services.commons.helperService:DrupalHelperService 7 | * @description 8 | * An abstract resource providing retrieve, create, update, delete and index functions. 9 | * This service is used to handle the resources basic get put pust delete operations. 10 | * @requires d7-services.commons.configurations:DrupalApiConstant 11 | */ 12 | angular.module('d7-services.commons.helperService', ['d7-services.commons.configurations']) 13 | .factory('DrupalHelperService', DrupalHelperService); 14 | 15 | DrupalHelperService.$inject = ['DrupalApiConstant']; 16 | 17 | /** @ngInject */ 18 | function DrupalHelperService(DrupalApiConstant) { 19 | 20 | var drupalHelperService = { 21 | getApiPath : getApiPath, 22 | getDrupalPath : getDrupalPath, 23 | getPathToImgByStyle : getPathToImgByStyle, 24 | structureField : structureField 25 | }; 26 | 27 | return drupalHelperService; 28 | 29 | //////////// 30 | 31 | /** 32 | * @ngdoc method 33 | * @name getApiPath 34 | * @methodOf d7-services.commons.helperService:DrupalHelperService 35 | * @description 36 | * Helper to get path to api 37 | * 38 | * @return {String} Path to api 39 | * 40 | * @example 41 | * Create path to resource 42 | *
 43 | 		 * angular
 44 | 		 *  .module('myModule', ['d7-services.commons'])
 45 | 		 *  .controller('myController',function ($scope,DrupalHelperService) {
 46 | 		 *    var requestConfig = {
 47 | 		 *    	url 	: DrupalHelperService.getApiPath()+'resource?param=test',
 48 | 		 *		method 	:'GET'
 49 | 		 *    };
 50 | 		 * }
 51 | 		 * 
52 | */ 53 | function getApiPath() { 54 | return DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint; 55 | } 56 | 57 | /** 58 | * @ngdoc method 59 | * @name getDrupalPath 60 | * @methodOf d7-services.commons.helperService:DrupalHelperService 61 | * @description 62 | * Helper to get path to drupal server 63 | * 64 | * @return {String} Path to drupal server 65 | * 66 | * @example 67 | * Create path to resource 68 | *
 69 | 		 * angular
 70 | 		 *  .module('myModule', ['d7-services.commons'])
 71 | 		 *  .controller('myController',function ($scope,DrupalHelperService) {
 72 | 		 *    var DrupalHelperService.getDrupalPath()+'resource?param=test';
 73 | 		 * }
 74 | 		 * 
75 | */ 76 | function getDrupalPath() { 77 | return DrupalApiConstant.drupal_instance; 78 | } 79 | 80 | // 81 | /** 82 | * @ngdoc method 83 | * @name getPathToImgByStyle 84 | * @methodOf d7-services.commons.helperService:DrupalHelperService 85 | * @description 86 | * Helper to get full path to image style. 87 | * 88 | * @param {String} style - Path segment from you image style path with out the "/". ("medium"). 89 | * Image styles are configurable in constant. 90 | * @see (link:d7-services.commons.configurations:DrupalApiConstant) 91 | * @param {String} [isPrivate] - whether the image is in your public our private folder. Default is public. 92 | * 93 | * @return {String} Full path to image style. 94 | * 95 | * @example 96 | * Create path to resource 97 | *
 98 | 		 * angular
 99 | 		 *  .module('myModule', ['d7-services.commons'])
100 | 		 *  .controller('myController',function ($scope,DrupalHelperService) {
101 | 		 *
102 | 		 *    var imgPath = DrupalHelperService.getPathToImgByStyle(DrupalApiConstant.imageStyles.medium)+'image_name_0.png';
103 | 		 * }
104 | 		 * 
105 | */ 106 | function getPathToImgByStyle(style, isPrivate) { 107 | return getDrupalPath() + DrupalApiConstant.filesPath+DrupalApiConstant.imageStylesPath+style+'/'+ ( (isPrivate)?DrupalApiConstant.privateFilePath:DrupalApiConstant.publicFilePath ); 108 | } 109 | 110 | 111 | 112 | /** 113 | * https://github.com/jbeuckm/drupal-client/blob/master/lib/field.js 114 | * Create the basic field structure for uploading a field. 115 | * 116 | * Example input output 117 | * 118 | * String: 119 | * IN: 120 | * OUT: 121 | * 122 | * Object: 123 | * IN: { value : 'foobar foo', summary : 'foobar' } 124 | * OUT: { und : [{ value : 'foobar foo', summary : 'foobar' }]} 125 | * 126 | */ 127 | //@TODO refactore and add language support 128 | function structureField(value, label, language) { 129 | // record optional label string 130 | // default is "value" 131 | var prepatedData = undefined, 132 | label = label || "value", 133 | language = (language !== undefined)?language:DrupalApiConstant.LANGUAGE_NONE; 134 | 135 | if (angular.isObject(value)) { 136 | prepatedData = {}; 137 | prepatedData[language] = [value]; 138 | } 139 | 140 | return prepatedData; 141 | 142 | if (value instanceof Date) { 143 | 144 | var prepatedData = { 145 | value: { 146 | date: (value.getMonth()+1)+'/'+value.getDate()+'/'+value.getFullYear()+' - '+value.getHours()+':'+value.getMinutes()+':'+value.getSeconds() 147 | } 148 | }; 149 | 150 | return { 151 | und: [ 152 | prepatedData 153 | ] 154 | }; 155 | 156 | } 157 | 158 | //// 159 | 160 | 161 | // record optional label string or default to "value" 162 | var label = label || "value"; 163 | var language_key = (language)? function() {return language}:function() {return baseResourceConfig.LANGUAGE_NONE}; 164 | 165 | if (angular.isArray(value)) { 166 | 167 | var field_array = []; 168 | for (var i= 0, l=value.length; i|POST|Content-Type,Authorization|true 17 | * 18 | **/ 19 | .factory('CommentResource', CommentResource); 20 | 21 | /** 22 | * Manually identify dependencies for minification-safe code 23 | * 24 | **/ 25 | CommentResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'CommentResourceConstant', 'CommentChannel']; 26 | 27 | /** @ngInject */ 28 | function CommentResource($http, BaseResource, DrupalApiConstant, CommentResourceConstant, CommentChannel) { 29 | 30 | //setup and return service 31 | var commentResourceService = { 32 | //CRUD operations 33 | retrieve : retrieve, 34 | create : create, 35 | update : update, 36 | delete : _delete, 37 | index : index, 38 | //Actions 39 | countAll : countAll, 40 | countNew : countNew 41 | 42 | }; 43 | 44 | return commentResourceService; 45 | 46 | //////////// 47 | 48 | /** 49 | * retrieve 50 | * 51 | * Retrieve a comment 52 | * 53 | * Method: GET 54 | * Url: http://drupal_instance/api_endpoint/comment/{CID} 55 | * 56 | * @params {Object} data The requests data 57 | * @key {Integer} cid The cid of the comment to retrieve., required:true, source:path 58 | * 59 | * @return {Promise} A comment object 60 | * 61 | **/ 62 | function retrieve(data) { 63 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath + '/' + data.cid; 64 | return BaseResource.retrieve( retrievePath,CommentChannel.pubRetrieveConfirmed, CommentChannel.pubRetrieveFailed); 65 | }; 66 | 67 | /** 68 | * create 69 | * 70 | * Create a comment 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/comment 76 | * 77 | * @params {Object} comment The data of the comment to create, 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 comment role, which is given by default. 82 | * 83 | * @return {Promise} The comment object of the newly created comment. 84 | * 85 | **/ 86 | function create(data) { 87 | 88 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath; 89 | 90 | var createData = { 91 | comment : data 92 | }; 93 | 94 | return BaseResource.create( createData, createPath, CommentChannel.pubCreateConfirmed, CommentChannel.pubCreateFailed); 95 | 96 | }; 97 | 98 | /** 99 | * update 100 | * 101 | * Update a comment 102 | * 103 | * Method: PUT 104 | * Url: http://drupal_instance/api_endpoint/comment/{CID} 105 | * 106 | * @params {Object} data The requests data 107 | * @key {Integer} cid The unique identifier for this comment., required:true, source:path 108 | * @key {Array} data The comment object with updated information, 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 + CommentResourceConstant.resourcePath + '/' + data.cid; 116 | 117 | delete data.cid 118 | var updateData = {comment : data}; 119 | 120 | return BaseResource.update( updateData, updatePath, CommentChannel.pubUpdateConfirmed, CommentChannel.pubUpdateFailed); 121 | 122 | }; 123 | 124 | /** 125 | * delete 126 | * 127 | * Delete the comment 128 | * 129 | * Method: DELETE 130 | * Url: http://drupal_instance/api_endpoint/comment/{CID} 131 | * 132 | * @params {Object} data the requests data 133 | * @key {Integer} cid The id of the comment to delete, required:true, source:path 134 | * 135 | * @return {Promise} 136 | * 137 | **/ 138 | function _delete(data) { 139 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath + '/' + data.cid 140 | return BaseResource.delete(deletePath, CommentChannel.pubDeleteConfirmed, CommentChannel.pubDeleteFailed); 141 | }; 142 | 143 | /** 144 | * index 145 | * 146 | * List all comments 147 | * 148 | * Method: GET 149 | * Url: http://drupal_instance/api_endpoint/comment 150 | * 151 | * @params {Object} data the requests data 152 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param 153 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param 154 | * @key {String} fields The fields to get., required:false, source:param 155 | * @key {Array} parameters Parameters, required:false, source:param 156 | * 157 | * 158 | * @return {Promise} 159 | * 160 | **/ 161 | function index(data) { 162 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath + '/'; 163 | return BaseResource.index(data, indexPath,CommentChannel.pubIndexConfirmed, CommentChannel.pubIndexFailed); 164 | }; 165 | 166 | /** 167 | * countAll 168 | * 169 | * Return number of comments on a given node. 170 | * 171 | * Method: POST 172 | * Url: http://drupal_instance/api_endpoint/comment/countAll 173 | * 174 | * @params {Object} data the requests data 175 | * @key {Integer} nid The node id to count all comments., separated by comma., required:true, source:post body 176 | * 177 | * @return {Promise} 178 | * 179 | **/ 180 | function countAll(data) { 181 | var pathTocountAll = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath + '/' + CommentResourceConstant.actions.countAll, 182 | requestConfig = { 183 | url : pathTocountAll, 184 | method : 'POST', 185 | data : data 186 | }; 187 | 188 | 189 | 190 | return BaseResource.request(requestConfig,CommentChannel.pubCountAllConfirmed, CommentChannel.pubCountAllFailed); 191 | 192 | }; 193 | 194 | /** 195 | * countNew 196 | * 197 | * Returns number of new comments on a given node since a given timestamp. 198 | * 199 | * Method: POST 200 | * Url: http://drupal_instance/api_endpoint/comment/countNew 201 | * 202 | * @params {Object} data the requests data 203 | * @key {Integer} cid The node id to load comments for., separated by comma., required:true, source:post body 204 | * @key {Integer} since Timestamp to count from (defaults to time of last user acces to node)., required:false, source:post body 205 | * 206 | * @return {Promise} 207 | * 208 | **/ 209 | function countNew(data) { 210 | var pathTocountNew = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + CommentResourceConstant.resourcePath + '/' + CommentResourceConstant.actions.countNew, 211 | requestConfig = { 212 | url : pathTocountNew, 213 | method : 'POST', 214 | data : data 215 | }; 216 | 217 | return BaseResource.request(requestConfig,CommentChannel.pubCountNewConfirmed, CommentChannel.pubCountNewFailed); 218 | 219 | }; 220 | 221 | }; 222 | 223 | })(); -------------------------------------------------------------------------------- /src/resources/comment/comment.resourceConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for CommentResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var CommentResourceConstant = { 10 | 11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal 12 | resourcePath : 'comment', 13 | //actions of comment 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 | countAll : 'countAll', 23 | countNew : 'countNew' 24 | } 25 | 26 | }; 27 | 28 | /** 29 | * Comment Constant Modules 30 | */ 31 | angular 32 | .module('d7-services.resources.comment.resourceConstant', []) 33 | .constant("CommentResourceConstant", CommentResourceConstant); 34 | 35 | })(); 36 | -------------------------------------------------------------------------------- /src/resources/definition/definition.bundle.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc object 6 | * @name d7-services.resources.definition:Definition 7 | * @description 8 | * This module bundles all modules related to drupal definition resource 9 | * @requires d7-services.resources.definition.resourceConstant:DefinitionResourceConstant 10 | * @requires d7-services.resources.definition.resource:DefinitionResource 11 | * @requires d7-services.resources.definition.channelConstant:DefinitionChannelConstant 12 | * @requires d7-services.resources.definition.channel:DefinitionChannel 13 | */ 14 | angular.module('d7-services.resources.definition', 15 | ['d7-services.resources.definition.resourceConstant', 16 | 'd7-services.resources.definition.resource', 17 | 'd7-services.resources.definition.channelConstant', 18 | 'd7-services.resources.definition.channel']); 19 | })(); -------------------------------------------------------------------------------- /src/resources/definition/definition.channel.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Definition Channel Module 6 | */ 7 | angular.module('d7-services.resources.definition.channel', ['d7-services.commons.baseChannel', 'd7-services.resources.definition.channelConstant']) 8 | .factory('DefinitionChannel', DefinitionChannel); 9 | 10 | 11 | /** 12 | * Manually identify dependencies for minification-safe code 13 | * 14 | **/ 15 | DefinitionChannel.$inject = [ 'BaseChannel', 'DefinitionChannelConstant' ]; 16 | 17 | /** 18 | * Notification channel for definition resource 19 | **/ 20 | 21 | /** @ngInject */ 22 | function DefinitionChannel(BaseChannel, DefinitionChannelConstant) { 23 | 24 | //setup and return service 25 | var definitionChannelService = { 26 | 27 | //definition index request 28 | pubIndexConfirmed : pubIndexConfirmed, 29 | subIndexConfirmed : subIndexConfirmed, 30 | pubIndexFailed : pubIndexFailed, 31 | subIndexFailed : subIndexFailed 32 | }; 33 | 34 | return definitionChannelService; 35 | 36 | //////////// 37 | 38 | //Definition index request functions 39 | 40 | /** 41 | * pubIndexConfirmed 42 | * 43 | * Publish the DefinitionIndexConfirmed event with giver args 44 | * 45 | * @param {Object} args The events arguments 46 | * 47 | * 48 | **/ 49 | function pubIndexConfirmed(args) { 50 | BaseChannel.pubRootEmit(DefinitionChannelConstant.indexConfirmed, args); 51 | }; 52 | 53 | /** 54 | * subIndexConfirmed 55 | * 56 | * subscribe for the DefinitionIndexConfirmed event 57 | * 58 | * @param {Object} _Scope The scope that calls the channels subIndexConfirmed function 59 | * @param {function} scopeHandler The callback handler for DefinitionIndexConfirmed event 60 | * 61 | * @return {function} The unsubscribe function from the $rootScope.on() call 62 | * 63 | **/ 64 | function subIndexConfirmed(_Scope, scopeHandler) { 65 | var unsubScopeHandler = BaseChannel.subRootEmit( DefinitionChannelConstant.indexConfirmed, _Scope, scopeHandler); 66 | return unsubScopeHandler; 67 | }; 68 | 69 | //############### 70 | 71 | 72 | /** 73 | * pubIndexConfirmed 74 | * 75 | * Publish the DefinitionIndexConfirmed event with giver args 76 | * 77 | * @param {Object} args The events arguments 78 | * 79 | * 80 | **/ 81 | function pubIndexFailed(args) { 82 | BaseChannel.pubRootEmit(DefinitionChannelConstant.indexFailed, args); 83 | }; 84 | 85 | /** 86 | * subIndexFailed 87 | * 88 | * subscribe for the DefinitionIndexFailed event 89 | * 90 | * @param {Object} _Scope The scope that calls the channels subIndexFailed function 91 | * @param {function} scopeHandler The callback handler for DefinitionIndexFailed event 92 | * 93 | * @return {function} The unsubscribe function from the $rootScope.on() call 94 | * 95 | **/ 96 | function subIndexFailed(_Scope, scopeHandler) { 97 | var unsubScopeHandler = BaseChannel.subRootEmit( DefinitionChannelConstant.indexFailed, _Scope, scopeHandler); 98 | return unsubScopeHandler; 99 | }; 100 | 101 | //________________________________________________________________________________________________________________________________________ 102 | 103 | }; 104 | 105 | })(); -------------------------------------------------------------------------------- /src/resources/definition/definition.channelConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for DefinitionChannel 6 | * 7 | * NOTE: if you want to change this constant do this in a config section of angular 8 | */ 9 | var DefinitionChannelConstant = { 10 | // Index action 11 | indexConfirmed : 'event:drupal-definition-indexConfirmed', 12 | indexFailed : 'event:drupal-definition-indexFailed' 13 | }; 14 | 15 | /** 16 | * Definition Channel Constant 17 | */ 18 | angular 19 | .module('d7-services.resources.definition.channelConstant', []) 20 | .constant("DefinitionChannelConstant", DefinitionChannelConstant); 21 | 22 | })(); 23 | -------------------------------------------------------------------------------- /src/resources/definition/definition.resource.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Definition Resource Modules 6 | * 7 | * see sourcecode in services/resources/definition_resource.inc 8 | **/ 9 | angular.module('d7-services.resources.definition.resource', ['d7-services.commons.configurations', 'd7-services.resources.definition.resourceConstant', 'd7-services.resources.definition.channel', 'd7-services.commons.baseResource']) 10 | 11 | /** 12 | * DefinitionResource 13 | * 14 | * This service mirrors the Drupal definition 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/definition/*||POST|Content-Type,Authorization|true 17 | * 18 | **/ 19 | .factory('DefinitionResource', DefinitionResource); 20 | 21 | /** 22 | * Manually identify dependencies for minification-safe code 23 | * 24 | **/ 25 | DefinitionResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'DefinitionResourceConstant', 'DefinitionChannel']; 26 | 27 | /** @ngInject */ 28 | function DefinitionResource($http, BaseResource, DrupalApiConstant, DefinitionResourceConstant, DefinitionChannel) { 29 | 30 | //setup and return service 31 | var definitionResourceService = { 32 | //CRUD operations 33 | index : index 34 | }; 35 | 36 | return definitionResourceService; 37 | 38 | //////////// 39 | 40 | /** 41 | * index 42 | * 43 | * List all definitions 44 | * 45 | * Method: GET 46 | * Url: http://drupal_instance/api_endpoint/definition 47 | * 48 | * @params {Object} data the requests data 49 | * 50 | * 51 | * @return {Promise} 52 | * 53 | **/ 54 | function index() { 55 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + DefinitionResourceConstant.resourcePath + '/'; 56 | return BaseResource.retrieve(indexPath, DefinitionChannel.pubIndexConfirmed, DefinitionChannel.pubIndexFailed); 57 | }; 58 | 59 | }; 60 | 61 | })(); -------------------------------------------------------------------------------- /src/resources/definition/definition.resourceConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for DefinitionResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var DefinitionResourceConstant = { 10 | 11 | // NOTE: This is the default alias aliases for your system resources defined in Drupal 12 | resourcePath : 'definition', 13 | //actions of user resource 14 | actions : { 15 | //following actions are defined over their request method (GET) so they are commented out 16 | //index : 'index' 17 | } 18 | 19 | }; 20 | 21 | /** 22 | * Definition Constant Modules 23 | */ 24 | angular 25 | .module('d7-services.resources.definition.resourceConstant', []) 26 | .constant("DefinitionResourceConstant", DefinitionResourceConstant); 27 | 28 | })(); 29 | -------------------------------------------------------------------------------- /src/resources/file/file.bundle.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc object 6 | * @name d7-services.resources.file:File 7 | * @description 8 | * This module bundles all modules related to drupal file resource 9 | * @requires d7-services.resources.file.resourceConstant:FileResourceConstant 10 | * @requires d7-services.resources.file.resource:FileResource 11 | * @requires d7-services.resources.file.channelConstant:FileChannelConstant 12 | * @requires d7-services.resources.file.channel:FileChannel 13 | */ 14 | angular.module('d7-services.resources.file', 15 | ['d7-services.resources.file.resourceConstant', 16 | 'd7-services.resources.file.resource', 17 | 'd7-services.resources.file.channelConstant', 18 | 'd7-services.resources.file.channel']); 19 | })(); -------------------------------------------------------------------------------- /src/resources/file/file.channel.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * File Channel Module 6 | */ 7 | angular.module('d7-services.resources.file.channel', ['d7-services.commons.baseChannel', 'd7-services.resources.file.channelConstant']) 8 | .factory('FileChannel', FileChannel); 9 | 10 | 11 | /** 12 | * Manually identify dependencies for minification-safe code 13 | * 14 | **/ 15 | FileChannel.$inject = [ 'BaseChannel', 'FileChannelConstant' ]; 16 | 17 | /** 18 | * Notification channel for file resource 19 | **/ 20 | 21 | /** @ngInject */ 22 | function FileChannel(BaseChannel, FileChannelConstant) { 23 | 24 | //setup and return service 25 | var fileChannelService = { 26 | 27 | //Retrieve event 28 | pubRetrieveConfirmed : pubRetrieveConfirmed, 29 | subRetrieveConfirmed : subRetrieveConfirmed, 30 | pubRetrieveFailed : pubRetrieveFailed, 31 | subRetrieveFailed : subRetrieveFailed, 32 | // Create action 33 | pubCreateConfirmed : pubCreateConfirmed, 34 | subCreateConfirmed : subCreateConfirmed, 35 | pubCreateFailed : pubCreateFailed, 36 | subCreateFailed : subCreateFailed, 37 | // Delete action 38 | pubDeleteConfirmed : pubDeleteConfirmed, 39 | subDeleteConfirmed : subDeleteConfirmed, 40 | pubDeleteFailed : pubDeleteFailed, 41 | subDeleteFailed : subDeleteFailed, 42 | // Index action 43 | pubIndexConfirmed : pubIndexConfirmed, 44 | subIndexConfirmed : subIndexConfirmed, 45 | pubIndexFailed : pubIndexFailed, 46 | subIndexFailed : subIndexFailed, 47 | // CreateRaw 48 | pubCreateRawConfirmed : pubCreateRawConfirmed, 49 | subCreateRawConfirmed : subCreateRawConfirmed, 50 | pubCreateRawFailed : pubCreateRawFailed, 51 | subCreateRawFailed : subCreateRawFailed 52 | 53 | }; 54 | 55 | return fileChannelService; 56 | 57 | //////////// 58 | 59 | //File retrieve request functions 60 | 61 | /** 62 | * pubRetrieveConfirmed 63 | * 64 | * Publish the FileRetrieveConfirmed event with giver args 65 | * 66 | * @param {Object} args The events arguments 67 | * 68 | * 69 | **/ 70 | function pubRetrieveConfirmed(args) { 71 | BaseChannel.pubRootEmit(FileChannelConstant.retrieveConfirmed, args); 72 | }; 73 | 74 | /** 75 | * subRetrieveConfirmed 76 | * 77 | * subscribe for the FileRetrieveConfirmed event 78 | * 79 | * @param {Object} _Scope The scope that calls the channels subRetrieveConfirmed function 80 | * @param {function} scopeHandler The callback handler for FileRetrieveConfirmed event 81 | * 82 | * @return {function} The unsubscribe function from the $rootScope.on() call 83 | * 84 | **/ 85 | function subRetrieveConfirmed(_Scope, scopeHandler) { 86 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.retrieveConfirmed, _Scope, scopeHandler); 87 | 88 | return unsubScopeHandler; 89 | }; 90 | 91 | //############### 92 | 93 | 94 | /** 95 | * pubRetrieveConfirmed 96 | * 97 | * Publish the FileRetrieveConfirmed event with giver args 98 | * 99 | * @param {Object} args The events arguments 100 | * 101 | * 102 | **/ 103 | function pubRetrieveFailed(args) { 104 | BaseChannel.pubRootEmit(FileChannelConstant.retrieveFailed, args); 105 | }; 106 | 107 | /** 108 | * subRetrieveFailed 109 | * 110 | * subscribe for the FileRetrieveFailed event 111 | * 112 | * @param {Object} _Scope The scope that calls the channels subRetrieveFailed function 113 | * @param {function} scopeHandler The callback handler for FileRetrieveFailed event 114 | * 115 | * @return {function} The unsubscribe function from the $rootScope.on() call 116 | * 117 | **/ 118 | function subRetrieveFailed(_Scope, scopeHandler) { 119 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.retrieveFailed, _Scope, scopeHandler); 120 | 121 | return unsubScopeHandler; 122 | }; 123 | 124 | //________________________________________________________________________________________________________________________________________ 125 | 126 | //File create request functions 127 | 128 | /** 129 | * pubCreateConfirmed 130 | * 131 | * Publish the FileCreateConfirmed event with giver args 132 | * 133 | * @param {Object} args The events arguments 134 | * 135 | * 136 | **/ 137 | function pubCreateConfirmed(args) { 138 | BaseChannel.pubRootEmit(FileChannelConstant.createConfirmed, args); 139 | }; 140 | 141 | /** 142 | * subCreateConfirmed 143 | * 144 | * subscribe for the FileCreateConfirmed event 145 | * 146 | * @param {Object} _Scope The scope that calls the channels subCreateConfirmed function 147 | * @param {function} scopeHandler The callback handler for FileCreateConfirmed event 148 | * 149 | * @return {function} The unsubscribe function from the $rootScope.on() call 150 | * 151 | **/ 152 | function subCreateConfirmed(_Scope, scopeHandler) { 153 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.createConfirmed, _Scope, scopeHandler); 154 | return unsubScopeHandler; 155 | }; 156 | 157 | //############### 158 | 159 | 160 | /** 161 | * pubCreateConfirmed 162 | * 163 | * Publish the FileCreateConfirmed event with giver args 164 | * 165 | * @param {Object} args The events arguments 166 | * 167 | * 168 | **/ 169 | function pubCreateFailed(args) { 170 | BaseChannel.pubRootEmit(FileChannelConstant.createFailed, args); 171 | }; 172 | 173 | /** 174 | * subCreateFailed 175 | * 176 | * subscribe for the FileCreateFailed event 177 | * 178 | * @param {Object} _Scope The scope that calls the channels subCreateFailed function 179 | * @param {function} scopeHandler The callback handler for FileCreateFailed event 180 | * 181 | * @return {function} The unsubscribe function from the $rootScope.on() call 182 | * 183 | **/ 184 | function subCreateFailed(_Scope, scopeHandler) { 185 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.createFailed, _Scope, scopeHandler); 186 | return unsubScopeHandler; 187 | }; 188 | 189 | //________________________________________________________________________________________________________________________________________ 190 | 191 | //File delete request functions 192 | 193 | /** 194 | * pubDeleteConfirmed 195 | * 196 | * Publish the FileDeleteConfirmed event with giver args 197 | * 198 | * @param {Object} args The events arguments 199 | * 200 | * 201 | **/ 202 | function pubDeleteConfirmed(args) { 203 | BaseChannel.pubRootEmit(FileChannelConstant.deleteConfirmed, args); 204 | }; 205 | 206 | /** 207 | * subDeleteConfirmed 208 | * 209 | * subscribe for the FileDeleteConfirmed event 210 | * 211 | * @param {Object} _Scope The scope that calls the channels subDeleteConfirmed function 212 | * @param {function} scopeHandler The callback handler for FileDeleteConfirmed event 213 | * 214 | * @return {function} The unsubscribe function from the $rootScope.on() call 215 | * 216 | **/ 217 | function subDeleteConfirmed(_Scope, scopeHandler) { 218 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.deleteConfirmed, _Scope, scopeHandler); 219 | return unsubScopeHandler; 220 | }; 221 | 222 | //############### 223 | 224 | 225 | /** 226 | * pubDeleteConfirmed 227 | * 228 | * Publish the FileDeleteConfirmed event with giver args 229 | * 230 | * @param {Object} args The events arguments 231 | * 232 | * 233 | **/ 234 | function pubDeleteFailed(args) { 235 | BaseChannel.pubRootEmit(FileChannelConstant.deleteFailed, args); 236 | }; 237 | 238 | /** 239 | * subDeleteFailed 240 | * 241 | * subscribe for the FileDeleteFailed event 242 | * 243 | * @param {Object} _Scope The scope that calls the channels subDeleteFailed function 244 | * @param {function} scopeHandler The callback handler for FileDeleteFailed event 245 | * 246 | * @return {function} The unsubscribe function from the $rootScope.on() call 247 | * 248 | **/ 249 | function subDeleteFailed(_Scope, scopeHandler) { 250 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.deleteFailed, _Scope, scopeHandler); 251 | return unsubScopeHandler; 252 | }; 253 | 254 | //________________________________________________________________________________________________________________________________________ 255 | 256 | //File index request functions 257 | 258 | /** 259 | * pubIndexConfirmed 260 | * 261 | * Publish the FileIndexConfirmed event with giver args 262 | * 263 | * @param {Object} args The events arguments 264 | * 265 | * 266 | **/ 267 | function pubIndexConfirmed(args) { 268 | BaseChannel.pubRootEmit(FileChannelConstant.indexConfirmed, args); 269 | }; 270 | 271 | /** 272 | * subIndexConfirmed 273 | * 274 | * subscribe for the FileIndexConfirmed event 275 | * 276 | * @param {Object} _Scope The scope that calls the channels subIndexConfirmed function 277 | * @param {function} scopeHandler The callback handler for FileIndexConfirmed event 278 | * 279 | * @return {function} The unsubscribe function from the $rootScope.on() call 280 | * 281 | **/ 282 | function subIndexConfirmed(_Scope, scopeHandler) { 283 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.indexConfirmed, _Scope, scopeHandler); 284 | return unsubScopeHandler; 285 | }; 286 | 287 | //############### 288 | 289 | 290 | /** 291 | * pubIndexConfirmed 292 | * 293 | * Publish the FileIndexConfirmed event with giver args 294 | * 295 | * @param {Object} args The events arguments 296 | * 297 | * 298 | **/ 299 | function pubIndexFailed(args) { 300 | BaseChannel.pubRootEmit(FileChannelConstant.indexFailed, args); 301 | }; 302 | 303 | /** 304 | * subIndexFailed 305 | * 306 | * subscribe for the FileIndexFailed event 307 | * 308 | * @param {Object} _Scope The scope that calls the channels subIndexFailed function 309 | * @param {function} scopeHandler The callback handler for FileIndexFailed event 310 | * 311 | * @return {function} The unsubscribe function from the $rootScope.on() call 312 | * 313 | **/ 314 | function subIndexFailed(_Scope, scopeHandler) { 315 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.indexFailed, _Scope, scopeHandler); 316 | return unsubScopeHandler; 317 | }; 318 | 319 | //________________________________________________________________________________________________________________________________________ 320 | 321 | //File create raw request functions 322 | 323 | /** 324 | * pubCreateRawConfirmed 325 | * 326 | * Publish the FileCreateRawConfirmed event with giver args 327 | * 328 | * @param {Object} args The events arguments 329 | * 330 | * 331 | **/ 332 | function pubCreateRawConfirmed(args) { 333 | BaseChannel.pubRootEmit(FileChannelConstant.createRawConfirmed, args); 334 | }; 335 | 336 | /** 337 | * subCreateRawConfirmed 338 | * 339 | * subscribe for the FileCreateRawConfirmed event 340 | * 341 | * @param {Object} _Scope The scope that calls the channels subCreateRawConfirmed function 342 | * @param {function} scopeHandler The callback handler for FileCreateRawConfirmed event 343 | * 344 | * @return {function} The unsubscribe function from the $rootScope.on() call 345 | * 346 | **/ 347 | function subCreateRawConfirmed(_Scope, scopeHandler) { 348 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.createRawConfirmed, _Scope, scopeHandler); 349 | return unsubScopeHandler; 350 | }; 351 | 352 | //############### 353 | 354 | 355 | /** 356 | * pubCreateRawConfirmed 357 | * 358 | * Publish the FileCreateRawConfirmed event with giver args 359 | * 360 | * @param {Object} args The events arguments 361 | * 362 | * 363 | **/ 364 | function pubCreateRawFailed(args) { 365 | BaseChannel.pubRootEmit(FileChannelConstant.createRawFailed, args); 366 | }; 367 | 368 | /** 369 | * subCreateRawFailed 370 | * 371 | * subscribe for the FileCreateRawFailed event 372 | * 373 | * @param {Object} _Scope The scope that calls the channels subCreateRawFailed function 374 | * @param {function} scopeHandler The callback handler for FileCreateRawFailed event 375 | * 376 | * @return {function} The unsubscribe function from the $rootScope.on() call 377 | * 378 | **/ 379 | function subCreateRawFailed(_Scope, scopeHandler) { 380 | var unsubScopeHandler = BaseChannel.subRootEmit( FileChannelConstant.createRawFailed, _Scope, scopeHandler); 381 | return unsubScopeHandler; 382 | }; 383 | 384 | //________________________________________________________________________________________________________________________________________ 385 | 386 | }; 387 | 388 | })(); -------------------------------------------------------------------------------- /src/resources/file/file.channelConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for FileChannel 6 | * 7 | * NOTE: if you want to change this constant do this in a config section of angular 8 | */ 9 | var FileChannelConstant = { 10 | // Retrieve action 11 | retrieveConfirmed : 'event:drupal-file-retrieveConfirmed', 12 | retrieveFailed : 'event:drupal-file-retrieveFailed', 13 | // Create action 14 | createConfirmed : 'event:drupal-file-createConfirmed', 15 | createFailed : 'event:drupal-file-createFailed', 16 | // Delete action 17 | deleteConfirmed : 'event:drupal-file-deleteConfirmed', 18 | deleteFailed : 'event:drupal-file-deleteFailed', 19 | // Index action 20 | indexConfirmed : 'event:drupal-file-indexConfirmed', 21 | indexFailed : 'event:drupal-file-indexFailed', 22 | // Files action 23 | filesConfirmed : 'event:drupal-file-filesConfirmed', 24 | filesFailed : 'event:drupal-file-filesFailed', 25 | 26 | // Create raw action 27 | createRawConfirmed : 'event:drupal-file-createRawConfirmed', 28 | createRawFailed : 'event:drupal-file-createRawFailed' 29 | }; 30 | 31 | /** 32 | * File Channel Constant 33 | */ 34 | angular 35 | .module('d7-services.resources.file.channelConstant', []) 36 | .constant("FileChannelConstant", FileChannelConstant); 37 | 38 | })(); 39 | -------------------------------------------------------------------------------- /src/resources/file/file.resource.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * File Resource Modules 6 | * 7 | * see sourcecode in services/resources/file_resource.inc 8 | **/ 9 | angular.module('d7-services.resources.file.resource', ['d7-services.commons.configurations', 'd7-services.resources.file.resourceConstant', 'd7-services.resources.file.channel', 'd7-services.commons.baseResource']) 10 | 11 | /** 12 | * FileResource 13 | * 14 | * This service mirrors the Drupal file 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/file/*||POST|Content-Type,Authorization|true 17 | * 18 | **/ 19 | .factory('FileResource', FileResource); 20 | 21 | /** 22 | * Manually identify dependencies for minification-safe code 23 | * 24 | **/ 25 | FileResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'FileResourceConstant', 'FileChannel']; 26 | 27 | /** @ngInject */ 28 | function FileResource($http, BaseResource, DrupalApiConstant, FileResourceConstant, FileChannel) { 29 | 30 | //setup and return service 31 | var fileResourceService = { 32 | //CRUD operations 33 | retrieve : retrieve, 34 | create : create, 35 | delete : _delete, 36 | index : index, 37 | //Actions 38 | createRaw : createRaw, 39 | }; 40 | 41 | return fileResourceService; 42 | 43 | //////////// 44 | 45 | /** 46 | * retrieve 47 | * 48 | * Retrieve a file 49 | * 50 | * Method: GET 51 | * Url: http://drupal_instance/api_endpoint/file/{FID} 52 | * 53 | * @params {Object} data The requests data 54 | * @key {Integer} fid FID of the file to be loaded, required:true, source:path 55 | * @key {Integer} file_contents To return file contents or not., required:false, source:param 56 | * @key {Integer} image_styles To return image styles or not., required:false, source:param 57 | * 58 | * @return {Promise} A file object 59 | * 60 | **/ 61 | function retrieve(data) { 62 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + FileResourceConstant.resourcePath + '/' + data.fid; 63 | 64 | if( data.file_contents || data.image_styles ) { 65 | retrievePath += '?'; 66 | } 67 | 68 | //optional data 69 | if(data.file_contents) { 70 | retrievePath += 'file_contents='+((data.file_contents)?1:0)+','; 71 | } 72 | 73 | if(data.image_styles) { 74 | retrievePath += 'image_styles='+((data.image_styles)?1:0)+','; 75 | } 76 | 77 | 78 | return BaseResource.retrieve( retrievePath,FileChannel.pubRetrieveConfirmed, FileChannel.pubRetrieveFailed); 79 | }; 80 | 81 | /** 82 | * create 83 | * 84 | * Create a file with base64 encoded data 85 | * 86 | * Method: POST 87 | * Url: http://drupal_instance/api_endpoint/file 88 | * 89 | * @params {Array} file An array representing a file., required:true, source:post body 90 | * 91 | * @return {Promise} The file object of the newly created file. 92 | * 93 | **/ 94 | function create(data) { 95 | 96 | var createPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + FileResourceConstant.resourcePath, 97 | formData = new FormData(); 98 | 99 | 100 | if(data.filename) {formData.append('filename', data.filename);} 101 | if(data.file) {formData.append('file', data.file);} 102 | if(data.filesize) {formData.append('filesize', "" + data.filesize);} 103 | if(data.image_file_name) {formData.append('filepath', DrupalApiConstant.publicFilePath + data.image_file_name); } 104 | 105 | var requestConfig = { 106 | method : 'POST', 107 | url : createPath, 108 | transformRequest: angular.identity, 109 | headers: {'Content-Type': undefined}, 110 | data: formData 111 | } 112 | 113 | return BaseResource.request(requestConfig, FileChannel.pubCreateConfirmed, FileChannel.pubCreateFailed); 114 | 115 | }; 116 | 117 | 118 | /** 119 | * delete 120 | * 121 | * Delete a file 122 | * 123 | * Method: DELETE 124 | * Url: http://drupal_instance/api_endpoint/file/{FID} 125 | * 126 | * @params {Object} data the requests data 127 | * @key {Integer} fid The id of the file to delete, required:true, source:path 128 | * 129 | * @return {Promise} 130 | * 131 | **/ 132 | function _delete(data) { 133 | var deletePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + FileResourceConstant.resourcePath + '/' + data.fid 134 | return BaseResource.delete(deletePath, FileChannel.pubDeleteConfirmed, FileChannel.pubDeleteFailed); 135 | }; 136 | 137 | /** 138 | * index 139 | * 140 | * List all files 141 | * 142 | * Method: GET 143 | * Url: http://drupal_instance/api_endpoint/file 144 | * 145 | * @params {Object} data the requests data 146 | * @key {Integer} page The zero-based index of the page to get. defaults to 0., required:false, source:param 147 | * @key {Integer} pagesize Number of records to get per page., required:false, source:param 148 | * @key {String} fields The fields to get., required:false, source:param 149 | * @key {Array} parameters Parameters, required:false, source:param 150 | * 151 | * 152 | * @return {Promise} 153 | * 154 | **/ 155 | function index(data) { 156 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + FileResourceConstant.resourcePath + '/'; 157 | return BaseResource.index(data, indexPath, FileChannel.pubIndexConfirmed, FileChannel.pubIndexFailed); 158 | }; 159 | 160 | 161 | /** 162 | * createRaw 163 | * 164 | * Create a file with raw data. 165 | * 166 | * Method: POST 167 | * Url: http://drupal_instance/api_endpoint/file/create_raw 168 | * 169 | * @return {Promise} 170 | * 171 | **/ 172 | function createRaw(data) { 173 | var createRawPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + FileResourceConstant.resourcePath + '/create_raw'; 174 | return BaseResource.request(null, createRawPath, FileChannel.pubIndexConfirmed, FileChannel.pubIndexFailed); 175 | }; 176 | 177 | } 178 | 179 | })(); -------------------------------------------------------------------------------- /src/resources/file/file.resourceConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for FileResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var FileResourceConstant = { 10 | 11 | // NOTE: if you set custom aliases for your recources in [your.domain.org]/admin/structure/services/list/[machinereadable_name_of_endpoint]/resources change value here 12 | resourcePath : 'file', 13 | //actions of file resource 14 | actions : { 15 | //retrieve : 'retrieve', 16 | //create : 'create', 17 | //delete : 'delete', 18 | //index : 'index', 19 | createRaw : 'create_raw' 20 | } 21 | 22 | }; 23 | 24 | /** 25 | * File Constant Modules 26 | */ 27 | angular 28 | .module('d7-services.resources.file.resourceConstant', []) 29 | .constant("FileResourceConstant", FileResourceConstant); 30 | 31 | })(); 32 | -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.bundle.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc object 6 | * @name d7-services.resources.geocoder:Geocoder 7 | * @description 8 | * This module bundles all modules related to drupal geocoder resource 9 | * @requires d7-services.resources.geocoder.resourceConstant:GeocoderResourceConstant 10 | * @requires d7-services.resources.geocoder.resource:GeocoderResource 11 | * @requires d7-services.resources.geocoder.channelConstant:GeocoderChannelConstant 12 | * @requires d7-services.resources.geocoder.channel:GeocoderChannel 13 | */ 14 | angular.module('d7-services.resources.geocoder', 15 | ['d7-services.resources.geocoder.resourceConstant', 16 | 'd7-services.resources.geocoder.resource', 17 | 'd7-services.resources.geocoder.channelConstant', 18 | 'd7-services.resources.geocoder.channel', 19 | 'd7-services.resources.geocoder.helperConstant']); 20 | })(); -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.channel.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Geocoder Channel Module 6 | */ 7 | angular.module('d7-services.resources.geocoder.channel', ['d7-services.commons.baseChannel', 'd7-services.resources.geocoder.channelConstant']) 8 | .factory('GeocoderChannel', GeocoderChannel); 9 | 10 | 11 | /** 12 | * Manually identify dependencies for minification-safe code 13 | * 14 | **/ 15 | GeocoderChannel.$inject = [ 'BaseChannel', 'GeocoderChannelConstant' ]; 16 | 17 | /** 18 | * Notification channel for geocoder resource 19 | **/ 20 | 21 | /** @ngInject */ 22 | function GeocoderChannel(BaseChannel, GeocoderChannelConstant) { 23 | 24 | //setup and return service 25 | var geocoderChannelService = { 26 | 27 | //Retrieve event 28 | pubRetrieveConfirmed : pubRetrieveConfirmed, 29 | subRetrieveConfirmed : subRetrieveConfirmed, 30 | pubRetrieveFailed : pubRetrieveFailed, 31 | subRetrieveFailed : subRetrieveFailed, 32 | // Index action 33 | pubIndexConfirmed : pubIndexConfirmed, 34 | subIndexConfirmed : subIndexConfirmed, 35 | pubIndexFailed : pubIndexFailed, 36 | subIndexFailed : subIndexFailed, 37 | }; 38 | 39 | return geocoderChannelService; 40 | 41 | //////////// 42 | 43 | //Geocoder retrieve request functions 44 | 45 | /** 46 | * pubRetrieveConfirmed 47 | * 48 | * Publish the GeocoderRetrieveConfirmed event with giver args 49 | * 50 | * @param {Object} args The events arguments 51 | * 52 | * 53 | **/ 54 | function pubRetrieveConfirmed(args) { 55 | BaseChannel.pubRootEmit(GeocoderChannelConstant.retrieveConfirmed, args); 56 | }; 57 | 58 | /** 59 | * subRetrieveConfirmed 60 | * 61 | * subscribe for the GeocoderRetrieveConfirmed event 62 | * 63 | * @param {Object} _Scope The scope that calls the channels subRetrieveConfirmed function 64 | * @param {function} scopeHandler The callback handler for GeocoderRetrieveConfirmed event 65 | * 66 | * @return {function} The unsubscribe function from the $rootScope.on() call 67 | * 68 | **/ 69 | function subRetrieveConfirmed(_Scope, scopeHandler) { 70 | var unsubScopeHandler = BaseChannel.subRootEmit( GeocoderChannelConstant.retrieveConfirmed, _Scope, scopeHandler); 71 | 72 | return unsubScopeHandler; 73 | }; 74 | 75 | //############### 76 | 77 | 78 | /** 79 | * pubRetrieveConfirmed 80 | * 81 | * Publish the GeocoderRetrieveConfirmed event with giver args 82 | * 83 | * @param {Object} args The events arguments 84 | * 85 | * 86 | **/ 87 | function pubRetrieveFailed(args) { 88 | BaseChannel.pubRootEmit(GeocoderChannelConstant.retrieveFailed, args); 89 | }; 90 | 91 | /** 92 | * subRetrieveFailed 93 | * 94 | * subscribe for the GeocoderRetrieveFailed event 95 | * 96 | * @param {Object} _Scope The scope that calls the channels subRetrieveFailed function 97 | * @param {function} scopeHandler The callback handler for GeocoderRetrieveFailed event 98 | * 99 | * @return {function} The unsubscribe function from the $rootScope.on() call 100 | * 101 | **/ 102 | function subRetrieveFailed(_Scope, scopeHandler) { 103 | var unsubScopeHandler = BaseChannel.subRootEmit( GeocoderChannelConstant.retrieveFailed, _Scope, scopeHandler); 104 | 105 | return unsubScopeHandler; 106 | }; 107 | 108 | //________________________________________________________________________________________________________________________________________ 109 | 110 | //Geocoder index request functions 111 | 112 | /** 113 | * pubIndexConfirmed 114 | * 115 | * Publish the GeocoderIndexConfirmed event with giver args 116 | * 117 | * @param {Object} args The events arguments 118 | * 119 | * 120 | **/ 121 | function pubIndexConfirmed(args) { 122 | BaseChannel.pubRootEmit(GeocoderChannelConstant.indexConfirmed, args); 123 | }; 124 | 125 | /** 126 | * subIndexConfirmed 127 | * 128 | * subscribe for the GeocoderIndexConfirmed event 129 | * 130 | * @param {Object} _Scope The scope that calls the channels subIndexConfirmed function 131 | * @param {function} scopeHandler The callback handler for GeocoderIndexConfirmed event 132 | * 133 | * @return {function} The unsubscribe function from the $rootScope.on() call 134 | * 135 | **/ 136 | function subIndexConfirmed(_Scope, scopeHandler) { 137 | var unsubScopeHandler = BaseChannel.subRootEmit( GeocoderChannelConstant.indexConfirmed, _Scope, scopeHandler); 138 | return unsubScopeHandler; 139 | }; 140 | 141 | //############### 142 | 143 | 144 | /** 145 | * pubIndexConfirmed 146 | * 147 | * Publish the GeocoderIndexConfirmed event with giver args 148 | * 149 | * @param {Object} args The events arguments 150 | * 151 | * 152 | **/ 153 | function pubIndexFailed(args) { 154 | BaseChannel.pubRootEmit(GeocoderChannelConstant.indexFailed, args); 155 | }; 156 | 157 | /** 158 | * subIndexFailed 159 | * 160 | * subscribe for the GeocoderIndexFailed event 161 | * 162 | * @param {Object} _Scope The scope that calls the channels subIndexFailed function 163 | * @param {function} scopeHandler The callback handler for GeocoderIndexFailed event 164 | * 165 | * @return {function} The unsubscribe function from the $rootScope.on() call 166 | * 167 | **/ 168 | function subIndexFailed(_Scope, scopeHandler) { 169 | var unsubScopeHandler = BaseChannel.subRootEmit( GeocoderChannelConstant.indexFailed, _Scope, scopeHandler); 170 | return unsubScopeHandler; 171 | }; 172 | 173 | //________________________________________________________________________________________________________________________________________ 174 | 175 | }; 176 | 177 | })(); -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.channelConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for GeocoderChannel 6 | * 7 | * NOTE: if you want to change this constant do this in a config section of angular 8 | */ 9 | var GeocoderChannelConstant = { 10 | // Retrieve action 11 | retrieveConfirmed : 'event:drupal-geocoder-retrieveConfirmed', 12 | retrieveFailed : 'event:drupal-geocoder-retrieveFailed', 13 | // Index action 14 | indexConfirmed : 'event:drupal-geocoder-indexConfirmed', 15 | indexFailed : 'event:drupal-geocoder-indexFailed' 16 | }; 17 | 18 | /** 19 | * Geocoder Channel Constant 20 | */ 21 | angular 22 | .module('d7-services.resources.geocoder.channelConstant', []) 23 | .constant("GeocoderChannelConstant", GeocoderChannelConstant); 24 | 25 | })(); 26 | -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.helperConstants.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Helper constants for GeocoderResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var GeocoderHelperConstant = { 10 | //default handlers 11 | "handlers": { 12 | "exif": "Image/exif - Get a location from an image that was taken with a GPS enabled phone or camera", 13 | "yahoo": "Yahoo Placefinder - Geocodes via Yahoo Placefinder", 14 | "mapquest_nominatim": "MapQuest Nominatim - Geocodes via MapQuest Nominatim", 15 | "latlon": "Latitude / Longitude - Parse location from freeform latitude and longitude string", 16 | "openstreetmap_nominatim": "OpenStreetMap Nominatim - Geocodes via OpenStreetMap Nominatim", 17 | "wkt": "WKT - Get the geometry of a WKT string", 18 | "google": "Google Geocoder - Geocodes via google geocoder", 19 | "json": "GeoJSON - Get the geometry of a GeoJSON string, file, or URL", 20 | "kml": "KML - Get the geometry out of a KML string, file, or URL. Supports KMZ files upload as well.", 21 | "yandex": "Yandex (??????.????) - Geocodes addresses via Yandex (??????.????)", 22 | "gpx": "GPX - Get the geometry of a GPX string or file", 23 | "bing": "Bing - Geocodes via Bing" 24 | }, 25 | //default output-formats 26 | "output_formats": { 27 | "wkt": "WKT", 28 | "ewkt": "EWKT", 29 | "wkb": "WKB", 30 | "ewkb": "EWKB", 31 | "json": "GeoJSON", 32 | "kml": "KML", 33 | "gpx": "GPX", 34 | "georss": "GeoRSS", 35 | "google_geocode": "GoogleGeocode", 36 | "geohash": "GeoHash" 37 | } 38 | 39 | }; 40 | 41 | /** 42 | * Geocoder Helper Constant Modules 43 | */ 44 | angular 45 | .module('d7-services.resources.geocoder.helperConstant', []) 46 | .constant("GeocoderHelperConstant", GeocoderHelperConstant); 47 | 48 | })(); 49 | -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.resource.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Geocoder Resource Modules 6 | * 7 | * see sourcecode in services/resources/geocoder_resource.inc 8 | **/ 9 | angular.module('d7-services.resources.geocoder.resource', ['d7-services.commons.configurations', 'd7-services.resources.geocoder', 'd7-services.resources', 'd7-services.commons.baseResource']) 10 | 11 | /** 12 | * GeocoderResource 13 | * 14 | * This service mirrors the Drupal geocoder 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/geocoder/*||POST|Content-Type,Authorization|true 17 | * 18 | **/ 19 | .factory('GeocoderResource', GeocoderResource); 20 | 21 | /** 22 | * Manually identify dependencies for minification-safe code 23 | * 24 | **/ 25 | GeocoderResource.$inject = ['$http', 'BaseResource', 'DrupalApiConstant', 'GeocoderResourceConstant', 'GeocoderChannel']; 26 | 27 | /** @ngInject */ 28 | function GeocoderResource($http, BaseResource, DrupalApiConstant, GeocoderResourceConstant, GeocoderChannel) { 29 | 30 | //setup and return service 31 | var geocoderResourceService = { 32 | //actions 33 | retrieve : retrieve, 34 | index : index 35 | }; 36 | 37 | return geocoderResourceService; 38 | 39 | //////////// 40 | 41 | /** 42 | * retrieve 43 | * 44 | * Geocode data 45 | * 46 | * Method: GET 47 | * Url: http://drupal_instance/api_endpoint/geocoder/{HANDLER} 48 | * 49 | * @params {Object} data The requests data 50 | * @key {String} handler The geocoder handler to use - google, gpx, kml etc., required:true, source:path 51 | * @key {String} data Value to geocode., required:true, source:param 52 | * @key {String} output Output Format (GPX, WKT, etc.), required:false, source:param 53 | * 54 | * @return {Promise} A geocoder object 55 | * 56 | **/ 57 | function retrieve(data) { 58 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + GeocoderResourceConstant.resourcePath + '/' + data.handler; 59 | delete data.handler; 60 | retrievePath += '?'+BaseResource.prepareGetParams(data, true,'json'); 61 | return BaseResource.retrieve( retrievePath,GeocoderChannel.pubRetrieveConfirmed, GeocoderChannel.pubRetrieveFailed); 62 | }; 63 | 64 | /** 65 | * index 66 | * 67 | * List Geocoder Capabilities 68 | * 69 | * Method: GET 70 | * Url: http://drupal_instance/api_endpoint/geocoder/ 71 | * 72 | * @return {Promise} A geocoder object 73 | * 74 | **/ 75 | function index() { 76 | var indexPath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + GeocoderResourceConstant.resourcePath ; 77 | return BaseResource.retrieve(indexPath, GeocoderChannel.pubIndexConfirmed, GeocoderChannel.pubIndexFailed); 78 | }; 79 | 80 | } 81 | 82 | })(); 83 | -------------------------------------------------------------------------------- /src/resources/geocoder/geocoder.resourceConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for GeocoderResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var GeocoderResourceConstant = { 10 | 11 | // NOTE: if you set custom aliases for your recources in [your.domain.org]/admin/structure/services/list/[machinereadable_name_of_endpoint]/resources change value here 12 | resourcePath : 'geocoder', 13 | //actions of geocoder resource 14 | actions : { 15 | //retrieve : 'retrieve', 16 | //index : 'index' 17 | } 18 | 19 | }; 20 | 21 | /** 22 | * Geocoder Constant Modules 23 | */ 24 | angular 25 | .module('d7-services.resources.geocoder.resourceConstant', []) 26 | .constant("GeocoderResourceConstant", GeocoderResourceConstant); 27 | 28 | })(); 29 | -------------------------------------------------------------------------------- /src/resources/menu/menu.bundle.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | 4 | /** 5 | * @ngdoc object 6 | * @name d7-services.resources.menu:Menu 7 | * @description 8 | * This module bundles all modules related to drupal menu resource 9 | * @requires d7-services.resources.menu.resourceConstant:MenuResourceConstant 10 | * @requires d7-services.resources.menu.resource:MenuResource 11 | * @requires d7-services.resources.menu.channelConstant:MenuChannelConstant 12 | * @requires d7-services.resources.menu.channel:MenuChannel 13 | */ 14 | angular.module('d7-services.resources.menu', [ 15 | 'd7-services.resources.menu.resourceConstant', 16 | 'd7-services.resources.menu.resource', 17 | 'd7-services.resources.menu.channelConstant', 18 | 'd7-services.resources.menu.channel']); 19 | })(); -------------------------------------------------------------------------------- /src/resources/menu/menu.channel.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Menu Channel Module 6 | */ 7 | angular.module('d7-services.resources.menu.channel', ['d7-services.commons.baseChannel', 'd7-services.resources.menu.channelConstant']) 8 | .factory('MenuChannel', MenuChannel); 9 | 10 | 11 | /** 12 | * Manually identify dependencies for minification-safe code 13 | * 14 | **/ 15 | MenuChannel.$inject = [ 'BaseChannel', 'MenuChannelConstant' ]; 16 | 17 | /** 18 | * Notification channel for menu resource 19 | **/ 20 | /** @ngInject */ 21 | function MenuChannel(BaseChannel, MenuChannelConstant) { 22 | 23 | //setup and return service 24 | var menuChannelService = { 25 | 26 | pubRetrieveConfirmed : pubRetrieveConfirmed, 27 | subRetrieveConfirmed : subRetrieveConfirmed, 28 | pubRetrieveFailed : pubRetrieveFailed, 29 | subRetrieveFailed : subRetrieveFailed 30 | 31 | }; 32 | 33 | return menuChannelService; 34 | 35 | //////////// 36 | 37 | //Menu retrieve request functions 38 | 39 | /** 40 | * pubRetrieveConfirmed 41 | * 42 | * Publish the MenuRetrieveConfirmed event with giver args 43 | * 44 | * @param {Object} args The events arguments 45 | * 46 | * 47 | **/ 48 | function pubRetrieveConfirmed(args) { 49 | BaseChannel.pubRootEmit(MenuChannelConstant.retrieveConfirmed, args); 50 | }; 51 | 52 | /** 53 | * subRetrieveConfirmed 54 | * 55 | * subscribe for the MenuRetrieveConfirmed event 56 | * 57 | * @param {Object} _Scope The scope that calls the channels subRetrieveConfirmed function 58 | * @param {function} scopeHandler The callback handler for MenuRetrieveConfirmed event 59 | * 60 | * @return {function} The unsubscribe function from the $rootScope.on() call 61 | * 62 | **/ 63 | function subRetrieveConfirmed(_Scope, scopeHandler) { 64 | var unsubScopeHandler = BaseChannel.subRootEmit( MenuChannelConstant.retrieveConfirmed, _Scope, scopeHandler); 65 | return unsubScopeHandler; 66 | }; 67 | 68 | //############### 69 | 70 | 71 | /** 72 | * pubRetrieveConfirmed 73 | * 74 | * Publish the MenuRetrieveConfirmed event with giver args 75 | * 76 | * @param {Object} args The events arguments 77 | * 78 | * 79 | **/ 80 | function pubRetrieveFailed(args) { 81 | BaseChannel.pubRootEmit(MenuChannelConstant.retrieveFailed, args); 82 | }; 83 | 84 | /** 85 | * subRetrieveFailed 86 | * 87 | * subscribe for the MenuRetrieveFailed event 88 | * 89 | * @param {Object} _Scope The scope that calls the channels subRetrieveFailed function 90 | * @param {function} scopeHandler The callback handler for MenuRetrieveFailed event 91 | * 92 | * @return {function} The unsubscribe function from the $rootScope.on() call 93 | * 94 | **/ 95 | function subRetrieveFailed(_Scope, scopeHandler) { 96 | var unsubScopeHandler = BaseChannel.subRootEmit( MenuChannelConstant.retrieveFailed, _Scope, scopeHandler); 97 | return unsubScopeHandler; 98 | }; 99 | 100 | }; 101 | 102 | })(); -------------------------------------------------------------------------------- /src/resources/menu/menu.channelConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for MenuChannel 6 | * 7 | * NOTE: if you want to change this constant do this in a config section of angular 8 | */ 9 | var MenuChannelConstant = { 10 | // Retrieve action 11 | retrieveConfirmed : 'event:drupal-menu-retrieveConfirmed', 12 | retrieveFailed : 'event:drupal-menu-retrieveFailed', 13 | }; 14 | 15 | /** 16 | * Menu Channel Constant 17 | */ 18 | angular 19 | .module('d7-services.resources.menu.channelConstant', []) 20 | .constant("MenuChannelConstant", MenuChannelConstant); 21 | 22 | })(); 23 | -------------------------------------------------------------------------------- /src/resources/menu/menu.resource.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Menu Resource Modules 6 | * 7 | * see sourcecode in services_menu/resources/menu_resource.inc 8 | * 9 | **/ 10 | angular.module('d7-services.resources.menu.resource', ['d7-services.commons.configurations', 'd7-services.commons.baseResource', 'd7-services.resources.menu.resourceConstant', 'd7-services.resources.menu.channel']) 11 | 12 | 13 | /** 14 | * MenuResource 15 | * 16 | * This service mirrors the Drupal menu resource of the services 3.x module. 17 | * To use this you have to set following line in your Drupal CORS module settings 18 | * 19 | **/ 20 | .factory('MenuResource', MenuResource); 21 | 22 | /** 23 | * Manually identify dependencies for minification-safe code 24 | * 25 | **/ 26 | MenuResource.$inject = ['$http', 'DrupalApiConstant', 'BaseResource', 'MenuResourceConstant', 'MenuChannel']; 27 | 28 | /** @ngInject */ 29 | function MenuResource($http, DrupalApiConstant, BaseResource, MenuResourceConstant, MenuChannel) { 30 | 31 | //setup and return service 32 | var menuResourceService = { 33 | retrieve : retrieve 34 | }; 35 | 36 | return menuResourceService; 37 | 38 | //////////// 39 | 40 | /** 41 | * retrieve 42 | * 43 | * Returns the details of currently logged in user. 44 | * 45 | * Method: GET 46 | * Url: http://drupal_instance/api_endpoint/menu/{MENU_NAME} 47 | * 48 | * @return {Promise} Object with session id, session name and a user object. 49 | * 50 | **/ 51 | function retrieve(data) { 52 | var errors = []; 53 | 54 | var retrievePath = DrupalApiConstant.drupal_instance + DrupalApiConstant.api_endpoint + MenuResourceConstant.resourcePath +'/'+data.menu_name, 55 | requestConfig = { 56 | method :'GET', 57 | url : retrievePath 58 | }; 59 | 60 | return BaseResource.request(requestConfig,MenuChannel.pubRetrieveConfirmed, MenuChannel.pubRetrieveFailed); 61 | 62 | }; 63 | 64 | 65 | }; 66 | 67 | })(); -------------------------------------------------------------------------------- /src/resources/menu/menu.resourceConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for MenuResourceModules 6 | * 7 | * NOTE: if you want to change this constant do this in your app.js config section 8 | */ 9 | var MenuResourceConstant = { 10 | 11 | // NOTE: This is the default alias aliases for your menu resources defined in Drupal 12 | resourcePath : 'menu', 13 | //actions of menu resource 14 | actions : { 15 | //retrieve : 'retrieve' 16 | } 17 | 18 | }; 19 | 20 | /** 21 | * Menu Constant Modules 22 | */ 23 | angular 24 | .module('d7-services.resources.menu.resourceConstant', []) 25 | .constant("MenuResourceConstant", MenuResourceConstant); 26 | 27 | })(); 28 | -------------------------------------------------------------------------------- /src/resources/node/node.bundle.js: -------------------------------------------------------------------------------- 1 | ; 2 | (function () { 3 | 'use strict'; 4 | 5 | /** 6 | * @ngdoc object 7 | * @name d7-services.resources.node:Node 8 | * @description 9 | * This Module bundles all modules related to drupal node resource 10 | * @requires d7-services.resources.node.resourceConstant:NodeResourceConstant 11 | * @requires d7-services.resources.node.resource:NodeResource 12 | * @requires d7-services.resources.node.channelConstant:NodeChannelConstant 13 | * @requires d7-services.resources.node.channel:NodeChannel 14 | */ 15 | angular.module('d7-services.resources.node', [ 16 | 'd7-services.resources.node.resourceConstant', 17 | 'd7-services.resources.node.resource', 18 | 'd7-services.resources.node.channelConstant', 19 | 'd7-services.resources.node.channel']); 20 | })(); -------------------------------------------------------------------------------- /src/resources/node/node.channelConstant.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Constants for NodeChannel 6 | * 7 | * NOTE: if you want to change this constant do this in a config section of angular 8 | */ 9 | var NodeChannelConstant = { 10 | // Retrieve action 11 | retrieveConfirmed : 'event:drupal-node-retrieveConfirmed', 12 | retrieveFailed : 'event:drupal-node-retrieveFailed', 13 | // Create action 14 | createConfirmed : 'event:drupal-node-createConfirmed', 15 | createFailed : 'event:drupal-node-createFailed', 16 | // Update action 17 | updateConfirmed : 'event:drupal-node-updateConfirmed', 18 | updateFailed : 'event:drupal-node-updateFailed', 19 | // Delete action 20 | deleteConfirmed : 'event:drupal-node-deleteConfirmed', 21 | deleteFailed : 'event:drupal-node-deleteFailed', 22 | // Index action 23 | indexConfirmed : 'event:drupal-node-indexConfirmed', 24 | indexFailed : 'event:drupal-node-indexFailed', 25 | // Files action 26 | filesConfirmed : 'event:drupal-node-filesConfirmed', 27 | filesFailed : 'event:drupal-node-filesFailed', 28 | // Comments action 29 | commentsConfirmed : 'event:drupal-node-commentsConfirmed', 30 | commentsFailed : 'event:drupal-node-commentsFailed', 31 | // Attach file action 32 | attachFileConfirmed : 'event:drupal-node-attachFileConfirmed', 33 | attachFileFailed : 'event:drupal-node-attachFileFailed' 34 | 35 | }; 36 | 37 | /** 38 | * Node Channel Constant 39 | */ 40 | angular 41 | .module('d7-services.resources.node.channelConstant', []) 42 | .constant("NodeChannelConstant", NodeChannelConstant); 43 | 44 | })(); 45 | -------------------------------------------------------------------------------- /src/resources/node/node.resource.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | 'use strict'; 3 | 4 | /** 5 | * Node Resource Modules 6 | * 7 | * see sourcecode in services/resources/node_resource.inc 8 | **/ 9 | angular.module('d7-services.resources.node.resource', ['d7-services.commons.configurations', 'd7-services.resources.node.resourceConstant', 'd7-services.resources.node.channel', 'd7-services.commons.baseResource']) 10 | 11 | /** 12 | * NodeResource 13 | * 14 | * This service mirrors the Drupal node 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/node/*||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 | --------------------------------------------------------------------------------