-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented basic Execute action and ExecuteLink
- Loading branch information
1 parent
70b7e44
commit 4b090fe
Showing
13 changed files
with
55,963 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"/app.js": "/app.js?id=5018256cfd2b5e61031b", | ||
"/app.css": "/app.css?id=f5f48ad7d78fef6b7e2e" | ||
"/app.js": "/app.js", | ||
"/app.css": "/app.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from 'react'; | ||
import Button from "../core/ui/button"; | ||
import UiLink from "../core/ui/link"; | ||
import api from "../api/api"; | ||
import util from "../core/ui/util"; | ||
import path from "../state/path"; | ||
import Overlay from "../core/ui/overlay"; | ||
import Window from "../core/ui/window"; | ||
import Form from "../core/ui/form"; | ||
import components from "../rendering/components"; | ||
import ReactDOM from "react-dom"; | ||
|
||
class ExecuteLink extends React.Component { | ||
|
||
static defaultProps = { | ||
path: {}, | ||
data: {}, | ||
action: '', | ||
components: [], | ||
notification: 'Success' | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
formErrors: {}, | ||
isOpen: false | ||
}; | ||
|
||
this.widgetMountEl = null; | ||
this.formRef = React.createRef(); | ||
} | ||
|
||
close() { | ||
this.widgetMountEl.remove(); | ||
} | ||
|
||
open() { | ||
this.widgetMountEl = document.body.appendChild(document.createElement('div')); | ||
ReactDOM.render(this.renderAskWidget(), this.widgetMountEl); | ||
} | ||
|
||
redirect(response) { | ||
path.handleRedirect(this.props, {id: response.data.id}); | ||
} | ||
|
||
handleClick() { | ||
if (this.props.components.length) { | ||
this.open(); | ||
return; | ||
} | ||
|
||
this.execute(); | ||
} | ||
|
||
execute(data) { | ||
|
||
this.close(); | ||
|
||
// Add the id to the data first | ||
data.id = this.props.data.id || null; | ||
|
||
let path = { ...this.props.path, action: this.props.action }; | ||
|
||
// Load the data from the backend (with id as param) | ||
api.modules.post(path,'handle', data).then(response => { | ||
util.notify(this.props.notification); | ||
this.redirect(response.data); | ||
}); | ||
} | ||
|
||
renderAskComponents() { | ||
return components.renderComponents(this.props.components, {}, this.props.path); | ||
} | ||
|
||
renderAskWidget() { | ||
return ( | ||
<Overlay> | ||
<Window title={this.props.text} style={'modal'} closeable={true} onClose={this.close.bind(this)}> | ||
<Form | ||
ref={this.formRef} | ||
errors={this.state.formErrors} | ||
realForm={false} | ||
onSubmit={this.execute.bind(this)} | ||
submitButtonText={'Submit'} | ||
> | ||
{this.renderAskComponents()} | ||
</Form> | ||
</Window> | ||
</Overlay> | ||
); | ||
} | ||
|
||
renderLink() { | ||
if (this.props.style) { | ||
return ( | ||
<Button style={this.props.style} text={this.props.text} onClick={this.handleClick.bind(this)} /> | ||
); | ||
} | ||
return <UiLink onClick={this.handleClick.bind(this)} text={this.props.text} />; | ||
} | ||
|
||
render() { | ||
if (this.props.style) { | ||
return ( | ||
<Button style={this.props.style} text={this.props.text} onClick={this.handleClick.bind(this)} /> | ||
); | ||
} | ||
|
||
return <UiLink onClick={this.handleClick.bind(this)} text={this.props.text} />; | ||
} | ||
} | ||
|
||
export default ExecuteLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace ReinVanOyen\Cmf\Action; | ||
|
||
use Illuminate\Http\Request; | ||
use ReinVanOyen\Cmf\Http\Resources\ModelResource; | ||
|
||
class Execute extends Action | ||
{ | ||
/** | ||
* @var callable $handle | ||
*/ | ||
private $handle; | ||
|
||
/** | ||
* @param string $meta | ||
* @throws \ReinVanOyen\Cmf\Exceptions\InvalidMetaException | ||
*/ | ||
public function __construct(string $meta) | ||
{ | ||
$this->meta($meta); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function type(): string | ||
{ | ||
return 'execute'; | ||
} | ||
|
||
/** | ||
* @param callable $handle | ||
* @return $this | ||
*/ | ||
public function handle(callable $handle) | ||
{ | ||
$this->handle = $handle; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @return ModelResource | ||
*/ | ||
public function apiHandle(Request $request) | ||
{ | ||
$modelClass = $this->getMeta()::getModel(); | ||
$modelInstance = $modelClass::findOrFail($request->input('id')); | ||
|
||
$result = call_user_func($this->handle, $modelInstance, $request); | ||
|
||
return new ModelResource($modelInstance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace ReinVanOyen\Cmf\Components; | ||
|
||
use ReinVanOyen\Cmf\Traits\CanRedirect; | ||
|
||
class ExecuteLink extends Component | ||
{ | ||
use CanRedirect; | ||
|
||
/** | ||
* Link constructor. | ||
* @param string $text | ||
* @param string $actionPath | ||
*/ | ||
public function __construct(string $text, string $actionPath) | ||
{ | ||
$this->export('text', $text); | ||
$this->export('action', $actionPath); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function type(): string | ||
{ | ||
return 'execute-link'; | ||
} | ||
|
||
/** | ||
* @param string $message | ||
* @return $this | ||
*/ | ||
public function notify(string $message) | ||
{ | ||
$this->export('notification', $message); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param mixed $style | ||
* @return $this | ||
*/ | ||
public function style($style) | ||
{ | ||
$this->export('style', $style); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $components | ||
* @return $this | ||
*/ | ||
public function ask(array $components) | ||
{ | ||
$this->export('components', $components); | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters