From 1655e79a7412aabbce8da2afcbaab3ac0aca25e0 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 25 Jul 2016 15:29:55 -0700 Subject: [PATCH] Fixes for fresh login check in API - Fixes enter key causing two requests - Makes sure fresh login is handled for resources as well Fixes #1625 --- static/js/services/api-service.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/static/js/services/api-service.js b/static/js/services/api-service.js index b0a48783c..1db52113a 100644 --- a/static/js/services/api-service.js +++ b/static/js/services/api-service.js @@ -6,9 +6,8 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService', function(Restangular, $q, UtilService) { var apiService = {}; - var getResource = function(path, opt_background) { + var getResource = function(getMethod, operation, opt_parameters, opt_background) { var resource = {}; - resource.url = path; resource.withOptions = function(options) { this.options = options; return this; @@ -16,21 +15,13 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService' resource.get = function(processor, opt_errorHandler) { var options = this.options; - var performer = Restangular.one(this.url); - var result = { 'loading': true, 'value': null, 'hasError': false }; - if (opt_background) { - performer.withHttpConfig({ - 'ignoreLoadingBar': true - }); - } - - performer.get(options).then(function(resp) { + getMethod(opt_parameters, options, opt_background).then(function(resp) { result.value = processor(resp); result.loading = false; }, function(resp) { @@ -136,6 +127,10 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService' }; var verifyNow = function() { + if (!$('#freshPassword').val()) { + return; + } + var info = { 'password': $('#freshPassword').val() }; @@ -234,7 +229,8 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService' // If the method for the operation is a GET, add an operationAsResource method. if (method == 'get') { apiService[operationName + 'AsResource'] = function(opt_parameters, opt_background) { - return getResource(buildUrl(urlPath, opt_parameters), opt_background); + var getMethod = apiService[operationName]; + return getResource(getMethod, operation, opt_parameters, opt_background); }; }