Skip to content

Commit 0e23f87

Browse files
committed
Add task management views
1 parent aea9b02 commit 0e23f87

File tree

7 files changed

+473
-20
lines changed

7 files changed

+473
-20
lines changed

app/Http/Controllers/Server/TaskController.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use Log;
2828
use Alert;
29+
use Javascript;
2930
use Pterodactyl\Models;
3031
use Illuminate\Http\Request;
3132
use Pterodactyl\Repositories;
@@ -44,14 +45,20 @@ public function getIndex(Request $request, $uuid)
4445
{
4546
$server = Models\Server::getByUUID($uuid);
4647
$this->authorize('list-tasks', $server);
48+
$node = Models\Node::find($server->node);
49+
50+
Javascript::put([
51+
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
52+
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
53+
]);
4754

4855
return view('server.tasks.index', [
4956
'server' => $server,
50-
'node' => Models\Node::findOrFail($server->node),
57+
'node' => $node,
5158
'tasks' => Models\Task::where('server', $server->id)->get(),
5259
'actions' => [
53-
'command' => 'Send Command',
54-
'power' => 'Set Power Status',
60+
'command' => trans('server.tasks.actions.command'),
61+
'power' => trans('server.tasks.actions.power'),
5562
],
5663
]);
5764
}
@@ -60,10 +67,15 @@ public function getNew(Request $request, $uuid)
6067
{
6168
$server = Models\Server::getByUUID($uuid);
6269
$this->authorize('create-task', $server);
70+
$node = Models\Node::find($server->node);
6371

72+
Javascript::put([
73+
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
74+
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
75+
]);
6476
return view('server.tasks.new', [
6577
'server' => $server,
66-
'node' => Models\Node::findOrFail($server->node),
78+
'node' => $node,
6779
]);
6880
}
6981

