64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Hive\Services\UserService;
|
|
use Illuminate\Support\Facades\App;
|
|
use Livewire\Component;
|
|
|
|
class AssignTo extends Component
|
|
{
|
|
private $queryResults = [];
|
|
|
|
public $query = "";
|
|
|
|
public $value = "";
|
|
|
|
private $selection = [];
|
|
|
|
public $display = "none";
|
|
|
|
public $simpleResult = "";
|
|
|
|
private $service;
|
|
|
|
function boot() {
|
|
$this->service = App::make(UserService::class);
|
|
}
|
|
|
|
function updated()
|
|
{
|
|
if (strlen($this->query) > 2) {
|
|
$this->display = "";
|
|
$this->queryResults = $this->service->search($this->query);
|
|
}
|
|
}
|
|
|
|
public function add($id)
|
|
{
|
|
if (!str_contains($this->value, $id)) {
|
|
$this->value .= $id . "|";
|
|
$this->selection[] = $this->service->getById($id);
|
|
}
|
|
}
|
|
|
|
public function remove($id)
|
|
{
|
|
if (str_contains($this->value, $id)) {
|
|
$this->value = str_replace($id . "|", "", $this->value);
|
|
$this->selection = collect($this->selection)->reject(function ($item) use ($id) {
|
|
return $item->id == $id;
|
|
});
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.assign-to', [
|
|
"queryResults" => $this->queryResults,
|
|
"simpleResult" => $this->simpleResult,
|
|
"selection" => $this->selection
|
|
]);
|
|
}
|
|
}
|