Skip to content

Commit 05d2a6d

Browse files
committed
Add back locations with new theme
1 parent db07202 commit 05d2a6d

File tree

7 files changed

+378
-182
lines changed

7 files changed

+378
-182
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Http\Controllers\Admin;
26+
27+
use Log;
28+
use Alert;
29+
use Illuminate\Http\Request;
30+
use Pterodactyl\Models\Location;
31+
use Pterodactyl\Exceptions\DisplayException;
32+
use Pterodactyl\Http\Controllers\Controller;
33+
use Pterodactyl\Repositories\LocationRepository;
34+
use Pterodactyl\Exceptions\DisplayValidationException;
35+
36+
class LocationController extends Controller
37+
{
38+
/**
39+
* Return the location overview page.
40+
*
41+
* @param Request $request
42+
* @return \Illuminate\View\View
43+
*/
44+
public function index(Request $request)
45+
{
46+
return view('admin.locations.index', [
47+
'locations' => Location::withCount('nodes', 'servers')->get(),
48+
]);
49+
}
50+
51+
/**
52+
* Return the location view page.
53+
*
54+
* @param Request $request
55+
* @param int $id
56+
* @return \Illuminate\View\View
57+
*/
58+
public function view(Request $request, $id)
59+
{
60+
return view('admin.locations.view', ['location' => Location::with('nodes.servers')->findOrFail($id)]);
61+
}
62+
63+
/**
64+
* Handle request to create new location.
65+
*
66+
* @param Request $request
67+
* @return \Illuminate\Response\RedirectResponse
68+
*/
69+
public function create(Request $request)
70+
{
71+
$repo = new LocationRepository;
72+
73+
try {
74+
$location = $repo->create($request->intersect(['short', 'long']));
75+
Alert::success('Location was created successfully.')->flash();
76+
77+
return redirect()->route('admin.locations.view', $location->id);
78+
} catch (DisplayValidationException $ex) {
79+
return redirect()->route('admin.locations')->withErrors(json_decode($ex->getMessage()));
80+
} catch (\Exception $ex) {
81+
Log::error($ex);
82+
Alert::error('An unhandled exception occurred while processing this request. This error has been logged.')->flash();
83+
}
84+
85+
return redirect()->route('admin.locations');
86+
}
87+
88+
/**
89+
* Handle request to update or delete location.
90+
*
91+
* @param Request $request
92+
* @param int $id
93+
* @return \Illuminate\Response\RedirectResponse
94+
*/
95+
public function update(Request $request, $id)
96+
{
97+
$repo = new LocationRepository;
98+
99+
try {
100+
if ($request->input('action') !== 'delete') {
101+
$location = $repo->update($id, $request->intersect(['short', 'long']));
102+
Alert::success('Location was updated successfully.')->flash();
103+
} else {
104+
$repo->delete($id);
105+
106+
return redirect()->route('admin.locations');
107+
}
108+
} catch (DisplayValidationException $ex) {
109+
return redirect()->route('admin.locations.view', $id)->withErrors(json_decode($ex->getMessage()));
110+
} catch (DisplayException $ex) {
111+
Alert::danger($ex->getMessage())->flash();
112+
} catch (\Exception $ex) {
113+
Log::error($ex);
114+
Alert::error('An unhandled exception occurred while processing this request. This error has been logged.')->flash();
115+
}
116+
117+
return redirect()->route('admin.locations.view', $id);
118+
}
119+
}

app/Http/Controllers/Admin/LocationsController.php

Lines changed: 0 additions & 100 deletions
This file was deleted.

app/Http/Routes/AdminRoutes.php

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ public function map(Router $router)
4343
'uses' => 'Admin\BaseController@getIndex',
4444
]);
4545

46+
$router->group([
47+
'prefix' => 'admin/locations',
48+
'middleware' => [
49+
'auth',
50+
'admin',
51+
'csrf',
52+
],
53+
], function () use ($router) {
54+
$router->get('/', [
55+
'as' => 'admin.locations',
56+
'uses' => 'Admin\LocationController@index',
57+
]);
58+
59+
$router->post('/', 'Admin\LocationController@create');
60+
61+
$router->get('/view/{id}', [
62+
'as' => 'admin.locations.view',
63+
'uses' => 'Admin\LocationController@view',
64+
]);
65+
66+
$router->post('/view/{id}', 'Admin\LocationController@update');
67+
});
68+
4669
$router->group([
4770
'prefix' => 'admin/settings',
4871
'middleware' => [
@@ -321,60 +344,6 @@ public function map(Router $router)
321344
]);
322345
});
323346

324-
// Location Routes
325-
$router->group([
326-
'prefix' => 'admin/locations',
327-
'middleware' => [
328-
'auth',
329-
'admin',
330-
'csrf',
331-
],
332-
], function () use ($router) {
333-
$router->get('/', [
334-
'as' => 'admin.locations',
335-
'uses' => 'Admin\LocationsController@getIndex',
336-
]);
337-
$router->delete('/{id}', [
338-
'uses' => 'Admin\LocationsController@deleteLocation',
339-
]);
340-
$router->patch('/{id}', [
341-
'uses' => 'Admin\LocationsController@patchLocation',
342-
]);
343-
$router->post('/', [
344-
'uses' => 'Admin\LocationsController@postLocation',
345-
]);
346-
});
347-
348-
// Database Routes
349-
$router->group([
350-
'prefix' => 'admin/databases',
351-
'middleware' => [
352-
'auth',
353-
'admin',
354-
'csrf',
355-
],
356-
], function () use ($router) {
357-
$router->get('/', [
358-
'as' => 'admin.databases',
359-
'uses' => 'Admin\DatabaseController@getIndex',
360-
]);
361-
$router->get('/new', [
362-
'as' => 'admin.databases.new',
363-
'uses' => 'Admin\DatabaseController@getNew',
364-
]);
365-
$router->post('/new', [
366-
'uses' => 'Admin\DatabaseController@postNew',
367-
]);
368-
$router->delete('/delete/{id}', [
369-
'as' => 'admin.databases.delete',
370-
'uses' => 'Admin\DatabaseController@deleteDatabase',
371-
]);
372-
$router->delete('/delete-server/{id}', [
373-
'as' => 'admin.databases.delete-server',
374-
'uses' => 'Admin\DatabaseController@deleteServer',
375-
]);
376-
});
377-
378347
// Service Routes
379348
$router->group([
380349
'prefix' => 'admin/services',

0 commit comments

Comments
 (0)