diff --git a/.travis/deploy_script.sh b/.travis/deploy_script.sh index 1399efaf..d29f1bfb 100755 --- a/.travis/deploy_script.sh +++ b/.travis/deploy_script.sh @@ -28,6 +28,7 @@ if [ "$TRAVIS" = "true" ]; then rm -rf env.php find ./vendor -type d -name ".git" -print0 | xargs rm -rf + find . -type d -name "sass-cache" -print0 | xargs rm -rf # clear any app specific stuff that might have been loaded in find storage/app/public -mindepth 1 -not -name '.gitignore' -print0 -exec rm -rf {} + diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index e6a874dc..918709d4 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -2,19 +2,23 @@ namespace App\Http\Controllers\Admin; +use Auth; use Illuminate\Http\Request; +use App\Repositories\NewsRepository; use App\Repositories\PirepRepository; use App\Repositories\UserRepository; class DashboardController extends BaseController { - private $pirepRepo, $userRepo; + private $newsRepo, $pirepRepo, $userRepo; public function __construct( + NewsRepository $newsRepo, PirepRepository $pirepRepo, UserRepository $userRepo ) { + $this->newsRepo = $newsRepo; $this->pirepRepo = $pirepRepo; $this->userRepo = $userRepo; } @@ -24,15 +28,32 @@ class DashboardController extends BaseController */ public function index(Request $request) { - /*Feed::$cacheDir = storage_path('app'); - Feed::$cacheExpire = '5 hours'; - - $feed = Feed::loadRss(config('phpvms.news_feed_url'));*/ - $feed = []; return view('admin.dashboard.index', [ - 'feed' => $feed, + 'news' => $this->newsRepo->getLatest(), 'pending_pireps' => $this->pirepRepo->getPendingCount(), 'pending_users' => $this->userRepo->getPendingCount(), ]); } + + /** + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function news(Request $request) + { + if($request->isMethod('post')) { + $attrs = $request->post(); + $attrs['user_id'] = Auth::user()->id; + + $this->newsRepo->create($request->post()); + } elseif ($request->isMethod('delete')) { + $news_id = $request->input('news_id'); + $this->newsRepo->delete($news_id); + } + + return view('admin.dashboard.news', [ + 'news' => $this->newsRepo->getLatest(), + ]); + } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index a7fbe51c..af709e8a 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -15,7 +15,6 @@ class Kernel extends HttpKernel */ protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, - \Spatie\Pjax\Middleware\FilterIfPjax::class, ]; /** @@ -32,6 +31,7 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, #\App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, + \Spatie\Pjax\Middleware\FilterIfPjax::class, ], 'api' => [ diff --git a/app/Repositories/NewsRepository.php b/app/Repositories/NewsRepository.php new file mode 100644 index 00000000..be29579a --- /dev/null +++ b/app/Repositories/NewsRepository.php @@ -0,0 +1,29 @@ +orderBy('created_at', 'desc') + ->with(['user']) + ->paginate($count); + } +} diff --git a/app/Repositories/PirepRepository.php b/app/Repositories/PirepRepository.php index 8d745570..9c080655 100644 --- a/app/Repositories/PirepRepository.php +++ b/app/Repositories/PirepRepository.php @@ -54,7 +54,9 @@ class PirepRepository extends BaseRepository $where['user_id'] = $user->id; } - $pireps = $this->orderBy('created_at', 'desc')->findWhere($where)->count(); + $pireps = $this->orderBy('created_at', 'desc') + ->findWhere($where, ['id']) + ->count(); return $pireps; } } diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 5d6d3df4..abbd9b8f 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -32,7 +32,10 @@ class UserRepository extends BaseRepository 'state' => UserState::PENDING, ]; - $users = $this->orderBy('created_at', 'desc')->findWhere($where)->count(); + $users = $this->orderBy('created_at', 'desc') + ->findWhere($where, ['id']) + ->count(); + return $users; } diff --git a/app/Routes/admin.php b/app/Routes/admin.php index 848cbf0a..4be061e0 100644 --- a/app/Routes/admin.php +++ b/app/Routes/admin.php @@ -50,5 +50,9 @@ Route::group([ # defaults Route::get('', ['uses' => 'DashboardController@index']); Route::get('/', ['uses' => 'DashboardController@index']); - Route::get('/dashboard', ['uses' => 'DashboardController@index', 'name' => 'dashboard']); + + Route::get('dashboard', ['uses' => 'DashboardController@index', 'name' => 'dashboard']); + Route::match(['get', 'post', 'delete'], + 'dashboard/news', ['uses' => 'DashboardController@news']) + ->name('dashboard.news'); }); diff --git a/resources/views/admin/dashboard/announcements.blade.php b/resources/views/admin/dashboard/announcements.blade.php deleted file mode 100644 index a678d955..00000000 --- a/resources/views/admin/dashboard/announcements.blade.php +++ /dev/null @@ -1,9 +0,0 @@ -
just updated
-{!! $item->user->name !!} - {!! show_datetime($item->created_at) !!}
+{!! Form::label('subject', 'Subject:') !!} | +{!! Form::text('subject', '', ['class' => 'form-control']) !!} | +
{!! Form::label('body', 'Body:') !!} | +{!! Form::textarea('body', '', ['class' => 'form-control']) !!} | +