refactor(agent): refactor rest factories to es6 (#4090)

* refactor(agent): replace v1 browse with es6 module

* refactor(agent): refactor agentv1 to es6

* refactor(agent): replace agent factory with es6

* refactor(agent): refactor browse response to es6

* refactor(agent): refactor browse to es6

* refactor(agent): import angular

* refactor(agent): refactor host to es6

* refactor(agent): refactor ping to es6
pull/4098/head
Chaim Lev-Ari 2020-07-23 10:45:01 +03:00 committed by GitHub
parent 435f15ec6a
commit 7eb8d5449a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 143 additions and 159 deletions

View File

@ -1,12 +1,10 @@
angular.module('portainer.agent').factory('Agent', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
'StateManager',
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
'use strict';
import angular from 'angular';
angular.module('portainer.agent').factory('Agent', AgentFactory);
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/v:version/agents',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/agents`,
{
endpointId: EndpointProvider.endpointID,
version: StateManager.getAgentApiVersion,
@ -15,5 +13,4 @@ angular.module('portainer.agent').factory('Agent', [
query: { method: 'GET', isArray: true },
}
);
},
]);
}

View File

@ -1,14 +1,12 @@
import angular from 'angular';
import { browseGetResponse } from './response/browse';
angular.module('portainer.agent').factory('Browse', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
'StateManager',
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
'use strict';
angular.module('portainer.agent').factory('Browse', BrowseFactory);
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/v:version/browse/:action',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/browse/:action`,
{
endpointId: EndpointProvider.endpointID,
version: StateManager.getAgentApiVersion,
@ -35,5 +33,4 @@ angular.module('portainer.agent').factory('Browse', [
},
}
);
},
]);
}

View File

@ -1,12 +1,10 @@
angular.module('portainer.agent').factory('Host', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
'StateManager',
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
'use strict';
import angular from 'angular';
angular.module('portainer.agent').factory('Host', HostFactory);
function HostFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/v:version/host/:action',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/host/:action`,
{
endpointId: EndpointProvider.endpointID,
version: StateManager.getAgentApiVersion,
@ -15,5 +13,4 @@ angular.module('portainer.agent').factory('Host', [
info: { method: 'GET', params: { action: 'info' } },
}
);
},
]);
}

View File

@ -1,12 +1,10 @@
angular.module('portainer.agent').factory('AgentPing', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
'$q',
function AgentPingFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, $q) {
'use strict';
import angular from 'angular';
angular.module('portainer.agent').factory('AgentPing', AgentPingFactory);
function AgentPingFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, $q) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/ping',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/ping`,
{
endpointId: EndpointProvider.endpointID,
},
@ -15,8 +13,8 @@ angular.module('portainer.agent').factory('AgentPing', [
method: 'GET',
interceptor: {
response: function versionInterceptor(response) {
var instance = response.resource;
var version = response.headers('Portainer-Agent-Api-Version') || 1;
const instance = response.resource;
const version = response.headers('Portainer-Agent-Api-Version') || 1;
instance.version = Number(version);
return instance;
},
@ -31,5 +29,4 @@ angular.module('portainer.agent').factory('AgentPing', [
},
}
);
},
]);
}

View File

@ -3,7 +3,7 @@
// This functions simply creates a response object and assign
// the data to a field.
export function browseGetResponse(data) {
var response = {};
const response = {};
response.file = data;
return response;
}

View File

@ -1,11 +1,10 @@
angular.module('portainer.agent').factory('AgentVersion1', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
import angular from 'angular';
angular.module('portainer.agent').factory('AgentVersion1', AgentFactory);
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/agents',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/agents`,
{
endpointId: EndpointProvider.endpointID,
},
@ -13,5 +12,4 @@ angular.module('portainer.agent').factory('AgentVersion1', [
query: { method: 'GET', isArray: true },
}
);
},
]);
}

View File

@ -1,13 +1,12 @@
import angular from 'angular';
import { browseGetResponse } from '../response/browse';
angular.module('portainer.agent').factory('BrowseVersion1', [
'$resource',
'API_ENDPOINT_ENDPOINTS',
'EndpointProvider',
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
angular.module('portainer.agent').factory('BrowseVersion1', BrowseFactory);
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
return $resource(
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/browse/:volumeID/:action',
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/browse/:volumeID/:action`,
{
endpointId: EndpointProvider.endpointID,
},
@ -33,5 +32,4 @@ angular.module('portainer.agent').factory('BrowseVersion1', [
},
}
);
},
]);
}