-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPublishProgrammeButton.php
86 lines (73 loc) · 2.67 KB
/
PublishProgrammeButton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace App\Livewire\Schedule;
use App\Models\Presentation;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
use Masmerise\Toaster\Toaster;
class PublishProgrammeButton extends Component
{
public $isReadyToBePublished;
public $allPresentationsAreApproved;
public $allPresentationsAreScheduled;
public $oldValue;
public $buttonClasses = "flex items-center justify-center p-3 text-sm font-semibold rounded-md focus:outline-none
focus:ring-2 focus:ring-offset-2 focus:ring-crew-400";
public $enabledClasses = "text-white bg-apricot-peach-500 hover:bg-apricot-peach-500";
public $disabledClasses = "text-gray-100 bg-gray-600";
public $iconClasses = "w-5 h-5 mr-2";
/**
* Initializes the component
*
* @return void
*/
public function mount()
{
$this->allPresentationsAreApproved = Presentation::all()->every(function ($presentation) {
return $presentation->is_approved;
});
$this->allPresentationsAreScheduled = Presentation::where('is_approved', true)
->get()
->every(function ($presentation) {
return $presentation->isScheduled;
});
$this->isReadyToBePublished = Presentation::all()->every(function ($presentation) {
return $presentation->isScheduled && $presentation->is_approved;
});
$this->oldValue = $this->isReadyToBePublished;
}
/**
* Function that rechecks whether the programme is ready for release
*
* @return void
*/
#[On('check-programme-status')]
public function checkIfProgrammeisReadyForRelease()
{
$this->isReadyToBePublished = Presentation::all()->every(function ($presentation) {
return $presentation->isScheduled && $presentation->is_approved;
});
$this->allPresentationsAreApproved = Presentation::all()->every(function ($presentation) {
return $presentation->is_approved;
});
$this->allPresentationsAreScheduled = Presentation::where('is_approved', true)
->get()
->every(function ($presentation) {
return $presentation->isScheduled;
});
if ($this->isReadyToBePublished && $this->isReadyToBePublished != $this->oldValue) {
Toaster::success('The programme is ready to be
published whenever you wish if the state remains the same.');
}
$this->oldValue = $this->isReadyToBePublished;
}
/**
* Renders the component
*
* @return View
*/
public function render(): View
{
return view('livewire.schedule.publish-programme-button');
}
}