mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
removed unused modules
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
@@ -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, '/');
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
}
|
@@ -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 {
|
||||
|
||||
}
|
@@ -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
|
||||
|
||||
}
|
@@ -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 {
|
||||
|
||||
}
|
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -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>;
|
||||
|
||||
}
|
@@ -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 {
|
||||
|
||||
}
|
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { TransferHttp } from './transfer-http';
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
TransferHttp
|
||||
]
|
||||
})
|
||||
export class TransferHttpModule {
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user