Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
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>Angular2</RootNamespace>
Copy link
Member

Choose a reason for hiding this comment

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

Please update this

<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>
Copy link
Member

Choose a reason for hiding this comment

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

Missing trailing linebreak which is present in most files. Could you add one here and to any other TS/JS/HTML/CSS file where it's missing?

19 changes: 19 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Aurelia} from 'aurelia-framework';
Copy link
Member

Choose a reason for hiding this comment

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

Some few formatting issues in this file:

  • missing spaces around { ImportedModule }
  • The config.map object looks pretty strange. Not sure if you were trying to line things up with tabs or something, but it's not lined up now. Also some of the key-value pairs have spaces after the colon and others don't. Could you lay this code out more conventionally?
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:{class:'home'}, moduleId: '../home/home', nav: true, title: 'Home' },
Copy link
Member

Choose a reason for hiding this comment

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

The use of the term class here is a bit odd. I'd naturally think that refers to a class in the code, but it looks like you're using that to mean "CSS class we should set on the icon element". Could you rename this to something more descriptive, such as icon or icon-className?

Choose a reason for hiding this comment

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

Prefer icon.

{ route: 'counter', name: 'counter', settings:{class:'education'}, moduleId: '../counter/counter', nav: true, title: 'Counter' },
{ route: 'fetch-data', name: 'fetchdata', settings:{class:'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,9 @@

Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary blank lines on line 1 and 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 class='table' if.bind="forecasts">
<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,27 @@
/// <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) {
this.http = http;
this.http.fetch('/api/SampleData/WeatherForecasts')
.then(result => result.json())
.then(data => {
this.forecasts = data;
});
}
}

interface WeatherForecast {
dateFormatted: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
18 changes: 18 additions & 0 deletions templates/AureliaSpa/ClientApp/app/components/home/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<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://angular.io/'>Angular 2</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>Server-side prerendering</strong>. For faster initial loading and improved SEO, your Angular 2 app is prerendered on the server. The resulting HTML is then transferred to the browser where a client-side copy of the app takes over.</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>Hot module replacement</strong>. In development mode, you don't even need to reload the page after making most changes. Within seconds of saving changes to files, your Angular 2 app will be rebuilt and a new instance injected is into the page.</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 class="${row.isActive ? 'link-active' : ''}" repeat.for = "row of router.navigation" >

Choose a reason for hiding this comment

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

For clarity, I would put the repeat.for first on the li, before the class binding.

<a href.bind = "row.href">
<span class='glyphicon glyphicon-${row.settings.class}'></span> ${row.title}
</a>
</li>
</ul>
</div>
</div>
</div>
</template>
15 changes: 15 additions & 0 deletions templates/AureliaSpa/ClientApp/boot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Aurelia} from 'aurelia-framework';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap';

// comment out if you don't want a Promise polyfill (remove also from webpack.config.js)
Copy link
Member

Choose a reason for hiding this comment

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

TBH I'd prefer not to include bluebird in the template, just because the template would be a little simpler without it. People can add their own choice of promise library if they want.

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, will drop

import * as Bluebird from 'bluebird';
Copy link
Member

Choose a reason for hiding this comment

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

Layout issues in this file (e.g., double-whitespace on line 1, uses two-char indentation elsewhere when we use four-char in all the other templates).

Bluebird.config({ warnings: false });

export function configure(aurelia: Aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
Copy link
Member

Choose a reason for hiding this comment

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

Can you adapt this so that the developmentLogging only happens from dev builds and not from prod builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I'll add a check for localhost in window location to decide whether to enable logging. Couldn't find a better suggestion not relying on a gulp task to actually edit code (that's what I've used in past). Only happens when app is loading so doesn't seem too bad.


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);
}
}
}
}
}
16 changes: 16 additions & 0 deletions templates/AureliaSpa/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM microsoft/dotnet:latest
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 slightly out of date (compared with the other templates). Would you be able to update it, e.g., based on https://github.com/aspnet/JavaScriptServices/blob/dev/templates/Angular2Spa/Dockerfile?


RUN apt-get update
RUN apt-get install -y build-essential nodejs nodejs-legacy

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