Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythos committed Feb 2, 2022
2 parents 6fc6f46 + a32a1c2 commit 8369c6b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 86 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.5.1 (2022-02-02)

- Improved ISBN validation
- Fixed possible errors when publish date is being empty

## 1.5.0 (2022-02-01)

- Added experimental barcode scanner when creating volumes
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Livewire/Volumes/CreateVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use App\Helpers\IsbnHelpers;
use App\Models\Series;
use App\Models\Volume;
use App\Rules\Isbn;
use Illuminate\Support\Str;
use Intervention\Validation\Rules\Isbn;
use Livewire\Component;

class CreateVolume extends Component
{
public string $publish_date = '';
public ?string $publish_date = '';

public string $isbn = '';

Expand All @@ -37,7 +37,7 @@ public function render()
protected function rules()
{
return [
'publish_date' => 'date',
'publish_date' => 'nullable|date',
'status' => 'required|integer|min:0',
'price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'isbn' => ['required', 'unique:volumes,isbn,NULL,id,series_id,' . $this->series->id, new Isbn()],
Expand Down Expand Up @@ -71,6 +71,9 @@ public function save(): void
} else {
$this->price = 0;
}
if (empty($this->publish_date)) {
$this->publish_date = null;
}
$volume = new Volume([
'series_id' => $this->series->id,
'number' => ++$number,
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Livewire/Volumes/EditVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use App\Models\Category;
use App\Models\Series;
use App\Models\Volume;
use App\Rules\Isbn;
use Illuminate\Support\Str;
use Intervention\Validation\Rules\Isbn;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;

Expand All @@ -31,7 +31,7 @@ public function mount(Category $category, Series $series, int $number): void
protected function rules()
{
return [
'volume.publish_date' => 'date',
'volume.publish_date' => 'nullable|date',
'volume.status' => 'required|integer|min:0',
'volume.price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'volume.isbn' => ['required', 'unique:volumes,isbn,' . $this->volume->id . ',id,series_id,' . $this->series->id, new Isbn()],
Expand All @@ -49,7 +49,7 @@ public function updated($property, $value): void
$this->validateOnly($property);
$isbn = IsbnHelpers::convertTo13($value);
if (!empty($isbn)) {
$this->volume->publish_date = IsbnHelpers::getPublishDateByIsbn($isbn) ?? '';
$this->volume->publish_date = IsbnHelpers::getPublishDateByIsbn($isbn) ?? null;
}
} else {
$this->validateOnly($property);
Expand All @@ -72,6 +72,9 @@ public function save()
} else {
$this->volume->price = 0;
}
if (empty($this->volume->publish_date)) {
$this->volume->publish_date = null;
}
$this->validate();
$this->volume->save();
toastr()->addSuccess(__('Volumme :number has been updated', ['number' => $this->volume->number]));
Expand Down
43 changes: 43 additions & 0 deletions app/Rules/Isbn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use Nicebooks\Isbn\IsbnTools;

class Isbn implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$tools = new IsbnTools();

return $tools->isValidIsbn($value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('The provided ISBN is invalid');
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.7",
"intervention/validation": "^3.0",
"jantinnerezo/livewire-alert": "^2.2",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
Expand Down
71 changes: 1 addition & 70 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| Current application version.
|
*/
'version' => env('APP_VERSION', '1.5.0'),
'version' => env('APP_VERSION', '1.5.1'),

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Finished": "Abgeschlossen",
"Forgot Your Password?": "Passwort vergessen?",
"Format ISBNs": "Formatiere ISBNs",
"The provided ISBN is invalid": "Die angegebene ISBN ist ungültig",
"Hide in upcoming releases": "In Anstehende Veröffentlichungen ausblenden",
"Hide NSFW": "NSFW ausblenden",
"Home": "Startseite",
Expand Down
15 changes: 7 additions & 8 deletions resources/views/livewire/volumes/create-volume.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@

<script type="text/javascript">
document.addEventListener('livewire:load', function() {
debugger;
// Create the QuaggaJS config object for the live stream
var liveStreamConfig = {
frequency: 10,
inputStream: {
type: "LiveStream",
constraints: {
Expand All @@ -153,19 +153,18 @@
min: 1,
max: 100
},
facingMode: "environment" // or "user" for the front camera
}
facingMode: "environment"
},
},
locator: {
patchSize: "medium",
halfSample: true
halfSample: true,
},
numOfWorkers: (navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4),
decoder: {
"readers": [{
"format": "ean_reader",
"config": {}
}]
readers: [
"ean_reader"
],
},
locate: true
};
Expand Down

0 comments on commit 8369c6b

Please sign in to comment.