mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 13:33:03 +00:00
Merge pull request #214 from artlowel/angular5-upgrade
Angular5 upgrade
This commit is contained in:
@@ -52,7 +52,7 @@ describe('CollectionGridElementComponent', () => {
|
||||
|
||||
if (mockCollection.shortDescription.length > 0) {
|
||||
expect(descriptionText).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(descriptionText).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -59,7 +59,7 @@ describe('CommunityGridElementComponent', () => {
|
||||
|
||||
if (mockCommunity.shortDescription.length > 0) {
|
||||
expect(descriptionText).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(descriptionText).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -59,7 +59,7 @@ describe('ItemGridElementComponent', () => {
|
||||
|
||||
if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) {
|
||||
expect(itemAuthorField).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(itemAuthorField).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -57,7 +57,7 @@ describe('CollectionSearchResultGridElementComponent', () => {
|
||||
|
||||
if (mockCollection.shortDescription.length > 0) {
|
||||
expect(descriptionText).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(descriptionText).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -56,7 +56,7 @@ describe('CommunitySearchResultGridElementComponent', () => {
|
||||
|
||||
if (mockCommunity.shortDescription.length > 0) {
|
||||
expect(descriptionText).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(descriptionText).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -62,7 +62,7 @@ describe('ItemSearchResultGridElementComponent', () => {
|
||||
|
||||
if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) {
|
||||
expect(itemAuthorField).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(itemAuthorField).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
@@ -72,7 +72,7 @@ describe('ItemSearchResultGridElementComponent', () => {
|
||||
|
||||
if (mockItem.findMetadata('dc.date.issued').length > 0) {
|
||||
expect(dateField).toBeDefined();
|
||||
}else {
|
||||
} else {
|
||||
expect(dateField).not.toBeDefined();
|
||||
}
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core';
|
||||
import { Component, Injector, Input, OnInit } from '@angular/core';
|
||||
import { ViewMode } from '../../../+search-page/search-options.model';
|
||||
import { GenericConstructor } from '../../../core/shared/generic-constructor';
|
||||
import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator';
|
||||
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||
import { ViewMode } from '../../../+search-page/search-options.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-wrapper-grid-element',
|
||||
@@ -13,11 +13,14 @@ export class WrapperGridElementComponent implements OnInit {
|
||||
@Input() object: ListableObject;
|
||||
objectInjector: Injector;
|
||||
|
||||
constructor(private injector: Injector) {}
|
||||
constructor(private injector: Injector) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.objectInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector);
|
||||
this.objectInjector = Injector.create({
|
||||
providers: [{ provide: 'objectElementProvider', useFactory: () => (this.object), deps:[] }],
|
||||
parent: this.injector
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core';
|
||||
import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'
|
||||
import { GenericConstructor } from '../../../core/shared/generic-constructor';
|
||||
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||
import { Component, Injector, Input, OnInit } from '@angular/core';
|
||||
import { ViewMode } from '../../../+search-page/search-options.model';
|
||||
import { GenericConstructor } from '../../../core/shared/generic-constructor';
|
||||
import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'
|
||||
import { ListableObject } from '../../object-collection/shared/listable-object.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-wrapper-list-element',
|
||||
@@ -16,8 +16,10 @@ export class WrapperListElementComponent implements OnInit {
|
||||
constructor(private injector: Injector) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.objectInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector);
|
||||
this.objectInjector = Injector.create({
|
||||
providers: [{ provide: 'objectElementProvider', useFactory: () => (this.object), deps:[] }],
|
||||
parent: this.injector
|
||||
});
|
||||
}
|
||||
|
||||
getListElement(): string {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { OpaqueToken } from '@angular/core';
|
||||
import { InjectionToken } from '@angular/core';
|
||||
|
||||
export const NativeWindowService = new OpaqueToken('NativeWindowService');
|
||||
export const NativeWindowService = new InjectionToken('NativeWindowService');
|
||||
|
||||
export class NativeWindowRef {
|
||||
get nativeWindow(): any {
|
||||
|
4
src/main.server.aot.ts
Normal file
4
src/main.server.aot.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { startServer } from './server';
|
||||
import { ServerAppModuleNgFactory } from './modules/app/server-app.module.ngfactory';
|
||||
|
||||
startServer(ServerAppModuleNgFactory);
|
@@ -1,134 +1,4 @@
|
||||
import 'zone.js/dist/zone-node';
|
||||
import 'reflect-metadata';
|
||||
import 'rxjs/Rx';
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as pem from 'pem';
|
||||
import * as https from 'https';
|
||||
import * as morgan from 'morgan';
|
||||
import * as express from 'express';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import * as compression from 'compression';
|
||||
import * as cookieParser from 'cookie-parser';
|
||||
|
||||
import { enableProdMode } from '@angular/core';
|
||||
|
||||
import { ngExpressEngine } from '@nguniversal/express-engine';
|
||||
|
||||
import { startServer } from './server';
|
||||
import { ServerAppModule } from './modules/app/server-app.module';
|
||||
|
||||
import { ROUTES } from './routes';
|
||||
import { ENV_CONFIG } from './config';
|
||||
|
||||
const app = express();
|
||||
|
||||
const port = ENV_CONFIG.ui.port ? ENV_CONFIG.ui.port : 80;
|
||||
|
||||
if (ENV_CONFIG.production) {
|
||||
enableProdMode();
|
||||
app.use(compression());
|
||||
}
|
||||
|
||||
app.use(morgan('dev'));
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.engine('html', ngExpressEngine({
|
||||
bootstrap: ServerAppModule
|
||||
}));
|
||||
|
||||
app.set('view engine', 'html');
|
||||
app.set('views', 'src');
|
||||
|
||||
function cacheControl(req, res, next) {
|
||||
// instruct browser to revalidate
|
||||
res.header('Cache-Control', ENV_CONFIG.cache.control || 'max-age=60');
|
||||
next();
|
||||
}
|
||||
|
||||
app.use('/', cacheControl, express.static('dist', { index: false }));
|
||||
|
||||
// TODO: either remove or update mock backend
|
||||
// app.get('/data.json', serverApi);
|
||||
// app.use('/api', createMockApi());
|
||||
|
||||
function ngApp(req, res) {
|
||||
|
||||
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
|
||||
console.warn('Error in SSR, serving for direct CSR');
|
||||
res.sendFile('index.csr.html', { root: './src' });
|
||||
}
|
||||
|
||||
if (ENV_CONFIG.universal.preboot) {
|
||||
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
|
||||
res.render('../dist/index', {
|
||||
req,
|
||||
res,
|
||||
preboot: ENV_CONFIG.universal.preboot,
|
||||
async: ENV_CONFIG.universal.async,
|
||||
time: ENV_CONFIG.universal.time,
|
||||
baseUrl: ENV_CONFIG.ui.nameSpace,
|
||||
originUrl: ENV_CONFIG.ui.baseUrl,
|
||||
requestUrl: req.originalUrl
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('Universal off, serving for direct CSR');
|
||||
res.sendFile('index.csr.html', { root: './src' });
|
||||
}
|
||||
}
|
||||
|
||||
ROUTES.forEach((route: string) => {
|
||||
app.get(route, ngApp);
|
||||
});
|
||||
|
||||
function serverStarted() {
|
||||
console.log(`[${new Date().toTimeString()}] Listening at ${ENV_CONFIG.ui.baseUrl}`);
|
||||
}
|
||||
|
||||
function createHttpsServer(keys) {
|
||||
https.createServer({
|
||||
key: keys.serviceKey,
|
||||
cert: keys.certificate
|
||||
}, app).listen(port, ENV_CONFIG.ui.host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
}
|
||||
|
||||
if (ENV_CONFIG.ui.ssl) {
|
||||
let serviceKey;
|
||||
try {
|
||||
serviceKey = fs.readFileSync('./config/ssl/key.pem');
|
||||
} catch (e) {
|
||||
console.warn('Service key not found at ./config/ssl/key.pem');
|
||||
}
|
||||
|
||||
let certificate;
|
||||
try {
|
||||
certificate = fs.readFileSync('./config/ssl/cert.pem');
|
||||
} catch (e) {
|
||||
console.warn('Certificate not found at ./config/ssl/key.pem');
|
||||
}
|
||||
|
||||
if (serviceKey && certificate) {
|
||||
createHttpsServer({
|
||||
serviceKey: serviceKey,
|
||||
certificate: certificate
|
||||
});
|
||||
} else {
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
|
||||
pem.createCertificate({
|
||||
days: 1,
|
||||
selfSigned: true
|
||||
}, (error, keys) => {
|
||||
createHttpsServer(keys);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
app.listen(port, ENV_CONFIG.ui.host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
}
|
||||
startServer(ServerAppModule);
|
||||
|
@@ -4,7 +4,7 @@ import { BrowserModule } from '@angular/platform-browser';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { IdlePreload, IdlePreloadModule } from '@angularclass/idle-preload';
|
||||
import { IdlePreload, IdlePreloadModule } from 'angular-idle-preload';
|
||||
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
|
133
src/server.ts
Normal file
133
src/server.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import 'zone.js/dist/zone-node';
|
||||
import 'reflect-metadata';
|
||||
import 'rxjs/Rx';
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as pem from 'pem';
|
||||
import * as https from 'https';
|
||||
import * as morgan from 'morgan';
|
||||
import * as express from 'express';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import * as compression from 'compression';
|
||||
import * as cookieParser from 'cookie-parser';
|
||||
|
||||
import { enableProdMode, NgModuleFactory, Type } from '@angular/core';
|
||||
|
||||
import { ngExpressEngine } from '@nguniversal/express-engine';
|
||||
|
||||
import { ROUTES } from './routes';
|
||||
import { ENV_CONFIG } from './config';
|
||||
|
||||
export function startServer(bootstrap: Type<{}> | NgModuleFactory<{}>) {
|
||||
const app = express();
|
||||
|
||||
const port = ENV_CONFIG.ui.port ? ENV_CONFIG.ui.port : 80;
|
||||
|
||||
if (ENV_CONFIG.production) {
|
||||
enableProdMode();
|
||||
app.use(compression());
|
||||
}
|
||||
|
||||
app.use(morgan('dev'));
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.engine('html', ngExpressEngine({
|
||||
bootstrap: bootstrap
|
||||
}));
|
||||
|
||||
app.set('view engine', 'html');
|
||||
app.set('views', 'src');
|
||||
|
||||
function cacheControl(req, res, next) {
|
||||
// instruct browser to revalidate
|
||||
res.header('Cache-Control', ENV_CONFIG.cache.control || 'max-age=60');
|
||||
next();
|
||||
}
|
||||
|
||||
app.use('/', cacheControl, express.static('dist', { index: false }));
|
||||
|
||||
// TODO: either remove or update mock backend
|
||||
// app.get('/data.json', serverApi);
|
||||
// app.use('/api', createMockApi());
|
||||
|
||||
function ngApp(req, res) {
|
||||
|
||||
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
|
||||
console.warn('Error in SSR, serving for direct CSR');
|
||||
res.sendFile('index.csr.html', { root: './src' });
|
||||
}
|
||||
|
||||
if (ENV_CONFIG.universal.preboot) {
|
||||
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
|
||||
res.render('../dist/index', {
|
||||
req,
|
||||
res,
|
||||
preboot: ENV_CONFIG.universal.preboot,
|
||||
async: ENV_CONFIG.universal.async,
|
||||
time: ENV_CONFIG.universal.time,
|
||||
baseUrl: ENV_CONFIG.ui.nameSpace,
|
||||
originUrl: ENV_CONFIG.ui.baseUrl,
|
||||
requestUrl: req.originalUrl
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('Universal off, serving for direct CSR');
|
||||
res.sendFile('index.csr.html', { root: './src' });
|
||||
}
|
||||
}
|
||||
|
||||
ROUTES.forEach((route: string) => {
|
||||
app.get(route, ngApp);
|
||||
});
|
||||
|
||||
function serverStarted() {
|
||||
console.log(`[${new Date().toTimeString()}] Listening at ${ENV_CONFIG.ui.baseUrl}`);
|
||||
}
|
||||
|
||||
function createHttpsServer(keys) {
|
||||
https.createServer({
|
||||
key: keys.serviceKey,
|
||||
cert: keys.certificate
|
||||
}, app).listen(port, ENV_CONFIG.ui.host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
}
|
||||
|
||||
if (ENV_CONFIG.ui.ssl) {
|
||||
let serviceKey;
|
||||
try {
|
||||
serviceKey = fs.readFileSync('./config/ssl/key.pem');
|
||||
} catch (e) {
|
||||
console.warn('Service key not found at ./config/ssl/key.pem');
|
||||
}
|
||||
|
||||
let certificate;
|
||||
try {
|
||||
certificate = fs.readFileSync('./config/ssl/cert.pem');
|
||||
} catch (e) {
|
||||
console.warn('Certificate not found at ./config/ssl/key.pem');
|
||||
}
|
||||
|
||||
if (serviceKey && certificate) {
|
||||
createHttpsServer({
|
||||
serviceKey: serviceKey,
|
||||
certificate: certificate
|
||||
});
|
||||
} else {
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
|
||||
pem.createCertificate({
|
||||
days: 1,
|
||||
selfSigned: true
|
||||
}, (error, keys) => {
|
||||
createHttpsServer(keys);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
app.listen(port, ENV_CONFIG.ui.host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
}}
|
7
src/tsconfig.server.aot.json
Normal file
7
src/tsconfig.server.aot.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.server.json",
|
||||
"angularCompilerOptions": {
|
||||
"entryModule": "./modules/app/server-app.module#ServerAppModule"
|
||||
},
|
||||
"exclude": []
|
||||
}
|
Reference in New Issue
Block a user