2626
2727use Log ;
2828use Alert ;
29- use Storage ;
3029use Pterodactyl \Models ;
3130use Illuminate \Http \Request ;
3231use Pterodactyl \Exceptions \DisplayException ;
@@ -74,6 +73,18 @@ public function view(Request $request, $id)
7473 ]);
7574 }
7675
76+ /**
77+ * Return function editing view for a service.
78+ *
79+ * @param Request $request
80+ * @param int $id
81+ * @return \Illuminate\View\View
82+ */
83+ public function viewFunctions (Request $ request , $ id )
84+ {
85+ return view ('admin.services.functions ' , ['service ' => Models \Service::findOrFail ($ id )]);
86+ }
87+
7788 /**
7889 * Handle post action for new service.
7990 *
@@ -113,11 +124,12 @@ public function create(Request $request)
113124 public function edit (Request $ request , $ id )
114125 {
115126 $ repo = new ServiceRepository ;
127+ $ redirectTo = ($ request ->input ('redirect_to ' )) ? 'admin.services.view.functions ' : 'admin.services.view ' ;
116128
117129 try {
118130 if ($ request ->input ('action ' ) !== 'delete ' ) {
119131 $ repo ->update ($ id , $ request ->intersect ([
120- 'name ' , 'description ' , 'folder ' , 'startup ' ,
132+ 'name ' , 'description ' , 'folder ' , 'startup ' , ' index_file ' ,
121133 ]));
122134 Alert::success ('Service has been updated successfully. ' )->flash ();
123135 } else {
@@ -127,201 +139,26 @@ public function edit(Request $request, $id)
127139 return redirect ()->route ('admin.services ' );
128140 }
129141 } catch (DisplayValidationException $ ex ) {
130- return redirect ()->route (' admin.services.view ' , $ id )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
142+ return redirect ()->route ($ redirectTo , $ id )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
131143 } catch (DisplayException $ ex ) {
132144 Alert::danger ($ ex ->getMessage ())->flash ();
133145 } catch (\Exception $ ex ) {
134146 Log::error ($ ex );
135147 Alert::danger ('An error occurred while attempting to update this service. This error has been logged. ' )->flash ();
136148 }
137149
138- return redirect ()->route (' admin.services.view ' , $ id );
150+ return redirect ()->route ($ redirectTo , $ id );
139151 }
140152
141- // public function getOption(Request $request, $service, $option)
142- // {
143- // $option = Models\ServiceOption::with('service', 'variables')->findOrFail($option);
144- // $option->setRelation('servers', $option->servers()->with('user')->paginate(25));
145- //
146- // return view('admin.services.options.view', ['option' => $option]);
147- // }
148- //
149- // public function postOption(Request $request, $service, $option)
150- // {
151- // try {
152- // $repo = new ServiceRepository\Option;
153- // $repo->update($option, $request->only([
154- // 'name', 'description', 'tag',
155- // 'executable', 'docker_image', 'startup',
156- // ]));
157- // Alert::success('Option settings successfully updated.')->flash();
158- // } catch (DisplayValidationException $ex) {
159- // return redirect()->route('admin.services.option', [$service, $option])->withErrors(json_decode($ex->getMessage()))->withInput();
160- // } catch (\Exception $ex) {
161- // Log::error($ex);
162- // Alert::danger('An error occured while attempting to modify this option.')->flash();
163- // }
164- //
165- // return redirect()->route('admin.services.option', [$service, $option])->withInput();
166- // }
167- //
168- // public function deleteOption(Request $request, $service, $option)
169- // {
170- // try {
171- // $repo = new ServiceRepository\Option;
172- // $repo->delete($option);
173- //
174- // Alert::success('Successfully deleted that option.')->flash();
175- //
176- // return redirect()->route('admin.services.service', $service);
177- // } catch (DisplayException $ex) {
178- // Alert::danger($ex->getMessage())->flash();
179- // } catch (\Exception $ex) {
180- // Log::error($ex);
181- // Alert::danger('An error was encountered while attempting to delete this option.')->flash();
182- // }
183- //
184- // return redirect()->route('admin.services.option', [$service, $option]);
185- // }
186- //
187- // public function postOptionVariable(Request $request, $service, $option, $variable)
188- // {
189- // try {
190- // $repo = new ServiceRepository\Variable;
191- //
192- // // Because of the way old() works on the display side we prefix all of the variables with thier ID
193- // // We need to remove that prefix here since the repo doesn't want it.
194- // $data = [
195- // 'user_viewable' => '0',
196- // 'user_editable' => '0',
197- // 'required' => '0',
198- // ];
199- // foreach ($request->except(['_token']) as $id => $val) {
200- // $data[str_replace($variable . '_', '', $id)] = $val;
201- // }
202- // $repo->update($variable, $data);
203- // Alert::success('Successfully updated variable.')->flash();
204- // } catch (DisplayValidationException $ex) {
205- // $data = [];
206- // foreach (json_decode($ex->getMessage(), true) as $id => $val) {
207- // $data[$variable . '_' . $id] = $val;
208- // }
209- //
210- // return redirect()->route('admin.services.option', [$service, $option])->withErrors((object) $data)->withInput();
211- // } catch (DisplayException $ex) {
212- // Alert::danger($ex->getMessage())->flash();
213- // } catch (\Exception $ex) {
214- // Log::error($ex);
215- // Alert::danger('An error occurred while attempting to update this service.')->flash();
216- // }
217- //
218- // return redirect()->route('admin.services.option', [$service, $option])->withInput();
219- // }
220- //
221- // public function getNewVariable(Request $request, $service, $option)
222- // {
223- // return view('admin.services.options.variable', [
224- // 'option' => Models\ServiceOption::with('service')->findOrFail($option),
225- // ]);
226- // }
227- //
228- // public function postNewVariable(Request $request, $service, $option)
229- // {
230- // try {
231- // $repo = new ServiceRepository\Variable;
232- // $repo->create($option, $request->only([
233- // 'name', 'description', 'env_variable',
234- // 'default_value', 'user_viewable',
235- // 'user_editable', 'required', 'regex',
236- // ]));
237- // Alert::success('Successfully added new variable to this option.')->flash();
238- //
239- // return redirect()->route('admin.services.option', [$service, $option]);
240- // } catch (DisplayValidationException $ex) {
241- // return redirect()->route('admin.services.option.variable.new', [$service, $option])->withErrors(json_decode($ex->getMessage()))->withInput();
242- // } catch (DisplayException $ex) {
243- // Alert::danger($ex->getMessage())->flash();
244- // } catch (\Exception $ex) {
245- // Log::error($ex);
246- // Alert::danger('An error occurred while attempting to add this variable.')->flash();
247- // }
248- //
249- // return redirect()->route('admin.services.option.variable.new', [$service, $option])->withInput();
250- // }
251- //
252- // public function newOption(Request $request, $service)
253- // {
254- // return view('admin.services.options.new', [
255- // 'service' => Models\Service::findOrFail($service),
256- // ]);
257- // }
258- //
259- // public function postNewOption(Request $request, $service)
260- // {
261- // try {
262- // $repo = new ServiceRepository\Option;
263- // $id = $repo->create($service, $request->except([
264- // '_token',
265- // ]));
266- // Alert::success('Successfully created new service option.')->flash();
267- //
268- // return redirect()->route('admin.services.option', [$service, $id]);
269- // } catch (DisplayValidationException $ex) {
270- // return redirect()->route('admin.services.option.new', $service)->withErrors(json_decode($ex->getMessage()))->withInput();
271- // } catch (\Exception $ex) {
272- // Log::error($ex);
273- // Alert::danger('An error occured while attempting to add this service option.')->flash();
274- // }
275- //
276- // return redirect()->route('admin.services.option.new', $service)->withInput();
277- // }
278- //
279- // public function deleteVariable(Request $request, $service, $option, $variable)
280- // {
281- // try {
282- // $repo = new ServiceRepository\Variable;
283- // $repo->delete($variable);
284- // Alert::success('Deleted variable.')->flash();
285- // } catch (DisplayException $ex) {
286- // Alert::danger($ex->getMessage())->flash();
287- // } catch (\Exception $ex) {
288- // Log::error($ex);
289- // Alert::danger('An error occured while attempting to delete that variable.')->flash();
290- // }
291- //
292- // return redirect()->route('admin.services.option', [$service, $option]);
293- // }
294- //
295- // public function getConfiguration(Request $request, $serviceId)
296- // {
297- // $service = Models\Service::findOrFail($serviceId);
298- //
299- // return view('admin.services.config', [
300- // 'service' => $service,
301- // 'contents' => [
302- // 'json' => Storage::get('services/' . $service->file . '/main.json'),
303- // 'index' => Storage::get('services/' . $service->file . '/index.js'),
304- // ],
305- // ]);
306- // }
307- //
308- // public function postConfiguration(Request $request, $serviceId)
309- // {
310- // try {
311- // $repo = new ServiceRepository\Service;
312- // $repo->updateFile($serviceId, $request->only(['file', 'contents']));
313- //
314- // return response('', 204);
315- // } catch (DisplayException $ex) {
316- // return response()->json([
317- // 'error' => $ex->getMessage(),
318- // ], 503);
319- // } catch (\Exception $ex) {
320- // Log::error($ex);
321- //
322- // return response()->json([
323- // 'error' => 'An error occured while attempting to save the file.',
324- // ], 503);
325- // }
326- // }
153+ /**
154+ * Edits function file for a service.
155+ *
156+ * @param Request $request
157+ * @param int $id
158+ * @return \Illuminate\Response\RedirectResponse
159+ */
160+ public function editFunctions (Request $ request , $ id )
161+ {
162+
163+ }
327164}
0 commit comments