Skip to content

Commit e09659a

Browse files
committed
support for pack editing
1 parent 09c2dcc commit e09659a

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

app/Http/Controllers/Admin/PackController.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ protected function formatServices()
6868

6969
public function listAll(Request $request)
7070
{
71-
//
71+
return view('admin.services.packs.index', [
72+
'services' => Models\Service::all()
73+
]);
7274
}
7375

7476
public function listByOption(Request $request, $id)
@@ -137,6 +139,23 @@ public function edit(Request $request, $id)
137139
]);
138140
}
139141

142+
public function update(Request $request, $id)
143+
{
144+
try {
145+
$repo = new Pack;
146+
$repo->update($id, $request->except([
147+
'_token'
148+
]));
149+
Alert::success('Service pack has been successfully updated.')->flash();
150+
} catch (DisplayValidationException $ex) {
151+
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
152+
} catch (\Exception $ex) {
153+
Log::error($ex);
154+
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
155+
}
156+
return redirect()->route('admin.services.packs.edit', $id);
157+
}
158+
140159
public function export(Request $request, $id, $files = false)
141160
{
142161
$pack = Models\ServicePack::findOrFail($id);

app/Repositories/ServiceRepository/Pack.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,45 @@ public function create(array $data)
102102
});
103103
}
104104

105+
public function update($id, array $data)
106+
{
107+
$validator = Validator::make($data, [
108+
'name' => 'required|string',
109+
'version' => 'required|string',
110+
'description' => 'string',
111+
'option' => 'required|exists:service_options,id',
112+
'selectable' => 'sometimes|boolean',
113+
'visible' => 'sometimes|boolean',
114+
'build_memory' => 'required|integer|min:0',
115+
'build_swap' => 'required|integer|min:0',
116+
'build_cpu' => 'required|integer|min:0',
117+
'build_io' => 'required|integer|min:10|max:1000',
118+
'build_container' => 'required|string',
119+
'build_script' => 'sometimes|string'
120+
]);
121+
122+
if ($validator->fails()) {
123+
throw new DisplayValidationException($validator->errors());
124+
}
125+
126+
DB::transaction(function () use ($id, $data) {
127+
Models\ServicePack::findOrFail($id)->update([
128+
'option' => $data['option'],
129+
'build_memory' => $data['build_memory'],
130+
'build_swap' => $data['build_swap'],
131+
'build_cpu' => $data['build_swap'],
132+
'build_io' => $data['build_io'],
133+
'build_script' => (empty($data['build_script'])) ? null : $data['build_script'],
134+
'build_container' => $data['build_container'],
135+
'name' => $data['name'],
136+
'version' => $data['version'],
137+
'description' => (empty($data['description'])) ? null : $data['description'],
138+
'selectable' => isset($data['selectable']),
139+
'visible' => isset($data['visible'])
140+
]);
141+
142+
return true;
143+
});
144+
}
145+
105146
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.admin')
21+
22+
@section('title')
23+
Service Packs
24+
@endsection
25+
26+
@section('content')
27+
<div class="col-md-12">
28+
<ul class="breadcrumb">
29+
<li><a href="/admin">Admin Control</a></li>
30+
<li><a href="/admin/services">Services</a></li>
31+
<li class="active">Packs</li>
32+
</ul>
33+
<h3 class="nopad">Service Packs</h3><hr />
34+
<div class="row">
35+
@foreach ($services as $service)
36+
<div class="col-md-6">
37+
<a href="{{ route('admin.services.packs.service', $service->id) }}"><button class="btn btn-lg btn-primary" style="width:100%;margin-bottom:25px;">{{ $service->name }}</button></a>
38+
</div>
39+
@endforeach
40+
</div>
41+
</div>
42+
<script>
43+
$(document).ready(function () {
44+
$('#sidebar_links').find("a[href='/admin/services/packs']").addClass('active');
45+
});
46+
</script>
47+
@endsection

0 commit comments

Comments
 (0)