-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2469612
commit 27e3492
Showing
9 changed files
with
218 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import Chart from 'chart.js/auto'; // todo limit size https://www.chartjs.org/docs/latest/getting-started/integration.html#bundle-optimization | ||
|
||
/* stimulusFetch: 'lazy' */ | ||
export default class extends Controller { | ||
static targets = [ | ||
'canvas', | ||
] | ||
|
||
static values = { | ||
data: Object, | ||
type: String, | ||
} | ||
|
||
connect() { | ||
const data = this.dataValue; | ||
const type = this.typeValue; | ||
|
||
new Chart( | ||
this.canvasTarget, | ||
{ | ||
type: 'line', | ||
data: this.parseData(data, type), | ||
}, | ||
); | ||
} | ||
|
||
parseData(data, type) { | ||
switch (type) { | ||
case 'daily': | ||
return { | ||
labels: Object.keys(data).map(key => `${key.substring(0, 4)}-${key.substring(4, 6)}-${key.substring(6, 8)}`), | ||
datasets: [ | ||
{ | ||
label: 'Installations per day', | ||
data: Object.values(data), | ||
}, | ||
], | ||
}; | ||
|
||
case 'daily-versions': | ||
const datasets = []; | ||
|
||
for (const key in data) { | ||
datasets.push({ | ||
label: key, | ||
data: Object.values(data[key]), | ||
}); | ||
} | ||
|
||
return { | ||
labels: Object.keys(data[0]).map(key => `${key.substring(0, 4)}-${key.substring(4, 6)}-${key.substring(6, 8)}`), | ||
datasets, | ||
}; | ||
} | ||
} | ||
} |
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,3 @@ | ||
|
||
/* | ||
* Welcome to your app's main JavaScript file! | ||
* | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,63 @@ | ||
{% extends '@EasyAdmin/page/content.html.twig' %} | ||
|
||
{% block page_title %}{{ package.name }}{% endblock %} | ||
|
||
{% block search_wrapper %} | ||
{% include 'dashboard/packages/search_box.html.twig' with {searchAutofocus: false} %} | ||
{% endblock %} | ||
|
||
{% block page_content %} | ||
{% include 'dashboard/packages/package_header.html.twig' with {currentPage: 'statistics'} %} | ||
|
||
<div class="mb-3"> | ||
<h2>{{ 'Installations'|trans }}</h2> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<div class="card mb-2"> | ||
<div class="card-body"> | ||
<div>{{ 'Total'|trans }}:</div> | ||
<div class="display-6">{{ installationsTotal|number_format(thousandSep: ' ') }}</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-md-4"> | ||
<div class="card mb-2"> | ||
<div class="card-body"> | ||
<div>{{ 'Last 30 days'|trans }}:</div> | ||
<div class="display-6">{{ installationsLast30Days|number_format(thousandSep: ' ') }}</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-md-4"> | ||
<div class="card mb-2"> | ||
<div class="card-body"> | ||
<div>{{ 'Today'|trans }}:</div> | ||
<div class="display-6">{{ installationsToday|number_format(thousandSep: ' ') }}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<h2>{{ 'Daily installations'|trans }}</h2> | ||
<div | ||
data-controller="chart" | ||
data-chart-data-value="{{ package.installations.data ? package.installations.data|json_encode|escape : '{}' }}" | ||
data-chart-type-value="daily" | ||
> | ||
<canvas data-chart-target="canvas"></canvas> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<h2>{{ 'Daily installations per version'|trans }}</h2> | ||
<div | ||
data-controller="chart" | ||
data-chart-data-value="{{ versionInstallationsData|json_encode|escape }}" | ||
data-chart-type-value="daily-versions" | ||
> | ||
<canvas data-chart-target="canvas"></canvas> | ||
</div> | ||
</div> | ||
{% endblock %} |
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