Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration to HttpClient #6951

Merged
merged 56 commits into from Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
740ec9e
Migrated account and admin module
Thisen Aug 31, 2017
960e785
Merge branch 'master' of https://github.com/jhipster/generator-jhipster
Thisen Aug 31, 2017
e1104d4
More migrations and fixes
Thisen Oct 2, 2017
7c294e9
merged Thisens repository
Jan 5, 2018
31a769c
remove orig files
Jan 5, 2018
047dc8d
migrated auth-interceptor to @angular/common/http
Jan 5, 2018
041fb50
migrated auth-expired.interceptor to @angular/common/http
Jan 5, 2018
049e012
migrated errorhandler.interceptor to @angular/common/http and updated…
Jan 5, 2018
5a7d16c
migrated notification.interceptor to @angular/common/http
Jan 5, 2018
3f59491
removed now unnecessaray http provider
Jan 5, 2018
542d094
forgot to delete the ts file of http provider
Jan 5, 2018
073cce3
migrated entities to @angular/common/http
Jan 5, 2018
fdcc558
migrated auth-jwt.service to @angular/common/http
Jan 5, 2018
3d330cc
migrated tests to @angular/common/http and remove dependency to old @…
Jan 5, 2018
1e92bed
fixed interceptor import conditions
Jan 5, 2018
84fcd68
cleanup based on comments
Jan 5, 2018
2adcb39
fixed wjitespace
Jan 5, 2018
b9ec610
provide interceptors with class instead of factory method
Jan 6, 2018
5e1edd7
removed injecto for auth-expired.interceptor
Jan 6, 2018
ebf9f0a
remove injector form notification.interceptor
Jan 6, 2018
0468bd9
made user service more consistent in return types
Jan 6, 2018
4a35965
changed test to fit ne HttpResponse
Jan 6, 2018
4607784
fixes
Jan 6, 2018
efa0c25
cleanup unused imports and some other lint errors
Jan 6, 2018
bfdbe06
fixed last lint errors in tests
Jan 6, 2018
4bc7b07
readded injectors where needed
Jan 6, 2018
f1b711b
lint fix
Jan 6, 2018
109fe55
typo -.-
Jan 6, 2018
a927fd9
resolved circular dependencies in httpinterceptor
Jan 6, 2018
ed9e5b2
shortened line to pass tests
Jan 6, 2018
59cd3f2
import fix
Jan 6, 2018
4145332
more fixes
Jan 6, 2018
1169abd
took change requests into consideration
Jan 6, 2018
db11427
fixes
Jan 6, 2018
02b506b
changed indexOf to includes
Jan 7, 2018
6f09f1f
Merge branch 'master' of https://github.com/NilsWild/generator-jhipster
deepu105 Jan 7, 2018
1657f29
Merge remote-tracking branch 'jhipster/master'
Jan 7, 2018
79f2113
polish templates
deepu105 Jan 7, 2018
be00c6f
Merge branch 'master' of https://github.com/NilsWild/generator-jhipster
deepu105 Jan 7, 2018
534b49e
update Typescript to es7 lib
deepu105 Jan 7, 2018
bc0eaf3
use type for entity service
deepu105 Jan 7, 2018
7a20baf
fixed lint errors
Jan 7, 2018
0fa3f1f
fix lint errors
deepu105 Jan 7, 2018
23f15fc
Merge branch 'master' of https://github.com/NilsWild/generator-jhipster
deepu105 Jan 7, 2018
f8cabdd
use es7 for tsconfig aot
deepu105 Jan 7, 2018
a5633b1
removed trailing whitespace
Jan 7, 2018
5421b43
fixed tests
Jan 8, 2018
98bb775
removed ) and fixed lint error
Jan 8, 2018
18f0104
fixed user-management-dialog.component.spec
Jan 8, 2018
450045f
fixed session service
Jan 8, 2018
f143214
mock http in correct testBed
Jan 9, 2018
c232cdd
fixed test. always have to subscribe to the Observable to send request
Jan 11, 2018
adc4d3c
Merge branch 'master' of https://github.com/NilsWild/generator-jhipster
deepu105 Jan 12, 2018
d4e3e49
checked req.sort for beeing undefined in audits service by using requ…
Jan 12, 2018
a1d8ebd
Merge branch 'master' of https://github.com/NilsWild/generator-jhipster
Jan 12, 2018
6cbfad8
fixed misssing negation that i lost when i converted the interceptors
Jan 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions generators/client/files-angular.js
Expand Up @@ -138,7 +138,6 @@ const files = {
// interceptors
'blocks/interceptor/_errorhandler.interceptor.ts',
'blocks/interceptor/_notification.interceptor.ts',
'blocks/interceptor/_http.provider.ts',
'blocks/interceptor/_auth-expired.interceptor.ts'
]
},
Expand Down Expand Up @@ -380,7 +379,6 @@ const files = {
'shared/constants/_error.constants.ts',
'shared/constants/_pagination.constants.ts',
// models
'shared/model/_response-wrapper.model.ts',
'shared/model/_request-util.ts',
'shared/model/_base-entity.ts',
'shared/user/_account.model.ts',
Expand Down
1 change: 0 additions & 1 deletion generators/client/templates/angular/_package.json
Expand Up @@ -30,7 +30,6 @@
"@angular/compiler": "5.1.0",
"@angular/core": "5.1.0",
"@angular/forms": "5.1.0",
"@angular/http": "5.1.0",
"@angular/platform-browser": "5.1.0",
"@angular/platform-browser-dynamic": "5.1.0",
"@angular/router": "5.1.0",
Expand Down
Expand Up @@ -18,9 +18,20 @@
-%>
import './vendor.ts';

import { NgModule } from '@angular/core';
import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Ng2Webstorage } from 'ngx-webstorage';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { Ng2Webstorage<% if (authenticationType === 'jwt') { %>, LocalStorageService, SessionStorageService <% } %> } from 'ngx-webstorage';
import { JhiEventManager } from 'ng-jhipster';

