Browse Source

Stub thread listing

staging
parent
commit
9363e2f9e4
8 changed files with 144 additions and 5 deletions
  1. +15
    -0
      app/Http/Controllers/ThreadController.php
  2. +32
    -0
      app/Http/Controllers/ThreadListController.php
  3. +20
    -3
      app/Knockout/Subforum.php
  4. +39
    -0
      app/Knockout/Thread.php
  5. +4
    -0
      resources/views/page/index.blade.php
  6. +28
    -0
      resources/views/page/subforum.blade.php
  7. +1
    -1
      resources/views/partial/header.blade.php
  8. +5
    -1
      routes/web.php

+ 15
- 0
app/Http/Controllers/ThreadController.php View File

@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Knockout\Subforum;

class ThreadController extends Controller {

public function get(Request $request)
{
return 'thread';
}

}

+ 32
- 0
app/Http/Controllers/ThreadListController.php View File

@@ -0,0 +1,32 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Knockout\Subforum;

class ThreadListController extends Controller {

public function subforum(Request $request)
{
$subforumId = $request->route('subforum', null);
$page = $request->route('page', 1);

$subforum = Subforum::get($subforumId, $page);

return view('page/subforum', [
'subforum' => $subforum
]);
}

public function popular(Request $request)
{
return 'popular';
}

public function latest(Request $request)
{
return 'latest';
}

}

+ 20
- 3
app/Knockout/Subforum.php View File

@@ -6,13 +6,23 @@ use Illuminate\Support\Facades\Cache;

class Subforum {

private static function unwrap($subforum)
public $id;
public $name;
public $description;

public $threads;

public static function unwrap($subforum)
{
$s = new self();

$s->id = $subforum->id;
$s->name = $subforum->name;
$s->description = $subforum->description;
$s->description = $subforum->description ?? null;

$s->threads = array_map(function($thread) {
return Thread::unwrap($thread);
}, $subforum->threads ?? []);

return $s;
}
@@ -26,6 +36,13 @@ class Subforum {
}, $json->list);
}

public static function get(int $subforumId, int $page = 1)
{
$data = (new AbstractData)->httpGet(sprintf('/subforum/%s/%s', $subforumId, $page));
$json = json_decode($data);
return self::unwrap($json);
}

public static function updateCache()
{
Cache::forever('subforums', self::getAll());
@@ -33,7 +50,7 @@ class Subforum {

public static function getCache()
{
return Cache::get('subforums', []);
return Cache::get('subforums', self::getAll());
}

}

+ 39
- 0
app/Knockout/Thread.php View File

@@ -0,0 +1,39 @@
<?php

namespace App\Knockout;

use Illuminate\Support\Facades\Cache;

class Thread {

public $id;
public $title;

public static function unwrap($thread)
{
$s = new self();

$s->id = $thread->id;
$s->title = $thread->title;

return $s;
}

public static function get(int $threadId, int $page = 1)
{
$data = (new AbstractData)->httpGet(sprintf('/thread/%s/%s', $threadId, $page));
$json = json_decode($data);
return self::unwrap($thread);
}

public static function updateCache(int $subforumId, int $page = 0)
{
Cache::forever('threads-' . $subforumId, self::getAll());
}

public static function getCache(int $subforumId, int $page = 0)
{
return Cache::get('threads-' . $subforumId, self::getAll());
}

}

+ 4
- 0
resources/views/page/index.blade.php View File

@@ -1,5 +1,9 @@
@extends('default')

@section('breadcrumb')
<a href="{{ route('index') }}">Home</a>
@endsection

@section('content')
<div class="row subforums">
<div class="cell left">


+ 28
- 0
resources/views/page/subforum.blade.php View File

@@ -0,0 +1,28 @@
@extends('default')

@section('breadcrumb')
<a href="{{ route('index') }}">Home</a>
<a>></a>
<a href="{{ route('subforum', ['subforum' => $subforum->id]) }}">{{ $subforum->name }}</a>
@endsection

@section('content')
<div class="row threads">
@foreach($subforum->threads as $key => $thread)
<div class="row thread {{ ($key % 2) ? 'even' : 'odd' }}">
<img class="icon" src="/img/thread-icons/tv-show.gif" alt="tv-show" />
<a class="main" href="{{ route('thread', ['thread' => $thread->id]) }}">{{ $thread->title }}</a>
<div class="meta">
<a class="left">by User, X replies</a>
<a class="right">last reply by User, X ago</a>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
@endforeach
</div>
@endsection

@section('scripts')
<link rel='stylesheet' type='text/css' href='/css/page/subforum.css'/>
@endsection

+ 1
- 1
resources/views/partial/header.blade.php View File

@@ -16,7 +16,7 @@
</div>
</div>
<div class="row breadcrumb">
<a href="/">Home</a>
@yield('breadcrumb')
</div>
<div class="row spacer">
<hr class="textonly"/>


+ 5
- 1
routes/web.php View File

@@ -1,6 +1,10 @@
<?php

use App\Http\Controllers\IndexController;
use App\Http\Controllers\ThreadListController;
use App\Http\Controllers\ThreadController;
use App\Http\Controllers\EventController;
use App\Http\Controllers\PreferenceController;

/** @var \Laravel\Lumen\Routing\Router $router */

@@ -23,7 +27,7 @@ $router->get('/', [

$router->get('/subforum/{subforum}[/{page}]', [
'as' => 'subforum',
'uses' => 'SubforumController@get'
'uses' => 'ThreadListController@subforum'
]);

$router->get('/thread/{thread}[/{page}]', [


Loading…
Cancel
Save