From bda64a21081800b4fc8165006c7f96b35903a0e2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 19 Feb 2016 00:22:43 -0800 Subject: [PATCH] GUAC-1378: Add service for communicating with the /api/patches REST endpoint. --- .../webapp/app/rest/services/cacheService.js | 7 ++ .../webapp/app/rest/services/patchService.js | 65 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 guacamole/src/main/webapp/app/rest/services/patchService.js diff --git a/guacamole/src/main/webapp/app/rest/services/cacheService.js b/guacamole/src/main/webapp/app/rest/services/cacheService.js index ef523dcb8..9fb9b4437 100644 --- a/guacamole/src/main/webapp/app/rest/services/cacheService.js +++ b/guacamole/src/main/webapp/app/rest/services/cacheService.js @@ -48,6 +48,13 @@ angular.module('rest').factory('cacheService', ['$injector', */ service.languages = $cacheFactory('API-LANGUAGES'); + /** + * Cache used by patchService. + * + * @type $cacheFactory.Cache + */ + service.patches = $cacheFactory('API-PATCHES'); + /** * Cache used by schemaService. * diff --git a/guacamole/src/main/webapp/app/rest/services/patchService.js b/guacamole/src/main/webapp/app/rest/services/patchService.js new file mode 100644 index 000000000..b3db669d2 --- /dev/null +++ b/guacamole/src/main/webapp/app/rest/services/patchService.js @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Service for operating on HTML patches via the REST API. + */ +angular.module('rest').factory('patchService', ['$injector', + function patchService($injector) { + + // Required services + var $http = $injector.get('$http'); + var authenticationService = $injector.get('authenticationService'); + var cacheService = $injector.get('cacheService'); + + var service = {}; + + /** + * Makes a request to the REST API to get the list of patches, returning + * a promise that provides the array of all applicable patches if + * successful. Each patch is a string of raw HTML with meta information + * describing the patch operation stored within meta tags. + * + * @returns {Promise.} + * A promise which will resolve with an array of HTML patches upon + * success. + */ + service.getPatches = function getPatches() { + + // Build HTTP parameters set + var httpParameters = { + token : authenticationService.getCurrentToken() + }; + + // Retrieve all applicable HTML patches + return $http({ + cache : cacheService.patches, + method : 'GET', + url : 'api/patches', + params : httpParameters + }); + + }; + + return service; + +}]);