<%_ if (authenticationType === 'jwt') { _%>
import { AuthInterceptor } from './blocks/interceptor/auth.interceptor';
<%_ } _%>
<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
import { AuthExpiredInterceptor } from './blocks/interceptor/auth-expired.interceptor';
<% } %>
import { ErrorHandlerInterceptor } from './blocks/interceptor/errorhandler.interceptor';
import { NotificationInterceptor } from './blocks/interceptor/notification.interceptor';

import { <%=angularXAppName%>SharedModule, UserRouteAccessService } from './shared';
import { <%=angularXAppName%>AppRoutingModule} from './app-routing.module';
Expand All @@ -30,9 +41,15 @@ import { <%=angularXAppName%>AdminModule } from './admin/admin.module';
import { <%=angularXAppName%>AccountModule } from './account/account.module';
<%_ } _%>
import { <%=angularXAppName%>EntityModule } from './entities/entity.module';
import { customHttpProvider } from './blocks/interceptor/http.provider';
import { PaginationConfig } from './blocks/config/uib-pagination.config';

<%_ if (authenticationType === 'session' || authenticationType === 'oauth2') { _%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ['session', 'oauth2'].includes(authenticationType) syntax as its easier to read

<%_ if (authenticationType === 'session') { _%>
import { LoginModalService } from './shared/login/login-modal.service';
<%_ } _%>
import { StateStorageService } from './shared/auth/state-storage.service';
<%_ } _%>

// jhipster-needle-angular-add-module-import JHipster will add new module here

