forked from projects/fipamo
ro
3d17771f76
The first part of improving the API is removing all admin functions from the front end so those no admin methods will be available client side. The urls in the FipamoAdmin js file have been changed to post directly to the system and they are handled from there. To account for this change controller routes for every standard method have been created for better organization and readability. The FipamoAdmin js file will be integrated with the rest of the front end code and will not be seperate library
144 lines
3.7 KiB
PHP
144 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
use App\Services\Data\ThemeService;
|
|
use App\Services\Data\SortingService;
|
|
|
|
class DashController extends Controller
|
|
{
|
|
protected PageRepositoryInterface $pages;
|
|
protected MemberRepositoryInterface $member;
|
|
protected ThemeService $themes;
|
|
protected SortingService $sort;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
MemberRepositoryInterface $memberRepo,
|
|
ThemeService $themeService,
|
|
SortingService $sortingService
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->member = $memberRepo;
|
|
$this->themes = $themeService;
|
|
$this->sort = $sortingService;
|
|
}
|
|
|
|
//---
|
|
// GET
|
|
//---
|
|
|
|
public function init($second, $third, $fourth)
|
|
{
|
|
switch ($second) {
|
|
case 'settings':
|
|
return $this->settings();
|
|
break;
|
|
case 'navigation':
|
|
return $this->navigation();
|
|
break;
|
|
case 'pages':
|
|
($third == null) ? $third = 'all' : $third = $third;
|
|
($fourth == null) ? $fourth = 1 : $fourth = $fourth;
|
|
return $this->book($third, $fourth);
|
|
break;
|
|
case 'page':
|
|
return $this->page($third, $fourth);
|
|
break;
|
|
case 'logout':
|
|
return $this->logout();
|
|
break;
|
|
default:
|
|
return $this->start();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$result = [];
|
|
if ($this->member::status()) {
|
|
$result = $this->pages->getGroup(1, 4);
|
|
}
|
|
return view('back.start', [
|
|
"status" => $this->member::status(),
|
|
"result" => $result,
|
|
"title" => "Start"
|
|
]);
|
|
}
|
|
|
|
public function book($pageFilter = 'all', $pageNum = 1)
|
|
{
|
|
$result = [];
|
|
if ($this->member::status()) {
|
|
$result = $this->pages->getGroup($pageNum, 4, $pageFilter);
|
|
}
|
|
return view('back.book', [
|
|
"status" => $this->member::status(),
|
|
"result" => $result,
|
|
"currentPage" => $pageNum,
|
|
"title" => "Pages"
|
|
]);
|
|
}
|
|
|
|
public function page($mode, $uuid)
|
|
{
|
|
$title;
|
|
$page = [];
|
|
$views = [];
|
|
$mode == 'edit' ? $page = $this->pages->getById($uuid) : $page = [];
|
|
$mode == 'edit' ? $title = $page['title'] : $title = 'Add New';
|
|
$mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page';
|
|
|
|
return view('back.page', [
|
|
"status" => $this->member::status(),
|
|
"mode" => $mode,
|
|
"page" => $page,
|
|
"views" => $views,
|
|
"title" => $title,
|
|
]);
|
|
}
|
|
|
|
public function navigation()
|
|
{
|
|
return view('back.navigation', $this->sort->navigation());
|
|
}
|
|
|
|
public function settings()
|
|
{
|
|
return view('back.settings', $this->sort->settings());
|
|
}
|
|
|
|
//---
|
|
// POST
|
|
//---
|
|
|
|
//---
|
|
// PUT
|
|
//---
|
|
|
|
//---
|
|
// AUTH
|
|
//---
|
|
|
|
public function login()
|
|
{
|
|
if ($this->member::status()) {
|
|
return redirect('dashboard');
|
|
} else {
|
|
return view('back.login', [
|
|
"status" => $this->member::status(),
|
|
"title" => "Hi!"
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
session()->flush();
|
|
return redirect()->intended('dashboard');
|
|
}
|
|
}
|