-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Cards #44
Open
navneetrai
wants to merge
11
commits into
master
Choose a base branch
from
feature/cards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Cards #44
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8b2727e
Added card component
navneetrai 3254b89
Added PHP Card
navneetrai a0e1e48
Updated Trait
navneetrai 3d1c9ba
Compilation Updates
navneetrai 67dc217
Updated Readme
navneetrai 58e7766
Style Updates
navneetrai 4cdf4c2
Return early for Resource cards
navneetrai d2d6f4b
Style Fixes
navneetrai 6a11b51
Update README.md
navneetrai 426a5ff
Update README.md
navneetrai 4054b9d
Updated readme indentation
navneetrai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<template> | ||
<card class="p-10 nova-chartjs-card"> | ||
<div class="w-full py-4"> | ||
<chartjs-bar-chart v-if="isType('bar')" | ||
:dataset="comparisonDataset" | ||
:additionalDatasets="card.additionalDatasets" | ||
:settings="card.settings" | ||
:height="card.settings.height" | ||
:width="card.settings.width" | ||
/> | ||
<chartjs-line-chart v-else | ||
:dataset="comparisonDataset" | ||
:additionalDatasets="card.additionalDatasets" | ||
:settings="card.settings" | ||
:height="card.settings.height" | ||
:width="card.settings.width" | ||
/> | ||
</div> | ||
</card> | ||
</template> | ||
|
||
<script> | ||
import ChartjsLineChart from "./ChartjsLineChart"; | ||
import ChartjsBarChart from "./ChartjsBarChart"; | ||
import colors from "../mixins/colors"; | ||
import datasetHandler from "../mixins/datasetHandler"; | ||
export default { | ||
components: { | ||
ChartjsLineChart, | ||
ChartjsBarChart | ||
}, | ||
|
||
mixins: [colors, datasetHandler], | ||
|
||
props: ['card'], | ||
|
||
data() { | ||
return { | ||
selected: [] | ||
} | ||
}, | ||
|
||
methods: { | ||
isType: function(type){ | ||
return this.card.settings.type.toLowerCase() === type | ||
}, | ||
|
||
getDatapoint: function(values, title, color){ | ||
if(!color){ | ||
color = this.getRandomColor(); | ||
} | ||
|
||
if(!values || (typeof values != 'object')){ | ||
values = []; | ||
} | ||
|
||
return { | ||
label: title, | ||
data: this.getAllowedParametersFromDataset(this.card.settings.parameters, values), | ||
...this.getChartTypeCustomizations(this.card.settings.type, color) | ||
} | ||
}, | ||
|
||
getChartTypeCustomizations: function(type, color){ | ||
if(this.isType('line')){ | ||
return { | ||
borderColor: color | ||
} | ||
}else{ | ||
return { | ||
backgroundColor: color | ||
} | ||
} | ||
} | ||
}, | ||
|
||
computed: { | ||
comparisonDataset: function(){ | ||
return [ | ||
...this.card.dataset.map( | ||
data => this.getDatapoint( | ||
data.novaChartjsComparisonData, | ||
data[this.card.settings.titleProp] | ||
) | ||
) | ||
]; | ||
}, | ||
} | ||
|
||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.nova-chartjs-card { | ||
height: auto !important; | ||
min-height: 150px; | ||
} | ||
</style> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,103 @@ | ||
<?php | ||
|
||
namespace KirschbaumDevelopment\NovaChartjs\Cards; | ||
|
||
use Laravel\Nova\Card; | ||
|
||
class NovaChartjsCard extends Card | ||
{ | ||
/** | ||
* The width of the card (1/3, 1/2, or full). | ||
* | ||
* @var string | ||
*/ | ||
public $width = 'full'; | ||
|
||
public function __construct($component = null) | ||
{ | ||
parent::__construct($component); | ||
} | ||
|
||
/** | ||
* Get the component name for the element. | ||
* | ||
* @return string | ||
*/ | ||
public function component() | ||
{ | ||
return 'card-nova-chartjs'; | ||
} | ||
|
||
public function settings(array $settings): self | ||
{ | ||
return $this->withMeta(['settings' => $settings]); | ||
} | ||
|
||
public function chartModel(string $model): self | ||
{ | ||
return $this->withMeta(['chartModel' => $model]); | ||
} | ||
|
||
public function additionalDatasets(array $additionalDatasets): self | ||
{ | ||
return $this->withMeta(['additionalDatasets' => $additionalDatasets]); | ||
} | ||
|
||
public function dataset(array $dataset): self | ||
{ | ||
return $this->withMeta(['dataset' => $dataset]); | ||
} | ||
|
||
/** | ||
* Set chart name for the chart. | ||
* | ||
* @param string $chartName | ||
* | ||
* @return NovaChartjs | ||
*/ | ||
public function chartName($chartName = 'default'): self | ||
{ | ||
return $this->withMeta([ | ||
'chartName' => $chartName, | ||
]); | ||
} | ||
|
||
/** | ||
* Prepare the element for JSON serialization. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
$this->updateChartMeta(); | ||
|
||
return parent::jsonSerialize(); | ||
} | ||
|
||
/** | ||
* Returns chartname for current chart. | ||
* | ||
* @return string | ||
*/ | ||
protected function getChartName() | ||
{ | ||
return data_get($this->meta(), 'chartName', 'default'); | ||
} | ||
|
||
/** | ||
* Updates Meta values for Charts. | ||
* | ||
* @throws \Illuminate\Contracts\Container\BindingResolutionException | ||
*/ | ||
protected function updateChartMeta() | ||
{ | ||
$model = app(data_get($this->meta(), 'chartModel')); | ||
$chartName = $this->getChartName(); | ||
|
||
$this->withMeta([ | ||
'dataset' => data_get($this->meta(), 'dataset', $model::getCardDatasets($chartName)), | ||
'settings' => data_get($this->meta(), 'settings', $model::getNovaChartjsCardSettings($chartName)), | ||
'additionalDatasets' => data_get($this->meta(), 'additionalDatasets', $model::getAdditionalCardDatasets($chartName)), | ||
]); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to use a dynamic component here since everything is the same except for the component itself? Maybe something along these lines:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dvanscott This change is already a part of #41
Is it okay to handle it in that rebase?