@@ -77,28 +89,17 @@ public function postNew(Request $request, $uuid)
7789
$repo->create($server->id, $request->except([
7890
'_token',
7991
]));
92+
return redirect()->route('server.tasks', $uuid);
8093
} catch (DisplayValidationException $ex) {
81-
return redirect()->route('server.tasks', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput();
94+
return redirect()->route('server.tasks.new', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput();
8295
} catch (DisplayException $ex) {
8396
Alert::danger($ex->getMessage())->flash();
8497
} catch (\Exception $ex) {
8598
Log::error($ex);
8699
Alert::danger('An unknown error occured while attempting to create this task.')->flash();
87100
}
88101

89-
return redirect()->route('server.tasks', $uuid);
90-
}
91-
92-
public function getView(Request $request, $uuid, $id)
93-
{
94-
$server = Models\Server::getByUUID($uuid);
95-
$this->authorize('view-task', $server);
96-
97-
return view('server.tasks.view', [
98-
'server' => $server,
99-
'node' => Models\Node::findOrFail($server->node),
100-
'task' => Models\Task::where('id', $id)->where('server', $server->id)->firstOrFail(),
101-
]);
102+
return redirect()->route('server.tasks.new', $uuid);
102103
}
103104

104105
public function deleteTask(Request $request, $uuid, $id)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
(function initTaskFunctions() {
21+
$('[data-action="delete-task"]').click(function (event) {
22+
var self = $(this);
23+
swal({
24+
type: 'error',
25+
title: 'Delete Task?',
26+
text: 'Are you sure you want to delete this task? There is no undo.',
27+
showCancelButton: true,
28+
allowOutsideClick: true,
29+
closeOnConfirm: false,
30+
confirmButtonText: 'Delete Task',
31+
confirmButtonColor: '#d9534f',
32+
showLoaderOnConfirm: true
33+
}, function () {
34+
$.ajax({
35+
method: 'DELETE',
36+
url: Router.route('server.tasks.delete', {
37+
server: Pterodactyl.server.uuidShort,
38+
id: self.data('id'),
39+
}),
40+
headers: {
41+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
42+
}
43+
}).done(function (data) {
44+
swal({
45+
type: 'success',
46+
title: '',
47+
text: 'Task has been deleted.'
48+
});
49+
self.parent().parent().slideUp();
50+
}).fail(function (jqXHR) {
51+
console.error(jqXHR);
52+
swal({
53+
type: 'error',
54+
title: 'Whoops!',
55+
text: 'An error occured while attempting to delete this task.'
56+
});
57+
});
58+
});
59+
});
60+
$('[data-action="toggle-task"]').click(function (event) {
61+
var self = $(this);
62+
swal({
63+
type: 'info',
64+
title: 'Toggle Task',
65+
text: 'This will toggle the selected task.',
66+
showCancelButton: true,
67+
allowOutsideClick: true,
68+
closeOnConfirm: false,
69+
confirmButtonText: 'Continue',
70+
showLoaderOnConfirm: true
71+
}, function () {
72+
$.ajax({
73+
method: 'POST',
74+
url: Router.route('server.tasks.toggle', {
75+
server: Pterodactyl.server.uuidShort,
76+
id: self.data('id'),
77+
}),
78+
headers: {
79+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
80+
}
81+
}).done(function (data) {
82+
swal({
83+
type: 'success',
84+
title: '',
85+
text: 'Task has been toggled.'
86+
});
87+
if (data.status !== 1) {
88+
self.parent().parent().addClass('muted muted-hover');
89+
} else {
90+
self.parent().parent().removeClass('muted muted-hover');
91+
}
92+
}).fail(function (jqXHR) {
93+
console.error(jqXHR);
94+
swal({
95+
type: 'error',
96+
title: 'Whoops!',
97+
text: 'An error occured while attempting to toggle this task.'
98+
});
99+
});
100+
});
101+
});
102+
})();

resources/lang/en/server.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66
'header' => 'Server Console',
77
'header_sub' => 'Control your server in real time.',
88
],
9+
'tasks' => [
10+
'header' => 'Scheduled Tasks',
11+
'header_sub' => 'Automate your server.',
12+
'current' => 'Current Scheduled Tasks',
13+
'actions' => [
14+
'command' => 'Send Command',
15+
'power' => 'Send Power Toggle',
16+
],
17+
'new_task' => 'Add New Task',
18+
'toggle' => 'Toggle Status',
19+
'new' => [
20+
'header' => 'New Task',
21+
'header_sub' => 'Create a new scheduled task for this server.',
22+
'day_of_week' => 'Day of Week',
23+
'custom' => 'Custom Value',
24+
'day_of_month' => 'Day of Month',
25+
'hour' => 'Hour',
26+
'minute' => 'Minute',
27+
'sun' => 'Sunday',
28+
'mon' => 'Monday',
29+
'tues' => 'Tuesday',
30+
'wed' => 'Wednesday',
31+
'thurs' => 'Thursday',
32+
'fri' => 'Friday',
33+
'sat' => 'Saturday',
34+
'submit' => 'Create Task',
35+
'type' => 'Task Type',
36+
'payload' => 'Task Payload',
37+
'payload_help' => 'For example, if you selected <code>Send Command</code> enter the command here. If you selected <code>Send Power Option</code> put the power action here (e.g. <code>restart</code>).',
38+
],
39+
],
940
'users' => [
1041
'header' => 'Manage Users',
1142
'header_sub' => 'Control who can access your server.',

resources/lang/en/strings.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@
5151
'none' => 'None',
5252
'cancel' => 'Cancel',
5353
'created_at' => 'Created At',
54+
'action' => 'Action',
55+
'data' => 'Data',
56+
'queued' => 'Queued',
57+
'last_run' => 'Last Run',
58+
'next_run' => 'Next Run',
59+
'yes' => 'Yes',
60+
'no' => 'No',
61+
'delete' => 'Delete',
5462
];

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,15 @@ class="active"
166166
<i class="fa fa-users"></i> <span>Subusers</span>
167167
</a>
168168
</li>
169-
<li>
169+
<li
170+
@if(in_array(Route::currentRouteName(), ['server.tasks', 'server.tasks.new']))
171+
class="active"
172+
@endif
173+
>
170174
<a href="{{ route('server.tasks', $server->uuidShort)}}">
171175
<i class="fa fa-clock-o"></i> <span>@lang('navigation.server.task_management')</span>
172176
<span class="pull-right-container">
173-
<span class="label label-primary pull-right">4</span>
177+
<span class="label label-primary pull-right">{{ \Pterodactyl\Models\Task::select('id')->where('server', $server->id)->where('active', 1)->count() }}</span>
174178
</span>
175179
</a>
176180
</li>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
2+
3+
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
4+
{{-- of this software and associated documentation files (the "Software"), to deal --}}
5+
{{-- in the Software without restriction, including without limitation the rights --}}
6+
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
7+
{{-- copies of the Software, and to permit persons to whom the Software is --}}
8+
{{-- furnished to do so, subject to the following conditions: --}}
9+
10+
{{-- The above copyright notice and this permission notice shall be included in all --}}
11+
{{-- copies or substantial portions of the Software. --}}
12+
13+
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
14+
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
15+
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
16+
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
17+
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
18+
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
19+
{{-- SOFTWARE. --}}
20+
@extends('layouts.master')
21+
22+
@section('title')
23+
@lang('server.tasks.header')
24+
@endsection
25+
26+
@section('content-header')
27+
<h1>@lang('server.tasks.header')<small>@lang('server.tasks.header_sub')</small></h1>
28+
<ol class="breadcrumb">
29+
<li><a href="{{ route('index') }}">@lang('strings.home')</a></li>
30+
<li><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></li>
31+
<li class="active">@lang('navigation.server.task_management')</li>
32+
</ol>
33+
@endsection
34+
35+
@section('content')
36+
<div class="row">
37+
<div class="col-xs-12">
38+
<div class="box">
39+
<div class="box-header with-border">
40+
<h3 class="box-title">@lang('server.tasks.current')</h3>
41+
</div>
42+
<div class="box-body table-responsive no-padding">
43+
<table class="table table-hover">
44+
<tbody>
45+
<tr>
46+
<th>@lang('strings.action')</th>
47+
<th>@lang('strings.data')</th>
48+
<th>@lang('strings.queued')</th>
49+
<th>@lang('strings.last_run')</th>
50+
<th>@lang('strings.next_run')</th>
51+
<th></th>
52+
<th></th>
53+
</tr>
54+
@foreach($tasks as $task)
55+
<tr @if($task->active === 0)class="muted muted-hover"@endif>
56+
<td class="middle">{{ $actions[$task->action] }}</td>
57+
<td class="middle"><code>{{ $task->data }}</code></td>
58+
<td class="middle">
59+
@if ($task->queued)
60+
<span class="label label-success">@lang('strings.yes')</span>
61+
@else
62+
<span class="label label-default">@lang('strings.no')</span>
63+
@endif
64+
</td>
65+
<td class="middle">{{ Carbon::parse($task->last_run)->toDayDateTimeString() }}<br /><span class="text-muted small">({{ Carbon::parse($task->last_run)->diffForHumans() }})</span></td>
66+
<td class="middle">
67+
@if($task->active !== 0)
68+
{{ Carbon::parse($task->next_run)->toDayDateTimeString() }}<br /><span class="text-muted small">({{ Carbon::parse($task->next_run)->diffForHumans() }})</span>
69+
@else
70+
<em>n/a</em>
71+
@endif
72+
</td>
73+
@can('delete-task', $server)
74+
<td class="text-center middle"><a href="#" data-action="delete-task" data-id="{{ $task->id }}"><i class="fa fa-fw fa-trash-o text-danger" data-toggle="tooltip" data-placement="top" title="@lang('strings.delete')"></i></a></td>
75+
@endcan
76+
@can('toggle-task', $server)
77+
<td class="text-center middle"><a href="#" data-action="toggle-task" data-active="{{ $task->active }}" data-id="{{ $task->id }}"><i class="fa fa-fw fa-eye-slash text-primary" data-toggle="tooltip" data-placement="top" title="@lang('server.tasks.toggle')"></i></a></td>
78+
@endcan
79+
</tr>
80+
@endforeach
81+
82+
</tbody>
83+
</table>
84+
</div>
85+
<div class="box-footer">
86+
<a href="{{ route('server.tasks.new', $server->uuidShort) }}">
87+
<button class="btn btn-sm btn-primary">@lang('server.tasks.new_task')</button>
88+
</a>
89+
</div>
90+
</div>
91+
</div>
92+
</div>
93+
@endsection
94+
95+
@section('footer-scripts')
96+
@parent
97+
{!! Theme::js('js/frontend/server.socket.js') !!}
98+
{!! Theme::js('js/frontend/tasks.js') !!}
99+
@endsection

0 commit comments

Comments
 (0)