tag add more customized options + NexusDB::rememter()

This commit is contained in:
xiaomlove
2022-03-28 15:58:12 +08:00
parent d15a837188
commit b613a46b8d
13 changed files with 164 additions and 33 deletions

View File

@@ -46,10 +46,7 @@ class TagController extends Controller
public function store(Request $request)
{
$request->validate($this->getRules());
$data = $request->all();
if (isset($data['priority'])) {
$data['priority'] = intval($data['priority']);
}
$data = array_filter($request->all());
$result = $this->repository->store($data);
$resource = new TagResource($result);
return $this->success($resource);

View File

@@ -18,6 +18,11 @@ class TagResource extends JsonResource
'id' => $this->id,
'name' => $this->name,
'color' => $this->color,
'font_color' => $this->font_color,
'font_size' => $this->font_size,
'padding' => $this->padding,
'margin' => $this->margin,
'border_radius' => $this->border_radius,
'priority' => $this->priority,
'created_at' => format_datetime($this->created_at),
'updated_at' => format_datetime($this->updated_at),

View File

@@ -3,6 +3,8 @@
namespace App\Models;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Nexus\Database\NexusDB;
class Setting extends NexusModel
{
@@ -10,9 +12,9 @@ class Setting extends NexusModel
public static function get($name = null)
{
static $settings;
if (is_null($settings)) {
$settings = NexusDB::remember("nexus_settings_in_laravel", 10, function () {
$rows = self::query()->get(['name', 'value']);
$result = [];
foreach ($rows as $row) {
$value = $row->value;
if (!is_null($value)) {
@@ -21,9 +23,10 @@ class Setting extends NexusModel
$value = $arr;
}
}
Arr::set($settings, $row->name, $value);
Arr::set($result, $row->name, $value);
}
}
return $result;
});
if (is_null($name)) {
return $settings;
}

View File

@@ -7,7 +7,7 @@ class Tag extends NexusModel
public $timestamps = true;
protected $fillable = [
'id', 'name', 'color', 'priority', 'created_at', 'updated_at'
'id', 'name', 'color', 'priority', 'created_at', 'updated_at', 'font_size', 'font_color', 'padding', 'margin', 'border_radius'
];
const DEFAULTS = [

View File

@@ -67,7 +67,10 @@ class TagRepository extends BaseRepository
foreach ($renderIdArr as $tagId) {
$value = $tagKeyById->get($tagId);
if ($value) {
$item = "<span style=\"background-color:{$value->color};color:white;border-radius:15%\">{$value->name}</span> ";
$item = sprintf(
"<span style=\"background-color:%s;color:%s;border-radius:%s;font-size:%s;margin:%s;padding:%s\">%s</span>",
$value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name
);
if ($withFilterLink) {
$html .= sprintf('<a href="torrents.php?tag_id=%s">%s</a>', $tagId, $item);
} else {

View File

@@ -661,8 +661,17 @@ class TrackerRepository extends BaseRepository
}
/**
*
* @param Torrent $torrent
* @param $queries
*/
private function updateTorrent(Torrent $torrent, $queries)
{
if (empty($queries['event'])) {
do_log("no event, return", 'debug');
return;
}
$torrent->seeders = Peer::query()
->where('torrent', $torrent->id)
->where('to_go', '=',0)