mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 22:05:23 +02:00
refactor(endpoints): remove endpointProvider from views [EE-1136] (#5359)
[EE-1136]
This commit is contained in:
parent
7088da5157
commit
eb9f6c77f4
56 changed files with 408 additions and 429 deletions
|
@ -141,8 +141,11 @@ export class HostBrowserController {
|
|||
return this.$async(this.onFileSelectedForUploadAsync, file);
|
||||
}
|
||||
async onFileSelectedForUploadAsync(file) {
|
||||
if (!this.endpointId) {
|
||||
throw new Error('missing endpoint id');
|
||||
}
|
||||
try {
|
||||
await this.HostBrowserService.upload(this.state.path, file);
|
||||
await this.HostBrowserService.upload(this.endpointId, this.state.path, file);
|
||||
this.onFileUploaded();
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to upload file');
|
||||
|
|
|
@ -4,4 +4,7 @@ import { HostBrowserController } from './hostBrowserController';
|
|||
angular.module('portainer.agent').component('hostBrowser', {
|
||||
controller: HostBrowserController,
|
||||
templateUrl: './hostBrowser.html',
|
||||
bindings: {
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -9,5 +9,6 @@ angular.module('portainer.agent').component('volumeBrowser', {
|
|||
volumeId: '<',
|
||||
nodeName: '<',
|
||||
isUploadEnabled: '<',
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -111,7 +111,7 @@ export class VolumeBrowserController {
|
|||
}
|
||||
async onFileSelectedForUploadAsync(file) {
|
||||
try {
|
||||
await this.VolumeBrowserService.upload(this.state.path, file, this.volumeId);
|
||||
await this.VolumeBrowserService.upload(this.endpointId, this.state.path, file, this.volumeId);
|
||||
this.onFileUploaded();
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to upload file');
|
||||
|
|
|
@ -2,7 +2,8 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('HostBrowserService', HostBrowserServiceFactory);
|
||||
|
||||
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, EndpointProvider, StateManager) {
|
||||
/* @ngInject */
|
||||
function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, StateManager) {
|
||||
return { ls, get, delete: deletePath, rename, upload };
|
||||
|
||||
function ls(path) {
|
||||
|
@ -25,14 +26,14 @@ function HostBrowserServiceFactory(Browse, Upload, API_ENDPOINT_ENDPOINTS, Endpo
|
|||
return Browse.rename({}, payload).$promise;
|
||||
}
|
||||
|
||||
function upload(path, file, onProgress) {
|
||||
function upload(endpointId, Path, file, onProgress) {
|
||||
const agentVersion = StateManager.getAgentApiVersion();
|
||||
const url = `${API_ENDPOINT_ENDPOINTS}/${EndpointProvider.endpointID()}/docker${agentVersion > 1 ? '/v' + agentVersion : ''}/browse/put`;
|
||||
const url = `${API_ENDPOINT_ENDPOINTS}/${endpointId}/docker${agentVersion > 1 ? '/v' + agentVersion : ''}/browse/put`;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Upload.upload({
|
||||
url: url,
|
||||
data: { file: file, Path: path },
|
||||
data: { file, Path },
|
||||
}).then(resolve, reject, onProgress);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ import angular from 'angular';
|
|||
|
||||
angular.module('portainer.agent').factory('VolumeBrowserService', VolumeBrowserServiceFactory);
|
||||
|
||||
function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, API_ENDPOINT_ENDPOINTS, EndpointProvider, Upload) {
|
||||
/* @ngInject */
|
||||
function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, API_ENDPOINT_ENDPOINTS, Upload) {
|
||||
return {
|
||||
ls,
|
||||
get,
|
||||
|
@ -41,13 +42,13 @@ function VolumeBrowserServiceFactory(StateManager, Browse, BrowseVersion1, API_E
|
|||
return getBrowseService().rename({ volumeID: volumeId, version: getAgentApiVersion() }, payload).$promise;
|
||||
}
|
||||
|
||||
function upload(path, file, volumeId, onProgress) {
|
||||
function upload(endpointId, path, file, volumeId, onProgress) {
|
||||
const agentVersion = StateManager.getAgentApiVersion();
|
||||
if (agentVersion < 2) {
|
||||
throw new Error('upload is not supported on this agent version');
|
||||
}
|
||||
|
||||
const url = `${API_ENDPOINT_ENDPOINTS}/${EndpointProvider.endpointID()}/docker/v${agentVersion}/browse/put?volumeID=${volumeId}`;
|
||||
const url = `${API_ENDPOINT_ENDPOINTS}/${endpointId}/docker/v${agentVersion}/browse/put?volumeID=${volumeId}`;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Upload.upload({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue