Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Add AureliaSpa template #398

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions templates/AureliaSpa/Aurelia.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>33d8dad9-74f9-471d-8bad-55f828faa736</ProjectGuid>
<RootNamespace>Aurelia</RootNamespace>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
6 changes: 6 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/app/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@media (max-width: 767px) {
/* On small screens, the nav menu spans the full width of the screen. Leave a space for it. */
.body-content {
padding-top: 50px;
}
}
14 changes: 14 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/app/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent quote style in this file. In TypeScript let's use single-quotes. In HTML templates, I don't know if Aurelia community has a standard, but can you find out what it is and use that?

Copy link

@EisenbergEffect EisenbergEffect Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer single quotes in JS/TS and double quotes in HTML.

<require from="../navmenu/navmenu.html"></require>
<require from="./app.css"></require>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
<navmenu router.bind="router"></navmenu>
</div>
<div class="col-sm-9 body-content">
<router-view></router-view>
</div>
</div>
</div>
</template>
17 changes: 17 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Aurelia } from 'aurelia-framework';
import { Router, RouterConfiguration } from 'aurelia-router';

export class App {
router: Router;

configureRouter(config: RouterConfiguration, router: Router) {
config.title = 'Aurelia';
config.map([
{ route: ['', 'home'], name: 'home', settings: {icon: 'home'}, moduleId: '../home/home', nav: true, title: 'Home' },
{ route: 'counter', name: 'counter', settings: {icon: 'education'}, moduleId: '../counter/counter', nav: true, title: 'Counter' },
{ route: 'fetch-data', name: 'fetchdata', settings: {icon: 'th-list'}, moduleId: '../fetchdata/fetchdata', nav: true, title: 'Fetch data' }
]);
this.router = router;
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 18 seems like unnecessary whitespace, then there's a missing trailing linebreak.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<h2>Counter</h2>

<p>This is a simple example of an Aurelia component.</p>

<p>Current count: <strong>${currentCount}</strong></p>

<button click.delegate="incrementCounter()">Increment</button>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Counter {
public currentCount = 0;

public incrementCounter() {
this.currentCount++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent quotes and ${ spacing } in this file

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

<p if.bind="!forecasts"><em>Loading...</em></p>

<table if.bind="forecasts" class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
<tr repeat.for="forecast of forecasts">
<td>${ forecast.dateFormatted }</td>
<td>${ forecast.temperatureC }</td>
<td>${ forecast.temperatureF }</td>
<td>${ forecast.summary }</td>
</tr>
</tbody>
</table>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference path="../../../../node_modules/aurelia-fetch-client/doc/whatwg-fetch.d.ts" />
/// <reference path="../../../../node_modules/aurelia-fetch-client/doc/url.d.ts" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that these are necessary. Has the underlying issue in Aurelia been reported? Is there any chance of getting a fix published?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't have anything to do with Aurelia as far as I know. They are standards that TypeScript is missing for some reason. However, I don't think that reference comments should be needed either way.

Copy link
Member

@SteveSandersonMS SteveSandersonMS Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EisenbergEffect I think @kmkatsma was saying they are needed because aurelia-fetch-client currently contains an incorrect .d.ts file. Not sure though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as we know, there's nothing incorrect in our dts. It's just that we use the Fetch spec which relies on the there being dts for fetch and url. Those should be provided by TS because they are standards, but they aren't, so you have to include your own. If there's something we need to fix on our side, we're happy to do it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, OK, that makes sense!

@kmkatsma In that case, the solution may be to reference whatwg-fetch from types in tsconfig.json, just like we do in the Knockout and ReactRedux templates. Then you should be able to remove these /// <reference> lines and have it still build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in general the change in type references for TS 2.0 was something I only realized this Saturday as I was cleaning up some things. Will look at.

import { HttpClient } from 'aurelia-fetch-client';
import { inject } from 'aurelia-framework';

@inject(HttpClient)
export class Fetchdata {
public forecasts: WeatherForecast[];
http: HttpClient;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why store this as a member property? It doesn't seem to be used anywhere outside the constructor.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I do find this entire class to be odd. I usually discourage making AJAX requests in a constructor function. Is this the way that other templates do it as well? Usually, a better practice is to have a service abstraction or "repository" type class that encapsulates the use of the http client and provides a simple method such as getForecast() to get the data. Internally, the method can cache that data if it wants to but it would always return a promise for consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EisenbergEffect It's the simplicity/extensibility tradeoff. In the Angular/Knockout/React templates we've followed this exact approach, as we're trying to make the templates accessible to newcompers and limit the concept count. People who get into using one of those frameworks won't struggle to create a service layer. In the ReactRedux template, we do the whole Redux thing which is a whole extra level of sophistication, but that's just fundamental to doing Redux. I think for this Aurelia template it's a reasonable choice of simplicity vs extensibility already, but we could change it if you think it's just flat out bad.


constructor(http: HttpClient) {
http.fetch('/api/SampleData/WeatherForecasts')
.then(result => result.json())
.then(data => {
this.forecasts = data;
});
}
}

interface WeatherForecast {
dateFormatted: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
16 changes: 16 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/home/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is about the Angular 2 template. Could you update it?

<h1>Hello, world!</h1>
<p>Welcome to your new single-page application, built with:</p>
<ul>
<li><a href="https://get.asp.net/">ASP.NET Core</a> and <a href="https://msdn.microsoft.com/en-us/library/67ef8sbd.aspx">C#</a> for cross-platform server-side code</li>
<li><a href="https://aurelia.io/">Aurelia</a> and <a href="http://www.typescriptlang.org/">TypeScript</a> for client-side code</li>
<li><a href="https://webpack.github.io/">Webpack</a> for building and bundling client-side resources</li>
<li><a href="http://getbootstrap.com/">Bootstrap</a> for layout and styling</li>
</ul>
<p>To help you get started, we've also set up:</p>
<ul>
<li><strong>Client-side navigation</strong>. For example, click <em>Counter</em> then <em>Back</em> to return here.</li>
<li><strong>Webpack dev middleware</strong>. In development mode, there's no need to run the <code>webpack</code> build tool. Your client-side resources are dynamically built on demand. Updates are available as soon as you modify any file.</li>
<li><strong>Efficient production builds</strong>. In production mode, development-time features are disabled, and the <code>webpack</code> build tool produces minified static CSS and JavaScript files.</li>
</ul>
</template>
2 changes: 2 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/home/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class Home {
}
59 changes: 59 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/navmenu/navmenu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
li .glyphicon {
margin-right: 10px;
}

/* Highlighting rules for nav menu items */
li.au-target.link-active a,
li.au-target.link-active a:hover,
li.au-target.link-active a:focus {
background-color: #4189C7;
color: white;
}

/* Keep the nav menu independent of scrolling and on top of other items */
.main-nav {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1;
}

@media (min-width: 768px) {
/* On small screens, convert the nav menu to a vertical sidebar */
.main-nav {
height: 100%;
width: calc(25% - 20px);
}
.navbar {
border-radius: 0px;
border-width: 0px;
height: 100%;
}
.navbar-header {
float: none;
}
.navbar-collapse {
border-top: 1px solid #444;
padding: 0px;
}
.navbar ul {
float: none;
}
.navbar li {
float: none;
font-size: 15px;
margin: 6px;
}
.navbar li a {
padding: 10px 16px;
border-radius: 4px;
}
.navbar a {
/* If a menu item's text is too long, truncate it */
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
26 changes: 26 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/navmenu/navmenu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template bindable="router">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent quotes in this file

<require from="./navmenu.css"></require>
<div class="main-nav">
<div class="navbar navbar-inverse">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#/home">Aurelia</a>
</div>
<div class="clearfix"></div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li repeat.for = "row of router.navigation" class="${ row.isActive ? 'link-active' : '' }" >
<a href.bind = "row.href">
<span class="glyphicon glyphicon-${ row.settings.icon }"></span> ${ row.title }
</a>
</li>
</ul>
</div>
</div>
</div>
</template>
11 changes: 11 additions & 0 deletions templates/AureliaSpa/ClientApp/boot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Aurelia } from 'aurelia-framework';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap';

export function configure(aurelia: Aurelia) {
aurelia.use.standardConfiguration();
if (window.location.host.includes('localhost')) {
aurelia.use.developmentLogging();
}
aurelia.start().then(() => aurelia.setRoot('app/components/app/app'));
}
21 changes: 21 additions & 0 deletions templates/AureliaSpa/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationBasic.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult Error()
{
return View();
}
}
}
44 changes: 44 additions & 0 deletions templates/AureliaSpa/Controllers/SampleDataController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationBasic.Controllers
{
[Route("api/[controller]")]
public class SampleDataController : Controller
{
private static string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

[HttpGet("[action]")]
public IEnumerable<WeatherForecast> WeatherForecasts()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
});
}

public class WeatherForecast
{
public string DateFormatted { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }

public int TemperatureF
{
get
{
return 32 + (int)(this.TemperatureC / 0.5556);
}
}
}
}
}
17 changes: 17 additions & 0 deletions templates/AureliaSpa/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM microsoft/dotnet:1.0.0-preview2-onbuild

RUN apt-get update
RUN wget -qO- https://deb.nodesource.com/setup_4.x | bash -
RUN apt-get install -y build-essential nodejs

WORKDIR /app

COPY project.json .
RUN ["dotnet", "restore"]

COPY . /app
RUN ["dotnet", "build"]

EXPOSE 5000/tcp

ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]
31 changes: 31 additions & 0 deletions templates/AureliaSpa/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

namespace WebApplicationBasic
{
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();

var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
Loading