removed unused modules

This commit is contained in:
William Welling
2017-09-29 20:44:11 -05:00
parent 81b2bff13e
commit 5b0dbfbc37
20 changed files with 10 additions and 366 deletions

View File

@@ -1,13 +0,0 @@
import { NgModule } from '@angular/core';
import { Cookies } from './cookies';
import { BrowserCookies } from './browser-cookies';
@NgModule({
providers: [
{ provide: Cookies, useClass: BrowserCookies }
]
})
export class BrowserCookiesModule {
}

View File

@@ -1,34 +0,0 @@
import { Injectable } from '@angular/core';
import { Cookies } from './cookies';
@Injectable()
export class BrowserCookies implements Cookies {
// TODO: improve - set domain from configuration value or ui baseUrl
set(name: string, value: string, days: number, path?: string): void {
const date: Date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires: string = 'expires=' + date.toUTCString();
window.document.cookie = [name, '=', value, '; ', expires, path ? '; path=' + path : ''].join('');
}
get(name: string): string {
const cookies: string[] = window.document.cookie.split(';');
let cookie: string;
for (const cc of cookies) {
const c: string = cc.replace(/^\s\+/g, '');
if (c.indexOf(name + '=') === 0) {
cookie = c.substring(name.length + 1, c.length);
break;
}
}
return cookie;
}
// TODO: set path from environment configuration
remove(name: string): void {
this.set(name, '', 0, '/');
}
}

View File

@@ -1,9 +0,0 @@
export abstract class Cookies {
abstract set(name: string, value: string, days: number, path?: string): void;
abstract get(name: string): string;
abstract remove(name: string): void;
}

View File

@@ -1,13 +0,0 @@
import { NgModule } from '@angular/core';
import { Cookies } from './cookies';
import { ServerCookies } from './server-cookies';
@NgModule({
providers: [
{ provide: Cookies, useClass: ServerCookies }
]
})
export class ServerCookiesModule {
}

View File

@@ -1,24 +0,0 @@
import { Injectable } from '@angular/core';
import { Cookies } from './cookies';
@Injectable()
export class ServerCookies implements Cookies {
// tslint:disable:no-empty
set(name: string, value: string, days: number, path?: string): void {
}
// tslint:enable:no-empty
get(name: string): string {
return undefined;
}
// tslint:disable:no-empty
remove(name: string): void {
}
// tslint:enable:no-empty
}

View File

@@ -1,13 +0,0 @@
import { NgModule } from '@angular/core';
import { DataLoader } from './data-loader';
import { BrowserDataLoader } from './browser-data-loader';
@NgModule({
providers: [
{ provide: DataLoader, useClass: BrowserDataLoader }
]
})
export class BrowserDataLoaderModule {
}

View File

@@ -1,27 +0,0 @@
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { DataLoader } from './data-loader';
@Injectable()
export class BrowserDataLoader extends DataLoader {
protected prefix: string;
protected suffix: string;
constructor(private http: Http) {
super();
this.prefix = 'assets/data';
this.suffix = '.json';
}
public getData(name: string): Observable<any> {
return this.http.get(`${this.prefix}/${this.language}/${name}${this.suffix}`, {}).map((response: Response) => {
return response.json();
});
}
}

View File

@@ -1,21 +0,0 @@
import { Observable } from 'rxjs/Observable';
export abstract class DataLoader {
protected language: string;
protected abstract prefix: string;
protected abstract suffix: string;
constructor() {
this.language = 'en';
}
public setLanguage(language: string): void {
this.language = language;
}
abstract getData(name: string): Observable<any>;
}

View File

@@ -1,13 +0,0 @@
import { NgModule } from '@angular/core';
import { DataLoader } from './data-loader';
import { ServerDataLoader } from './server-data-loader';
@NgModule({
providers: [
{ provide: DataLoader, useClass: ServerDataLoader }
]
})
export class ServerDataLoaderModule {
}

View File

@@ -1,28 +0,0 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import * as fs from 'fs';
import { DataLoader } from './data-loader';
@Injectable()
export class ServerDataLoader extends DataLoader {
protected prefix: string;
protected suffix: string;
constructor() {
super();
this.prefix = 'dist/assets/data';
this.suffix = '.json';
}
public getData(name: string): Observable<any> {
return Observable.create((observer: any) => {
observer.next(JSON.parse(fs.readFileSync(`${this.prefix}/${this.language}/${name}${this.suffix}`, 'utf8')));
observer.complete();
});
}
}

View File

@@ -1,12 +0,0 @@
import { NgModule } from '@angular/core';
import { TransferHttp } from './transfer-http';
@NgModule({
providers: [
TransferHttp
]
})
export class TransferHttpModule {
}

View File

@@ -1,132 +0,0 @@
import { Injectable } from '@angular/core';
import { ConnectionBackend, Http, Request, RequestOptions, RequestOptionsArgs, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { TransferState } from '../transfer-state/transfer-state';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/observable/of';
@Injectable()
export class TransferHttp {
constructor(private http: Http, protected transferState: TransferState) { }
request(uri: string | Request, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(uri, options, (url: string, options: RequestOptionsArgs) => {
return this.http.request(url, options);
});
}
get(url: string, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(url, options, (url: string, options: RequestOptionsArgs) => {
return this.http.get(url, options);
});
}
post(url: string, body: any, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getPostData(url, body, options, (url: string, body: any, options: RequestOptionsArgs) => {
return this.http.post(url, body, options);
});
}
put(url: string, body: any, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(url, options, (url: string, options: RequestOptionsArgs) => {
return this.http.put(url, options);
});
}
delete(url: string, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(url, options, (url: string, options: RequestOptionsArgs) => {
return this.http.delete(url, options);
});
}
patch(url: string, body: any, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getPostData(url, body, options, (url: string, body: any, options: RequestOptionsArgs) => {
return this.http.patch(url, body, options);
});
}
head(url: string, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(url, options, (url: string, options: RequestOptionsArgs) => {
return this.http.head(url, options);
});
}
options(url: string, options?: RequestOptionsArgs): Observable<any> {
// tslint:disable-next-line:no-shadowed-variable
return this.getData(url, options, (url: string, options: RequestOptionsArgs) => {
return this.http.options(url, options);
});
}
// tslint:disable-next-line:max-line-length
private getData(uri: string | Request, options: RequestOptionsArgs, callback: (uri: string | Request, options?: RequestOptionsArgs) => Observable<Response>) {
let url = uri;
if (typeof uri !== 'string') {
url = uri.url;
}
const key = url + JSON.stringify(options);
try {
return this.resolveData(key);
} catch (e) {
return callback(uri, options)
.map((res: Response) => res.json())
.do((data: any) => {
this.setCache(key, data);
});
}
}
private getPostData(uri: string | Request, body: any, options: RequestOptionsArgs, callback: (uri: string | Request, body: any, options?: RequestOptionsArgs) => Observable<Response>) {
let url = uri;
if (typeof uri !== 'string') {
url = uri.url;
}
const key = url + JSON.stringify(body) + JSON.stringify(options);
try {
return this.resolveData(key);
} catch (e) {
return callback(uri, body, options)
.map((res: Response) => res.json())
.do((data: any) => {
this.setCache(key, data);
});
}
}
private resolveData(key: string) {
const data = this.getFromCache(key);
if (!data) {
throw new Error();
}
return Observable.of(data);
}
private setCache(key, data) {
return this.transferState.set(key, data);
}
private getFromCache(key): any {
return this.transferState.get(key);
}
}