import {
Expand Down Expand Up @@ -73,9 +90,66 @@ import {
],
providers: [
ProfileService,
customHttpProvider(),
PaginationConfig,
UserRouteAccessService
UserRouteAccessService,
<%_ if (authenticationType === 'jwt') { _%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this template seems wrong compared to existing logic, correct one should be

        <%_ if (authenticationType === 'jwt') { _%>
        {
             provide: HTTP_INTERCEPTORS,
             useClass: AuthInterceptor,
             multi: true,
             deps: [
                 LocalStorageService,
                 SessionStorageService
             ]
         },
         <%_ } _%>
         {
             provide: HTTP_INTERCEPTORS,
             useClass: AuthExpiredInterceptor,
             multi: true,
             deps: [
                 Injector<% if (['session', 'oauth2'].includes(authenticationType)) { %>,
                 StateStorageService<% } if(authenticationType === 'session') %>,
                 LoginModalService<% } %>
             ]
         },
         {
             provide: HTTP_INTERCEPTORS,
             useClass: ErrorHandlerInterceptor,
             multi: true,
             deps: [
                 JhiEventManager
             ]
         },
         {
             provide: HTTP_INTERCEPTORS,
             useClass: NotificationInterceptor,
             multi: true,
             deps: [
                 Injector
             ]
         }

Copy link
Contributor Author

@NilsWild NilsWild Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can shrink them to only switch the dependencies i removed the Modal to solve cyclic dependencies in case of session based auth
its injected via injector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged them

{
provide: HTTP_INTERCEPTORS,
useFactory: (localStorageService, sessionStorageService) => new AuthInterceptor(localStorageService, sessionStorageService),
multi: true,
deps: [
LocalStorageService,
SessionStorageService
]
},
<%_ } _%>
<%_ if (authenticationType === 'jwt' || authenticationType === 'uaa') { _%>
{
provide: HTTP_INTERCEPTORS,
useFactory: (injector) => new AuthExpiredInterceptor(injector),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked, this part? (I am not sure)AOT is handling this correctly in the new version...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use useClass here?

multi: true,
deps: [
Injector
]
},
<%_ } else if (authenticationType === 'session') { _%>
{
provide: HTTP_INTERCEPTORS,
useFactory: (injector, stateStorageService, loginModalService) => new AuthExpiredInterceptor(injector, stateStorageService, loginModalService),
multi: true,
deps: [
Injector,
StateStorageService,
LoginModalService
]
},
<%_ } else if (authenticationType === 'oauth2') { _%>
{
provide: HTTP_INTERCEPTORS,
useFactory: (injector, stateStorageService) => new AuthExpiredInterceptor(injector, stateStorageService),
multi: true,
deps: [
Injector,
StateStorageService,
]
},
<%_ } _%>
{
provide: HTTP_INTERCEPTORS,
useFactory: (eventManager) => new ErrorHandlerInterceptor(eventManager),
multi: true,
deps: [
JhiEventManager,
]
},
{
provide: HTTP_INTERCEPTORS,
useFactory: (injector) => new NotificationInterceptor(injector),
multi: true,
deps: [
Injector
]
}
],
bootstrap: [ <%=jhiPrefixCapitalized%>MainComponent ]
})
Expand Down
Expand Up @@ -17,21 +17,18 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http, Response, URLSearchParams } from '@angular/http';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';

@Injectable()
export class ActivateService {

constructor(private http: Http) {}
constructor(private http: HttpClient) {}

get(key: string): Observable<any> {
const params: URLSearchParams = new URLSearchParams();
params.set('key', key);

return this.http.get(SERVER_API_URL + '<%- apiUaaPath %>api/activate', {
search: params
}).map((res: Response) => res);
params: new HttpParams().set('key', key)
});
}
}
Expand Up @@ -17,14 +17,14 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../../app.constants';

