chore: remove deprecated router 1/2

This commit is contained in:
Misko Hevery
2016-08-09 11:48:05 -07:00
committed by Alex Rickabaugh
parent beadf6167a
commit a20a420be6
88 changed files with 0 additions and 12963 deletions

View File

@ -1,51 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {verifyNoBrowserErrors} from 'e2e_util/e2e_util';
function waitForElement(selector: any /** TODO #9100 */) {
var EC = (<any>protractor).ExpectedConditions;
// Waits for the element with id 'abc' to be present on the dom.
browser.wait(EC.presenceOf($(selector)), 20000);
}
describe('hash routing example app', function() {
afterEach(verifyNoBrowserErrors);
var URL = 'all/playground/src/hash_routing/index.html';
it('should navigate between routes', function() {
browser.get(URL + '#/bye');
waitForElement('goodbye-cmp');
element(by.css('#hello-link')).click();
waitForElement('hello-cmp');
expect(element(by.css('hello-cmp')).getText()).toContain('hello');
browser.navigate().back();
waitForElement('goodbye-cmp');
expect(element(by.css('goodbye-cmp')).getText()).toContain('goodbye');
});
it('should open in new window if target is _blank', () => {
var URL = 'all/playground/src/hash_routing/index.html';
browser.get(URL + '#/');
waitForElement('hello-cmp');
element(by.css('#goodbye-link-blank')).click();
expect(browser.driver.getCurrentUrl()).not.toContain('#/bye');
browser.getAllWindowHandles().then(function(windows) {
browser.switchTo().window(windows[1]).then(function() {
expect(browser.driver.getCurrentUrl()).toContain('#/bye');
});
});
});
});

View File

