{"id":15077776,"url":"https://github.com/vardius/angular-repository","last_synced_at":"2026-01-03T16:05:00.343Z","repository":{"id":57178988,"uuid":"53501179","full_name":"vardius/angular-repository","owner":"vardius","description":"API Repository factory for Angular Js based on ngResource","archived":false,"fork":false,"pushed_at":"2016-05-31T13:13:07.000Z","size":97,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T16:06:09.385Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vardius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-09T13:49:22.000Z","updated_at":"2017-04-15T01:10:08.000Z","dependencies_parsed_at":"2022-09-09T19:00:47.480Z","dependency_job_id":null,"html_url":"https://github.com/vardius/angular-repository","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fangular-repository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fangular-repository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fangular-repository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fangular-repository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vardius","download_url":"https://codeload.github.com/vardius/angular-repository/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235213356,"owners_count":18953732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T04:32:10.845Z","updated_at":"2026-01-03T16:05:00.307Z","avatar_url":"https://github.com/vardius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"angular-repository\n==================\n\nAPI Repository factory for Angular Js based on ngResource\n\n## Installation\n\nInstall with bower:\n\n```bash\n$ bower install angular-vrepository --save\n```\n\nInstall with npm:\n\n```bash\n$ npm install angular-repository\n```\n\nLoad the `angular-repository` module in your app.\n\n```javascript\nangular.module('app', ['vRepository']);\n```\n\n## Configure\n\n```javascript\n    angular\n        .module('app', [\n            'vRepository',\n        ])\n        .config(['RepositoryFactoryProvider', config])\n    ;\n        \n    function config(RepositoryFactoryProvider) {\n        var myConfig = {\n            url: 'http://api.com'           //required config parameter\n            onError: (response) =\u003e {        //optional global callback\n                return response;\n            },\n            onSuccess: (response) =\u003e {      //optional global callback example\n                if (this.checkPropertyExistence(response, ['data'])) {\n                    let data = response.data;\n                    if (data instanceof Array) {\n                        for (var key in data) {\n                            if (data.hasOwnProperty(key)) {\n                                data[key] = new this.model(data[key]);\n                            }\n                        }\n    \n                        return data;\n                    } else {\n                        return new this.model(data);\n                    }\n                }\n            }\n        };\n        RepositoryFactoryProvider.configure(myConfig);\n    }\n\n    /**\n     * Check if property exist\n     *\n     * @param obj\n     * @param paths\n     * @returns {boolean}\n     */\n    function checkPropertyExistence(obj, paths = []) {\n        for (var i = 0; i \u003c paths.length; i++) {\n            if (!obj || !obj.hasOwnProperty(paths[i])) {\n                return false;\n            }\n            obj = obj[paths[i]];\n        }\n        return true;\n    }\n```\n\n## Usage Example\n\nExample usage:\n\nCreate your entity class\n```javascript\n                        \n//remeber that your mdoel class has to extend Entity class provider by this package\nclass User extends Entity {\n    constructor(parameters, merge = false) {\n        //this 2 lines are required !!!\n        let entity = super(parameters, merge);\n        if (entity.id) return entity;\n        \n        this.id = parameters.id;\n        this.email = parameters.email;\n        this.name = parameters.name;\n        \n        //after parameter remember to turn on watcher\n        //so multiple API call will not reset your changes\n        this.watch();\n    }\n}\n\n```\n\nExample List controller for your model\n```javascript\nexport class ListController {\n    static $inject = ['$scope', 'RepositoryFactory'];\n    \n    this.repository = this.getRepository(User, '/users');\n\n    constructor($scope, factory) {\n        this.factory = factory;\n        this.$scope = $scope;\n\n        this.$scope.$watch(() =\u003e {\n            return this.page\n        }, this.onChange.bind(this));\n\n        this.$scope.$watch(() =\u003e {\n            return this.limit\n        }, this.onChange.bind(this));\n    }\n\n    onChange(newValue, oldValue) {\n        if (newValue !== oldValue) {\n            this.repository.getAll({\n                page: this.page,\n                limit: this.limit\n            }).then((response) =\u003e {\n                this.items = response;\n            });\n        }\n    }\n\n    getRepository(model, path) {\n        return this.factory.getRepository(model, path);\n    }\n}\n```\n\nYou can also provide `onSuccess` and `onError` callback to the `getRepository` method\n```javascript\nexport class ListController {\n\n    //....\n\n    getRepository(model, path) {\n        return this.factory.getRepository(model, path, this.onSuccess, this.onError);\n    }\n    \n    onError(response) {\n        return response;\n    }\n    \n    onSuccess(response) {\n        return response;\n    }\n}\n```\n\nThey will override global callback provided in your config for this specific model only.\n\n* [Extending `Entity` class model](doc/entity.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fangular-repository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvardius%2Fangular-repository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fangular-repository/lists"}