1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\FileStorage\Seeds; |
4
|
|
|
|
5
|
|
|
use Epesi\FileStorage\Integration\Joints\FileStorageAccessJoint; |
6
|
|
|
use Epesi\FileStorage\Database\Models\File; |
7
|
|
|
use Epesi\Core\Helpers\Utils; |
|
|
|
|
8
|
|
|
use atk4\ui\Modal; |
9
|
|
|
use Epesi\FileStorage\Database\Models\FileRemoteAccess; |
10
|
|
|
use atk4\ui\jsExpression; |
11
|
|
|
use Illuminate\Support\Facades\Auth; |
12
|
|
|
|
13
|
|
|
class FileModal extends Modal |
14
|
|
|
{ |
15
|
|
|
public $defaultPeriod = '1 weeks'; |
16
|
|
|
|
17
|
|
|
public $periodSelection; |
18
|
|
|
|
19
|
|
|
protected $canvas; |
20
|
|
|
|
21
|
|
|
protected $file; |
22
|
|
|
|
23
|
|
|
public function init() |
24
|
|
|
{ |
25
|
|
|
$this->title = __('File'); |
|
|
|
|
26
|
|
|
|
27
|
|
|
parent::init(); |
28
|
|
|
|
29
|
|
|
$this->setPeriodSelection(); |
30
|
|
|
|
31
|
|
|
$this->set(\Closure::fromCallable([$this, 'addContents'])); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function setPeriodSelection() |
35
|
|
|
{ |
36
|
|
|
if (! $this->periodSelection) { |
37
|
|
|
$this->periodSelection = []; |
38
|
|
|
foreach ([1, 2, 3, 4] as $count) { |
39
|
|
|
$this->periodSelection[$count . ' weeks'] = trans_choice('{1} :count week |[2,*] :count weeks', $count); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
foreach ($this->periodSelection as $key => $period) { |
44
|
|
|
$default = $key == $this->defaultPeriod? ' (' . __('Default') . ')': ''; |
|
|
|
|
45
|
|
|
|
46
|
|
|
$this->periodSelection[$key] = $period . $default; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function addContents($canvas) |
51
|
|
|
{ |
52
|
|
|
$this->canvas = $canvas; |
53
|
|
|
|
54
|
|
|
if (! $this->file()) { |
55
|
|
|
$canvas->set(__('Wrong parameters for file')); |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$columns = $canvas->add('Columns'); |
60
|
|
|
|
61
|
|
|
$column = $columns->addColumn(); |
62
|
|
|
|
63
|
|
|
$this->addFileDetails($column); |
64
|
|
|
|
65
|
|
|
$column = $columns->addColumn(); |
66
|
|
|
|
67
|
|
|
$this->addFileRemoteLinks($column); |
68
|
|
|
|
69
|
|
|
$this->addFileControlButtons(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function file() |
73
|
|
|
{ |
74
|
|
|
return $this->file?: ($this->file = File::get($this->canvas->stickyGET('id'))); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function addFileDetails($container = null) |
78
|
|
|
{ |
79
|
|
|
$container = $container?: $this->canvas; |
80
|
|
|
|
81
|
|
|
$container->add(['Lister', 'template'=> new \atk4\ui\Template(' |
82
|
|
|
<div class="item" style="margin: 0 15px 15px 0"> |
83
|
|
|
<div class="content"><strong>{$title}</strong> |
84
|
|
|
<div class="description">{$descr}</div> |
85
|
|
|
</div> |
86
|
|
|
</div>{empty}' . __('No file details') . '{/}')])->setSource([ |
|
|
|
|
87
|
|
|
['title'=> __('Name'), 'descr'=> $this->file()->name], |
88
|
|
|
['title'=> __('Size'), 'descr'=> Utils::bytesToHuman($this->file()->content->size)], |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function addFileRemoteLinks($container = null) { |
93
|
|
|
$container = $container?: $this->canvas; |
94
|
|
|
|
95
|
|
|
foreach ($this->file()->links()->where('created_by', Auth::id())->get() as $link) { |
96
|
|
|
$container->add(['View', __('Remote access link expiring :expiry', ['expiry' => $link->expires_at])]); |
97
|
|
|
$linkInput = $container->add([new \atk4\ui\FormField\Input(['readonly' => true, 'iconLeft' => 'linkify'])])->set($link->href)->setStyle(['width' => '100%', 'margin-bottom' => '15px']); |
98
|
|
|
|
99
|
|
|
$linkInput->action = new \atk4\ui\Button([ |
100
|
|
|
'Copy', 'iconRight' => 'copy', 'attr' => ['data-clipboard-target' => "#{$linkInput->id}_input", 'title' => __('Click to copy link')], 'class' => ['copy-button'] |
101
|
|
|
]); |
102
|
|
|
|
103
|
|
|
$linkInput->add(['Button', 'icon'=>'red x icon', 'class' => ['delete-link']], 'AfterAfterInput')->setAttr(['data-id' => $link->id, 'title' => __('Disable link')]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$container->js(true, new jsExpression('new ClipboardJS(".copy-button")')); |
107
|
|
|
|
108
|
|
|
$container->on('click', '.delete-link', $container->add(['jsCallback', 'postTrigger' => 'link'])->set(function($j, $linkId) { |
109
|
|
|
if (! $link = FileRemoteAccess::find($linkId)) return; |
110
|
|
|
|
111
|
|
|
$link->delete(); |
112
|
|
|
|
113
|
|
|
return $this->reload(); |
114
|
|
|
}, ['link' => new jsExpression('$(this).data("id")')])); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
protected function addFileControlButtons() { |
118
|
|
|
$urls = FileStorageAccessJoint::getActionUrls($this->file()); |
119
|
|
|
|
120
|
|
|
if ($urls['preview']?? null) { |
121
|
|
|
$this->canvas->add(['Button', 'class' => ['basic'], 'icon' => 'file alternate outline'])->set(__('View'))->link($urls['preview'])->setAttr(['target' => '_blank']); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ($urls['download']?? null) { |
125
|
|
|
$this->canvas->add(['Button', 'class' => ['basic'], 'icon' => 'file download'])->set(__('Download'))->link($urls['download']); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$linkControl = $this->canvas->add(['View', 'ui' => 'basic buttons']); |
129
|
|
|
|
130
|
|
|
$linkButton = $linkControl->add(['Button', 'class' => ['basic'], 'icon' => 'linkify'])->set(__('Get Remote Link')); |
131
|
|
|
|
132
|
|
|
$dropdown = $linkControl->add(['DropDownButton', 'class' => ['floating icon button']]); |
133
|
|
|
|
134
|
|
|
$dropdown->setSource($this->periodSelection); |
135
|
|
|
|
136
|
|
|
$dropdown->onChange(function($value) { |
137
|
|
|
$period = array_search($value, $this->periodSelection)?: $this->defaultPeriod; |
138
|
|
|
|
139
|
|
|
FileRemoteAccess::grant($this->file(), $period); |
140
|
|
|
|
141
|
|
|
return $this->reload(); |
142
|
|
|
}); |
143
|
|
|
|
144
|
|
|
$linkButton->on('click', $dropdown->cb); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
protected function reload() { |
148
|
|
|
return new \atk4\ui\jsReload($this->canvas); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function show($args = []) |
152
|
|
|
{ |
153
|
|
|
return parent::show(array_merge([ |
154
|
|
|
'id' => new jsExpression('$(this).data("id")') |
155
|
|
|
], $args)); |
156
|
|
|
} |
157
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths