features/loading-data-by-source #3

Merged
jtom38 merged 8 commits from features/loading-data-by-source into main 2023-06-15 21:55:19 -07:00
13 changed files with 109 additions and 67 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
appsettings.json
**/bin/
**/obj/

View File

@ -6,15 +6,17 @@ name: build
steps: steps:
- name: build image - name: build image
image: plugins/docker image: plugins/docker
environment:
PAT:
from_secret: DockerPushPat
settings: settings:
repo: 192.168.1.196:5000/jtom38/newsbot-portal username: jtom38
registry: 192.168.1.196:5000 password: $PAT
insecure: true repo: jtom38/newsbot-portal
tags:
- latest
trigger: trigger:
branch: branch:
- master - master
- releases/*
--- ---
kind: pipeline kind: pipeline

View File

@ -2,6 +2,6 @@ namespace Newsbot.Portal.Blazor.Server;
public static class Global public static class Global
{ {
public static HttpClient HttpClient { get; set; } public static HttpClient? HttpClient { get; set; }
public static string? DefaultInstanceUri { get; set; } public static string? DefaultInstanceUri { get; set; }
} }

View File

@ -7,12 +7,6 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Newsbot.Collector.Client\Newsbot.Collector.Client.csproj" /> <ProjectReference Include="..\Newsbot.Collector.Client\Newsbot.Collector.Client.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,7 +1,9 @@
@page "/articles/newest" @page "/articles/latest"
@using Newsbot.Collector.Client @using Newsbot.Collector.Client
@using Newsbot.Collector.Client.Domain.Dto @using Newsbot.Collector.Client.Domain.Dto
<h3>List Articles</h3>
<PageTitle>Latest</PageTitle>
<h3>Latest Posts</h3>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@ -11,7 +13,10 @@
<div class="card" style="width: 18rem;"> <div class="card" style="width: 18rem;">
<img src="@item.Thumbnail" class="card-img-top" alt="..."> <img src="@item.Thumbnail" class="card-img-top" alt="...">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">@item.Title</h5> <h5 class="card-title">
<a href="@item.Url" target="_blank">@item.Title</a>
</h5>
<p class="card-text">@item.PubDate</p>
<p class="card-text">@item.Description</p> <p class="card-text">@item.Description</p>
<a href="@item.Url" class="btn btn-primary" target="_blank">View</a> <a href="@item.Url" class="btn btn-primary" target="_blank">View</a>
</div> </div>

View File

@ -2,32 +2,42 @@
@using Newsbot.Collector.Client.Domain.Dto @using Newsbot.Collector.Client.Domain.Dto
@using Newsbot.Collector.Client @using Newsbot.Collector.Client
<h3>ListBySource</h3> <PageTitle>@Record?.Name</PageTitle>
<h3>@Record?.Name</h3>
<table> <div class="container">
<tr> <div class="row">
<td>Title</td>
<td>Publish Date</td>
</tr>
@foreach (var item in Data ??= new List<ArticlesDto>()) @foreach (var item in Data ??= new List<ArticlesDto>())
{ {
<tr> <div class="col-sm">
<td> <div class="card" style="width: 18rem;">
<a href="@item.Url" target="_blank">@item.Title</a><br/> <img src="@item.Thumbnail" class="card-img-top" alt="...">
</td> <div class="card-body">
<td>@item.PubDate</td> <h5 class="card-title">
</tr> <a href="@item.Url" target="_blank">@item.Title</a>
</h5>
<p class="card-text">@item.PubDate</p>
<p class="card-text">@item.Description</p>
<a href="@item.Url" class="btn btn-primary" target="_blank">View</a>
</div>
</div>
</div>
} }
</table> </div>
</div>
@code { @code {
[Parameter] [Parameter]
public string? Id { get; set; } public string? Id { get; set; }
List<ArticlesDto>? Data { get; set; } List<ArticlesDto>? Data { get; set; }
SourcesDto? Record { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var s = new SourcesClient(Global.HttpClient, Global.DefaultInstanceUri ?? "");
Record = await s.GetAsync(Guid.Parse(Id ?? ""));
var c = new ArticlesClient(Global.HttpClient, Global.DefaultInstanceUri ?? ""); var c = new ArticlesClient(Global.HttpClient, Global.DefaultInstanceUri ?? "");
var items = await c.ListBySourceAsync(Guid.Parse(Id ?? "")); var items = await c.ListBySourceAsync(Guid.Parse(Id ?? ""));
Data = items; Data = items;

View File

@ -1,33 +0,0 @@
@page "/articles/sources"
@using Newsbot.Collector.Client
@using Newsbot.Collector.Client.Domain.Dto
<h3>Select Source</h3>
<table>
<tr>
<td>Source</td>
<td>Name</td>
<td>Type</td>
</tr>
@foreach (var item in Items ??= new List<SourcesDto>())
{
<tr>
<td>@item.Source</td>
<td>
<a href="/articles/sources/@item.Id">@item.Name</a>
</td>
<td>@item.Type</td>
</tr>
}
</table>
@code {
private List<SourcesDto>? Items { get; set; }
protected override async Task OnInitializedAsync()
{
var c = new SourcesClient(Global.HttpClient, Global.DefaultInstanceUri ?? "");
Items = await c.ListAsync();
}
}

View File

@ -1,4 +1,4 @@
@page "/sources/list" @page "/sources"
@using Newsbot.Collector.Client @using Newsbot.Collector.Client
@using Newsbot.Collector.Client.Domain.Dto @using Newsbot.Collector.Client.Domain.Dto
@ -8,6 +8,7 @@
<tr> <tr>
<td>Title</td> <td>Title</td>
<td>Publish Date</td> <td>Publish Date</td>
<td>Tags</td>
</tr> </tr>
@foreach (var item in Data ??= new List<SourcesDto>()) @foreach (var item in Data ??= new List<SourcesDto>())
{ {
@ -21,12 +22,34 @@
<a href="@item.Url" target="_blank">@item.Name</a><br/> <a href="@item.Url" target="_blank">@item.Name</a><br/>
</td> </td>
<td>@item.Source</td> <td>@item.Source</td>
<td>@FlattenTags(@item.Tags ??= new List<string>())</td>
<td>
<a href="/articles/sources/@item.Id">View News</a>
</td>
</tr> </tr>
} }
</table> </table>
@code { @code {
private List<SourcesDto> Data { get; set; } private List<SourcesDto>? Data { get; set; }
private string FlattenTags(List<string> tags)
{
string res = "";
foreach (var tag in tags)
{
if (res == "")
{
res = tag;
}
else
{
res += $", {tag}";
}
}
return res;
}
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {

View File

@ -1,6 +1,6 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
<PageTitle>Newsbot.Portal.Blazor.Server</PageTitle> <PageTitle>Newsbot</PageTitle>
<div class="page"> <div class="page">
<div class="sidebar"> <div class="sidebar">
@ -8,8 +8,10 @@
</div> </div>
<main> <main>
<div class="top-row px-4"> <div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> <a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
<a href="">Login</a>
</div> </div>
<article class="content px-4"> <article class="content px-4">

View File

@ -1,6 +1,6 @@
<div class="top-row ps-3 navbar navbar-dark"> <div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="">Newsbot.Portal.Blazor.Server</a> <a class="navbar-brand" href="">Newsbot</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu"> <button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
@ -20,8 +20,8 @@
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3"> <div class="nav-item px-3">
<NavLink class="nav-link" href="sources/list"> <NavLink class="nav-link" href="sources">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data <span class="oi oi-list-rich" aria-hidden="true"></span> Sources
</NavLink> </NavLink>
</div> </div>
</nav> </nav>

16
docker-compose.yml Normal file
View File

@ -0,0 +1,16 @@
version: "3"
networks:
newsbot:
services:
portal:
image: newsbot.portal:latest
environment:
Logging__LogLevel__Default: "Information"
Logging__LogLevel__Microsoft.AspNetCore: "Warning"
DefaultInstanceUri: "http://192.168.1.225:5001"
ports:
- "5002:80"
networks:
- newsbot

20
makefile Normal file
View File

@ -0,0 +1,20 @@
.PHONY: help
help: ## Shows this help command
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## builds the application
dotnet restore
dotnet build
pub: ## Build and publish the artifacts
dotnet restore
dotnet publish -o out
rm ./out/appsettings.json
docker-build: ## Generates the docker image
docker build -t "newsbot.portal" .
docker image ls | grep newsbot.portal
docker-run: ## Runs the docker compose
docker compose up -d