@Injectable()
export class PasswordResetFinishService {

constructor(private http: Http) {}
constructor(private http: HttpClient) {}

save(keyAndPassword: any): Observable<any> {
return this.http.post(SERVER_API_URL + '<%- apiUaaPath %>api/account/reset-password/finish', keyAndPassword);
Expand Down
Expand Up @@ -17,14 +17,14 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../../app.constants';

@Injectable()
export class PasswordResetInitService {

constructor(private http: Http) {}
constructor(private http: HttpClient) {}

save(mail: string): Observable<any> {
return this.http.post(SERVER_API_URL + '<%- apiUaaPath %>api/account/reset-password/init', mail);
Expand Down
Expand Up @@ -17,14 +17,14 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';

@Injectable()
export class PasswordService {

constructor(private http: Http) {}
constructor(private http: HttpClient) {}

save(newPassword: string): Observable<any> {
return this.http.post(SERVER_API_URL + '<%- apiUaaPath %>api/account/change-password', newPassword);
Expand Down
Expand Up @@ -17,14 +17,14 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';

@Injectable()
export class Register {

constructor(private http: Http) {}
constructor(private http: HttpClient) {}

save(account: any): Observable<any> {
return this.http.post(SERVER_API_URL + '<%- apiUaaPath %>api/register', account);
Expand Down
Expand Up @@ -17,7 +17,7 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

import { Session } from './session.model';
Expand All @@ -30,10 +30,10 @@ export class SessionsService {
constructor(private http: Http) { }

findAll(): Observable<Session[]> {
return this.http.get(this.resourceUrl).map((res: Response) => res.json());
return this.http.get<Session[]>(this.resourceUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really liked this one 👍 It clearly states what is gonna be there ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried to type everything i stubled over not sure though if i really did it eveywhere so far

}

delete(series: string): Observable<Response> {
return this.http.delete(`${this.resourceUrl}${series}`);
delete(series: string): Observable<HttpResponse<any>> {
return this.http.delete(`${this.resourceUrl}${series}`, { observe: 'response' });
}
}
Expand Up @@ -70,7 +70,7 @@ export class AuditsComponent implements OnInit {
this.auditsService.query({page: this.page - 1, size: this.itemsPerPage,
fromDate: this.fromDate, toDate: this.toDate}).subscribe((res) => {

this.audits = res.json();
this.audits = res.body;
this.links = this.parseLinks.parse(res.headers.get('link'));
this.totalItems = + res.headers.get('X-Total-Count');
});
Expand Down
Expand Up @@ -17,26 +17,28 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http, Response, URLSearchParams } from '@angular/http';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';
import { Audit } from './audit.model';

@Injectable()
export class AuditsService {
constructor(private http: Http) { }

query(req: any): Observable<Response> {
const params: URLSearchParams = new URLSearchParams();
params.set('fromDate', req.fromDate);
params.set('toDate', req.toDate);
params.set('page', req.page);
params.set('size', req.size);
params.set('sort', req.sort);

const options = {
search: params
};

return this.http.get(SERVER_API_URL + '<%- apiUaaPath %>management/audits', options);
constructor(private http: HttpClient) { }

query(req: any): Observable<HttpResponse<Audit[]>> {
const params: HttpParams = new HttpParams()
.set('fromDate', req.fromDate)
.set('toDate', req.toDate)
.set('page', req.page)
.set('size', req.size)
.set('sort', req.sort)

const requestURL = SERVER_API_URL + '<%- apiUaaPath %>management/audits';

return this.http.get<Audit[]>(requestURL, {
params,
observe: 'response'
});
}
}
Expand Up @@ -17,21 +17,21 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { SERVER_API_URL } from '../../app.constants';

@Injectable()
export class <%=jhiPrefixCapitalized%>ConfigurationService {

constructor(private http: Http) {
constructor(private http: HttpClient) {
}

get(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/configprops').map((res: Response) => {
return this.http.get(SERVER_API_URL + 'management/configprops', { observe: 'response' }).map((res: HttpResponse<any>) => {
const properties: any[] = [];

const propertiesObject = res.json();
const propertiesObject = res.body;

for (const key in propertiesObject) {
if (propertiesObject.hasOwnProperty(key)) {
Expand All @@ -47,10 +47,10 @@ export class <%=jhiPrefixCapitalized%>ConfigurationService {
}

getEnv(): Observable<any> {
return this.http.get(SERVER_API_URL + 'management/env').map((res: Response) => {
return this.http.get(SERVER_API_URL + 'management/env', { observe: 'response' }).map((res: HttpResponse<any>) => {
const properties: any = {};

const propertiesObject = res.json();
const propertiesObject = res.body;

for (const key in propertiesObject) {
if (propertiesObject.hasOwnProperty(key)) {
Expand Down
@@ -1,5 +1,5 @@
<%#
Copyright 2013-2017 the original author or authors from the JHipster project.
Copyright 2013-2018 the original author or authors from the JHipster project.

This file is part of the JHipster project, see http://www.jhipster.tech/
for more information.
Expand Down
@@ -1,5 +1,5 @@
<%#
Copyright 2013-2017 the original author or authors from the JHipster project.
Copyright 2013-2018 the original author or authors from the JHipster project.

This file is part of the JHipster project, see http://www.jhipster.tech/
for more information.
Expand Down
@@ -1,5 +1,5 @@
<%#
Copyright 2013-2017 the original author or authors from the JHipster project.
Copyright 2013-2018 the original author or authors from the JHipster project.

This file is part of the JHipster project, see http://www.jhipster.tech/
for more information.
Expand Down
Expand Up @@ -17,17 +17,17 @@
limitations under the License.
-%>
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

import { SERVER_API_URL } from '../../app.constants';
import { GatewayRoute } from './gateway-route.model';

@Injectable()
export class GatewayRoutesService {
constructor(private http: Http) { }
constructor(private http: HttpClient) { }

findAll(): Observable<GatewayRoute[]> {
return this.http.get(SERVER_API_URL + 'api/gateway/routes/').map((res: Response) => res.json());
return this.http.get<GatewayRoute[]>(SERVER_API_URL + 'api/gateway/routes/');
}
}