Commit c87cf192 by Tuukka Kivilahti

nagular 5 is now working

1 parent 29ceaba7
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
...@@ -8,11 +8,13 @@ const MODULES = [ ...@@ -8,11 +8,13 @@ const MODULES = [
MoyaRestModule MoyaRestModule
]; ];
/*
@NgModule({ @NgModule({
imports: [MoyaRestModule.forRoot()], imports: [MoyaRestModule.forRoot()],
exports: MODULES exports: MODULES
}) })*/
/*
@NgModule({exports: MODULES}) @NgModule({imports: MODULES, exports: MODULES})
export class MoyaAngularCommonModule { export class MoyaAngularCommonModule {
} }
\ No newline at end of file */
import {NgModule, ModuleWithProviders, NgZone} from '@angular/core'; import {NgModule, ModuleWithProviders, NgZone, Injector} from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import {HttpModule} from "@angular/http";
import {MoyaRestService} from "./services/moya-rest.service"; import {MoyaRestService} from "./services/moya-rest.service";
import {ViplistService} from "./services/viplist.service"; import {ViplistService} from "./services/viplist.service";
import {CacheService} from "./services/cache.service"; import {CacheService} from "./services/cache.service";
import {UserService} from "./services/user.service"; import {UserService} from "./services/user.service";
import {HttpClientModule} from "@angular/common/http";
import {HttpModule} from "@angular/http";
export * from "./services/moya-rest.service"; export * from "./services/moya-rest.service";
export * from "./services/viplist.service"; export * from "./services/viplist.service";
...@@ -20,14 +21,25 @@ export * from "./models/vip-product-delivery.model"; ...@@ -20,14 +21,25 @@ export * from "./models/vip-product-delivery.model";
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
HttpModule HttpClientModule
],
declarations: [ ],
providers: [
MoyaRestService,
ViplistService,
CacheService,
UserService,
HttpClientModule
/*{ provide: NgZone, useFactory: () => new NgZone({}) },
{ provide: Injector, useFactory: () => Injector.create({providers: []}) } */
],
exports: [
], ],
declarations: []
}) })
export class MoyaRestModule { export class MoyaRestModule {
/*
static forRoot(): ModuleWithProviders { static forRoot(): ModuleWithProviders {
return { return {
ngModule: MoyaRestModule, ngModule: MoyaRestModule,
...@@ -35,9 +47,12 @@ export class MoyaRestModule { ...@@ -35,9 +47,12 @@ export class MoyaRestModule {
MoyaRestService, MoyaRestService,
ViplistService, ViplistService,
CacheService, CacheService,
UserService UserService,
HttpClientModule
/*{ provide: NgZone, useFactory: () => new NgZone({}) },
{ provide: Injector, useFactory: () => Injector.create({providers: []}) }
] ]
}; };
} }*/
} }
import {Injectable, NgZone} from "@angular/core"; import {Injectable, NgZone} from "@angular/core";
import {Observable, Subscriber, Subscription} from "rxjs"; import {Observable} from "rxjs/Observable";
import 'rxjs/add/observable/timer';
import {forkJoin} from "rxjs/observable/forkJoin";
import "rxjs/add/operator/do";
import "rxjs/add/operator/publishLast";
import "rxjs/add/observable/of";
import {Subscription} from "rxjs/Subscription";
const DEFAULT_EXPIRE_MS = 300000; // 5min const DEFAULT_EXPIRE_MS = 300000; // 5min
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {Http, Response} from "@angular/http"; import {Observable} from "rxjs/Observable";
import {Observable, Observer} from "rxjs"; import "rxjs/add/operator/catch";
import {HttpClient, HttpResponse} from "@angular/common/http";
@Injectable() @Injectable()
export class MoyaRestService { export class MoyaRestService {
constructor(private http: Http) { } constructor(private http: HttpClient) { }
post(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<Response> { post(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<HttpResponse<any> > {
return this.http.post(this.genUrl(subUrl, pathParameters), body) return this.http.post(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse) .map(this.handleResponse)
.catch(this.handleException); .catch(this.handleException);
} }
put(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<Response> { put(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<HttpResponse <any>> {
return this.http.put(this.genUrl(subUrl, pathParameters), body) return this.http.put(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse) .map(this.handleResponse)
.catch(this.handleException); .catch(this.handleException);
} }
delete(subUrl: string, pathParameters?: Map<string, string>): Observable<Response> { delete(subUrl: string, pathParameters?: Map<string, string>): Observable<HttpResponse<any> > {
return this.http.delete(this.genUrl(subUrl, pathParameters)) return this.http.delete(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse) .map(this.handleResponse)
.catch(this.handleException); .catch(this.handleException);
} }
get(subUrl: string, pathParameters?: Map<string, string>): Observable<Response> { get(subUrl: string, pathParameters?: Map<string, string>): Observable<HttpResponse<any> > {
return this.http.get(this.genUrl(subUrl, pathParameters)) return this.http.get(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse) .map(this.handleResponse)
.catch(this.handleException); .catch(this.handleException);
...@@ -54,7 +55,7 @@ export class MoyaRestService { ...@@ -54,7 +55,7 @@ export class MoyaRestService {
return "/MoyaWeb/rest/" + subUrl + suffix; // <-- TODO: kauneista return "/MoyaWeb/rest/" + subUrl + suffix; // <-- TODO: kauneista
} }
private handleResponse(res: Response) { private handleResponse(res: HttpResponse<any>) {
// basicly, 200 statuscodes means success // basicly, 200 statuscodes means success
if(!(res.status >= 200 && res.status <= 299 )) { if(!(res.status >= 200 && res.status <= 299 )) {
...@@ -67,7 +68,7 @@ export class MoyaRestService { ...@@ -67,7 +68,7 @@ export class MoyaRestService {
return res; return res;
} }
private handleException(error: Response | any) { private handleException(error: HttpResponse<any> | any) {
console.log("error on jira rest connection", error); console.log("error on jira rest connection", error);
......
import {Injectable} from "@angular/core"; import {Injectable} from "@angular/core";
import {Observable} from "rxjs";
import {User} from "../models/user.model"; import {User} from "../models/user.model";
import {MoyaRestService} from "./moya-rest.service"; import {MoyaRestService} from "./moya-rest.service";
import {CacheService} from "./cache.service"; import {CacheService} from "./cache.service";
import {Observable} from "rxjs/Observable";
@Injectable() @Injectable()
export class UserService { export class UserService {
...@@ -20,8 +21,7 @@ export class UserService { ...@@ -20,8 +21,7 @@ export class UserService {
return this.cacheService.cacheObservable("moya:UserService", path, return this.cacheService.cacheObservable("moya:UserService", path,
this.moyaRest.get(path) this.moyaRest.get(path)
.do(v => {console.log("getting user outside of cache", path)}) .do(v => {console.log("getting user outside of cache", path)})
.map(res => (<User> res.json())) .map(res => (<User> res.body)));
);
} }
} }
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {MoyaRestService} from "./moya-rest.service"; import {MoyaRestService} from "./moya-rest.service";
import {Observable} from "rxjs";
import {Vip} from "../models/vip.model"; import {Vip} from "../models/vip.model";
import {Response} from "@angular/http"; import {Response} from "@angular/http";
import {User} from "../models/user.model"; import {User} from "../models/user.model";
import {UserService} from "./user.service"; import {UserService} from "./user.service";
import {Observable} from "rxjs/Observable";
import "rxjs/add/operator/map";
import "rxjs/add/operator/switchMap";
import "rxjs/add/observable/forkJoin";
import "rxjs/add/operator/first";
import {HttpResponse} from "@angular/common/http";
@Injectable() @Injectable()
export class ViplistService { export class ViplistService {
...@@ -22,11 +27,11 @@ export class ViplistService { ...@@ -22,11 +27,11 @@ export class ViplistService {
if (!searchString) { if (!searchString) {
return this.moyaRestService.get("v3/vip/all") return this.moyaRestService.get("v3/vip/all")
.switchMap(res => Observable.forkJoin(...res.json().map(apiRow => this.hostPopulator(apiRow)))); .switchMap(res => Observable.forkJoin(...res.body.map(apiRow => this.hostPopulator(apiRow))));
} }
return this.moyaRestService.get("v3/vip/search/" + searchString) return this.moyaRestService.get("v3/vip/search/" + searchString)
.switchMap(v => Observable.forkJoin(...v.json().map(x => this.hostPopulator(x)))); .switchMap(v => Observable.forkJoin(...v.body.map(x => this.hostPopulator(x))));
} }
...@@ -34,45 +39,30 @@ export class ViplistService { ...@@ -34,45 +39,30 @@ export class ViplistService {
* Delete vip. * Delete vip.
* *
* @param vip * @param vip
* @return Observable * @return Promise
*/ */
public async delete(vip: Vip): Promise<boolean> { public async delete(vip: Vip): Promise<boolean> {
if (!vip.id) if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi"); throw new Error("TODO: errori, tyhmä vippi");
let res: Response = await this.moyaRestService.delete("v3/vip/" + vip.id) let res: HttpResponse<any> = await this.moyaRestService.delete("v3/vip/" + vip.id)
.first() .first()
.toPromise(); .toPromise();
return res.ok; return res.ok;
} }
/*
public deleteProm(vip: Vip): Promise<boolean> {
if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi");
return this.moyaRestService.delete("v3/vip/" + vip.id)
.first()
.toPromise()
.then(r => r.ok);
}
*/
public getWithId(id: number): Observable<Vip> { public getWithId(id: number): Observable<Vip> {
return this.moyaRestService.get("v3/vip/" + id) return this.moyaRestService.get("v3/vip/" + id)
.map(v => v.json()); .map(v => v.body);
} }
public create(vip: Vip): Observable<Vip> { public create(vip: Vip): Observable<Vip> {
return this.moyaRestService.post("v3/vip/create", vip) return this.moyaRestService.post("v3/vip/create", vip)
.map(v => v.json()); .map(v => v.body);
} }
private hostPopulator(rawVip : any): Observable<Vip> { private hostPopulator(rawVip : any): Observable<Vip> {
......
...@@ -3,5 +3,33 @@ ...@@ -3,5 +3,33 @@
"version": "0.0.1", "version": "0.0.1",
"license": "UNLICENSED", "license": "UNLICENSED",
"scripts": {}, "scripts": {},
"private": true "private": true,
"peerDependencies": {
"@angular/http": "^5.2.4",
"rxjs": "^5.5.6",
"@angular/core": "^5.2.4",
"@angular/animations": "^5.2.4",
"@angular/common": "^5.2.4",
"@angular/compiler": "^5.2.4",
"@angular/forms": "^5.2.4",
"@angular/platform-browser": "^5.2.4",
"@angular/platform-browser-dynamic": "^5.2.4",
"@angular/router": "^5.2.4",
"core-js": "^2.4.1",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/http": "^5.2.4",
"rxjs": "^5.5.6",
"@angular/core": "^5.2.4",
"@angular/animations": "^5.2.4",
"@angular/common": "^5.2.4",
"@angular/compiler": "^5.2.4",
"@angular/forms": "^5.2.4",
"@angular/platform-browser": "^5.2.4",
"@angular/platform-browser-dynamic": "^5.2.4",
"@angular/router": "^5.2.4",
"core-js": "^2.4.1",
"zone.js": "^0.8.19"
}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"declaration": false, "declaration": false,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"lib": ["es6", "dom"], "lib": ["es2017", "dom"],
"mapRoot": "./", "mapRoot": "./",
"module": "es6", "module": "es6",
"moduleResolution": "node", "moduleResolution": "node",
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
"ng2-bootstrap": "^1.3.3", "ng2-bootstrap": "^1.3.3",
"rxjs": "^5.4.3", "rxjs": "^5.4.3",
"ts-helpers": "^1.1.1", "ts-helpers": "^1.1.1",
"zone.js": "^0.8.18" "zone.js": "^0.8.19"
}, },
"devDependencies": { "devDependencies": {
"@angular/cli": "^1.4.5", "@angular/cli": "^1.6.8",
"@angular/compiler-cli": "^5.2.4", "@angular/compiler-cli": "^5.2.4",
"@angularclass/hmr": "^2.1.3", "@angularclass/hmr": "^2.1.3",
"@types/jasmine": "2.8.6", "@types/jasmine": "2.8.6",
......
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core'; import {Injector, NgModule, ReflectiveInjector} from '@angular/core';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {ViplistComponent} from './viplist/viplist.component'; import {ViplistComponent} from './viplist/viplist.component';
...@@ -21,6 +20,11 @@ import {UserComponent} from './user/user.component'; ...@@ -21,6 +20,11 @@ import {UserComponent} from './user/user.component';
import {InfoComponent} from './info/info.component'; import {InfoComponent} from './info/info.component';
import {AdminComponent} from './admin/admin.component'; import {AdminComponent} from './admin/admin.component';
import {I18nPipe} from './pipes/i18n.pipe'; import {I18nPipe} from './pipes/i18n.pipe';
import {HttpClientModule, HttpHandler } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import {CacheService} from "moya-angular-common";
import {StaticInjector} from "@angular/core/src/di/injector";
import {CommonModule} from "@angular/common";
const appRoutes: Routes = [ const appRoutes: Routes = [
{ {
...@@ -69,16 +73,20 @@ const appRoutes: Routes = [ ...@@ -69,16 +73,20 @@ const appRoutes: Routes = [
InfoComponent, InfoComponent,
AdminComponent, AdminComponent,
I18nPipe I18nPipe
], ],
imports: [ imports: [
CommonModule,
BrowserModule, BrowserModule,
FormsModule, FormsModule,
HttpModule, HttpClientModule,
AlertModule.forRoot(), AlertModule.forRoot(),
MoyaRestModule.forRoot(), MoyaRestModule,
//MoyaRestModule.forRoot(),
RouterModule.forRoot(appRoutes) RouterModule.forRoot(appRoutes)
], ],
providers: [], providers: [CacheService,
{ provide: Injector, useFactory: () => Injector.create({providers: []}) }],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { export class AppModule {
......
...@@ -14,7 +14,7 @@ export class MENU { ...@@ -14,7 +14,7 @@ export class MENU {
]} ]}
]; ];
static INFO: MenuGroup[]= [ static INFO: MenuGroup[] = [
{ {
'name': 'Users', 'name': 'Users',
'items': [ 'items': [
......
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import {Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy} from '@angular/common'; import {Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy} from '@angular/common';
import {NavigationExtras, ActivatedRoute, Router} from '@angular/router'; import {NavigationExtras, ActivatedRoute, Router} from '@angular/router';
import {Observable} from 'rxjs';
@Component({ @Component({
selector: 'old-moya', selector: 'old-moya',
...@@ -43,7 +42,7 @@ export class OldMoyaComponent implements OnInit { ...@@ -43,7 +42,7 @@ export class OldMoyaComponent implements OnInit {
console.log(this.iframe.nativeElement.contentWindow.document.body.height); console.log(this.iframe.nativeElement.contentWindow.document.body.height);
this.height = this.iframe.nativeElement.contentWindow.document.body.scrollHeight + 'px'; this.height = (this.iframe.nativeElement.contentWindow.document.body.scrollHeight + 50) + 'px';
......
import {Component, OnInit} from '@angular/core'; import {Component, NgZone, OnInit} from '@angular/core';
import {Observable} from 'rxjs'; import {Observable} from "rxjs/Observable";
import {ViplistService, Vip} from 'moya-angular-common'; import {ViplistService, Vip} from 'moya-angular-common';
@Component({ @Component({
...@@ -14,7 +14,6 @@ export class ViplistComponent implements OnInit { ...@@ -14,7 +14,6 @@ export class ViplistComponent implements OnInit {
constructor(private viplistService: ViplistService) { constructor(private viplistService: ViplistService) {
} }
ngOnInit() { ngOnInit() {
this.vips = this.viplistService.get(); this.vips = this.viplistService.get();
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
}, },
"include": [ "include": [
"**/*.ts", "**/*.ts",
"../node_modules/moya-angular-common/**/*.ts" "../node_modules/moya-angular-common/*.ts",
"../node_modules/moya-angular-common/moya-rest/**/*.ts"
] ]
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!