Procházet zdrojové kódy

Add event log page

staging
rodič
revize
dc8b93a0af
8 změnil soubory, kde provedl 147 přidání a 9 odebrání
  1. +24
    -0
      app/Console/Commands/Events.php
  2. +3
    -1
      app/Console/Kernel.php
  3. +19
    -0
      app/Http/Controllers/EventController.php
  4. +63
    -0
      app/Knockout/Event.php
  5. +7
    -6
      composer.json
  6. +2
    -2
      composer.lock
  7. +19
    -0
      resources/views/page/events.blade.php
  8. +10
    -0
      resources/views/partial/event.blade.php

+ 24
- 0
app/Console/Commands/Events.php Zobrazit soubor

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

namespace App\Console\Commands;

use Exception;
use Illuminate\Console\Command;
use App\Knockout\Event;

class Events extends Command {

protected $name = 'knockout:events';
protected $description = 'Fetch event list';

public function handle()
{
try {
Event::updateAll();
echo '[ OK ] Events cached' . PHP_EOL;
} catch (Exception $e) {
echo '[FAIL] Events cached' . PHP_EOL;
}
}

}

+ 3
- 1
app/Console/Kernel.php Zobrazit soubor

@@ -16,7 +16,8 @@ class Kernel extends ConsoleKernel
\App\Console\Commands\Subforums::class,
\App\Console\Commands\Stats::class,
\App\Console\Commands\Popular::class,
\App\Console\Commands\Latest::class
\App\Console\Commands\Latest::class,
\App\Console\Commands\Events::class
];

/**
@@ -30,6 +31,7 @@ class Kernel extends ConsoleKernel
$schedule->command('knockout:subforums')->everyMinute();
$schedule->command('knockout:latest')->everyFiveMinutes();
$schedule->command('knockout:popular')->everyFiveMinutes();
$schedule->command('knockout:events')->everyFiveMinutes();
$schedule->command('knockout:stats')->hourly();
}
}

+ 19
- 0
app/Http/Controllers/EventController.php Zobrazit soubor

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

namespace App\Http\Controllers;

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

class EventController extends Controller {

public function get(Request $request)
{
$events = Event::all();

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

}

+ 63
- 0
app/Knockout/Event.php Zobrazit soubor

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

namespace App\Knockout;

use Illuminate\Support\Facades\Cache;
use Carbon\Carbon;

class Event {

public $id;
public $executedBy;
public $content;
public $date;

private static function unwrapContent($content)
{
return [];
}

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

$payload = json_decode($event->content);

$s->id = $event->id;
$s->executedBy = $event->executed_by;
$s->date = Carbon::parse($event->created_at)->format('d/m/Y H:i');

$s->content = array_map(function($item) {
return (object) [
'text' => stripslashes($item->text ?? $item),
'link' => stripcslashes($item->link ?? null)
];
}, $payload->content ?? []);

return $s;
}

private static function requestAll()
{
$data = (new AbstractData)->httpGet('/events');
$json = json_decode($data);
return array_map(function($event) {
return self::unwrap($event);
}, $json);
}

public static function updateAll()
{
$data = self::requestAll();
Cache::put('events', $data, 3600);
return $data;
}

public static function all()
{
return Cache::get('events', function() {
return self::requestAll();
});
}

}

+ 7
- 6
composer.json Zobrazit soubor

@@ -1,13 +1,14 @@
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"name": "mos6581/knockout-lite",
"description": "A lightweight client for knockout",
"keywords": ["forum", "web1.0", "client"],
"license": "AGPL3",
"type": "project",
"require": {
"php": "7.4",
"php": "^7.4",
"chriskonnertz/bbcode": "^1.1",
"laravel/lumen-framework": "^8.0"
"laravel/lumen-framework": "^8.0",
"nesbot/carbon": "^2.43"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",


+ 2
- 2
composer.lock Zobrazit soubor

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "72fb89de6eafd0b6af24e81bf00fddca",
"content-hash": "caf91257a77d672a001170237e64fe29",
"packages": [
{
"name": "brick/math",
@@ -7395,7 +7395,7 @@
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.3|^8.0"
"php": "^7.4"
},
"platform-dev": [],
"plugin-api-version": "2.0.0"


+ 19
- 0
resources/views/page/events.blade.php Zobrazit soubor

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

@section('title', 'Event Log')

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

@section('content')
@foreach($events as $key => $event)
@include('partial/event')
@endforeach
@endsection

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

+ 10
- 0
resources/views/partial/event.blade.php Zobrazit soubor

@@ -0,0 +1,10 @@
<div class="row event {{ ($key % 2) ? 'even' : 'odd' }}">
@foreach($event->content as $item)
@if($item->link == null)
<p>{{ $item->text }}</p>
@else
<a href="{{ $item->link }}">{{ $item->text }}</a>
@endif
@endforeach
<span>{{ $event->date }}</span>
</div>

Načítá se…
Zrušit
Uložit