💄 Show link's http status and last checked date in the link card

This commit is contained in:
Erik Yeoh 2020-09-03 12:17:06 +08:00
parent 8313e36383
commit 710b60c53f
2 changed files with 38 additions and 0 deletions

View File

@ -13,6 +13,9 @@ class LinkResource extends JsonResource
'title' => $this->title,
'content' => $this->content,
'url' => $this->url,
'http_status' => $this->getStatusText($this->http_status),
'http_status_color' => $this->getStatusColor($this->http_status),
'http_checked_at' => $this->http_checked_at,
'permalink' => $this->permalink,
'is_private' => $this->post->is_private,
'is_pinned' => $this->post->is_pinned,
@ -33,4 +36,34 @@ class LinkResource extends JsonResource
])
];
}
public function getStatusText($status)
{
if (is_null($status)) {
return null;
}
if ($status == 200) {
return 'Healthy (200)';
}
if (400 <= $status and $status <= 499) {
return 'Dead (4xx)';
}
return 'Other (3xx, 5xx)';
}
public function getStatusColor($status)
{
if ($status == 200) {
return 'success';
}
if (400 <= $status and $status <= 499) {
return 'danger';
}
return 'warning';
}
}

View File

@ -14,6 +14,11 @@
<p class="card-text mt-1" v-if="link.tags.length > 0">
<a v-for="tag in link.tags" class="badge badge-secondary mr-1" :href="`/tag/${tag}`">{{ tag }}</a>
</p>
<p v-if="link.http_status">
<span class="badge" :class="'badge-' + link.http_status_color">{{ __(link.http_status) }}</span>
<small class="text-muted">{{ __('Last Checked') }}: {{ link.http_checked_at }}</small>
</p>
</div>
<div class="card-footer d-flex justify-content-between">