-
-
Save DavidGangel/dd9d5da245784a9a5fa8 to your computer and use it in GitHub Desktop.
App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
skins.ts: | |
/// <reference path="../../custom_typings/_custom.d.ts" /> | |
import { Component, View } from 'angular2/angular2'; | |
import { ROUTER_DIRECTIVES } from 'angular2/router'; | |
import { RouterManagerService } from '../../services/router/router_manager_service'; | |
import { RestManagerService } from '../../services/rest/rest_manager_service'; | |
@Component({ | |
selector: 'skins' | |
}) | |
@View({ | |
directives: [ ROUTER_DIRECTIVES ], | |
templateUrl: "./components/app/skins.html" | |
}) | |
// Component controller | |
export class Skins { | |
restManager: RestManagerService; | |
routerManager: RouterManagerService; | |
constructor(restManager:RestManagerService, routerManager:RouterManagerService) { | |
this.restManager = restManager; | |
this.routerManager = routerManager; | |
} | |
onInit() { | |
var promise = this.restManager.getSiteMapConfiguration(); | |
promise.then((data) => { this.routerManager.configureRootRouter(data) }); | |
} | |
} | |
--------------------- | |
router_manager_service.ts | |
/// <reference path="../../custom_typings/_custom.d.ts" /> | |
import { RouteDefinition, Router, Route, RouteConfig,ComponentDefinition } from 'angular2/router'; | |
import { Injectable, Dependency } from 'angular2/di'; | |
import { IRouterManagerService } from 'router_manager_service_interface'; | |
import { RestManagerService } from '../rest/rest_manager_service'; | |
import { SiteMapItem } from '../rest/sitemap/sitemap_item'; | |
import { Home } from '../../components/home/home'; | |
import { Prices } from '../../components/prices/prices'; | |
import { AboutUs } from '../../components/aboutus/aboutus'; | |
import { Products } from '../../components/products/products'; | |
@Injectable() | |
export class RouterManagerService/* implements IRouterManagerService*/ { | |
private router: Router; | |
constructor(router: Router) { | |
this.router = router; | |
} | |
configureRootRouter(data) { | |
console.log(1, 'success', data); | |
this.router.config([ | |
{ path: '/', component: Home, as: 'home' }, | |
{ path: '/services/website-development/personal', component: Products, as: 'products'}, | |
{ path: '/prices/website-development/personal', component: Prices, as: 'prices'}, | |
{ path: '/company/own/aboutus', component: AboutUs, as: 'aboutus'} | |
]); | |
} | |
} | |
----------- | |
rest_manager_service.ts: | |
/// <reference path="../../custom_typings/_custom.d.ts" /> | |
import { HTTP_BINDINGS, Http } from 'angular2/http'; | |
import { Injectable } from 'angular2/di'; | |
import { IRestManagerService } from 'rest_manager_service_interface'; | |
import { SiteMapItem } from './sitemap/sitemap_item'; | |
@Injectable() | |
export class RestManagerService { | |
private static REST_API_ENDPOINT: String ="./plainrestservice"; | |
private static REQUEST_SITE_MAP: String = RestManagerService.REST_API_ENDPOINT+"/Sitemap"; | |
private http: Http; | |
constructor(http: Http) { | |
this.http = http; | |
} | |
/* | |
public createPromise() { | |
return new Promise((success) => { this.getSiteMapConfiguration() }) | |
} | |
*/ | |
public getSiteMapConfiguration() { | |
return new Promise((success) => { | |
this.http.get(RestManagerService.REQUEST_SITE_MAP.toString()) | |
.toRx() | |
.map(res => res.json()) | |
.subscribe((res) => { | |
console.log("Records fetched from the backend."); | |
var result:Array<SiteMapItem> = new Array<SiteMapItem>(); | |
result = res.map((siteMapItem) => { | |
return new SiteMapItem( | |
siteMapItem.siteMapItemName, | |
siteMapItem.parameters, | |
siteMapItem.childSiteMapItems | |
); | |
}); | |
success(result); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment