-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): upload files inside containers
- Loading branch information
Showing
6 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/docker/views/containers/import/containerImportFiles.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<rd-header> | ||
<rd-header-title title-text="Import files"></rd-header-title> | ||
<rd-header-content> | ||
<a ui-sref="docker.containers">Containers</a> > <a ui-sref="docker.containers.container({id: ctrl.container.Id})">{{ ctrl.container.Name|trimcontainername }}</a> > Import files | ||
</rd-header-content> | ||
</rd-header> | ||
|
||
<div class="row" authorization="DockerContainerPutContainerArchive"> | ||
<div class="col-sm-12"> | ||
<rd-widget> | ||
<rd-widget-body> | ||
<form class="form-horizontal"> | ||
<!-- upload --> | ||
<div class="col-sm-12 form-section-title"> | ||
Upload | ||
</div> | ||
<div class="form-group"> | ||
<span class="col-sm-12 text-muted small"> | ||
You can upload a tar archive containing your files. Accepted compressions: identity (no compression), gzip, bzip2, xz. | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-sm-12"> | ||
<button class="btn btn-sm btn-primary" ngf-select ngf-min-size="10" ngf-accept="'application/x-tar,application/x-gzip'" ng-model="ctrl.formValues.UploadFile">Select file</button> | ||
<span style="margin-left: 5px;"> | ||
{{ ctrl.formValues.UploadFile.name }} | ||
<i class="fa fa-times red-icon" ng-if="!ctrl.formValues.UploadFile" aria-hidden="true"></i> | ||
</span> | ||
</div> | ||
</div> | ||
<!-- path-input --> | ||
<div class="form-group"> | ||
<label for="container_path" class="col-sm-1 control-label text-left">Path</label> | ||
<div class="col-sm-11"> | ||
<input type="text" class="form-control" ng-model="ctrl.formValues.Path" id="container_path" placeholder="/my/path/inside/container"> | ||
</div> | ||
</div> | ||
<!-- !path-input --> | ||
<!-- !upload --> | ||
<!-- actions --> | ||
<div class="col-sm-12 form-section-title"> | ||
Actions | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-sm-12"> | ||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="ctrl.state.actionInProgress || !ctrl.formValues.UploadFile || !ctrl.formValues.Path" | ||
ng-click="ctrl.uploadFiles()" button-spinner="ctrl.state.actionInProgress"> | ||
<span ng-hide="ctrl.state.actionInProgress">Upload</span> | ||
<span ng-show="ctrl.state.actionInProgress">Files uploading in progress...</span> | ||
</button> | ||
<span class="text-danger" ng-if="ctrl.state.formValidationError" style="margin-left: 5px;">{{ ctrl.state.formValidationError }}</span> | ||
</div> | ||
</div> | ||
<!-- !actions --> | ||
</form> | ||
</rd-widget-body> | ||
</rd-widget> | ||
</div> | ||
</div> |
58 changes: 58 additions & 0 deletions
58
app/docker/views/containers/import/containerImportFilesController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import angular from "angular"; | ||
|
||
class ContainerImportFilesController { | ||
/* @ngInject */ | ||
constructor($transition$, ContainerService, Notifications, HttpRequestHelper, $async) { | ||
this.$transition$ = $transition$; | ||
this.ContainerService = ContainerService; | ||
this.Notifications = Notifications; | ||
this.HttpRequestHelper = HttpRequestHelper; | ||
this.$async = $async; | ||
|
||
this.uploadFilesAsync = this.uploadFilesAsync.bind(this); | ||
} | ||
|
||
async $onInit() { | ||
this.state = { | ||
actionInProgress: false, | ||
nodeName: this.$transition$.params().nodeName | ||
}; | ||
|
||
this.formValues = { | ||
UploadFile: null, | ||
Path: null | ||
}; | ||
|
||
const containerId = this.$transition$.params().id; | ||
try { | ||
this.HttpRequestHelper.setPortainerAgentTargetHeader(this.state.nodeName); | ||
this.container = await this.ContainerService.container(containerId); | ||
} catch (err) { | ||
this.Notifications.error("Failure", err, "Unable retrieve container details"); | ||
} | ||
} | ||
|
||
uploadFiles() { | ||
return this.$async(this.uploadFilesAsync); | ||
} | ||
|
||
async uploadFilesAsync() { | ||
this.state.actionInProgress = true; | ||
const containerId = this.container.Id; | ||
const file = this.formValues.UploadFile; | ||
const path = this.formValues.Path; | ||
try { | ||
await this.ContainerService.uploadFiles(containerId, file, path); | ||
this.Notifications.success("Files successfully uploaded"); | ||
} catch (err) { | ||
this.Notifications.error("Failure", err, "Unable to upload files"); | ||
} finally { | ||
this.state.actionInProgress = false; | ||
} | ||
} | ||
} | ||
|
||
export default ContainerImportFilesController; | ||
angular | ||
.module("portainer.docker") | ||
.controller("ContainerImportFilesController", ContainerImportFilesController); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters