├── .bowerrc ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── .jshintignore ├── .jshintrc ├── .yo-rc.json ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bower.json ├── client ├── README.md ├── css │ └── styles.css ├── index.html ├── js │ ├── app.js │ ├── controllers │ │ └── todo.js │ └── services │ │ └── lb-services.js └── views │ └── todo.html ├── common └── models │ ├── todo.js │ └── todo.json ├── package.json ├── server ├── boot │ └── authentication.js ├── component-config.json ├── config.json ├── datasources.json ├── middleware.json ├── model-config.json └── server.js └── tests └── smoke.js /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "client/vendor" 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # http://editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style = space 9 | indent_size = 2 10 | end_of_line = lf 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | # Description/Steps to reproduce 11 | 12 | 16 | 17 | # Link to reproduction sandbox 18 | 19 | 24 | 25 | # Expected result 26 | 27 | 30 | 31 | # Additional information 32 | 33 | 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 4 | #### Related issues 5 | 6 | 12 | 13 | - connect to 14 | 15 | ### Checklist 16 | 17 | 22 | 23 | - [ ] New tests added or existing tests modified to cover all changes 24 | - [ ] Code conforms with the [style 25 | guide](http://loopback.io/doc/en/contrib/style-guide.html) 26 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | - critical 10 | - p1 11 | - major 12 | # Label to use when marking an issue as stale 13 | staleLabel: stale 14 | # Comment to post when marking an issue as stale. Set to `false` to disable 15 | markComment: > 16 | This issue has been automatically marked as stale because it has not had 17 | recent activity. It will be closed if no further activity occurs. Thank you 18 | for your contributions. 19 | # Comment to post when closing a stale issue. Set to `false` to disable 20 | closeComment: > 21 | This issue has been closed due to continued inactivity. Thank you for your understanding. 22 | If you believe this to be in error, please contact one of the code owners, 23 | listed in the `CODEOWNERS` file at the top-level of this repository. 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.csv 2 | *.dat 3 | *.iml 4 | *.log 5 | *.out 6 | *.pid 7 | *.seed 8 | *.sublime-* 9 | *.swo 10 | *.swp 11 | *.tgz 12 | *.xml 13 | .DS_Store 14 | .idea 15 | .project 16 | .strong-pm 17 | coverage 18 | node_modules 19 | npm-debug.log 20 | client/vendor 21 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | /client/ 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "eqeqeq": true, 7 | "eqnull": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": "nofunc", 11 | "newcap": true, 12 | "nonew": true, 13 | "noarg": true, 14 | "quotmark": "single", 15 | "regexp": true, 16 | "undef": true, 17 | "unused": false, 18 | "trailing": true, 19 | "sub": true, 20 | "maxlen": 80 21 | } 22 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-loopback": {} 3 | } -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners, 3 | # the last matching pattern has the most precendence. 4 | 5 | # Core team members from IBM 6 | * @kjdelisle @jannyHou @loay @b-admike @ssh24 @virkt25 @dhmlau 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ### Contributing ### 2 | 3 | Thank you for your interest in `loopback-example-angular`, an open source project 4 | administered by StrongLoop. 5 | 6 | Contributing to `loopback-example-angular` is easy. In a few simple steps: 7 | 8 | * Ensure that your effort is aligned with the project's roadmap by 9 | talking to the maintainers, especially if you are going to spend a 10 | lot of time on it. 11 | 12 | * Make something better or fix a bug. 13 | 14 | * Adhere to code style outlined in the [Google C++ Style Guide][] and 15 | [Google Javascript Style Guide][]. 16 | 17 | * Sign the [Contributor License Agreement](https://cla.strongloop.com/strongloop/loopback-example-angular) 18 | 19 | * Submit a pull request through Github. 20 | 21 | 22 | ### Contributor License Agreement ### 23 | 24 | ``` 25 | Individual Contributor License Agreement 26 | 27 | By signing this Individual Contributor License Agreement 28 | ("Agreement"), and making a Contribution (as defined below) to 29 | StrongLoop, Inc. ("StrongLoop"), You (as defined below) accept and 30 | agree to the following terms and conditions for Your present and 31 | future Contributions submitted to StrongLoop. Except for the license 32 | granted in this Agreement to StrongLoop and recipients of software 33 | distributed by StrongLoop, You reserve all right, title, and interest 34 | in and to Your Contributions. 35 | 36 | 1. Definitions 37 | 38 | "You" or "Your" shall mean the copyright owner or the individual 39 | authorized by the copyright owner that is entering into this 40 | Agreement with StrongLoop. 41 | 42 | "Contribution" shall mean any original work of authorship, 43 | including any modifications or additions to an existing work, that 44 | is intentionally submitted by You to StrongLoop for inclusion in, 45 | or documentation of, any of the products owned or managed by 46 | StrongLoop ("Work"). For purposes of this definition, "submitted" 47 | means any form of electronic, verbal, or written communication 48 | sent to StrongLoop or its representatives, including but not 49 | limited to communication or electronic mailing lists, source code 50 | control systems, and issue tracking systems that are managed by, 51 | or on behalf of, StrongLoop for the purpose of discussing and 52 | improving the Work, but excluding communication that is 53 | conspicuously marked or otherwise designated in writing by You as 54 | "Not a Contribution." 55 | 56 | 2. You Grant a Copyright License to StrongLoop 57 | 58 | Subject to the terms and conditions of this Agreement, You hereby 59 | grant to StrongLoop and recipients of software distributed by 60 | StrongLoop, a perpetual, worldwide, non-exclusive, no-charge, 61 | royalty-free, irrevocable copyright license to reproduce, prepare 62 | derivative works of, publicly display, publicly perform, 63 | sublicense, and distribute Your Contributions and such derivative 64 | works under any license and without any restrictions. 65 | 66 | 3. You Grant a Patent License to StrongLoop 67 | 68 | Subject to the terms and conditions of this Agreement, You hereby 69 | grant to StrongLoop and to recipients of software distributed by 70 | StrongLoop a perpetual, worldwide, non-exclusive, no-charge, 71 | royalty-free, irrevocable (except as stated in this Section) 72 | patent license to make, have made, use, offer to sell, sell, 73 | import, and otherwise transfer the Work under any license and 74 | without any restrictions. The patent license You grant to 75 | StrongLoop under this Section applies only to those patent claims 76 | licensable by You that are necessarily infringed by Your 77 | Contributions(s) alone or by combination of Your Contributions(s) 78 | with the Work to which such Contribution(s) was submitted. If any 79 | entity institutes a patent litigation against You or any other 80 | entity (including a cross-claim or counterclaim in a lawsuit) 81 | alleging that Your Contribution, or the Work to which You have 82 | contributed, constitutes direct or contributory patent 83 | infringement, any patent licenses granted to that entity under 84 | this Agreement for that Contribution or Work shall terminate as 85 | of the date such litigation is filed. 86 | 87 | 4. You Have the Right to Grant Licenses to StrongLoop 88 | 89 | You represent that You are legally entitled to grant the licenses 90 | in this Agreement. 91 | 92 | If Your employer(s) has rights to intellectual property that You 93 | create, You represent that You have received permission to make 94 | the Contributions on behalf of that employer, that Your employer 95 | has waived such rights for Your Contributions, or that Your 96 | employer has executed a separate Corporate Contributor License 97 | Agreement with StrongLoop. 98 | 99 | 5. The Contributions Are Your Original Work 100 | 101 | You represent that each of Your Contributions are Your original 102 | works of authorship (see Section 8 (Submissions on Behalf of 103 | Others) for submission on behalf of others). You represent that to 104 | Your knowledge, no other person claims, or has the right to claim, 105 | any right in any intellectual property right related to Your 106 | Contributions. 107 | 108 | You also represent that You are not legally obligated, whether by 109 | entering into an agreement or otherwise, in any way that conflicts 110 | with the terms of this Agreement. 111 | 112 | You represent that Your Contribution submissions include complete 113 | details of any third-party license or other restriction (including, 114 | but not limited to, related patents and trademarks) of which You 115 | are personally aware and which are associated with any part of 116 | Your Contributions. 117 | 118 | 6. You Don't Have an Obligation to Provide Support for Your Contributions 119 | 120 | You are not expected to provide support for Your Contributions, 121 | except to the extent You desire to provide support. You may provide 122 | support for free, for a fee, or not at all. 123 | 124 | 6. No Warranties or Conditions 125 | 126 | StrongLoop acknowledges that unless required by applicable law or 127 | agreed to in writing, You provide Your Contributions on an "AS IS" 128 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 129 | EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES 130 | OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR 131 | FITNESS FOR A PARTICULAR PURPOSE. 132 | 133 | 7. Submission on Behalf of Others 134 | 135 | If You wish to submit work that is not Your original creation, You 136 | may submit it to StrongLoop separately from any Contribution, 137 | identifying the complete details of its source and of any license 138 | or other restriction (including, but not limited to, related 139 | patents, trademarks, and license agreements) of which You are 140 | personally aware, and conspicuously marking the work as 141 | "Submitted on Behalf of a Third-Party: [named here]". 142 | 143 | 8. Agree to Notify of Change of Circumstances 144 | 145 | You agree to notify StrongLoop of any facts or circumstances of 146 | which You become aware that would make these representations 147 | inaccurate in any respect. Email us at callback@strongloop.com. 148 | ``` 149 | 150 | [Google C++ Style Guide]: https://google.github.io/styleguide/cppguide.html 151 | [Google Javascript Style Guide]: https://google.github.io/styleguide/javascriptguide.xml 152 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) IBM Corp. 2015,2017. All Rights Reserved. 2 | Node module: loopback-example-angular 3 | This project is licensed under the MIT License, full text below. 4 | 5 | -------- 6 | 7 | MIT license 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # loopback-example-angular 2 | 3 | **⚠️ This LoopBack 3 example project is no longer maintained. Please refer to [LoopBack 4 Examples](https://loopback.io/doc/en/lb4/Examples.html) instead. ⚠️** 4 | 5 | ``` 6 | $ git clone https://github.com/strongloop/loopback-example-angular.git 7 | $ cd loopback-example-angular 8 | $ npm install 9 | $ node . # then browse to localhost:3000 10 | ``` 11 | 12 | A simple todo list using AngularJS on the client-side and LoopBack on the 13 | server-side. 14 | 15 | ## Prerequisites 16 | 17 | ### Tutorials 18 | 19 | - [Getting started with LoopBack](https://github.com/strongloop/loopback-getting-started) 20 | - [Tutorial series, step 1](https://github.com/strongloop/loopback-example#the-basics) 21 | 22 | ### Knowledge of 23 | 24 | - [Angular](https://angularjs.org/) 25 | - [Angular Resource](https://docs.angularjs.org/api/ngResource/service/$resource) 26 | - [AngularUI Router](https://github.com/angular-ui/ui-router) 27 | - [Bootstrap](http://getbootstrap.com/) 28 | - [Bower](http://bower.io/) 29 | - [LoopBack](http://loopback.io/) 30 | - [LoopBack AngularJS SDK](http://loopback.io/doc/en/lb2/AngularJS-JavaScript-SDK.html) 31 | - [LoopBack models](http://loopback.io/doc/en/lb2/Defining-models.html) 32 | - [LoopBack middleware](http://loopback.io/doc/en/lb2/Defining-middleware.html) 33 | 34 | ## Procedure 35 | 36 | ### Create the application 37 | 38 | #### Application information 39 | 40 | - Name: `loopback-example-angular` 41 | - Directory to contain the project: `loopback-example-angular` 42 | 43 | ``` 44 | $ slc loopback loopback-example-angular 45 | ... # follow the prompts 46 | $ cd loopback-example-angular 47 | ``` 48 | 49 | ### Create the `Todo` model 50 | 51 | #### Model information 52 | 53 | - Name: `Todo` 54 | - Data source: `db (memory)` 55 | - Base class: `PersistedModel` 56 | - Expose over REST: `Yes` 57 | - Custom plural form: *Leave blank* 58 | - Properties: 59 | - `content` 60 | - String 61 | - Required 62 | 63 | ``` 64 | $ slc loopback:model Todo 65 | ... # follow the prompts 66 | ``` 67 | 68 | ### Configure the vendor directory 69 | 70 | In the project root, create [`.bowerrc`](https://github.com/strongloop/loopback-example-angular/blob/master/.bowerrc). 71 | 72 | >Bower installs packages in `bower_components` by default, but we reconfigure 73 | this to `client/vendor` to make [importing files into `index.html`](https://github.com/strongloop/loopback-example-angular/blob/master/client/index.html#L33-L37) 74 | more convenient. 75 | 76 | ### Install client-side dependencies 77 | 78 | From the project root, run: 79 | 80 | ``` 81 | $ bower install angular angular-resource angular-ui-router bootstrap 82 | ``` 83 | 84 | ### Create the home page 85 | 86 | Create [`index.html`](https://github.com/strongloop/loopback-example-angular/blob/master/client/index.html) in the [`client`](https://github.com/strongloop/loopback-example-angular/blob/master/client) directory. 87 | 88 | ### Create the main stylesheet 89 | 90 | Create a [`css` directory](https://github.com/strongloop/loopback-example-angular/blob/master/client/css) to store stylesheets. 91 | 92 | ``` 93 | $ mkdir client/css 94 | ``` 95 | 96 | In this directory, create [`styles.css`](https://github.com/strongloop/loopback-example-angular/blob/master/client/css/styles.css). 97 | 98 | ### Serve static assets from the `client` directory 99 | 100 | Delete `/server/boot/root.js`. 101 | 102 | Add static middleware to the [`files` section in `middleware.json`](https://github.com/strongloop/loopback-example-angular/blob/master/server/middleware.json#L23-L27) 103 | . 104 | 105 | ### Create `app.js` 106 | 107 | Create a [`js` directory](https://github.com/strongloop/loopback-example-angular/blob/master/client/js) to hold scripts files. 108 | 109 | ``` 110 | $ mkdir client/js 111 | ``` 112 | 113 | In this directory, create [`app.js`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/app.js). 114 | 115 | >Notice we declare [`lbServices`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/app.js#L3) as a dependency. We 116 | will generate this file using the `lb-ng` command in a later step. 117 | 118 | ### Create `todo.html` 119 | 120 | Create a [`views`](https://github.com/strongloop/loopback-example-angular/blob/master/client/views) to store view templates. 121 | 122 | ``` 123 | $ mkdir client/views 124 | ``` 125 | 126 | In this directory, create [`todo.html`](https://github.com/strongloop/loopback-example-angular/blob/master/client/views/todo.html). 127 | 128 | ### Create `controllers.js` 129 | 130 | Create a [`controllers`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/controllers) directory to store controller 131 | files. 132 | 133 | ``` 134 | $ mkdir client/js/controllers 135 | ``` 136 | 137 | In this directory, create [`todo.js`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/controllers/todo.js). 138 | 139 | ### Generate `lb-services.js` 140 | 141 | Create a [`services` directory](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/services) to store service files. 142 | 143 | ``` 144 | $ mkdir client/js/services 145 | ``` 146 | 147 | `lb-ng` is automatically installed along with the `slc` command-line tool (ie. 148 | when you ran `npm install -g strongloop`). `lb-ng` takes two arguments: the 149 | path to [`server.js`](https://github.com/strongloop/loopback-example-angular/blob/master/server/server.js) and the path 150 | to the [generated services file](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/services/lb-services.js). 151 | [`lb-services.js`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/services/lb-services.js) is an Angular service 152 | used to interact with LoopBack models. 153 | 154 | Create [`lb-services.js`](https://github.com/strongloop/loopback-example-angular/blob/master/client/js/services/lb-services.js) using the `lb-ng` 155 | command. 156 | 157 | ``` 158 | $ lb-ng server/server.js client/js/services/lb-services.js 159 | ``` 160 | 161 | ### Run the application 162 | 163 | From the project root, enter `node .` and browse to [`localhost:3000`](http://localhost:3000) 164 | to view the application. 165 | 166 | --- 167 | 168 | [More LoopBack examples](https://loopback.io/doc/en/lb3/Tutorials-and-examples.html) 169 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loopback-example-angular", 3 | "license": "MIT", 4 | "version": "0.0.0", 5 | "homepage": "https://github.com/strongloop/loopback-example-angular", 6 | "ignore": [ 7 | "**/.*", 8 | "node_modules", 9 | "bower_components", 10 | "client/vendor", 11 | "test", 12 | "tests" 13 | ], 14 | "dependencies": { 15 | "angular-resource": "~1.3.15", 16 | "angular-ui-router": "~0.2.13", 17 | "bootstrap": "~3.3.4" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | ## Client 2 | 3 | This is the place for your application front-end files. 4 | -------------------------------------------------------------------------------- /client/css/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top:50px 3 | } 4 | .glyphicon-remove:hover { 5 | cursor:pointer 6 | } 7 | -------------------------------------------------------------------------------- /client/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | LoopBack Angular example 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /client/js/app.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | angular 7 | .module('app', [ 8 | 'lbServices', 9 | 'ui.router' 10 | ]) 11 | .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, 12 | $urlRouterProvider) { 13 | $stateProvider 14 | .state('todo', { 15 | url: '', 16 | templateUrl: 'views/todo.html', 17 | controller: 'TodoController' 18 | }); 19 | 20 | $urlRouterProvider.otherwise('todo'); 21 | }]); 22 | -------------------------------------------------------------------------------- /client/js/controllers/todo.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | angular 7 | .module('app') 8 | .controller('TodoController', ['$scope', '$state', 'Todo', function($scope, 9 | $state, Todo) { 10 | $scope.todos = []; 11 | function getTodos() { 12 | Todo 13 | .find() 14 | .$promise 15 | .then(function(results) { 16 | $scope.todos = results; 17 | }); 18 | } 19 | getTodos(); 20 | 21 | $scope.addTodo = function() { 22 | Todo 23 | .create($scope.newTodo) 24 | .$promise 25 | .then(function(todo) { 26 | $scope.newTodo = ''; 27 | $scope.todoForm.content.$setPristine(); 28 | $('.focus').focus(); 29 | getTodos(); 30 | }); 31 | }; 32 | 33 | $scope.removeTodo = function(item) { 34 | Todo 35 | .deleteById(item) 36 | .$promise 37 | .then(function() { 38 | getTodos(); 39 | }); 40 | }; 41 | }]); 42 | -------------------------------------------------------------------------------- /client/js/services/lb-services.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | (function(window, angular, undefined) {'use strict'; 7 | 8 | var urlBase = "/api"; 9 | var authHeader = 'authorization'; 10 | 11 | /** 12 | * @ngdoc overview 13 | * @name lbServices 14 | * @module 15 | * @description 16 | * 17 | * The `lbServices` module provides services for interacting with 18 | * the models exposed by the LoopBack server via the REST API. 19 | * 20 | */ 21 | var module = angular.module("lbServices", ['ngResource']); 22 | 23 | /** 24 | * @ngdoc object 25 | * @name lbServices.User 26 | * @header lbServices.User 27 | * @object 28 | * 29 | * @description 30 | * 31 | * A $resource object for interacting with the `User` model. 32 | * 33 | * ## Example 34 | * 35 | * See 36 | * {@link http://docs.angularjs.org/api/ngResource.$resource#example $resource} 37 | * for an example of using this object. 38 | * 39 | */ 40 | module.factory( 41 | "User", 42 | ['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) { 43 | var R = Resource( 44 | urlBase + "/Users/:id", 45 | { 'id': '@id' }, 46 | { 47 | 48 | /** 49 | * @ngdoc method 50 | * @name lbServices.User#prototype$__findById__accessTokens 51 | * @methodOf lbServices.User 52 | * 53 | * @description 54 | * 55 | * Find a related item by id for accessTokens 56 | * 57 | * @param {Object=} parameters Request parameters. 58 | * 59 | * - `id` – `{*}` - User id 60 | * 61 | * - `fk` – `{*}` - Foreign key for accessTokens 62 | * 63 | * @param {function(Object,Object)=} successCb 64 | * Success callback with two arguments: `value`, `responseHeaders`. 65 | * 66 | * @param {function(Object)=} errorCb Error callback with one argument: 67 | * `httpResponse`. 68 | * 69 | * @returns {Object} An empty reference that will be 70 | * populated with the actual data once the response is returned 71 | * from the server. 72 | * 73 | * 74 | * (The remote method definition does not provide any description. 75 | * This usually means the response is a `User` object.) 76 | * 77 | */ 78 | "prototype$__findById__accessTokens": { 79 | url: urlBase + "/Users/:id/accessTokens/:fk", 80 | method: "GET" 81 | }, 82 | 83 | /** 84 | * @ngdoc method 85 | * @name lbServices.User#prototype$__destroyById__accessTokens 86 | * @methodOf lbServices.User 87 | * 88 | * @description 89 | * 90 | * Delete a related item by id for accessTokens 91 | * 92 | * @param {Object=} parameters Request parameters. 93 | * 94 | * - `id` – `{*}` - User id 95 | * 96 | * - `fk` – `{*}` - Foreign key for accessTokens 97 | * 98 | * @param {function(Object,Object)=} successCb 99 | * Success callback with two arguments: `value`, `responseHeaders`. 100 | * 101 | * @param {function(Object)=} errorCb Error callback with one argument: 102 | * `httpResponse`. 103 | * 104 | * @returns {Object} An empty reference that will be 105 | * populated with the actual data once the response is returned 106 | * from the server. 107 | * 108 | * This method returns no data. 109 | */ 110 | "prototype$__destroyById__accessTokens": { 111 | url: urlBase + "/Users/:id/accessTokens/:fk", 112 | method: "DELETE" 113 | }, 114 | 115 | /** 116 | * @ngdoc method 117 | * @name lbServices.User#prototype$__updateById__accessTokens 118 | * @methodOf lbServices.User 119 | * 120 | * @description 121 | * 122 | * Update a related item by id for accessTokens 123 | * 124 | * @param {Object=} parameters Request parameters. 125 | * 126 | * - `id` – `{*}` - User id 127 | * 128 | * - `fk` – `{*}` - Foreign key for accessTokens 129 | * 130 | * @param {Object} postData Request data. 131 | * 132 | * This method expects a subset of model properties as request parameters. 133 | * 134 | * @param {function(Object,Object)=} successCb 135 | * Success callback with two arguments: `value`, `responseHeaders`. 136 | * 137 | * @param {function(Object)=} errorCb Error callback with one argument: 138 | * `httpResponse`. 139 | * 140 | * @returns {Object} An empty reference that will be 141 | * populated with the actual data once the response is returned 142 | * from the server. 143 | * 144 | * 145 | * (The remote method definition does not provide any description. 146 | * This usually means the response is a `User` object.) 147 | * 148 | */ 149 | "prototype$__updateById__accessTokens": { 150 | url: urlBase + "/Users/:id/accessTokens/:fk", 151 | method: "PUT" 152 | }, 153 | 154 | /** 155 | * @ngdoc method 156 | * @name lbServices.User#prototype$__get__accessTokens 157 | * @methodOf lbServices.User 158 | * 159 | * @description 160 | * 161 | * Queries accessTokens of User. 162 | * 163 | * @param {Object=} parameters Request parameters. 164 | * 165 | * - `id` – `{*}` - User id 166 | * 167 | * - `filter` – `{object=}` - 168 | * 169 | * @param {function(Array.,Object)=} successCb 170 | * Success callback with two arguments: `value`, `responseHeaders`. 171 | * 172 | * @param {function(Object)=} errorCb Error callback with one argument: 173 | * `httpResponse`. 174 | * 175 | * @returns {Array.} An empty reference that will be 176 | * populated with the actual data once the response is returned 177 | * from the server. 178 | * 179 | * 180 | * (The remote method definition does not provide any description. 181 | * This usually means the response is a `User` object.) 182 | * 183 | */ 184 | "prototype$__get__accessTokens": { 185 | isArray: true, 186 | url: urlBase + "/Users/:id/accessTokens", 187 | method: "GET" 188 | }, 189 | 190 | /** 191 | * @ngdoc method 192 | * @name lbServices.User#prototype$__create__accessTokens 193 | * @methodOf lbServices.User 194 | * 195 | * @description 196 | * 197 | * Creates a new instance in accessTokens of this model. 198 | * 199 | * @param {Object=} parameters Request parameters. 200 | * 201 | * - `id` – `{*}` - User id 202 | * 203 | * @param {Object} postData Request data. 204 | * 205 | * This method expects a subset of model properties as request parameters. 206 | * 207 | * @param {function(Object,Object)=} successCb 208 | * Success callback with two arguments: `value`, `responseHeaders`. 209 | * 210 | * @param {function(Object)=} errorCb Error callback with one argument: 211 | * `httpResponse`. 212 | * 213 | * @returns {Object} An empty reference that will be 214 | * populated with the actual data once the response is returned 215 | * from the server. 216 | * 217 | * 218 | * (The remote method definition does not provide any description. 219 | * This usually means the response is a `User` object.) 220 | * 221 | */ 222 | "prototype$__create__accessTokens": { 223 | url: urlBase + "/Users/:id/accessTokens", 224 | method: "POST" 225 | }, 226 | 227 | /** 228 | * @ngdoc method 229 | * @name lbServices.User#prototype$__delete__accessTokens 230 | * @methodOf lbServices.User 231 | * 232 | * @description 233 | * 234 | * Deletes all accessTokens of this model. 235 | * 236 | * @param {Object=} parameters Request parameters. 237 | * 238 | * - `id` – `{*}` - User id 239 | * 240 | * @param {function(Object,Object)=} successCb 241 | * Success callback with two arguments: `value`, `responseHeaders`. 242 | * 243 | * @param {function(Object)=} errorCb Error callback with one argument: 244 | * `httpResponse`. 245 | * 246 | * @returns {Object} An empty reference that will be 247 | * populated with the actual data once the response is returned 248 | * from the server. 249 | * 250 | * This method returns no data. 251 | */ 252 | "prototype$__delete__accessTokens": { 253 | url: urlBase + "/Users/:id/accessTokens", 254 | method: "DELETE" 255 | }, 256 | 257 | /** 258 | * @ngdoc method 259 | * @name lbServices.User#prototype$__count__accessTokens 260 | * @methodOf lbServices.User 261 | * 262 | * @description 263 | * 264 | * Counts accessTokens of User. 265 | * 266 | * @param {Object=} parameters Request parameters. 267 | * 268 | * - `id` – `{*}` - User id 269 | * 270 | * - `where` – `{object=}` - Criteria to match model instances 271 | * 272 | * @param {function(Object,Object)=} successCb 273 | * Success callback with two arguments: `value`, `responseHeaders`. 274 | * 275 | * @param {function(Object)=} errorCb Error callback with one argument: 276 | * `httpResponse`. 277 | * 278 | * @returns {Object} An empty reference that will be 279 | * populated with the actual data once the response is returned 280 | * from the server. 281 | * 282 | * Data properties: 283 | * 284 | * - `count` – `{number=}` - 285 | */ 286 | "prototype$__count__accessTokens": { 287 | url: urlBase + "/Users/:id/accessTokens/count", 288 | method: "GET" 289 | }, 290 | 291 | /** 292 | * @ngdoc method 293 | * @name lbServices.User#create 294 | * @methodOf lbServices.User 295 | * 296 | * @description 297 | * 298 | * Create a new instance of the model and persist it into the data source 299 | * 300 | * @param {Object=} parameters Request parameters. 301 | * 302 | * This method does not accept any parameters. 303 | * Supply an empty object or omit this argument altogether. 304 | * 305 | * @param {Object} postData Request data. 306 | * 307 | * This method expects a subset of model properties as request parameters. 308 | * 309 | * @param {function(Object,Object)=} successCb 310 | * Success callback with two arguments: `value`, `responseHeaders`. 311 | * 312 | * @param {function(Object)=} errorCb Error callback with one argument: 313 | * `httpResponse`. 314 | * 315 | * @returns {Object} An empty reference that will be 316 | * populated with the actual data once the response is returned 317 | * from the server. 318 | * 319 | * 320 | * (The remote method definition does not provide any description. 321 | * This usually means the response is a `User` object.) 322 | * 323 | */ 324 | "create": { 325 | url: urlBase + "/Users", 326 | method: "POST" 327 | }, 328 | 329 | /** 330 | * @ngdoc method 331 | * @name lbServices.User#upsert 332 | * @methodOf lbServices.User 333 | * 334 | * @description 335 | * 336 | * Update an existing model instance or insert a new one into the data source 337 | * 338 | * @param {Object=} parameters Request parameters. 339 | * 340 | * This method does not accept any parameters. 341 | * Supply an empty object or omit this argument altogether. 342 | * 343 | * @param {Object} postData Request data. 344 | * 345 | * This method expects a subset of model properties as request parameters. 346 | * 347 | * @param {function(Object,Object)=} successCb 348 | * Success callback with two arguments: `value`, `responseHeaders`. 349 | * 350 | * @param {function(Object)=} errorCb Error callback with one argument: 351 | * `httpResponse`. 352 | * 353 | * @returns {Object} An empty reference that will be 354 | * populated with the actual data once the response is returned 355 | * from the server. 356 | * 357 | * 358 | * (The remote method definition does not provide any description. 359 | * This usually means the response is a `User` object.) 360 | * 361 | */ 362 | "upsert": { 363 | url: urlBase + "/Users", 364 | method: "PUT" 365 | }, 366 | 367 | /** 368 | * @ngdoc method 369 | * @name lbServices.User#exists 370 | * @methodOf lbServices.User 371 | * 372 | * @description 373 | * 374 | * Check whether a model instance exists in the data source 375 | * 376 | * @param {Object=} parameters Request parameters. 377 | * 378 | * - `id` – `{*}` - Model id 379 | * 380 | * @param {function(Object,Object)=} successCb 381 | * Success callback with two arguments: `value`, `responseHeaders`. 382 | * 383 | * @param {function(Object)=} errorCb Error callback with one argument: 384 | * `httpResponse`. 385 | * 386 | * @returns {Object} An empty reference that will be 387 | * populated with the actual data once the response is returned 388 | * from the server. 389 | * 390 | * Data properties: 391 | * 392 | * - `exists` – `{boolean=}` - 393 | */ 394 | "exists": { 395 | url: urlBase + "/Users/:id/exists", 396 | method: "GET" 397 | }, 398 | 399 | /** 400 | * @ngdoc method 401 | * @name lbServices.User#findById 402 | * @methodOf lbServices.User 403 | * 404 | * @description 405 | * 406 | * Find a model instance by id from the data source 407 | * 408 | * @param {Object=} parameters Request parameters. 409 | * 410 | * - `id` – `{*}` - Model id 411 | * 412 | * @param {function(Object,Object)=} successCb 413 | * Success callback with two arguments: `value`, `responseHeaders`. 414 | * 415 | * @param {function(Object)=} errorCb Error callback with one argument: 416 | * `httpResponse`. 417 | * 418 | * @returns {Object} An empty reference that will be 419 | * populated with the actual data once the response is returned 420 | * from the server. 421 | * 422 | * 423 | * (The remote method definition does not provide any description. 424 | * This usually means the response is a `User` object.) 425 | * 426 | */ 427 | "findById": { 428 | url: urlBase + "/Users/:id", 429 | method: "GET" 430 | }, 431 | 432 | /** 433 | * @ngdoc method 434 | * @name lbServices.User#find 435 | * @methodOf lbServices.User 436 | * 437 | * @description 438 | * 439 | * Find all instances of the model matched by filter from the data source 440 | * 441 | * @param {Object=} parameters Request parameters. 442 | * 443 | * - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit 444 | * 445 | * @param {function(Array.,Object)=} successCb 446 | * Success callback with two arguments: `value`, `responseHeaders`. 447 | * 448 | * @param {function(Object)=} errorCb Error callback with one argument: 449 | * `httpResponse`. 450 | * 451 | * @returns {Array.} An empty reference that will be 452 | * populated with the actual data once the response is returned 453 | * from the server. 454 | * 455 | * 456 | * (The remote method definition does not provide any description. 457 | * This usually means the response is a `User` object.) 458 | * 459 | */ 460 | "find": { 461 | isArray: true, 462 | url: urlBase + "/Users", 463 | method: "GET" 464 | }, 465 | 466 | /** 467 | * @ngdoc method 468 | * @name lbServices.User#findOne 469 | * @methodOf lbServices.User 470 | * 471 | * @description 472 | * 473 | * Find first instance of the model matched by filter from the data source 474 | * 475 | * @param {Object=} parameters Request parameters. 476 | * 477 | * - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit 478 | * 479 | * @param {function(Object,Object)=} successCb 480 | * Success callback with two arguments: `value`, `responseHeaders`. 481 | * 482 | * @param {function(Object)=} errorCb Error callback with one argument: 483 | * `httpResponse`. 484 | * 485 | * @returns {Object} An empty reference that will be 486 | * populated with the actual data once the response is returned 487 | * from the server. 488 | * 489 | * 490 | * (The remote method definition does not provide any description. 491 | * This usually means the response is a `User` object.) 492 | * 493 | */ 494 | "findOne": { 495 | url: urlBase + "/Users/findOne", 496 | method: "GET" 497 | }, 498 | 499 | /** 500 | * @ngdoc method 501 | * @name lbServices.User#updateAll 502 | * @methodOf lbServices.User 503 | * 504 | * @description 505 | * 506 | * Update instances of the model matched by where from the data source 507 | * 508 | * @param {Object=} parameters Request parameters. 509 | * 510 | * - `where` – `{object=}` - Criteria to match model instances 511 | * 512 | * @param {Object} postData Request data. 513 | * 514 | * This method expects a subset of model properties as request parameters. 515 | * 516 | * @param {function(Object,Object)=} successCb 517 | * Success callback with two arguments: `value`, `responseHeaders`. 518 | * 519 | * @param {function(Object)=} errorCb Error callback with one argument: 520 | * `httpResponse`. 521 | * 522 | * @returns {Object} An empty reference that will be 523 | * populated with the actual data once the response is returned 524 | * from the server. 525 | * 526 | * This method returns no data. 527 | */ 528 | "updateAll": { 529 | url: urlBase + "/Users/update", 530 | method: "POST" 531 | }, 532 | 533 | /** 534 | * @ngdoc method 535 | * @name lbServices.User#deleteById 536 | * @methodOf lbServices.User 537 | * 538 | * @description 539 | * 540 | * Delete a model instance by id from the data source 541 | * 542 | * @param {Object=} parameters Request parameters. 543 | * 544 | * - `id` – `{*}` - Model id 545 | * 546 | * @param {function(Object,Object)=} successCb 547 | * Success callback with two arguments: `value`, `responseHeaders`. 548 | * 549 | * @param {function(Object)=} errorCb Error callback with one argument: 550 | * `httpResponse`. 551 | * 552 | * @returns {Object} An empty reference that will be 553 | * populated with the actual data once the response is returned 554 | * from the server. 555 | * 556 | * This method returns no data. 557 | */ 558 | "deleteById": { 559 | url: urlBase + "/Users/:id", 560 | method: "DELETE" 561 | }, 562 | 563 | /** 564 | * @ngdoc method 565 | * @name lbServices.User#count 566 | * @methodOf lbServices.User 567 | * 568 | * @description 569 | * 570 | * Count instances of the model matched by where from the data source 571 | * 572 | * @param {Object=} parameters Request parameters. 573 | * 574 | * - `where` – `{object=}` - Criteria to match model instances 575 | * 576 | * @param {function(Object,Object)=} successCb 577 | * Success callback with two arguments: `value`, `responseHeaders`. 578 | * 579 | * @param {function(Object)=} errorCb Error callback with one argument: 580 | * `httpResponse`. 581 | * 582 | * @returns {Object} An empty reference that will be 583 | * populated with the actual data once the response is returned 584 | * from the server. 585 | * 586 | * Data properties: 587 | * 588 | * - `count` – `{number=}` - 589 | */ 590 | "count": { 591 | url: urlBase + "/Users/count", 592 | method: "GET" 593 | }, 594 | 595 | /** 596 | * @ngdoc method 597 | * @name lbServices.User#prototype$updateAttributes 598 | * @methodOf lbServices.User 599 | * 600 | * @description 601 | * 602 | * Update attributes for a model instance and persist it into the data source 603 | * 604 | * @param {Object=} parameters Request parameters. 605 | * 606 | * - `id` – `{*}` - User id 607 | * 608 | * @param {Object} postData Request data. 609 | * 610 | * This method expects a subset of model properties as request parameters. 611 | * 612 | * @param {function(Object,Object)=} successCb 613 | * Success callback with two arguments: `value`, `responseHeaders`. 614 | * 615 | * @param {function(Object)=} errorCb Error callback with one argument: 616 | * `httpResponse`. 617 | * 618 | * @returns {Object} An empty reference that will be 619 | * populated with the actual data once the response is returned 620 | * from the server. 621 | * 622 | * 623 | * (The remote method definition does not provide any description. 624 | * This usually means the response is a `User` object.) 625 | * 626 | */ 627 | "prototype$updateAttributes": { 628 | url: urlBase + "/Users/:id", 629 | method: "PUT" 630 | }, 631 | 632 | /** 633 | * @ngdoc method 634 | * @name lbServices.User#login 635 | * @methodOf lbServices.User 636 | * 637 | * @description 638 | * 639 | * Login a user with username/email and password 640 | * 641 | * @param {Object=} parameters Request parameters. 642 | * 643 | * - `include` – `{string=}` - Related objects to include in the response. See the description of return value for more details. 644 | * Default value: `user`. 645 | * 646 | * - `rememberMe` - `boolean` - Whether the authentication credentials 647 | * should be remembered in localStorage across app/browser restarts. 648 | * Default: `true`. 649 | * 650 | * @param {Object} postData Request data. 651 | * 652 | * This method expects a subset of model properties as request parameters. 653 | * 654 | * @param {function(Object,Object)=} successCb 655 | * Success callback with two arguments: `value`, `responseHeaders`. 656 | * 657 | * @param {function(Object)=} errorCb Error callback with one argument: 658 | * `httpResponse`. 659 | * 660 | * @returns {Object} An empty reference that will be 661 | * populated with the actual data once the response is returned 662 | * from the server. 663 | * 664 | * The response body contains properties of the AccessToken created on login. 665 | * Depending on the value of `include` parameter, the body may contain additional properties: 666 | * 667 | * - `user` - `{User}` - Data of the currently logged in user. (`include=user`) 668 | * 669 | * 670 | */ 671 | "login": { 672 | params: { 673 | include: "user" 674 | }, 675 | interceptor: { 676 | response: function(response) { 677 | var accessToken = response.data; 678 | LoopBackAuth.setUser(accessToken.id, accessToken.userId, accessToken.user); 679 | LoopBackAuth.rememberMe = response.config.params.rememberMe !== false; 680 | LoopBackAuth.save(); 681 | return response.resource; 682 | } 683 | }, 684 | url: urlBase + "/Users/login", 685 | method: "POST" 686 | }, 687 | 688 | /** 689 | * @ngdoc method 690 | * @name lbServices.User#logout 691 | * @methodOf lbServices.User 692 | * 693 | * @description 694 | * 695 | * Logout a user with access token 696 | * 697 | * @param {Object=} parameters Request parameters. 698 | * 699 | * This method does not accept any parameters. 700 | * Supply an empty object or omit this argument altogether. 701 | * 702 | * @param {Object} postData Request data. 703 | * 704 | * - `access_token` – `{string}` - Do not supply this argument, it is automatically extracted from request headers. 705 | * 706 | * @param {function(Object,Object)=} successCb 707 | * Success callback with two arguments: `value`, `responseHeaders`. 708 | * 709 | * @param {function(Object)=} errorCb Error callback with one argument: 710 | * `httpResponse`. 711 | * 712 | * @returns {Object} An empty reference that will be 713 | * populated with the actual data once the response is returned 714 | * from the server. 715 | * 716 | * This method returns no data. 717 | */ 718 | "logout": { 719 | interceptor: { 720 | response: function(response) { 721 | LoopBackAuth.clearUser(); 722 | LoopBackAuth.clearStorage(); 723 | return response.resource; 724 | } 725 | }, 726 | url: urlBase + "/Users/logout", 727 | method: "POST" 728 | }, 729 | 730 | /** 731 | * @ngdoc method 732 | * @name lbServices.User#confirm 733 | * @methodOf lbServices.User 734 | * 735 | * @description 736 | * 737 | * Confirm a user registration with email verification token 738 | * 739 | * @param {Object=} parameters Request parameters. 740 | * 741 | * - `uid` – `{string}` - 742 | * 743 | * - `token` – `{string}` - 744 | * 745 | * - `redirect` – `{string=}` - 746 | * 747 | * @param {function(Object,Object)=} successCb 748 | * Success callback with two arguments: `value`, `responseHeaders`. 749 | * 750 | * @param {function(Object)=} errorCb Error callback with one argument: 751 | * `httpResponse`. 752 | * 753 | * @returns {Object} An empty reference that will be 754 | * populated with the actual data once the response is returned 755 | * from the server. 756 | * 757 | * This method returns no data. 758 | */ 759 | "confirm": { 760 | url: urlBase + "/Users/confirm", 761 | method: "GET" 762 | }, 763 | 764 | /** 765 | * @ngdoc method 766 | * @name lbServices.User#resetPassword 767 | * @methodOf lbServices.User 768 | * 769 | * @description 770 | * 771 | * Reset password for a user with email 772 | * 773 | * @param {Object=} parameters Request parameters. 774 | * 775 | * This method does not accept any parameters. 776 | * Supply an empty object or omit this argument altogether. 777 | * 778 | * @param {Object} postData Request data. 779 | * 780 | * This method expects a subset of model properties as request parameters. 781 | * 782 | * @param {function(Object,Object)=} successCb 783 | * Success callback with two arguments: `value`, `responseHeaders`. 784 | * 785 | * @param {function(Object)=} errorCb Error callback with one argument: 786 | * `httpResponse`. 787 | * 788 | * @returns {Object} An empty reference that will be 789 | * populated with the actual data once the response is returned 790 | * from the server. 791 | * 792 | * This method returns no data. 793 | */ 794 | "resetPassword": { 795 | url: urlBase + "/Users/reset", 796 | method: "POST" 797 | }, 798 | 799 | /** 800 | * @ngdoc method 801 | * @name lbServices.User#getCurrent 802 | * @methodOf lbServices.User 803 | * 804 | * @description 805 | * 806 | * Get data of the currently logged user. Fail with HTTP result 401 807 | * when there is no user logged in. 808 | * 809 | * @param {function(Object,Object)=} successCb 810 | * Success callback with two arguments: `value`, `responseHeaders`. 811 | * 812 | * @param {function(Object)=} errorCb Error callback with one argument: 813 | * `httpResponse`. 814 | * 815 | * @returns {Object} An empty reference that will be 816 | * populated with the actual data once the response is returned 817 | * from the server. 818 | */ 819 | "getCurrent": { 820 | url: urlBase + "/Users" + "/:id", 821 | method: "GET", 822 | params: { 823 | id: function() { 824 | var id = LoopBackAuth.currentUserId; 825 | if (id == null) id = '__anonymous__'; 826 | return id; 827 | }, 828 | }, 829 | interceptor: { 830 | response: function(response) { 831 | LoopBackAuth.currentUserData = response.data; 832 | return response.resource; 833 | } 834 | }, 835 | __isGetCurrentUser__ : true 836 | } 837 | } 838 | ); 839 | 840 | 841 | 842 | /** 843 | * @ngdoc method 844 | * @name lbServices.User#updateOrCreate 845 | * @methodOf lbServices.User 846 | * 847 | * @description 848 | * 849 | * Update an existing model instance or insert a new one into the data source 850 | * 851 | * @param {Object=} parameters Request parameters. 852 | * 853 | * This method does not accept any parameters. 854 | * Supply an empty object or omit this argument altogether. 855 | * 856 | * @param {Object} postData Request data. 857 | * 858 | * This method expects a subset of model properties as request parameters. 859 | * 860 | * @param {function(Object,Object)=} successCb 861 | * Success callback with two arguments: `value`, `responseHeaders`. 862 | * 863 | * @param {function(Object)=} errorCb Error callback with one argument: 864 | * `httpResponse`. 865 | * 866 | * @returns {Object} An empty reference that will be 867 | * populated with the actual data once the response is returned 868 | * from the server. 869 | * 870 | * 871 | * (The remote method definition does not provide any description. 872 | * This usually means the response is a `User` object.) 873 | * 874 | */ 875 | R["updateOrCreate"] = R["upsert"]; 876 | 877 | /** 878 | * @ngdoc method 879 | * @name lbServices.User#update 880 | * @methodOf lbServices.User 881 | * 882 | * @description 883 | * 884 | * Update instances of the model matched by where from the data source 885 | * 886 | * @param {Object=} parameters Request parameters. 887 | * 888 | * - `where` – `{object=}` - Criteria to match model instances 889 | * 890 | * @param {Object} postData Request data. 891 | * 892 | * This method expects a subset of model properties as request parameters. 893 | * 894 | * @param {function(Object,Object)=} successCb 895 | * Success callback with two arguments: `value`, `responseHeaders`. 896 | * 897 | * @param {function(Object)=} errorCb Error callback with one argument: 898 | * `httpResponse`. 899 | * 900 | * @returns {Object} An empty reference that will be 901 | * populated with the actual data once the response is returned 902 | * from the server. 903 | * 904 | * This method returns no data. 905 | */ 906 | R["update"] = R["updateAll"]; 907 | 908 | /** 909 | * @ngdoc method 910 | * @name lbServices.User#destroyById 911 | * @methodOf lbServices.User 912 | * 913 | * @description 914 | * 915 | * Delete a model instance by id from the data source 916 | * 917 | * @param {Object=} parameters Request parameters. 918 | * 919 | * - `id` – `{*}` - Model id 920 | * 921 | * @param {function(Object,Object)=} successCb 922 | * Success callback with two arguments: `value`, `responseHeaders`. 923 | * 924 | * @param {function(Object)=} errorCb Error callback with one argument: 925 | * `httpResponse`. 926 | * 927 | * @returns {Object} An empty reference that will be 928 | * populated with the actual data once the response is returned 929 | * from the server. 930 | * 931 | * This method returns no data. 932 | */ 933 | R["destroyById"] = R["deleteById"]; 934 | 935 | /** 936 | * @ngdoc method 937 | * @name lbServices.User#removeById 938 | * @methodOf lbServices.User 939 | * 940 | * @description 941 | * 942 | * Delete a model instance by id from the data source 943 | * 944 | * @param {Object=} parameters Request parameters. 945 | * 946 | * - `id` – `{*}` - Model id 947 | * 948 | * @param {function(Object,Object)=} successCb 949 | * Success callback with two arguments: `value`, `responseHeaders`. 950 | * 951 | * @param {function(Object)=} errorCb Error callback with one argument: 952 | * `httpResponse`. 953 | * 954 | * @returns {Object} An empty reference that will be 955 | * populated with the actual data once the response is returned 956 | * from the server. 957 | * 958 | * This method returns no data. 959 | */ 960 | R["removeById"] = R["deleteById"]; 961 | 962 | /** 963 | * @ngdoc method 964 | * @name lbServices.User#getCachedCurrent 965 | * @methodOf lbServices.User 966 | * 967 | * @description 968 | * 969 | * Get data of the currently logged user that was returned by the last 970 | * call to {@link lbServices.User#login} or 971 | * {@link lbServices.User#getCurrent}. Return null when there 972 | * is no user logged in or the data of the current user were not fetched 973 | * yet. 974 | * 975 | * @returns {Object} A User instance. 976 | */ 977 | R.getCachedCurrent = function() { 978 | var data = LoopBackAuth.currentUserData; 979 | return data ? new R(data) : null; 980 | }; 981 | 982 | /** 983 | * @ngdoc method 984 | * @name lbServices.User#isAuthenticated 985 | * @methodOf lbServices.User 986 | * 987 | * @returns {boolean} True if the current user is authenticated (logged in). 988 | */ 989 | R.isAuthenticated = function() { 990 | return this.getCurrentId() != null; 991 | }; 992 | 993 | /** 994 | * @ngdoc method 995 | * @name lbServices.User#getCurrentId 996 | * @methodOf lbServices.User 997 | * 998 | * @returns {Object} Id of the currently logged-in user or null. 999 | */ 1000 | R.getCurrentId = function() { 1001 | return LoopBackAuth.currentUserId; 1002 | }; 1003 | 1004 | /** 1005 | * @ngdoc property 1006 | * @name lbServices.User#modelName 1007 | * @propertyOf lbServices.User 1008 | * @description 1009 | * The name of the model represented by this $resource, 1010 | * i.e. `User`. 1011 | */ 1012 | R.modelName = "User"; 1013 | 1014 | 1015 | return R; 1016 | }]); 1017 | 1018 | /** 1019 | * @ngdoc object 1020 | * @name lbServices.Todo 1021 | * @header lbServices.Todo 1022 | * @object 1023 | * 1024 | * @description 1025 | * 1026 | * A $resource object for interacting with the `Todo` model. 1027 | * 1028 | * ## Example 1029 | * 1030 | * See 1031 | * {@link http://docs.angularjs.org/api/ngResource.$resource#example $resource} 1032 | * for an example of using this object. 1033 | * 1034 | */ 1035 | module.factory( 1036 | "Todo", 1037 | ['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) { 1038 | var R = Resource( 1039 | urlBase + "/Todos/:id", 1040 | { 'id': '@id' }, 1041 | { 1042 | 1043 | /** 1044 | * @ngdoc method 1045 | * @name lbServices.Todo#create 1046 | * @methodOf lbServices.Todo 1047 | * 1048 | * @description 1049 | * 1050 | * Create a new instance of the model and persist it into the data source 1051 | * 1052 | * @param {Object=} parameters Request parameters. 1053 | * 1054 | * This method does not accept any parameters. 1055 | * Supply an empty object or omit this argument altogether. 1056 | * 1057 | * @param {Object} postData Request data. 1058 | * 1059 | * This method expects a subset of model properties as request parameters. 1060 | * 1061 | * @param {function(Object,Object)=} successCb 1062 | * Success callback with two arguments: `value`, `responseHeaders`. 1063 | * 1064 | * @param {function(Object)=} errorCb Error callback with one argument: 1065 | * `httpResponse`. 1066 | * 1067 | * @returns {Object} An empty reference that will be 1068 | * populated with the actual data once the response is returned 1069 | * from the server. 1070 | * 1071 | * 1072 | * (The remote method definition does not provide any description. 1073 | * This usually means the response is a `Todo` object.) 1074 | * 1075 | */ 1076 | "create": { 1077 | url: urlBase + "/Todos", 1078 | method: "POST" 1079 | }, 1080 | 1081 | /** 1082 | * @ngdoc method 1083 | * @name lbServices.Todo#upsert 1084 | * @methodOf lbServices.Todo 1085 | * 1086 | * @description 1087 | * 1088 | * Update an existing model instance or insert a new one into the data source 1089 | * 1090 | * @param {Object=} parameters Request parameters. 1091 | * 1092 | * This method does not accept any parameters. 1093 | * Supply an empty object or omit this argument altogether. 1094 | * 1095 | * @param {Object} postData Request data. 1096 | * 1097 | * This method expects a subset of model properties as request parameters. 1098 | * 1099 | * @param {function(Object,Object)=} successCb 1100 | * Success callback with two arguments: `value`, `responseHeaders`. 1101 | * 1102 | * @param {function(Object)=} errorCb Error callback with one argument: 1103 | * `httpResponse`. 1104 | * 1105 | * @returns {Object} An empty reference that will be 1106 | * populated with the actual data once the response is returned 1107 | * from the server. 1108 | * 1109 | * 1110 | * (The remote method definition does not provide any description. 1111 | * This usually means the response is a `Todo` object.) 1112 | * 1113 | */ 1114 | "upsert": { 1115 | url: urlBase + "/Todos", 1116 | method: "PUT" 1117 | }, 1118 | 1119 | /** 1120 | * @ngdoc method 1121 | * @name lbServices.Todo#exists 1122 | * @methodOf lbServices.Todo 1123 | * 1124 | * @description 1125 | * 1126 | * Check whether a model instance exists in the data source 1127 | * 1128 | * @param {Object=} parameters Request parameters. 1129 | * 1130 | * - `id` – `{*}` - Model id 1131 | * 1132 | * @param {function(Object,Object)=} successCb 1133 | * Success callback with two arguments: `value`, `responseHeaders`. 1134 | * 1135 | * @param {function(Object)=} errorCb Error callback with one argument: 1136 | * `httpResponse`. 1137 | * 1138 | * @returns {Object} An empty reference that will be 1139 | * populated with the actual data once the response is returned 1140 | * from the server. 1141 | * 1142 | * Data properties: 1143 | * 1144 | * - `exists` – `{boolean=}` - 1145 | */ 1146 | "exists": { 1147 | url: urlBase + "/Todos/:id/exists", 1148 | method: "GET" 1149 | }, 1150 | 1151 | /** 1152 | * @ngdoc method 1153 | * @name lbServices.Todo#findById 1154 | * @methodOf lbServices.Todo 1155 | * 1156 | * @description 1157 | * 1158 | * Find a model instance by id from the data source 1159 | * 1160 | * @param {Object=} parameters Request parameters. 1161 | * 1162 | * - `id` – `{*}` - Model id 1163 | * 1164 | * @param {function(Object,Object)=} successCb 1165 | * Success callback with two arguments: `value`, `responseHeaders`. 1166 | * 1167 | * @param {function(Object)=} errorCb Error callback with one argument: 1168 | * `httpResponse`. 1169 | * 1170 | * @returns {Object} An empty reference that will be 1171 | * populated with the actual data once the response is returned 1172 | * from the server. 1173 | * 1174 | * 1175 | * (The remote method definition does not provide any description. 1176 | * This usually means the response is a `Todo` object.) 1177 | * 1178 | */ 1179 | "findById": { 1180 | url: urlBase + "/Todos/:id", 1181 | method: "GET" 1182 | }, 1183 | 1184 | /** 1185 | * @ngdoc method 1186 | * @name lbServices.Todo#find 1187 | * @methodOf lbServices.Todo 1188 | * 1189 | * @description 1190 | * 1191 | * Find all instances of the model matched by filter from the data source 1192 | * 1193 | * @param {Object=} parameters Request parameters. 1194 | * 1195 | * - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit 1196 | * 1197 | * @param {function(Array.,Object)=} successCb 1198 | * Success callback with two arguments: `value`, `responseHeaders`. 1199 | * 1200 | * @param {function(Object)=} errorCb Error callback with one argument: 1201 | * `httpResponse`. 1202 | * 1203 | * @returns {Array.} An empty reference that will be 1204 | * populated with the actual data once the response is returned 1205 | * from the server. 1206 | * 1207 | * 1208 | * (The remote method definition does not provide any description. 1209 | * This usually means the response is a `Todo` object.) 1210 | * 1211 | */ 1212 | "find": { 1213 | isArray: true, 1214 | url: urlBase + "/Todos", 1215 | method: "GET" 1216 | }, 1217 | 1218 | /** 1219 | * @ngdoc method 1220 | * @name lbServices.Todo#findOne 1221 | * @methodOf lbServices.Todo 1222 | * 1223 | * @description 1224 | * 1225 | * Find first instance of the model matched by filter from the data source 1226 | * 1227 | * @param {Object=} parameters Request parameters. 1228 | * 1229 | * - `filter` – `{object=}` - Filter defining fields, where, orderBy, offset, and limit 1230 | * 1231 | * @param {function(Object,Object)=} successCb 1232 | * Success callback with two arguments: `value`, `responseHeaders`. 1233 | * 1234 | * @param {function(Object)=} errorCb Error callback with one argument: 1235 | * `httpResponse`. 1236 | * 1237 | * @returns {Object} An empty reference that will be 1238 | * populated with the actual data once the response is returned 1239 | * from the server. 1240 | * 1241 | * 1242 | * (The remote method definition does not provide any description. 1243 | * This usually means the response is a `Todo` object.) 1244 | * 1245 | */ 1246 | "findOne": { 1247 | url: urlBase + "/Todos/findOne", 1248 | method: "GET" 1249 | }, 1250 | 1251 | /** 1252 | * @ngdoc method 1253 | * @name lbServices.Todo#updateAll 1254 | * @methodOf lbServices.Todo 1255 | * 1256 | * @description 1257 | * 1258 | * Update instances of the model matched by where from the data source 1259 | * 1260 | * @param {Object=} parameters Request parameters. 1261 | * 1262 | * - `where` – `{object=}` - Criteria to match model instances 1263 | * 1264 | * @param {Object} postData Request data. 1265 | * 1266 | * This method expects a subset of model properties as request parameters. 1267 | * 1268 | * @param {function(Object,Object)=} successCb 1269 | * Success callback with two arguments: `value`, `responseHeaders`. 1270 | * 1271 | * @param {function(Object)=} errorCb Error callback with one argument: 1272 | * `httpResponse`. 1273 | * 1274 | * @returns {Object} An empty reference that will be 1275 | * populated with the actual data once the response is returned 1276 | * from the server. 1277 | * 1278 | * This method returns no data. 1279 | */ 1280 | "updateAll": { 1281 | url: urlBase + "/Todos/update", 1282 | method: "POST" 1283 | }, 1284 | 1285 | /** 1286 | * @ngdoc method 1287 | * @name lbServices.Todo#deleteById 1288 | * @methodOf lbServices.Todo 1289 | * 1290 | * @description 1291 | * 1292 | * Delete a model instance by id from the data source 1293 | * 1294 | * @param {Object=} parameters Request parameters. 1295 | * 1296 | * - `id` – `{*}` - Model id 1297 | * 1298 | * @param {function(Object,Object)=} successCb 1299 | * Success callback with two arguments: `value`, `responseHeaders`. 1300 | * 1301 | * @param {function(Object)=} errorCb Error callback with one argument: 1302 | * `httpResponse`. 1303 | * 1304 | * @returns {Object} An empty reference that will be 1305 | * populated with the actual data once the response is returned 1306 | * from the server. 1307 | * 1308 | * This method returns no data. 1309 | */ 1310 | "deleteById": { 1311 | url: urlBase + "/Todos/:id", 1312 | method: "DELETE" 1313 | }, 1314 | 1315 | /** 1316 | * @ngdoc method 1317 | * @name lbServices.Todo#count 1318 | * @methodOf lbServices.Todo 1319 | * 1320 | * @description 1321 | * 1322 | * Count instances of the model matched by where from the data source 1323 | * 1324 | * @param {Object=} parameters Request parameters. 1325 | * 1326 | * - `where` – `{object=}` - Criteria to match model instances 1327 | * 1328 | * @param {function(Object,Object)=} successCb 1329 | * Success callback with two arguments: `value`, `responseHeaders`. 1330 | * 1331 | * @param {function(Object)=} errorCb Error callback with one argument: 1332 | * `httpResponse`. 1333 | * 1334 | * @returns {Object} An empty reference that will be 1335 | * populated with the actual data once the response is returned 1336 | * from the server. 1337 | * 1338 | * Data properties: 1339 | * 1340 | * - `count` – `{number=}` - 1341 | */ 1342 | "count": { 1343 | url: urlBase + "/Todos/count", 1344 | method: "GET" 1345 | }, 1346 | 1347 | /** 1348 | * @ngdoc method 1349 | * @name lbServices.Todo#prototype$updateAttributes 1350 | * @methodOf lbServices.Todo 1351 | * 1352 | * @description 1353 | * 1354 | * Update attributes for a model instance and persist it into the data source 1355 | * 1356 | * @param {Object=} parameters Request parameters. 1357 | * 1358 | * - `id` – `{*}` - PersistedModel id 1359 | * 1360 | * @param {Object} postData Request data. 1361 | * 1362 | * This method expects a subset of model properties as request parameters. 1363 | * 1364 | * @param {function(Object,Object)=} successCb 1365 | * Success callback with two arguments: `value`, `responseHeaders`. 1366 | * 1367 | * @param {function(Object)=} errorCb Error callback with one argument: 1368 | * `httpResponse`. 1369 | * 1370 | * @returns {Object} An empty reference that will be 1371 | * populated with the actual data once the response is returned 1372 | * from the server. 1373 | * 1374 | * 1375 | * (The remote method definition does not provide any description. 1376 | * This usually means the response is a `Todo` object.) 1377 | * 1378 | */ 1379 | "prototype$updateAttributes": { 1380 | url: urlBase + "/Todos/:id", 1381 | method: "PUT" 1382 | }, 1383 | } 1384 | ); 1385 | 1386 | 1387 | 1388 | /** 1389 | * @ngdoc method 1390 | * @name lbServices.Todo#updateOrCreate 1391 | * @methodOf lbServices.Todo 1392 | * 1393 | * @description 1394 | * 1395 | * Update an existing model instance or insert a new one into the data source 1396 | * 1397 | * @param {Object=} parameters Request parameters. 1398 | * 1399 | * This method does not accept any parameters. 1400 | * Supply an empty object or omit this argument altogether. 1401 | * 1402 | * @param {Object} postData Request data. 1403 | * 1404 | * This method expects a subset of model properties as request parameters. 1405 | * 1406 | * @param {function(Object,Object)=} successCb 1407 | * Success callback with two arguments: `value`, `responseHeaders`. 1408 | * 1409 | * @param {function(Object)=} errorCb Error callback with one argument: 1410 | * `httpResponse`. 1411 | * 1412 | * @returns {Object} An empty reference that will be 1413 | * populated with the actual data once the response is returned 1414 | * from the server. 1415 | * 1416 | * 1417 | * (The remote method definition does not provide any description. 1418 | * This usually means the response is a `Todo` object.) 1419 | * 1420 | */ 1421 | R["updateOrCreate"] = R["upsert"]; 1422 | 1423 | /** 1424 | * @ngdoc method 1425 | * @name lbServices.Todo#update 1426 | * @methodOf lbServices.Todo 1427 | * 1428 | * @description 1429 | * 1430 | * Update instances of the model matched by where from the data source 1431 | * 1432 | * @param {Object=} parameters Request parameters. 1433 | * 1434 | * - `where` – `{object=}` - Criteria to match model instances 1435 | * 1436 | * @param {Object} postData Request data. 1437 | * 1438 | * This method expects a subset of model properties as request parameters. 1439 | * 1440 | * @param {function(Object,Object)=} successCb 1441 | * Success callback with two arguments: `value`, `responseHeaders`. 1442 | * 1443 | * @param {function(Object)=} errorCb Error callback with one argument: 1444 | * `httpResponse`. 1445 | * 1446 | * @returns {Object} An empty reference that will be 1447 | * populated with the actual data once the response is returned 1448 | * from the server. 1449 | * 1450 | * This method returns no data. 1451 | */ 1452 | R["update"] = R["updateAll"]; 1453 | 1454 | /** 1455 | * @ngdoc method 1456 | * @name lbServices.Todo#destroyById 1457 | * @methodOf lbServices.Todo 1458 | * 1459 | * @description 1460 | * 1461 | * Delete a model instance by id from the data source 1462 | * 1463 | * @param {Object=} parameters Request parameters. 1464 | * 1465 | * - `id` – `{*}` - Model id 1466 | * 1467 | * @param {function(Object,Object)=} successCb 1468 | * Success callback with two arguments: `value`, `responseHeaders`. 1469 | * 1470 | * @param {function(Object)=} errorCb Error callback with one argument: 1471 | * `httpResponse`. 1472 | * 1473 | * @returns {Object} An empty reference that will be 1474 | * populated with the actual data once the response is returned 1475 | * from the server. 1476 | * 1477 | * This method returns no data. 1478 | */ 1479 | R["destroyById"] = R["deleteById"]; 1480 | 1481 | /** 1482 | * @ngdoc method 1483 | * @name lbServices.Todo#removeById 1484 | * @methodOf lbServices.Todo 1485 | * 1486 | * @description 1487 | * 1488 | * Delete a model instance by id from the data source 1489 | * 1490 | * @param {Object=} parameters Request parameters. 1491 | * 1492 | * - `id` – `{*}` - Model id 1493 | * 1494 | * @param {function(Object,Object)=} successCb 1495 | * Success callback with two arguments: `value`, `responseHeaders`. 1496 | * 1497 | * @param {function(Object)=} errorCb Error callback with one argument: 1498 | * `httpResponse`. 1499 | * 1500 | * @returns {Object} An empty reference that will be 1501 | * populated with the actual data once the response is returned 1502 | * from the server. 1503 | * 1504 | * This method returns no data. 1505 | */ 1506 | R["removeById"] = R["deleteById"]; 1507 | 1508 | 1509 | /** 1510 | * @ngdoc property 1511 | * @name lbServices.Todo#modelName 1512 | * @propertyOf lbServices.Todo 1513 | * @description 1514 | * The name of the model represented by this $resource, 1515 | * i.e. `Todo`. 1516 | */ 1517 | R.modelName = "Todo"; 1518 | 1519 | 1520 | return R; 1521 | }]); 1522 | 1523 | 1524 | module 1525 | .factory('LoopBackAuth', function() { 1526 | var props = ['accessTokenId', 'currentUserId']; 1527 | var propsPrefix = '$LoopBack$'; 1528 | 1529 | function LoopBackAuth() { 1530 | var self = this; 1531 | props.forEach(function(name) { 1532 | self[name] = load(name); 1533 | }); 1534 | this.rememberMe = undefined; 1535 | this.currentUserData = null; 1536 | } 1537 | 1538 | LoopBackAuth.prototype.save = function() { 1539 | var self = this; 1540 | var storage = this.rememberMe ? localStorage : sessionStorage; 1541 | props.forEach(function(name) { 1542 | save(storage, name, self[name]); 1543 | }); 1544 | }; 1545 | 1546 | LoopBackAuth.prototype.setUser = function(accessTokenId, userId, userData) { 1547 | this.accessTokenId = accessTokenId; 1548 | this.currentUserId = userId; 1549 | this.currentUserData = userData; 1550 | } 1551 | 1552 | LoopBackAuth.prototype.clearUser = function() { 1553 | this.accessTokenId = null; 1554 | this.currentUserId = null; 1555 | this.currentUserData = null; 1556 | } 1557 | 1558 | LoopBackAuth.prototype.clearStorage = function() { 1559 | props.forEach(function(name) { 1560 | save(sessionStorage, name, null); 1561 | save(localStorage, name, null); 1562 | }); 1563 | }; 1564 | 1565 | return new LoopBackAuth(); 1566 | 1567 | // Note: LocalStorage converts the value to string 1568 | // We are using empty string as a marker for null/undefined values. 1569 | function save(storage, name, value) { 1570 | var key = propsPrefix + name; 1571 | if (value == null) value = ''; 1572 | storage[key] = value; 1573 | } 1574 | 1575 | function load(name) { 1576 | var key = propsPrefix + name; 1577 | return localStorage[key] || sessionStorage[key] || null; 1578 | } 1579 | }) 1580 | .config(['$httpProvider', function($httpProvider) { 1581 | $httpProvider.interceptors.push('LoopBackAuthRequestInterceptor'); 1582 | }]) 1583 | .factory('LoopBackAuthRequestInterceptor', [ '$q', 'LoopBackAuth', 1584 | function($q, LoopBackAuth) { 1585 | return { 1586 | 'request': function(config) { 1587 | 1588 | // filter out non urlBase requests 1589 | if (config.url.substr(0, urlBase.length) !== urlBase) { 1590 | return config; 1591 | } 1592 | 1593 | if (LoopBackAuth.accessTokenId) { 1594 | config.headers[authHeader] = LoopBackAuth.accessTokenId; 1595 | } else if (config.__isGetCurrentUser__) { 1596 | // Return a stub 401 error for User.getCurrent() when 1597 | // there is no user logged in 1598 | var res = { 1599 | body: { error: { status: 401 } }, 1600 | status: 401, 1601 | config: config, 1602 | headers: function() { return undefined; } 1603 | }; 1604 | return $q.reject(res); 1605 | } 1606 | return config || $q.when(config); 1607 | } 1608 | } 1609 | }]) 1610 | 1611 | /** 1612 | * @ngdoc object 1613 | * @name lbServices.LoopBackResourceProvider 1614 | * @header lbServices.LoopBackResourceProvider 1615 | * @description 1616 | * Use `LoopBackResourceProvider` to change the global configuration 1617 | * settings used by all models. Note that the provider is available 1618 | * to Configuration Blocks only, see 1619 | * {@link https://docs.angularjs.org/guide/module#module-loading-dependencies Module Loading & Dependencies} 1620 | * for more details. 1621 | * 1622 | * ## Example 1623 | * 1624 | * ```js 1625 | * angular.module('app') 1626 | * .config(function(LoopBackResourceProvider) { 1627 | * LoopBackResourceProvider.setAuthHeader('X-Access-Token'); 1628 | * }); 1629 | * ``` 1630 | */ 1631 | .provider('LoopBackResource', function LoopBackResourceProvider() { 1632 | /** 1633 | * @ngdoc method 1634 | * @name lbServices.LoopBackResourceProvider#setAuthHeader 1635 | * @methodOf lbServices.LoopBackResourceProvider 1636 | * @param {string} header The header name to use, e.g. `X-Access-Token` 1637 | * @description 1638 | * Configure the REST transport to use a different header for sending 1639 | * the authentication token. It is sent in the `Authorization` header 1640 | * by default. 1641 | */ 1642 | this.setAuthHeader = function(header) { 1643 | authHeader = header; 1644 | }; 1645 | 1646 | /** 1647 | * @ngdoc method 1648 | * @name lbServices.LoopBackResourceProvider#setUrlBase 1649 | * @methodOf lbServices.LoopBackResourceProvider 1650 | * @param {string} url The URL to use, e.g. `/api` or `//example.com/api`. 1651 | * @description 1652 | * Change the URL of the REST API server. By default, the URL provided 1653 | * to the code generator (`lb-ng` or `grunt-loopback-sdk-angular`) is used. 1654 | */ 1655 | this.setUrlBase = function(url) { 1656 | urlBase = url; 1657 | }; 1658 | 1659 | this.$get = ['$resource', function($resource) { 1660 | return function(url, params, actions) { 1661 | var resource = $resource(url, params, actions); 1662 | 1663 | // Angular always calls POST on $save() 1664 | // This hack is based on 1665 | // http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/ 1666 | resource.prototype.$save = function(success, error) { 1667 | // Fortunately, LoopBack provides a convenient `upsert` method 1668 | // that exactly fits our needs. 1669 | var result = resource.upsert.call(this, {}, this, success, error); 1670 | return result.$promise || result; 1671 | }; 1672 | return resource; 1673 | }; 1674 | }]; 1675 | }); 1676 | 1677 | })(window, window.angular); 1678 | -------------------------------------------------------------------------------- /client/views/todo.html: -------------------------------------------------------------------------------- 1 |

