wip (notification)
This commit is contained in:
parent
af1135e52a
commit
66b58ced54
26
laravel_app/app/Imports/ExcelFileImport.php
Normal file
26
laravel_app/app/Imports/ExcelFileImport.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||||
|
|
||||||
|
class ExcelFileImport implements ToCollection
|
||||||
|
{
|
||||||
|
public $min;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->min = now();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $collection
|
||||||
|
*/
|
||||||
|
public function collection(Collection $collection)
|
||||||
|
{
|
||||||
|
return collect([1,2,3]);
|
||||||
|
foreach ($collection as $row){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
laravel_app/app/Imports/HarvestDataImport.php
Normal file
16
laravel_app/app/Imports/HarvestDataImport.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Imports;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
|
||||||
|
class HarvestDataImport implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
15
laravel_app/app/Livewire/Components/DownloadNotification.php
Normal file
15
laravel_app/app/Livewire/Components/DownloadNotification.php
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire\Components;
|
||||||
|
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class DownloadNotification extends Component
|
||||||
|
{
|
||||||
|
public $show_download_notification;
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire.components.download-notification');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,10 +5,14 @@
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\ProjectEmailRecipient;
|
use App\Models\ProjectEmailRecipient;
|
||||||
use App\Rules\HarvestFile;
|
use App\Rules\HarvestFile;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithFileUploads;
|
use Livewire\WithFileUploads;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
|
||||||
|
|
||||||
class ProjectManager extends Component
|
class ProjectManager extends Component
|
||||||
{
|
{
|
||||||
|
|
@ -249,4 +253,6 @@ public function mergeFormData(): void
|
||||||
$this->formData['harvest_file'] = $this->harvestDataFiles[0] ?? null;
|
$this->formData['harvest_file'] = $this->harvestDataFiles[0] ?? null;
|
||||||
$this->formData['download_path'] = $this->formData['download_path'] ?? $this->formData['name'];
|
$this->formData['download_path'] = $this->formData['download_path'] ?? $this->formData['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,13 @@
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Laravel\Jetstream\InteractsWithBanner;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithFileUploads;
|
use Livewire\WithFileUploads;
|
||||||
|
|
||||||
class Settings extends Component
|
class Settings extends Component
|
||||||
{
|
{
|
||||||
|
use InteractsWithBanner;
|
||||||
use WithFileUploads;
|
use WithFileUploads;
|
||||||
|
|
||||||
public $formData = [];
|
public $formData = [];
|
||||||
|
|
@ -63,6 +65,7 @@ public function saveProject()
|
||||||
//dd(route('project.show',[$this->formData['name'],$this->formData['id'],'settings']));
|
//dd(route('project.show',[$this->formData['name'],$this->formData['id'],'settings']));
|
||||||
return redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
return redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
||||||
//$this->dispatch('saved');
|
//$this->dispatch('saved');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveMailSettings()
|
public function saveMailSettings()
|
||||||
|
|
@ -82,6 +85,7 @@ public function saveSettings()
|
||||||
$this->shouldReload();
|
$this->shouldReload();
|
||||||
Project::saveWithFormData($this->formData);
|
Project::saveWithFormData($this->formData);
|
||||||
if($this->isDirty) redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
if($this->isDirty) redirect()->route('project.show',[$this->formData['name'],$this->formData['id'],'settings']);
|
||||||
|
$this->dispatch('download_notify',title:'Download',message:'hallo');
|
||||||
$this->dispatch('saved');
|
$this->dispatch('saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,6 +199,7 @@ private function validateForm()
|
||||||
}],
|
}],
|
||||||
'harvest_file' => ['sometimes', new HarvestFile],
|
'harvest_file' => ['sometimes', new HarvestFile],
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateEmailSettingsForm()
|
private function validateEmailSettingsForm()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@
|
||||||
use Illuminate\Support\Facades\Bus;
|
use Illuminate\Support\Facades\Bus;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use function Livewire\off;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
|
||||||
|
|
||||||
class Project extends Model
|
class Project extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -331,4 +332,21 @@ public function getMosaicsFor(Carbon $endDate, int $offset= 7): array
|
||||||
->filter()
|
->filter()
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function missingDownloadsInHarvestFile()
|
||||||
|
{
|
||||||
|
if(!$this->harvest_json_path){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$dates = $this->downloads->map(fn($d)=>$d->date)->sort();
|
||||||
|
}
|
||||||
|
private function getMinimumDateFromHarvestExcelFile()
|
||||||
|
{
|
||||||
|
$value = Storage::disk('local')->path($this->harvest_json_path);
|
||||||
|
$data = Excel::toCollection(new \App\Imports\ExcelFileImport(),$value);
|
||||||
|
$season_start_index = $data->first()->first()->search('season_start');
|
||||||
|
return collect($data->first()->slice(1))->reduce(function($carry,$value,$key) use ($season_start_index){
|
||||||
|
return min($carry,Carbon::instance(SharedDate::excelToDateTimeObject($value[$season_start_index])));
|
||||||
|
},now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use App\Events\ProjectDownloadStatus;
|
use App\Events\ProjectDownloadStatus;
|
||||||
use App\Traits\HasStatus;
|
use App\Traits\HasStatus;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
|
@ -24,6 +25,11 @@ public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
return $this->belongsTo(Project::class);
|
return $this->belongsTo(Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDateAttribute():Carbon
|
||||||
|
{
|
||||||
|
return Carbon::parse(explode('.',$this->name)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
protected static function booted(): void
|
protected static function booted(): void
|
||||||
{
|
{
|
||||||
parent::booted();
|
parent::booted();
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||||
if(!in_array($value['extension'], ['xlsx', 'xls', 'csv', 'ods'])) {
|
if(!in_array($value['extension'], ['xlsx', 'xls', 'csv', 'ods'])) {
|
||||||
$fail($value['extension'].' is not a valid file (.xlsx, .xls, .csv, .ods).');
|
$fail($value['extension'].' is not a valid file (.xlsx, .xls, .csv, .ods).');
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$excelHeaderArray = (new HeadingRowImport)->toArray($value['path']);
|
$excelHeaderArray = (new HeadingRowImport)->toArray($value['path']);
|
||||||
$header = $excelHeaderArray[0][0];
|
$header = $excelHeaderArray[0][0];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('projects', function (Blueprint $table) {
|
||||||
|
$table->date('min_harvest_date')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('projects', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('min_harvest_date');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
<x-notification />
|
<x-notification />
|
||||||
|
<livewire:components.download-notification></livewire:components.download-notification>
|
||||||
|
|
||||||
@stack('modals')
|
@stack('modals')
|
||||||
@stack('map')
|
@stack('map')
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<!-- Global notification live region, render this permanently at the end of the document -->
|
||||||
|
<div aria-live="assertive" class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6"
|
||||||
|
x-data="{
|
||||||
|
open: $wire.entangle('show_download_notification').live,
|
||||||
|
message: 'If you see this, a notification has been triggered.',
|
||||||
|
title: 'Download Notification'
|
||||||
|
|
||||||
|
}"
|
||||||
|
x-show="open"
|
||||||
|
x-cloak
|
||||||
|
@download_notify.window="message = event.detail.message; title = event.detail.title;open = true;"
|
||||||
|
>
|
||||||
|
|
||||||
|
<div class="flex w-full flex-col items-center space-y-4 sm:items-end"
|
||||||
|
x-transition:enter="transform ease-out duration-300 transition"
|
||||||
|
x-transition:enter-start="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
|
||||||
|
x-transition:enter-end="translate-y-0 opacity-100 sm:translate-x-0"
|
||||||
|
x-transition:leave="transition ease-in duration-100"
|
||||||
|
x-transition:leave-start="opacity-100"
|
||||||
|
x-transition:leave-end="opacity-0">
|
||||||
|
|
||||||
|
<div class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5">
|
||||||
|
<div class="p-4">
|
||||||
|
<div class="flex items-start">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<svg class="h-6 w-6 text-gray-400" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 13.5h3.86a2.25 2.25 0 012.012 1.244l.256.512a2.25 2.25 0 002.013 1.244h3.218a2.25 2.25 0 002.013-1.244l.256-.512a2.25 2.25 0 012.013-1.244h3.859m-19.5.338V18a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18v-4.162c0-.224-.034-.447-.1-.661L19.24 5.338a2.25 2.25 0 00-2.15-1.588H6.911a2.25 2.25 0 00-2.15 1.588L2.35 13.177a2.25 2.25 0 00-.1.661z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-3 w-0 flex-1 pt-0.5">
|
||||||
|
<p class="text-sm font-medium text-gray-900" x-cloak x-text="title"></p>
|
||||||
|
<p class="mt-1 text-sm text-gray-500" x-cloak x-text="message"></p>
|
||||||
|
<div class="mt-4 flex">
|
||||||
|
<button type="button" class="inline-flex items-center rounded-md bg-indigo-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Accept</button>
|
||||||
|
<button type="button" class="ml-3 inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
|
||||||
|
@click="open=false"
|
||||||
|
>Decline</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
51
laravel_app/tests/Unit/Imports/HarvestDataImportTest.php
Normal file
51
laravel_app/tests/Unit/Imports/HarvestDataImportTest.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Imports;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use function PHPUnit\Framework\assertEquals;
|
||||||
|
|
||||||
|
class HarvestDataImportTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function test_it_gets_data_from_excel_file()
|
||||||
|
{
|
||||||
|
$value = Storage::disk('local')->path('Chemba/Data/harvest.xlsx');
|
||||||
|
$data = Excel::toCollection(new \App\Imports\ExcelFileImport(),$value);
|
||||||
|
$season_start_index = $data->first()->first()->search('season_start');
|
||||||
|
$min = now();
|
||||||
|
collect($data->first()->slice(1))->each(function($value) use (&$min,$season_start_index){
|
||||||
|
$min = min($min,Carbon::instance(SharedDate::excelToDateTimeObject($value[$season_start_index])));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_gets_the_min_value()
|
||||||
|
{
|
||||||
|
$value = Storage::disk('local')->path('Chemba/Data/harvest.xlsx');
|
||||||
|
$data = Excel::toCollection(new \App\Imports\ExcelFileImport(),$value);
|
||||||
|
$season_start_index = $data->first()->first()->search('season_start');
|
||||||
|
$min = now();
|
||||||
|
collect($data->first()->slice(1))->each(function($value) use (&$min,$season_start_index){
|
||||||
|
$min = min($min,Carbon::instance(SharedDate::excelToDateTimeObject($value[$season_start_index])));
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals(Carbon::parse('2023-01-12'),$min);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_gets_the_min_value_using_reduce()
|
||||||
|
{
|
||||||
|
$value = Storage::disk('local')->path('chemba/Data/harvest.xlsx');
|
||||||
|
$data = Excel::toCollection(new \App\Imports\ExcelFileImport(),$value);
|
||||||
|
$season_start_index = $data->first()->first()->search('season_start');
|
||||||
|
$min = collect($data->first()->slice(1))->reduce(function($carry,$value,$key) use ($season_start_index){
|
||||||
|
return min($carry,Carbon::instance(SharedDate::excelToDateTimeObject($value[$season_start_index])));
|
||||||
|
},now());
|
||||||
|
assertEquals(Carbon::parse('2023-01-12'),$min);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue