Skip to content

Commit

Permalink
feat: cycle through months
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Apr 7, 2022
1 parent 82d5f05 commit cbf6f09
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 58 deletions.
67 changes: 40 additions & 27 deletions components/areas.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,50 @@
'link' => 'webmentions',
'views' => [
[
'pattern' => 'webmentions',
'action' => function () {
'pattern' => ['webmentions', 'webmentions/(:any)/(:any)'],
'action' => function ($year = null, $month = null) {
if (is_null($year) || is_null($month)) {
$timestamp = time();
$year = date('Y', $timestamp);
$month = date('m', $timestamp);
}

if ($month < 12) {
$nextMonth = $month + 1;
$nextYear = $year;
} else {
$nextMonth = 1;
$nextYear = $year + 1;
}

if ($month > 1) {
$prevMonth = $month - 1;
$prevYear = $year;
} else {
$prevMonth = 12;
$prevYear = $year - 1;
}

$stats = new WebmentionStats();
$summary = $stats->getSummaryByMonth($year, $month);
$targets = $stats->getTargets($year, $month);
$sources = $stats->getSources($year, $month);
$version = $stats->getPluginVersion();

return [
'component' => 'k-webmentions-view',
'title' => 'Webmentions',
'props' => [
'summary' => function () {
$stats = new WebmentionStats();
$timestamp = time();
$summary = $stats->getSummaryByMonth($timestamp);

return $summary;
},
'targets' => function () {
$stats = new WebmentionStats();
$timestamp = time();
$summary = $stats->getTargets($timestamp);

return $summary;
},
'sources' => function () {
$stats = new WebmentionStats();
$timestamp = time();
$summary = $stats->getSources($timestamp);

return $summary;
},
'version' => function () {
$stats = new WebmentionStats();
return $stats->getPluginVersion();
}
'year' => $year,
'month' => $month,
'nextYear' => $nextYear,
'nextMonth' => $nextMonth,
'prevYear' => $prevYear,
'prevMonth' => $prevMonth,
'summary' => $summary,
'targets' => $targets,
'sources' => $sources,
'version' => $version
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

15 changes: 2 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"recognizeSelfClosing": true
},
"dependencies": {
"date-fns": "2.11.0",
"vue": "^2.6.14",
"vue-hot-reload-api": "^2.3.4"
},
Expand Down
22 changes: 22 additions & 0 deletions src/components/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<k-inside>
<k-view class="k-webmentions-view">
<k-header>Webmentions</k-header>
<div class="prev-next">
<button class="k-link k-button" v-on:click="goToPrevMonth"><k-icon type="angle-left" /></button>
{{ month }} / {{ year }}
<button class="k-link k-button" v-on:click="goToNextMonth"><k-icon type="angle-right" /></button>
</div>
<Version :version="version" />

<DetailsByMonth :summary="summary" />
Expand All @@ -14,11 +19,28 @@
<script>
export default {
props: {
year: Number,
month: Number,
nextYear: Number,
nextMonth: Number,
prevYear: Number,
prevMonth: Number,
summary: Object,
targets: Array,
sources: Array,
version: Object,
},
methods: {
goToPrevMonth() {
const panelPath = window.location.pathname.split('webmentions')
window.location.pathname = `${panelPath[0]}webmentions/${this.prevYear}/${this.prevMonth}`
},
goToNextMonth() {
const panelPath = window.location.pathname.split('webmentions')
window.location.pathname = `${panelPath[0]}webmentions/${this.nextYear}/${this.nextMonth}`
},
},
}
</script>

Expand Down
15 changes: 3 additions & 12 deletions utils/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ public function trackMention(string $target, string $source, string $type, strin
}
}

public function getSummaryByMonth(int $timestamp)
public function getSummaryByMonth(int $year, int $month)
{
$year = date('Y', $timestamp);
$month = date('m', $timestamp);

try {
$result = $this->db->query('SELECT COUNT(id) as summary, * FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_type;');
$summary = [
Expand Down Expand Up @@ -111,11 +108,8 @@ public function getDetailsByMonth(int $timestamp)
}
}

public function getTargets(int $timestamp)
public function getTargets(int $year, int $month)
{
$year = date('Y', $timestamp);
$month = date('m', $timestamp);

try {
$result = $this->db->query('SELECT mention_target, mention_type, COUNT(mention_type) as mentions FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_target, mention_type;');
$targets = [];
Expand Down Expand Up @@ -152,11 +146,8 @@ public function getTargets(int $timestamp)
}
}

public function getSources(int $timestamp)
public function getSources(int $year, int $month)
{
$year = date('Y', $timestamp);
$month = date('m', $timestamp);

try {
$result = $this->db->query('SELECT mention_source, mention_type, mention_image, COUNT(mention_type) as mentions FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_source, mention_type;');
$sources = [];
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php return array(
'root' => array(
'pretty_version' => '1.2.4',
'version' => '1.2.4.0',
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -29,8 +29,8 @@
'dev_requirement' => false,
),
'mauricerenck/indieconnector' => array(
'pretty_version' => '1.2.4',
'version' => '1.2.4.0',
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit cbf6f09

Please sign in to comment.