@ -1,99 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {verifyNoBrowserErrors} from 'e2e_util/e2e_util';
function waitForElement(selector: any /** TODO #9100 */) {
var EC = (<any>protractor).ExpectedConditions;
// Waits for the element with id 'abc' to be present on the dom.
browser.wait(EC.presenceOf($(selector)), 20000);
}
describe('deprecated routing inbox-app', () => {
afterEach(verifyNoBrowserErrors);
describe('index view', () => {
var URL = 'all/playground/src/routing_deprecated/';
it('should list out the current collection of items', () => {
browser.get(URL);
waitForElement('.inbox-item-record');
expect(element.all(by.css('.inbox-item-record')).count()).toEqual(200);
});
it('should build a link which points to the detail page', () => {
browser.get(URL);
waitForElement('#item-15');
expect(element(by.css('#item-15')).getAttribute('href')).toMatch(/#\/detail\/15$/);
element(by.css('#item-15')).click();
waitForElement('#record-id');
expect(browser.getCurrentUrl()).toMatch(/\/detail\/15$/);
});
});
describe('drafts view', () => {
var URL = 'all/playground/src/routing_deprecated/#/drafts';
it('should navigate to the drafts view when the drafts link is clicked', () => {
browser.get(URL);
waitForElement('.inbox-item-record');
element(by.linkText('Drafts')).click();
waitForElement('.page-title');
expect(element(by.css('.page-title')).getText()).toEqual('Drafts');
});
it('should navigate to email details', () => {
browser.get(URL);
element(by.linkText('Drafts')).click();
waitForElement('.inbox-item-record');
expect(element.all(by.css('.inbox-item-record')).count()).toEqual(2);
expect(element(by.css('#item-201')).getAttribute('href')).toMatch(/#\/detail\/201$/);
element(by.css('#item-201')).click();
waitForElement('#record-id');
expect(browser.getCurrentUrl()).toMatch(/\/detail\/201$/);
});
});
describe('detail view', () => {
var URL = 'all/playground/src/routing_deprecated/';
it('should navigate to the detail view when an email is clicked', () => {
browser.get(URL);
waitForElement('#item-10');
element(by.css('#item-10')).click();
waitForElement('#record-id');
var recordId = element(by.css('#record-id'));
browser.wait(protractor.until.elementTextIs(recordId, 'ID: 10'), 5000);
expect(recordId.getText()).toEqual('ID: 10');
});
it('should navigate back to the email inbox page when the back button is clicked', () => {
browser.get(URL);
waitForElement('#item-10');
element(by.css('#item-10')).click();
waitForElement('.back-button');
element(by.css('.back-button')).click();
expect(browser.getCurrentUrl()).toMatch(/\/$/);
});
it('should navigate back to index and sort the page items based on the provided querystring param',
() => {
browser.get(URL);
waitForElement('#item-10');
element(by.css('#item-10')).click();
waitForElement('.sort-button');
element(by.css('.sort-button')).click();
expect(browser.getCurrentUrl()).toMatch(/\/#\?sort=date$/);
waitForElement('.inbox-item-record');
expect(element(by.css('.inbox-item-record > a')).getAttribute('id')).toEqual('item-137');
});
})
});

View File

@ -1,12 +0,0 @@
<!doctype html>
<html>
<title>Routing Example</title>
<base href="/all/playground/src/hash_routing/">
<body>
<example-app>
Loading...
</example-app>
<script src="../bootstrap.js"></script>
</body>
</html>

View File

@ -1,51 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {HashLocationStrategy, LocationStrategy} from '@angular/common';
import {Component} from '@angular/core';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Route, RouteConfig} from '@angular/router-deprecated';
@Component({selector: 'hello-cmp', template: `hello`})
class HelloCmp {
}
@Component({selector: 'goodbye-cmp', template: `goodbye`})
class GoodByeCmp {
}
@Component({
selector: 'example-app',
template: `
<h1>My App</h1>
<nav>
<a href="#/" id="hello-link">Navigate via href</a> |
<a [routerLink]="['/GoodbyeCmp']" id="goodbye-link">Navigate with Link DSL</a>
<a [routerLink]="['/GoodbyeCmp']" id="goodbye-link-blank" target="_blank">
Navigate with Link DSL _blank target
</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
new Route({path: '/', component: HelloCmp, name: 'HelloCmp'}),
new Route({path: '/bye', component: GoodByeCmp, name: 'GoodbyeCmp'})
])
class AppCmp {
}
export function main() {
bootstrap(
AppCmp, [ROUTER_PROVIDERS, {provide: LocationStrategy, useClass: HashLocationStrategy}]);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
<div>
<h2 class="page-title">Drafts</h2>
<ol class="inbox-list">
<li *ngFor="let item of items" class="inbox-item-record">
<a id="item-{{ item.id }}"
[routerLink]="['/DetailPage', {'id':item.id}]">
{{ item.subject }}</a>
</li>
</ol>
</div>

View File

@ -1,5 +0,0 @@
<inbox-side-menu class="inbox-aside">
<a [routerLink]="['/Inbox']" class="link" [class.active]="inboxPageActive()">Inbox</a>
<a [routerLink]="['/Drafts']" class="link" [class.active]="draftsPageActive()">Drafts</a>
</inbox-side-menu>
<router-outlet></router-outlet>

View File

@ -1,159 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Location} from '@angular/common';
import {Component, Injectable} from '@angular/core';
import {DateWrapper, isPresent} from '@angular/core/src/facade/lang';
import {Route, RouteConfig, RouteParams, Router, RouterLink, RouterOutlet} from '@angular/router-deprecated';
import * as db from './data';
class InboxRecord {
id: string = '';
subject: string = '';
content: string = '';
email: string = '';
firstName: string = '';
lastName: string = '';
date: string;
draft: boolean = false;
constructor(data: {
id: string,
subject: string,
content: string,
email: string,
firstName: string,
lastName: string,
date: string, draft?: boolean
} = null) {
if (isPresent(data)) {
this.setData(data);
}
}
setData(record: {
id: string,
subject: string,
content: string,
email: string,
firstName: string,
lastName: string,
date: string, draft?: boolean
}) {
this.id = record['id'];
this.subject = record['subject'];
this.content = record['content'];
this.email = record['email'];
this.firstName = (record as any /** TODO #9100 */)['first-name'];
this.lastName = (record as any /** TODO #9100 */)['last-name'];
this.date = record['date'];
this.draft = record['draft'] == true;
}
}
@Injectable()
class DbService {
getData(): Promise<any[]> { return Promise.resolve(db.data); }
drafts(): Promise<any[]> {
return this.getData().then(
(data: any[]): any[] =>
data.filter(record => isPresent(record['draft']) && record['draft'] == true));
}
emails(): Promise<any[]> {
return this.getData().then(
(data: any[]): any[] => data.filter(record => !isPresent(record['draft'])));
}
email(id: any /** TODO #9100 */): Promise<any> {
return this.getData().then((data: any[]) => {
for (var i = 0; i < data.length; i++) {
var entry = data[i];
if (entry['id'] == id) {
return entry;
}
}
return null;
});
}
}
@Component(
{selector: 'inbox-detail', directives: [RouterLink], templateUrl: 'app/inbox-detail.html'})
class InboxDetailCmp {
record: InboxRecord = new InboxRecord();
ready: boolean = false;
constructor(db: DbService, params: RouteParams) {
var id = params.get('id');
db.email(id).then((data) => { this.record.setData(data); });
}
}
@Component({selector: 'inbox', templateUrl: 'app/inbox.html', directives: [RouterLink]})
class InboxCmp {
items: InboxRecord[] = [];
ready: boolean = false;
constructor(public router: Router, db: DbService, params: RouteParams) {
var sortType = params.get('sort');
var sortEmailsByDate = isPresent(sortType) && sortType == 'date';
db.emails().then((emails: any[]) => {
this.ready = true;
this.items = emails.map(data => new InboxRecord(data));
if (sortEmailsByDate) {
this.items.sort(
(a: InboxRecord, b: InboxRecord) =>
DateWrapper.toMillis(DateWrapper.fromISOString(a.date)) <
DateWrapper.toMillis(DateWrapper.fromISOString(b.date)) ?
-1 :
1);
}
});
}
}
@Component({selector: 'drafts', templateUrl: 'app/drafts.html', directives: [RouterLink]})
class DraftsCmp {
items: InboxRecord[] = [];
ready: boolean = false;
constructor(public router: Router, db: DbService) {
db.drafts().then((drafts: any[]) => {
this.ready = true;
this.items = drafts.map(data => new InboxRecord(data));
});
}
}
@Component({
selector: 'inbox-app',
viewProviders: [DbService],
templateUrl: 'app/inbox-app.html',
directives: [RouterOutlet, RouterLink]
})
@RouteConfig([
new Route({path: '/', component: InboxCmp, name: 'Inbox'}),
new Route({path: '/drafts', component: DraftsCmp, name: 'Drafts'}),
new Route({path: '/detail/:id', component: InboxDetailCmp, name: 'DetailPage'})
])
export class InboxApp {
router: Router;
location: Location;
constructor(router: Router, location: Location) {
this.router = router;
this.location = location;
}
inboxPageActive() { return this.location.path() == ''; }
draftsPageActive() { return this.location.path() == '/drafts'; }
}

View File

@ -1,24 +0,0 @@
<div>
<h2 class="page-title">{{ record.subject }}</h2>
<ul>
<li id="record-id">ID: {{ record.id }}</li>
<li id="record-name">Name: {{ record.firstName }} {{ record.lastName }}</li>
<li id="record-email">Email: {{ record.email }}</li>
<li id="record-date">Date: {{ record.date }}</li>
</ul>
<p>
{{ record.content }}
</p>
<span class="btn medium primary">
<a [routerLink]="record.draft ? ['../Drafts'] : ['../Inbox']" class="back-button">Back</a>
</span>
<hr />
<a [routerLink]="['../Inbox', { sort: 'date'} ]" class="sort-button">
View Latest Messages
</a>
</div>

View File

@ -1,10 +0,0 @@
<div>
<h2 class="page-title">Inbox</h2>
<ol class="inbox-list">
<li *ngFor="let item of items" class="inbox-item-record">
<a id="item-{{ item.id }}"
[routerLink]="['/DetailPage', {'id':item.id}]">{{ item.subject }}</a>
</li>
</ol>
</div>

View File

@ -1,57 +0,0 @@
body {
background:#eee;
color:black;
}
.inbox-list,
.inbox-list li {
list-style:none;
padding:0;
margin:0;
}
.inbox-list a {
padding:5px;
display:block;
}
inbox, drafts, inbox-side-menu {
display:block;
}
inbox-side-menu .link {
display:block;
text-align:center;
padding:1em;
}
inbox-side-menu .link.active {
background:white;
}
inbox-side-menu .link:hover {
background:#eee;
}
inbox-side-menu {
position:fixed;
left:0;
top:0;
bottom:0;
width:200px;
background:#ddd;
}
inbox-side-menu a {
display: block;
}
inbox, drafts, inbox-detail {
padding:1em;
margin-left:200px;
}
inbox-detail {
display:block;
margin-left:200px;
}

View File

@ -1,14 +0,0 @@
<!doctype html>
<html>
<title>Routing Example</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/gumby/2.6.0/css/gumby.css" />
<link rel="stylesheet" type="text/css" href="./css/app.css" />
<base href="/all/playground/src/routing_deprecated/">
<body>
<inbox-app>
Loading...
</inbox-app>
<script src="../bootstrap.js"></script>
</body>
</html>

View File

@ -1,18 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {HashLocationStrategy, LocationStrategy} from '@angular/common';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {InboxApp} from './app/inbox-app';
export function main() {
bootstrap(
InboxApp, [ROUTER_PROVIDERS, {provide: LocationStrategy, useClass: HashLocationStrategy}]);
}