mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 13:55:21 +02:00
refactor(environments): remove endpoints cache [DTD-100] (#6408)
This commit is contained in:
parent
9ef2e27aae
commit
37d4a80769
51 changed files with 155 additions and 353 deletions
|
@ -52,7 +52,7 @@ export class HostBrowserController {
|
|||
}
|
||||
async getFilesForPathAsync(path) {
|
||||
try {
|
||||
const files = await this.HostBrowserService.ls(path);
|
||||
const files = await this.HostBrowserService.ls(this.endpointId, path);
|
||||
this.state.path = path;
|
||||
this.files = files;
|
||||
} catch (err) {
|
||||
|
@ -67,9 +67,9 @@ export class HostBrowserController {
|
|||
const filePath = this.buildPath(this.state.path, name);
|
||||
const newFilePath = this.buildPath(this.state.path, newName);
|
||||
try {
|
||||
await this.HostBrowserService.rename(filePath, newFilePath);
|
||||
await this.HostBrowserService.rename(this.endpointId, filePath, newFilePath);
|
||||
this.Notifications.success('File successfully renamed', this.getRelativePath(newFilePath));
|
||||
const files = await this.HostBrowserService.ls(this.state.path);
|
||||
const files = await this.HostBrowserService.ls(this.endpointId, this.state.path);
|
||||
this.files = files;
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to rename file');
|
||||
|
@ -82,7 +82,7 @@ export class HostBrowserController {
|
|||
async downloadFileAsync(fileName) {
|
||||
const filePath = this.buildPath(this.state.path, fileName);
|
||||
try {
|
||||
const { file } = await this.HostBrowserService.get(filePath);
|
||||
const { file } = await this.HostBrowserService.get(this.endpointId, filePath);
|
||||
const downloadData = new Blob([file], {
|
||||
type: 'text/plain;charset=utf-8',
|
||||
});
|
||||
|
@ -108,9 +108,9 @@ export class HostBrowserController {
|
|||
}
|
||||
async deleteFileAsync(path) {
|
||||
try {
|
||||
await this.HostBrowserService.delete(path);
|
||||
await this.HostBrowserService.delete(this.endpointId, path);
|
||||
this.Notifications.success('File successfully deleted', this.getRelativePath(path));
|
||||
const files = await this.HostBrowserService.ls(this.state.path);
|
||||
const files = await this.HostBrowserService.ls(this.endpointId, this.state.path);
|
||||
this.files = files;
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to delete file');
|
||||
|
|
|
@ -7,5 +7,6 @@ angular.module('portainer.agent').component('nodeSelector', {
|
|||
controller: NodeSelectorController,
|
||||
bindings: {
|
||||
model: '=',
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ export class NodeSelectorController {
|
|||
|
||||
async $onInit() {
|
||||
try {
|
||||
const agents = await this.AgentService.agents();
|
||||
const agents = await this.AgentService.agents(this.endpointId);
|
||||
this.agents = agents;
|
||||
if (!this.model) {
|
||||
this.model = agents[0].NodeName;
|
||||
|
|
|
@ -36,9 +36,9 @@ export class VolumeBrowserController {
|
|||
const newFilePath = this.state.path === '/' ? newName : `${this.state.path}/${newName}`;
|
||||
|
||||
try {
|
||||
await this.VolumeBrowserService.rename(this.volumeId, filePath, newFilePath);
|
||||
await this.VolumeBrowserService.rename(this.endpointId, this.volumeId, filePath, newFilePath);
|
||||
this.Notifications.success('File successfully renamed', newFilePath);
|
||||
this.files = await this.VolumeBrowserService.ls(this.volumeId, this.state.path);
|
||||
this.files = await this.VolumeBrowserService.ls(this.endpointId, this.volumeId, this.state.path);
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to rename file');
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ export class VolumeBrowserController {
|
|||
const filePath = this.state.path === '/' ? file : `${this.state.path}/${file}`;
|
||||
|
||||
try {
|
||||
const data = await this.VolumeBrowserService.get(this.volumeId, filePath);
|
||||
const data = await this.VolumeBrowserService.get(this.endpointId, this.volumeId, filePath);
|
||||
const downloadData = new Blob([data.file]);
|
||||
this.FileSaver.saveAs(downloadData, file);
|
||||
} catch (err) {
|
||||
|
@ -85,9 +85,9 @@ export class VolumeBrowserController {
|
|||
}
|
||||
async deleteFileAsync(file) {
|
||||
try {
|
||||
await this.VolumeBrowserService.delete(this.volumeId, file);
|
||||
await this.VolumeBrowserService.delete(this.endpointId, this.volumeId, file);
|
||||
this.Notifications.success('File successfully deleted', file);
|
||||
this.files = await this.VolumeBrowserService.ls(this.volumeId, this.state.path);
|
||||
this.files = await this.VolumeBrowserService.ls(this.endpointId, this.volumeId, this.state.path);
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to delete file');
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ export class VolumeBrowserController {
|
|||
}
|
||||
async getFilesForPathAsync(path) {
|
||||
try {
|
||||
const files = await this.VolumeBrowserService.ls(this.volumeId, path);
|
||||
const files = await this.VolumeBrowserService.ls(this.endpointId, this.volumeId, path);
|
||||
this.state.path = path;
|
||||
this.files = files;
|
||||
} catch (err) {
|
||||
|
@ -145,7 +145,7 @@ export class VolumeBrowserController {
|
|||
async $onInit() {
|
||||
this.HttpRequestHelper.setPortainerAgentTargetHeader(this.nodeName);
|
||||
try {
|
||||
this.files = await this.VolumeBrowserService.ls(this.volumeId, this.state.path);
|
||||
this.files = await this.VolumeBrowserService.ls(this.endpointId, this.volumeId, this.state.path);
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to browse volume');
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('Agent', AgentFactory);
|
||||
|
||||
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
||||
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, StateManager) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/agents`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
version: StateManager.getAgentApiVersion,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -4,11 +4,10 @@ import { browseGetResponse } from './response/browse';
|
|||
|
||||
angular.module('portainer.agent').factory('Browse', BrowseFactory);
|
||||
|
||||
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
||||
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, StateManager) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/browse/:action`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
version: StateManager.getAgentApiVersion,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -2,11 +2,10 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('Host', HostFactory);
|
||||
|
||||
function HostFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
||||
function HostFactory($resource, API_ENDPOINT_ENDPOINTS, StateManager) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/v:version/host/:action`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
version: StateManager.getAgentApiVersion,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -2,12 +2,10 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('AgentPing', AgentPingFactory);
|
||||
|
||||
function AgentPingFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider, $q) {
|
||||
function AgentPingFactory($resource, API_ENDPOINT_ENDPOINTS, $q) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/ping`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
},
|
||||
{},
|
||||
{
|
||||
ping: {
|
||||
method: 'GET',
|
||||
|
|
|
@ -2,12 +2,10 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('AgentVersion1', AgentFactory);
|
||||
|
||||
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
|
||||
function AgentFactory($resource, API_ENDPOINT_ENDPOINTS) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/agents`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
},
|
||||
{},
|
||||
{
|
||||
query: { method: 'GET', isArray: true },
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@ import { browseGetResponse } from '../response/browse';
|
|||
|
||||
angular.module('portainer.agent').factory('BrowseVersion1', BrowseFactory);
|
||||
|
||||
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
|
||||
function BrowseFactory($resource, API_ENDPOINT_ENDPOINTS) {
|
||||
return $resource(
|
||||
`${API_ENDPOINT_ENDPOINTS}/:endpointId/docker/browse/:volumeID/:action`,
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID,
|
||||
},
|
||||
{},
|
||||
{
|
||||
ls: {
|
||||
method: 'GET',
|
||||
|
|
|
@ -15,16 +15,16 @@ function AgentServiceFactory(Agent, AgentVersion1, HttpRequestHelper, Host, Stat
|
|||
return state.endpoint.agentApiVersion;
|
||||
}
|
||||
|
||||
function hostInfo(nodeName) {
|
||||
function hostInfo(endpointId, nodeName) {
|
||||
HttpRequestHelper.setPortainerAgentTargetHeader(nodeName);
|
||||
return Host.info().$promise;
|
||||
return Host.info({ endpointId }).$promise;
|
||||
}
|
||||
|
||||
async function agents() {
|
||||
async function agents(endpointId) {
|
||||
const agentVersion = getAgentApiVersion();
|
||||
const service = agentVersion > 1 ? Agent : AgentVersion1;
|
||||
try {
|
||||
const agents = await service.query({ version: agentVersion }).$promise;
|
||||
const agents = await service.query({ version: agentVersion, endpointId }).$promise;
|
||||
return agents.map(function (item) {
|
||||
return new AgentViewModel(item);
|
||||
});
|
||||
|
|
|
@ -6,24 +6,24 @@ angular.module('portainer.agent').factory('HostBrowserService', HostBrowserServi
|
|||
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, StateManager) {
|
||||
return { ls, get, delete: deletePath, rename, upload };
|
||||
|
||||
function ls(path) {
|
||||
return Browse.ls({ path: path }).$promise;
|
||||
function ls(endpointId, path) {
|
||||
return Browse.ls({ endpointId, path: path }).$promise;
|
||||
}
|
||||
|
||||
function get(path) {
|
||||
return Browse.get({ path: path }).$promise;
|
||||
function get(endpointId, path) {
|
||||
return Browse.get({ endpointId, path: path }).$promise;
|
||||
}
|
||||
|
||||
function deletePath(path) {
|
||||
return Browse.delete({ path: path }).$promise;
|
||||
function deletePath(endpointId, path) {
|
||||
return Browse.delete({ endpointId, path: path }).$promise;
|
||||
}
|
||||
|
||||
function rename(path, newPath) {
|
||||
function rename(endpointId, path, newPath) {
|
||||
const payload = {
|
||||
CurrentFilePath: path,
|
||||
NewFilePath: newPath,
|
||||
};
|
||||
return Browse.rename({}, payload).$promise;
|
||||
return Browse.rename({ endpointId }, payload).$promise;
|
||||
}
|
||||
|
||||
function upload(endpointId, Path, file, onProgress) {
|
||||
|
|
|
@ -5,7 +5,7 @@ angular.module('portainer.agent').service('AgentPingService', AgentPingService);
|
|||
function AgentPingService(AgentPing) {
|
||||
return { ping };
|
||||
|
||||
function ping() {
|
||||
return AgentPing.ping().$promise;
|
||||
function ping(endpointId) {
|
||||
return AgentPing.ping({ endpointId }).$promise;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,24 +22,24 @@ function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, API_E
|
|||
return agentVersion > 1 ? Browse : BrowseVersion1;
|
||||
}
|
||||
|
||||
function ls(volumeId, path) {
|
||||
return getBrowseService().ls({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
function ls(endpointId, volumeId, path) {
|
||||
return getBrowseService().ls({ endpointId, volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
}
|
||||
|
||||
function get(volumeId, path) {
|
||||
return getBrowseService().get({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
function get(endpointId, volumeId, path) {
|
||||
return getBrowseService().get({ endpointId, volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
}
|
||||
|
||||
function deletePath(volumeId, path) {
|
||||
return getBrowseService().delete({ volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
function deletePath(endpointId, volumeId, path) {
|
||||
return getBrowseService().delete({ endpointId, volumeID: volumeId, path, version: getAgentApiVersion() }).$promise;
|
||||
}
|
||||
|
||||
function rename(volumeId, path, newPath) {
|
||||
function rename(endpointId, volumeId, path, newPath) {
|
||||
const payload = {
|
||||
CurrentFilePath: path,
|
||||
NewFilePath: newPath,
|
||||
};
|
||||
return getBrowseService().rename({ volumeID: volumeId, version: getAgentApiVersion() }, payload).$promise;
|
||||
return getBrowseService().rename({ endpointId, volumeID: volumeId, version: getAgentApiVersion() }, payload).$promise;
|
||||
}
|
||||
|
||||
function upload(endpointId, path, file, volumeId, onProgress) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue