1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-08 15:25:22 +02:00

feat(schedules): add the ability to update a schedule script (#2438)

This commit is contained in:
Anthony Lapenna 2018-11-07 17:19:10 +13:00 committed by GitHub
parent 695c28d4f8
commit 807c830db0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 124 additions and 56 deletions

View file

@ -55,14 +55,14 @@
</div>
</div>
<!-- !image-input -->
<div class="form-group">
<span class="col-sm-12 text-muted small">
This schedule will be executed via a privileged container on the target hosts. You can access the host filesystem under the
<code>/host</code> folder.
</span>
</div>
<!-- execution-method -->
<div ng-if="!$ctrl.model.Id">
<div class="form-group">
<span class="col-sm-12 text-muted small">
This schedule will be executed via a privileged container on the target hosts. You can access the host filesystem under the
<code>/host</code> folder.
</span>
</div>
<!-- execution-method -->
<div class="col-sm-12 form-section-title">
Job content
</div>
@ -91,46 +91,46 @@
</div>
</div>
</div>
<!-- !execution-method -->
<!-- web-editor -->
<div ng-show="$ctrl.model.Job.Method === 'editor'">
<div class="col-sm-12 form-section-title">
Web editor
</div>
<div class="form-group">
<div class="col-sm-12">
<code-editor
identifier="execute-schedule-editor"
placeholder="# Define or paste the content of your script file here"
on-change="$ctrl.editorUpdate"
value="$ctrl.model.Job.FileContent"
></code-editor>
</div>
</div>
<!-- !execution-method -->
<!-- web-editor -->
<div ng-show="$ctrl.model.Job.Method === 'editor'">
<div class="col-sm-12 form-section-title">
Web editor
</div>
<div class="form-group">
<div class="col-sm-12">
<code-editor
identifier="execute-schedule-editor"
placeholder="# Define or paste the content of your script file here"
on-change="$ctrl.editorUpdate"
value="$ctrl.model.Job.FileContent"
></code-editor>
</div>
</div>
<!-- !web-editor -->
<!-- upload -->
<div ng-show="$ctrl.model.Job.Method === '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 script file from your computer.
</div>
<!-- !web-editor -->
<!-- upload -->
<div ng-show="$ctrl.model.Job.Method === '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 script file from your computer.
</span>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-sm btn-primary" ngf-select ng-model="$ctrl.model.Job.File">Select file</button>
<span style="margin-left: 5px;">
{{ $ctrl.model.Job.File.name }}
<i class="fa fa-times red-icon" ng-if="!$ctrl.model.Job.File" aria-hidden="true"></i>
</span>
</div>
<div class="form-group">
<div class="col-sm-12">
<button class="btn btn-sm btn-primary" ngf-select ng-model="$ctrl.model.Job.File">Select file</button>
<span style="margin-left: 5px;">
{{ $ctrl.model.Job.File.name }}
<i class="fa fa-times red-icon" ng-if="!$ctrl.model.Job.File" aria-hidden="true"></i>
</span>
</div>
</div>
</div>
<!-- !upload -->
</div>
<!-- !upload -->
<div class="col-sm-12 form-section-title">
Target endpoints
</div>

View file

@ -27,6 +27,8 @@ function ScheduleModel(data) {
function ScriptExecutionJobModel(data) {
this.Image = data.Image;
this.Endpoints = data.Endpoints;
this.FileContent = '';
this.Method = 'editor';
}
function ScheduleCreateRequest(model) {
@ -44,4 +46,5 @@ function ScheduleUpdateRequest(model) {
this.CronExpression = model.CronExpression;
this.Image = model.Job.Image;
this.Endpoints = model.Job.Endpoints;
this.FileContent = model.Job.FileContent;
}

View file

@ -2,11 +2,12 @@ angular.module('portainer.app')
.factory('Schedules', ['$resource', 'API_ENDPOINT_SCHEDULES',
function SchedulesFactory($resource, API_ENDPOINT_SCHEDULES) {
'use strict';
return $resource(API_ENDPOINT_SCHEDULES + '/:id', {}, {
return $resource(API_ENDPOINT_SCHEDULES + '/:id/:action', {}, {
create: { method: 'POST' },
query: { method: 'GET', isArray: true },
get: { method: 'GET', params: { id: '@id' } },
update: { method: 'PUT', params: { id: '@id' } },
remove: { method: 'DELETE', params: { id: '@id'} }
remove: { method: 'DELETE', params: { id: '@id'} },
file: { method: 'GET', params: { id : '@id', action: 'file' } }
});
}]);

View file

@ -55,5 +55,9 @@ function ScheduleService($q, Schedules, FileUploadService) {
return Schedules.remove({ id: scheduleId }).$promise;
};
service.getScriptFile = function(scheduleId) {
return Schedules.file({ id: scheduleId }).$promise;
};
return service;
}]);

View file

@ -14,6 +14,7 @@
<rd-widget>
<rd-widget-body>
<schedule-form
ng-if="schedule"
model="schedule"
endpoints="endpoints"
groups="groups"

View file

@ -27,6 +27,7 @@ function ($q, $scope, $transition$, $state, Notifications, EndpointService, Grou
function initView() {
var id = $transition$.params().id;
var schedule = null;
$q.all({
schedule: ScheduleService.schedule(id),
@ -34,9 +35,15 @@ function ($q, $scope, $transition$, $state, Notifications, EndpointService, Grou
groups: GroupService.groups()
})
.then(function success(data) {
$scope.schedule = data.schedule;
schedule = data.schedule;
$scope.endpoints = data.endpoints;
$scope.groups = data.groups;
return ScheduleService.getScriptFile(schedule.Id);
})
.then(function success(data) {
schedule.Job.FileContent = data.ScheduleFileContent;
$scope.schedule = schedule;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve endpoint list');