Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythos committed Jan 28, 2022
2 parents 390a5ea + 9a837fd commit 58a4ba7
Show file tree
Hide file tree
Showing 45 changed files with 1,211 additions and 585 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 1.3.0 (2022-01-28)

- Added publishers in the Administration menu
- Added publishers to series
- Added series/articles count next to category name
- Added a pie chart for volume statistics in series
- Filtering also applies to statistics now
- Fixed filter being lost when updating an upcoming release
- Renamed global statistics to overview

## 1.2.5 (2022-01-25)

- Made table header for upcoming releases sticky
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Articles/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Gallery extends Component
{
public $articles = [];

private string $search = '';
public string $search = '';

public Category $category;

Expand Down
43 changes: 0 additions & 43 deletions app/Http/Livewire/GlobalStatistics.php

This file was deleted.

77 changes: 77 additions & 0 deletions app/Http/Livewire/Overview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Http\Livewire;

use App\Models\Volume;
use Exception;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Overview extends Component
{
public $volumeStatistics = [];

public $articleStatistics = [];

public string $search;

protected $listeners = [
'$refresh',
'search' => 'filter',
];

public function render()
{
$this->volumeStatistics = $this->getVolumeStatistics();
$this->articleStatistics = $this->getArticleStatistics();

return view('livewire.overview');
}

public function filter($filter): void
{
$this->search = $filter;
}

private function getVolumeStatistics()
{
$volumes = DB::table('volumes')
->join('series', 'volumes.series_id', '=', 'series.id')
->leftJoin('publishers', 'series.publisher_id', '=', 'publishers.id');
if (!empty($this->search)) {
$volumes->where('isbn', 'like', '%' . $this->search . '%')
->orWhere('series.name', 'like', '%' . $this->search . '%')
->orWhere('publishers.name', 'like', '%' . $this->search . '%');
}
$volumeStatistics = $volumes->select([
DB::raw('COALESCE(sum(case when volumes.status = 0 then 1 else 0 end), 0) as new'),
DB::raw('COALESCE(sum(case when volumes.status = 1 then 1 else 0 end), 0) as ordered'),
DB::raw('COALESCE(sum(case when volumes.status = 2 then 1 else 0 end), 0) as shipped'),
DB::raw('COALESCE(sum(case when volumes.status = 3 then 1 else 0 end), 0) as delivered'),
DB::raw('COALESCE(sum(case when volumes.status = 4 then 1 else 0 end), 0) as `read`'),
DB::raw('COALESCE(sum(case when volumes.status = 3 OR volumes.status = 4 then price else 0 end), 0) as price'),
DB::raw('count(*) as total'),
])->first();

return json_decode(json_encode($volumeStatistics), true);
}

private function getArticleStatistics()
{
$articles = DB::table('articles');
if (!empty($this->search)) {
$articles->where('name', 'like', '%' . $this->search . '%');
}
$articleStatistics = $articles->select([
DB::raw('COALESCE(sum(case when status = 0 then 1 else 0 end), 0) as new'),
DB::raw('COALESCE(sum(case when status = 1 then 1 else 0 end), 0) as ordered'),
DB::raw('COALESCE(sum(case when status = 2 then 1 else 0 end), 0) as shipped'),
DB::raw('COALESCE(sum(case when status = 3 then 1 else 0 end), 0) as delivered'),
DB::raw('0 as `read`'),
DB::raw('COALESCE(sum(case when status = 3 then price else 0 end), 0) as price'),
DB::raw('count(*) as total'),
])->first();

return json_decode(json_encode($articleStatistics), true);
}
}
40 changes: 40 additions & 0 deletions app/Http/Livewire/Publishers/CreatePublisher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Livewire\Publishers;

use App\Models\Publisher;
use Livewire\Component;

class CreatePublisher extends Component
{
public Publisher $publisher;

protected $rules = [
'publisher.name' => 'required',
];

public function updated($property, $value): void
{
$this->validateOnly($property);
}

public function mount(): void
{
$this->publisher = new Publisher();
}

public function render()
{
return view('livewire.publishers.create-publisher')->extends('layouts.app')->section('content');
}

public function save()
{
$this->validate();

$this->publisher->save();
toastr()->addSuccess(__(':name has been created', ['name' => $this->publisher->name]));

return redirect()->route('publishers.index');
}
}
63 changes: 63 additions & 0 deletions app/Http/Livewire/Publishers/EditPublisher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Http\Livewire\Publishers;

use App\Models\Publisher;
use App\Models\Series;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;

class EditPublisher extends Component
{
use LivewireAlert;

public Publisher $publisher;

protected $rules = [
'publisher.name' => 'required',
];

protected $listeners = [
'confirmedDelete',
];

public function updated($property, $value): void
{
$this->validateOnly($property);
}

public function mount(Publisher $publisher): void
{
$this->publisher = $publisher;
}

public function render()
{
return view('livewire.publishers.edit-publisher')->extends('layouts.app')->section('content');
}

public function save(): void
{
$this->validate();

$this->publisher->save();
toastr()->livewire()->addSuccess(__(':name has been updated', ['name' => $this->publisher->name]));
}

public function delete(): void
{
$this->confirm(__('Are you sure you want to delete :name?', ['name' => $this->publisher->name]), [
'confirmButtonText' => __('Delete'),
'cancelButtonText' => __('Cancel'),
'onConfirmed' => 'confirmedDelete',
]);
}

public function confirmedDelete(): void
{
Series::wherePublisherId($this->publisher->id)->update(['publisher_id' => null]);
$this->publisher->delete();
toastr()->addSuccess(__(':name has been deleted', ['name' => $this->publisher->name]));
redirect()->route('publishers.index');
}
}
18 changes: 18 additions & 0 deletions app/Http/Livewire/Publishers/PublisherTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Livewire\Publishers;

use App\Models\Publisher;
use Livewire\Component;

class PublisherTable extends Component
{
public $publishers;

public function render()
{
$this->publishers = Publisher::orderBy('name')->get();

return view('livewire.publishers.publisher-table')->extends('layouts.app')->section('content');
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function render()

public function updated(): void
{
$this->emit('search', $this->search);
$this->emit('search', trim($this->search));
}
}
8 changes: 8 additions & 0 deletions app/Http/Livewire/Series/CreateSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire\Series;

use App\Models\Category;
use App\Models\Publisher;
use App\Models\Series;
use Exception;
use Illuminate\Support\Facades\Log;
Expand All @@ -14,6 +15,8 @@

class CreateSeries extends Component
{
public $publishers;

public Category $category;

public Series $series;
Expand All @@ -27,6 +30,7 @@ class CreateSeries extends Component
'series.category_id' => 'required|exists:categories,id',
'series.is_nsfw' => 'boolean',
'series.default_price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'series.publisher_id' => 'nullable|exists:publishers,id',
'image_url' => 'required|url',
];

Expand All @@ -35,11 +39,15 @@ public function updated($property, $value): void
if ($property == 'series.total' && empty($value)) {
$this->series->total = null;
}
if ($property == 'series.publisher_id' && empty($value)) {
$this->series->publisher_id = null;
}
$this->validateOnly($property);
}

public function mount(Category $category): void
{
$this->publishers = Publisher::orderBy('name')->get();
$this->category = $category;
$this->series = new Series([
'status' => 0,
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Livewire/Series/EditSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Traits\LivewireDelete;
use App\Models\Category;
use App\Models\Publisher;
use App\Models\Series;
use App\Models\Volume;
use Exception;
Expand All @@ -19,6 +20,8 @@ class EditSeries extends Component
{
use LivewireAlert;

public $publishers;

public Category $category;

public Series $series;
Expand All @@ -32,6 +35,7 @@ class EditSeries extends Component
'series.category_id' => 'required|exists:categories,id',
'series.is_nsfw' => 'boolean',
'series.default_price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'series.publisher_id' => 'nullable|exists:publishers,id',
'image_url' => 'url',
];

Expand All @@ -44,11 +48,15 @@ public function updated($property, $value): void
if ($property == 'series.total' && empty($value)) {
$this->series->total = null;
}
if ($property == 'series.publisher_id' && empty($value)) {
$this->series->publisher_id = null;
}
$this->validateOnly($property);
}

public function mount(Category $category, Series $series): void
{
$this->publishers = Publisher::orderBy('name')->get();
$this->series = $series;
}

Expand Down
7 changes: 5 additions & 2 deletions app/Http/Livewire/Series/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Gallery extends Component
{
public $series = [];

private string $search = '';
public string $search = '';

public Category $category;

Expand All @@ -23,11 +23,14 @@ public function mount(Category $category): void

public function render()
{
$series = Series::whereCategoryId($this->category->id)->with('volumes');
$series = Series::whereCategoryId($this->category->id)->with(['volumes', 'publisher']);
if (!empty($this->search)) {
$series->where('name', 'like', '%' . $this->search . '%')
->orWhereHas('volumes', function ($query): void {
$query->where('isbn', 'like', '%' . $this->search . '%');
})
->orWhereHas('publisher', function ($query): void {
$query->where('name', 'like', '%' . $this->search . '%');
});
}
$this->series = $series->orderBy('status')->orderBy('name')->get();
Expand Down
Loading

0 comments on commit 58a4ba7

Please sign in to comment.