Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Felice Ostuni committed Jun 16, 2024
1 parent 684f828 commit 812b118
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/Commands/RapydMakeEditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ public function handle()

$edit_view = $viewPath.'/'.str_replace('edit', 'view', $component_name).'.blade.php';
$table_view = $viewPath.'/'.str_replace('edit', 'table', $component_name).'.blade.php';
$edit_class = $classPath.'/'.$componentName.'.php';

$this->buildLinkToEdit($edit_view, $routename);
$this->buildLinkToAdd($table_view, $routename);


if($routeparent_view) {
$this->buildRedirect($edit_class, $routeparent_view, $routeparent_view_parameter);
} elseif($routeparent_table) {
$this->buildRedirect($edit_class, $routeparent_table);
}
$this->comment("component url: $routeuri ".$routename);
}

Expand Down Expand Up @@ -175,4 +183,17 @@ protected function buildLinkToAdd($viewpath, $route)
}

}

protected function buildRedirect($viewpath, $route, $route_parameter = '')
{
$viewContent = File::get($viewpath);
if($viewContent) {

$precompiler = new RapydTagPrecompiler();
$newViewContent = $precompiler($viewContent, ['route' => $route, 'route_parameter'=>$route_parameter, 'ref'=>'redirect']);

File::put($viewpath, $newViewContent);
}

}
}
2 changes: 1 addition & 1 deletion src/Commands/Templates/Livewire/DataEdit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class {{class}} extends {{baseClassName}}
{
$this->validate();
$this->{{ item }}->save();
// $this->emit('saved');
#redirect
}

public function render()
Expand Down
21 changes: 18 additions & 3 deletions src/Mechanisms/RapydTagPrecompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public function __invoke($value, $params = [])
if ($params['ref'] === 'link-add') {
$value = $this->replaceLinkAddTags($value, '/<a\s+data-ref="link-add"\s+href="#"><\/a>/', $params);
}
if ($params['ref'] === 'redirect') {
$value = $this->replaceRedirect($value, '/#redirect/', $params);
}

}

return $value;
Expand All @@ -30,7 +34,7 @@ protected function replaceLinkViewTags($value, $pattern, $params = [])
$viewId = str_replace(['{{', '}}'], '', $content);
if(count($params) && isset($params['route'])) {

return '<a href="{{ route(\'' . $params['route'] . '\','.$viewId.') }}">' . $content . '</a>';
return '<a href="{{ route_lang(\'' . $params['route'] . '\','.$viewId.') }}">' . $content . '</a>';
}

return $matches[0];
Expand All @@ -43,7 +47,7 @@ protected function replaceLinkEditTags($value, $pattern, $params = [])
$content = $matches[1];
$viewId = str_replace(['{{', '}}'], '', $content);
if(count($params) && isset($params['route'])) {
return '<a href="{{ route(\'' . $params['route'] . '\','.$viewId.') }}" class="btn btn-outline-primary">Edit</a>';
return '<a href="{{ route_lang(\'' . $params['route'] . '\','.$viewId.') }}" class="btn btn-outline-primary">Edit</a>';
}

return $matches[0];
Expand All @@ -54,7 +58,18 @@ protected function replaceLinkAddTags($value, $pattern, $params = [])
{
return preg_replace_callback($pattern, function (array $matches) use ($params) {
if(count($params) && isset($params['route'])) {
return '<a href="{{ route(\'' . $params['route'] . '\') }}" class="btn btn-outline-primary">Add</a>';
return '<a href="{{ route_lang(\'' . $params['route'] . '\') }}" class="btn btn-outline-primary">Add</a>';
}
return $matches[0];
}, $value);
}

protected function replaceRedirect($value, $pattern, $params = [])
{
return preg_replace_callback($pattern, function (array $matches) use ($params) {
if(count($params) && isset($params['route']) && isset($params['route_parameter'])) {
$parameter = str_replace('$','$this->',$params['route_parameter']);
return 'return redirect()->to(route_lang("'.$params['route'].'",'.$parameter.' ));';
}

return $matches[0];
Expand Down

0 comments on commit 812b118

Please sign in to comment.