Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
use svelte for admin queue
Browse files Browse the repository at this point in the history
  • Loading branch information
peppage committed Jul 10, 2019
1 parent 09a16d3 commit 33cfab1
Show file tree
Hide file tree
Showing 14 changed files with 1,104 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,7 @@ healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# bundled javascript
bundle.css*
bundle.js*
7 changes: 4 additions & 3 deletions src/Wanderinglunch.Data/Interfaces/ITweetRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace Wanderinglunch.Data.Interfaces
{
public interface ITweetRepo
{
Task<object> CreateAsync(Tweet tweet);
object Create(Tweet tweet);
Task<List<Tweet>> GetByIdAsync(string id);
Task SaveAsync(Tweet tweet);
void Create(Tweet tweet);
Task<Tweet> GetById(string id);
Task<List<Tweet>> GetByTruckIdAsync(string id);
Task<List<Tweet>> GetRecentAsync(string site, bool notDone = false, int amount = 35);
}
}
8 changes: 5 additions & 3 deletions src/Wanderinglunch.Data/Repositories/TweetRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public TweetRepo(IDatabase db)
this.db = db;
}

public object Create(Tweet tweet) => db.Insert(tweet);
public void Create(Tweet tweet) => db.Save(tweet);

public Task<object> CreateAsync(Tweet tweet) => db.InsertAsync(tweet);
public Task SaveAsync(Tweet tweet) => db.SaveAsync(tweet);

public Task<List<Tweet>> GetByIdAsync(string id) => db.FetchAsync<Tweet>("WHERE truck_id = @0 ORDER BY time DESC", id);
public Task<Tweet> GetById(string id) => db.SingleOrDefaultAsync<Tweet>("WHERE id = @0", id);

public Task<List<Tweet>> GetByTruckIdAsync(string id) => db.FetchAsync<Tweet>("WHERE truck_id = @0 ORDER BY time DESC", id);

public Task<List<Tweet>> GetRecentAsync(string site, bool includeNotDone = false, int amount = 35)
{
Expand Down
35 changes: 4 additions & 31 deletions src/Wanderinglunch.Web/Pages/Admin/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
@page
@page "{handler?}"
@model AdminIndexModel
@{
ViewData["Title"] = "Admin Queue";
ViewData["Site"] = "";
}
<h1>Admin Queue</h1>

<table>
<thead>
<tr>
<th>Text</th>
<th>Locations</th>
<th></th>
</tr>
</thead>
@foreach (var tweet in Model.Tweets)
{
<tr>
<td>
@tweet.Text
<br>
<a href="@($"https://twitter.com/{tweet.TruckId}")">@tweet.TruckId</a>
<a href="@($"https://twitter.com/{tweet.TruckId}/status/{tweet.Id}")">@Model.FormatTime(tweet.Time)</a>
</td>
<td>
@foreach(var loc in Model.FindLocations(tweet.Text))
{
@loc.Display
<br>
}
</td>
<td>
<button>Done</button>
</td>
</tr>
}
</table>
@Html.AntiForgeryToken()

<div id="adminQueue"></div>
49 changes: 32 additions & 17 deletions src/Wanderinglunch.Web/Pages/Admin/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Wanderinglunch.Data;
using Wanderinglunch.Data.Models;
using Wanderinglunch.Logic;

namespace Wanderinglunch.Web.Pages
{
public class AdminIndexModel : PageModel
{
private readonly ILunchContext lunchContext;
public List<Tweet> Tweets;
private List<Location> LocationList;

public AdminIndexModel(ILunchContext lunchContext)
{
this.lunchContext = lunchContext;
}
public async Task OnGetAsync()

public class DoneRequest
{
public string Id { get; set; }
}

public string FormatTime(long epoch)
{
var dto = DateTimeOffset.FromUnixTimeSeconds(epoch).ToLocalTime();
return dto.ToString("M/d/yy hh:mm tt");
}

public async Task<JsonResult> OnGetTweetsAsync()
{
Tweets = await lunchContext.TweetRepo.GetRecentAsync("nyc");
var tweetsWithLocations = new List<object>();

var tweets = await lunchContext.TweetRepo.GetRecentAsync("nyc");
var subs = await lunchContext.SubRepo.AllAsync();

foreach (var tweet in Tweets)
var locations = lunchContext.LocationRepo.All();

foreach (var tweet in tweets)
{
tweet.Text = Substitions.DoSubstitions(subs, tweet.Text);

tweetsWithLocations.Add(new
{
tweet = tweet,
locations = Locations.FindLocations(locations, "nyc", tweet.Text),
time = FormatTime(tweet.Time),
});
}

LocationList = lunchContext.LocationRepo.All();
return new JsonResult(tweetsWithLocations);
}

public List<Location> FindLocations(string text)
public async Task<IActionResult> OnPostMarkDoneAsync([FromBody] DoneRequest req)
{
return Locations.FindLocations(LocationList, "nyc", text);
}

public string FormatTime(long epoch)
{
var dto = DateTimeOffset.FromUnixTimeSeconds(epoch).ToLocalTime();
return dto.ToString("M/d/yy hh:mm tt");
var tweet = await lunchContext.TweetRepo.GetById(req.Id);
tweet.Done = true;
await lunchContext.TweetRepo.SaveAsync(tweet);
return null;
}
}
}
2 changes: 2 additions & 0 deletions src/Wanderinglunch.Web/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@(((string) ViewData["Site"]).ToUpper()) Food Truck Finder | @ViewData["Title"]</title>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/bundle.css" asp-append-version="true"/>
<link rel="icon" type="image/x-icon" href="@Url.Content("~/images/favicon.ico")" />
</head>
<body>
Expand Down Expand Up @@ -72,6 +73,7 @@
</script>
</environment>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/bundle.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)
</body>
</html>
2 changes: 1 addition & 1 deletion src/Wanderinglunch.Web/Pages/truck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TruckModel(ILunchContext lunchContext)
public async Task<IActionResult> OnGetAsync(string id)
{
Truck = await lunchContext.TruckRepo.GetByIdAsync(id);
Tweets = await lunchContext.TweetRepo.GetByIdAsync(id);
Tweets = await lunchContext.TweetRepo.GetByTruckIdAsync(id);
Images = await lunchContext.ImageRepo.ByTruckIdAsync(id);
return Page();
}
Expand Down
26 changes: 26 additions & 0 deletions src/Wanderinglunch.Web/Wanderinglunch.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<SvelteRoot>svelte\</SvelteRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SvelteRoot)node_modules\**</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<Content Remove="$(SvelteRoot)**" />
<None Remove="$(SvelteRoot)**" />
<None Include="$(SvelteRoot)**" Exclude="$(SvelteRoot)node_modules\**" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\js\" />
<Folder Include="wwwroot\css\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="3.1.3" />
Expand All @@ -17,4 +29,18 @@
<ProjectReference Include="..\Wanderinglunch.Logic\Wanderinglunch.Logic.csproj" />
</ItemGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SvelteRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SvelteRoot)" Command="npm install" EnvironmentVariables="NO_UPDATE_NOTIFIER=1" />
</Target>

<Target Name="BuildSvelte" BeforeTargets="Build">
<Exec WorkingDirectory="$(SvelteRoot)" Command="npm run build" ContinueOnError="false" EnvironmentVariables="NO_UPDATE_NOTIFIER=1" />
</Target>

</Project>
23 changes: 23 additions & 0 deletions src/Wanderinglunch.Web/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

bundle.*
Loading

0 comments on commit 33cfab1

Please sign in to comment.