EVIDENCESView.php
1 <?php 2 3 namespace App\Http\Livewire\Jsons; 4 5 use App\Models\JsonDraft; 6 use Illuminate\Support\Collection; 7 use Livewire\Component; 8 use Livewire\WithPagination; 9 10 class EVIDENCESView extends BaseJsonView 11 { 12 public function getEvidencesProperty() 13 { 14 $evidences = collect($this->json->json['evidences']); 15 return $this->getPaginate($evidences, 'evidences'); 16 } 17 18 public function diffedEvidencesList() 19 { 20 $olds = collect($this->oldJson->json['evidences']); 21 $news = collect($this->json->json['evidences']); 22 $result = []; 23 $used = []; 24 25 foreach ($news as $new) { 26 $used[] = $new['code']; 27 $aux = $olds->where('code', $new['code'])->first(); 28 29 $result[] = [ 30 "type"=> $this->applyDiff($new['type'] ?? '', $aux['type'] ?? ''), 31 "code"=> $this->applyDiff($new['code'] ?? '', $aux['code'] ?? ''), 32 "name"=> $this->applyDiff($new['name'] ?? '', $aux['name'] ?? ''), 33 'version' => $this->applyDiff($new['version'] ?? '', $aux['version'] ?? ''), 34 "path"=> $this->applyDiff($new['path'] ?? '', $aux['path'] ?? ''), 35 "sha256Checksum"=> $this->applyDiff($new['sha256Checksum'] ?? '', $aux['sha256Checksum'] ?? ''), 36 ]; 37 } 38 39 foreach ($olds->whereNotIn('code', $used) as $old) { 40 $result[] = [ 41 "type"=> $this->applyDiff('', $old['type'] ?? ''), 42 "code"=> $this->applyDiff('', $old['code'] ?? ''), 43 "name"=> $this->applyDiff('', $old['name'] ?? ''), 44 'version' => $this->applyDiff('', $old['version'] ?? ''), 45 "path"=> $this->applyDiff('', $old['path'] ?? ''), 46 "sha256Checksum"=> $this->applyDiff('', $old['sha256Checksum'] ?? ''), 47 ]; 48 } 49 50 return $this->getPaginate(collect($result), 'evidences'); 51 } 52 53 54 public function render() 55 { 56 return view('livewire.jsons.evidences-view') 57 ->layoutData([ 58 'title' => $this->json->schema_name, 59 'entity' => $this->json, 60 'breadcrumb' => 'jsons.view', 61 ]); 62 } 63 }