diff --git a/frontend/app/components/api/hal-api-resource/hal-api-resource.service.js b/frontend/app/components/api/hal-api-resource/hal-api-resource.service.js deleted file mode 100644 index 933d94f7eeb..00000000000 --- a/frontend/app/components/api/hal-api-resource/hal-api-resource.service.js +++ /dev/null @@ -1,63 +0,0 @@ -// -- copyright -// OpenProject is a project management system. -// Copyright (C) 2012-2015 the OpenProject Foundation (OPF) -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License version 3. -// -// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: -// Copyright (C) 2006-2013 Jean-Philippe Lang -// Copyright (C) 2010-2013 the ChiliProject Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// See doc/COPYRIGHT.rdoc for more details. -// ++ - -/* globals Hyperagent */ -require('hyperagent'); - -angular.module('openproject.api') - .run(run) - .factory('HALAPIResource', HALAPIResource); - -function run($http, $q) { - Hyperagent.configure('ajax', function(settings) { - settings.transformResponse = function (data) { return data; }; - - return $http(settings).then( - function (response) { settings.success(response.data); }, - settings.error - ); - }); - Hyperagent.configure('defer', $q.defer); - Hyperagent.configure('_', _); -} - -function HALAPIResource () { - return { - setup: function(uri, params) { - params = params || {}; - var link = new Hyperagent.Resource(_.extend({ url: uri }, params)); - - if (params.method) { - link.props.href = uri; - link.props.method = params.method; - } - - return link; - } - }; -} diff --git a/frontend/app/components/api/hal-api-resource/hal-api-resource.service.test.js b/frontend/app/components/api/hal-api-resource/hal-api-resource.service.test.js deleted file mode 100644 index 6095ce09dfd..00000000000 --- a/frontend/app/components/api/hal-api-resource/hal-api-resource.service.test.js +++ /dev/null @@ -1,64 +0,0 @@ -// -- copyright -// OpenProject is a project management system. -// Copyright (C) 2012-2015 the OpenProject Foundation (OPF) -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License version 3. -// -// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: -// Copyright (C) 2006-2013 Jean-Philippe Lang -// Copyright (C) 2010-2013 the ChiliProject Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// See doc/COPYRIGHT.rdoc for more details. -// ++ - -describe('HALAPIResource', function() { - - var HALAPIResource; - beforeEach(angular.mock.module('openproject.api')); - beforeEach(angular.mock.module('openproject.services')); - - beforeEach(inject(function(_HALAPIResource_) { - HALAPIResource = _HALAPIResource_; - })); - - describe('setup', function() { - var apiResource, resourceFunction; - var workPackageUri = 'api/v3/work_packages/1'; - - beforeEach(inject(function($q) { - apiResource = { - fetch: $q.when(function() { return { id: workPackageId }; }) - }; - })); - - beforeEach(inject(function(HALAPIResource) { - resourceFunction = sinon.stub(Hyperagent, 'Resource').returns(apiResource); - HALAPIResource.setup(workPackageUri); - })); - - afterEach(function() { - resourceFunction.restore(); - }); - - it('makes an api setup call', function() { - expect(resourceFunction).to.have.been.calledWith({ - url: workPackageUri - }); - }); - }); -}); diff --git a/frontend/app/services/activity-service.js b/frontend/app/services/activity-service.js index 3c79c157b26..49f4207c677 100644 --- a/frontend/app/services/activity-service.js +++ b/frontend/app/services/activity-service.js @@ -28,7 +28,6 @@ /* globals URI */ module.exports = function( - HALAPIResource, $http, I18n, NotificationsService diff --git a/frontend/app/services/index.js b/frontend/app/services/index.js index 7fc621eee76..ad77c76b274 100644 --- a/frontend/app/services/index.js +++ b/frontend/app/services/index.js @@ -28,7 +28,6 @@ angular.module('openproject.services') .service('ActivityService', [ - 'HALAPIResource', '$http', 'I18n', 'NotificationsService', @@ -60,7 +59,6 @@ angular.module('openproject.services') './timezone-service')]) .service('TypeService', ['$http', 'PathHelper', require('./type-service')]) .service('UserService', [ - 'HALAPIResource', '$http', 'PathHelper', 'CacheService', diff --git a/frontend/app/services/user-service.js b/frontend/app/services/user-service.js index 981b1168569..b172b4dbd26 100644 --- a/frontend/app/services/user-service.js +++ b/frontend/app/services/user-service.js @@ -27,7 +27,6 @@ //++ module.exports = function( - HALAPIResource, $http, PathHelper, CacheService) { diff --git a/frontend/doc/API.md b/frontend/doc/API.md index 1a7710b2c8e..536f0b9fdf0 100644 --- a/frontend/doc/API.md +++ b/frontend/doc/API.md @@ -66,26 +66,3 @@ ProjectsService.getProject('project_identifier').then(function(project) { This is in principle a very good concept to delegate responsibility of inference to the client and absolves the client of having to know each path in the application in advance. -## Using hyperagent.js - -For all practical purposes, the OpenProject frontend uses a fork of [`hyperagent.js`](https://github.com/weluse/hyperagent) (actually [this one is used](https://github.com/manwithtwowatches/hyperagent)). - -`hyperagent.js` aims to provide an interface to a structed JSON response, providing a resource object automatically. While this is a nice goal, the current implementation used is not complete. - -The library has been wrapped as a service in `./frontend/app/api/hal-api-resource.js` and can be injected when needed. - -What the service actually does is making resource objects out out of certain API responses (`v3` only) and providing `LazyResource`s to attached links. This is also the difference to using `_links` and `links` as a property sometimes: - -```javascript -//@see ./frontend/app/work_packages/services/work-package-attachments-service.js - -// `workPackage` Hyperagent resource -var addAttachmentPath = workPackage.links.addAttachment.url(); - -// `workPackage` is an API response -var addAttachmentPath = workPackage._links.addAttachment.href; -``` - -One of the minor drawbacks of `hyperagent.js` is that it (_read_: the fork used) only supports `GET` requests at the moment and one has to awkwardly inject the `method` desired into the `options` of the AJAX call made (see also the `setup` method of `hal-api-resource.js`, as well as an example in `loadWorkPackageForm` in `./frontend/app/services/work-package-service.js`). - -__Note__: The long term goal should be to leverage `angular.$http` and make the calls accordingly. One of the short term goals should be to remove duplication introduced when building requests via the `HALAPIResource`.