Todo list

2 |
3 |
4 |
7 | 10 | 12 | Content is required. 13 | 14 |
15 | 16 |
17 |
18 | 23 | -------------------------------------------------------------------------------- /common/models/todo.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | module.exports = function(Todo) { 7 | 8 | }; 9 | -------------------------------------------------------------------------------- /common/models/todo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Todo", 3 | "base": "PersistedModel", 4 | "idInjection": true, 5 | "properties": { 6 | "content": { 7 | "type": "string", 8 | "required": true 9 | } 10 | }, 11 | "validations": [], 12 | "relations": {}, 13 | "acls": [], 14 | "methods": [] 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loopback-example-angular", 3 | "version": "1.0.0", 4 | "description": "loopback-example-angular", 5 | "main": "server/server.js", 6 | "scripts": { 7 | "pretest": "jshint .", 8 | "postinstall": "bower install", 9 | "start": "node .", 10 | "test": "tape tests/**/*.js" 11 | }, 12 | "dependencies": { 13 | "compression": "^1.0.3", 14 | "cors": "^2.8.1", 15 | "strong-error-handler": "^1.1.1", 16 | "loopback": "^3.0.0", 17 | "loopback-boot": "^2.6.5", 18 | "serve-favicon": "^2.0.1" 19 | }, 20 | "optionalDependencies": { 21 | "loopback-component-explorer": "^2.1.0" 22 | }, 23 | "devDependencies": { 24 | "bower": "^1.5.2", 25 | "jshint": "^2.5.6", 26 | "tape": "^4.2.0" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/strongloop/loopback-example-angular" 31 | }, 32 | "license": "MIT", 33 | "author": "IBM Corp." 34 | } 35 | -------------------------------------------------------------------------------- /server/boot/authentication.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | module.exports = function enableAuthentication(server) { 7 | // enable authentication 8 | server.enableAuth(); 9 | }; 10 | -------------------------------------------------------------------------------- /server/component-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "loopback-component-explorer": { 3 | "mountPath": "/explorer" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /server/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "restApiRoot": "/api", 3 | "host": "0.0.0.0", 4 | "port": 3000, 5 | "remoting": { 6 | "context": false, 7 | "rest": { 8 | "normalizeHttpPath": false, 9 | "xml": false 10 | }, 11 | "json": { 12 | "strict": false, 13 | "limit": "100kb" 14 | }, 15 | "urlencoded": { 16 | "extended": true, 17 | "limit": "100kb" 18 | }, 19 | "cors": false, 20 | "handleErrors": false 21 | }, 22 | "legacyExplorer": false 23 | } 24 | -------------------------------------------------------------------------------- /server/datasources.json: -------------------------------------------------------------------------------- 1 | { 2 | "db": { 3 | "name": "db", 4 | "connector": "memory" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /server/middleware.json: -------------------------------------------------------------------------------- 1 | { 2 | "initial:before": { 3 | "loopback#favicon": {} 4 | }, 5 | "initial": { 6 | "compression": {}, 7 | "cors": { 8 | "params": { 9 | "origin": true, 10 | "credentials": true, 11 | "maxAge": 86400 12 | } 13 | } 14 | }, 15 | "session": { 16 | }, 17 | "auth": { 18 | }, 19 | "parse": { 20 | }, 21 | "routes": { 22 | "loopback#rest": { 23 | "paths": ["${restApiRoot}"] 24 | } 25 | }, 26 | "files": { 27 | "loopback#static": { 28 | "params": "$!../client" 29 | } 30 | }, 31 | "final": { 32 | "loopback#urlNotFound": {} 33 | }, 34 | "final:after": { 35 | "strong-error-handler": {} 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/model-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "sources": [ 4 | "loopback/common/models", 5 | "loopback/server/models", 6 | "../common/models", 7 | "./models" 8 | ] 9 | }, 10 | "User": { 11 | "dataSource": "db" 12 | }, 13 | "AccessToken": { 14 | "dataSource": "db", 15 | "public": false 16 | }, 17 | "ACL": { 18 | "dataSource": "db", 19 | "public": false 20 | }, 21 | "RoleMapping": { 22 | "dataSource": "db", 23 | "public": false 24 | }, 25 | "Role": { 26 | "dataSource": "db", 27 | "public": false 28 | }, 29 | "Todo": { 30 | "dataSource": "db", 31 | "public": true 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/server.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | var loopback = require('loopback'); 7 | var boot = require('loopback-boot'); 8 | 9 | var app = module.exports = loopback(); 10 | 11 | app.start = function() { 12 | // start the web server 13 | return app.listen(function() { 14 | app.emit('started'); 15 | var baseUrl = app.get('url').replace(/\/$/, ''); 16 | console.log('Web server listening at: %s', baseUrl); 17 | if (app.get('loopback-component-explorer')) { 18 | var explorerPath = app.get('loopback-component-explorer').mountPath; 19 | console.log('Browse your REST API at %s%s', baseUrl, explorerPath); 20 | } 21 | }); 22 | }; 23 | 24 | // Bootstrap the application, configure models, datasources and middleware. 25 | // Sub-apps like REST API are mounted via boot scripts. 26 | boot(app, __dirname, function(err) { 27 | if (err) throw err; 28 | 29 | // start the server if `$ node server.js` 30 | if (require.main === module) 31 | app.start(); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/smoke.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2015,2016. All Rights Reserved. 2 | // Node module: loopback-example-angular 3 | // This file is licensed under the MIT License. 4 | // License text available at https://opensource.org/licenses/MIT 5 | 6 | var test = require('tape'); 7 | 8 | test('smoke test', function(t) { 9 | t.plan(1); 10 | t.equal(1, 1); 11 | }); 12 | --------------------------------------------------------------------------------