AMBARI-21403 Log Search UI: production build issues. (ababiichuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9a45ef6c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9a45ef6c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9a45ef6c Branch: refs/heads/branch-feature-logsearch-ui Commit: 9a45ef6ceb51f5c1ddcc106a54ddb9ae256f2622 Parents: 0b6679a Author: ababiichuk <ababiic...@hortonworks.com> Authored: Wed Jul 5 13:59:09 2017 +0300 Committer: ababiichuk <ababiic...@hortonworks.com> Committed: Wed Jul 5 13:59:09 2017 +0300 ---------------------------------------------------------------------- .../src/app/app.module.ts | 19 ++++--- .../accordion-panel.component.ts | 9 +--- .../src/app/components/app.component.spec.ts | 24 ++++++--- .../src/app/components/app.component.ts | 16 +++--- .../dropdown-list/dropdown-list.component.ts | 9 +--- .../filter-button/filter-button.component.ts | 15 +++--- .../filter-dropdown.component.spec.ts | 4 +- .../filter-dropdown.component.ts | 7 +-- .../filter-text-field.component.spec.ts | 4 +- .../filter-text-field.component.ts | 7 +-- .../filters-panel/filters-panel.component.html | 2 +- .../filters-panel/filters-panel.component.ts | 14 ++---- .../login-form/login-form.component.html | 2 +- .../login-form/login-form.component.spec.ts | 23 +++++---- .../login-form/login-form.component.ts | 35 +++++++------ .../logs-list/logs-list.component.html | 2 +- .../components/logs-list/logs-list.component.ts | 7 ++- .../main-container.component.html | 5 +- .../main-container.component.spec.ts | 14 +++++- .../main-container/main-container.component.ts | 18 +++---- .../menu-button/menu-button.component.spec.ts | 9 +++- .../menu-button/menu-button.component.ts | 6 +-- .../src/app/models/app-state.model.ts | 29 +++++++++++ .../src/app/models/store.model.ts | 12 +++-- .../services/component-actions.service.spec.ts | 12 ++++- .../app/services/component-actions.service.ts | 7 ++- .../src/app/services/filtering.service.ts | 2 +- .../app/services/http-client.service.spec.ts | 14 +++++- .../src/app/services/http-client.service.ts | 53 ++++++++++++++------ .../src/app/services/mock-api-data.service.ts | 9 ++-- .../services/storage/app-settings.service.ts | 4 +- .../app/services/storage/app-state.service.ts | 33 ++++++++++++ .../app/services/storage/audit-logs.service.ts | 4 +- .../app/services/storage/bar-graphs.service.ts | 4 +- .../src/app/services/storage/filters.service.ts | 4 +- .../src/app/services/storage/graphs.service.ts | 4 +- .../src/app/services/storage/nodes.service.ts | 4 +- .../services/storage/service-logs.service.ts | 4 +- .../services/storage/user-configs.service.ts | 4 +- 39 files changed, 301 insertions(+), 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/app.module.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/app.module.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/app.module.ts index 1e0ebb0..65139db 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/app.module.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/app.module.ts @@ -34,6 +34,7 @@ import {ComponentActionsService} from '@app/services/component-actions.service'; import {FilteringService} from '@app/services/filtering.service'; import {AppSettingsService, appSettings} from '@app/services/storage/app-settings.service'; +import {AppStateService, appState} from '@app/services/storage/app-state.service'; import {AuditLogsService, auditLogs} from '@app/services/storage/audit-logs.service'; import {ServiceLogsService, serviceLogs} from '@app/services/storage/service-logs.service'; import {BarGraphsService, barGraphs} from '@app/services/storage/bar-graphs.service'; @@ -104,14 +105,15 @@ export function getXHRBackend(injector: Injector, browser: BrowserXhr, xsrf: XSR } }), StoreModule.provideStore({ - appSettings, - auditLogs, - serviceLogs, - barGraphs, - graphs, - nodes, - userConfigs, - filters + appSettings: appSettings, + appState: appState, + auditLogs: auditLogs, + serviceLogs: serviceLogs, + barGraphs: barGraphs, + graphs: graphs, + nodes: nodes, + userConfigs: userConfigs, + filters: filters }), MomentModule, MomentTimezoneModule @@ -121,6 +123,7 @@ export function getXHRBackend(injector: Injector, browser: BrowserXhr, xsrf: XSR ComponentActionsService, FilteringService, AppSettingsService, + AppStateService, AuditLogsService, ServiceLogsService, BarGraphsService, http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/accordion-panel/accordion-panel.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/accordion-panel/accordion-panel.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/accordion-panel/accordion-panel.component.ts index 85031b6..131edcd 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/accordion-panel/accordion-panel.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/accordion-panel/accordion-panel.component.ts @@ -15,19 +15,14 @@ * limitations under the License. */ -import {Component, OnInit, Input, ContentChild, TemplateRef} from '@angular/core'; +import {Component, Input, ContentChild, TemplateRef} from '@angular/core'; @Component({ selector: 'accordion-panel', templateUrl: './accordion-panel.component.html', styleUrls: ['./accordion-panel.component.less'] }) -export class AccordionPanelComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } +export class AccordionPanelComponent { @Input() toggleId: string; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.spec.ts index 3442132..b1b691c 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.spec.ts @@ -21,6 +21,8 @@ import {TestBed, async} from '@angular/core/testing'; import {Http} from '@angular/http'; import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; import {TranslateHttpLoader} from '@ngx-translate/http-loader'; +import {StoreModule} from '@ngrx/store'; +import {AppStateService, appState} from '@app/services/storage/app-state.service'; import {HttpClientService} from '@app/services/http-client.service'; import {AppComponent} from './app.component'; @@ -32,16 +34,26 @@ export function HttpLoaderFactory(http: Http) { describe('AppComponent', () => { beforeEach(async(() => { const httpClient = { - get: () => {} + get: () => { + return { + subscribe: () => {} + } + } }; TestBed.configureTestingModule({ declarations: [AppComponent], - imports: [TranslateModule.forRoot({ - provide: TranslateLoader, - useFactory: HttpLoaderFactory, - deps: [Http] - })], + imports: [ + StoreModule.provideStore({ + appState + }), + TranslateModule.forRoot({ + provide: TranslateLoader, + useFactory: HttpLoaderFactory, + deps: [Http] + }) + ], providers: [ + AppStateService, { provide: HttpClientService, useValue: httpClient http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.ts index c5a17c2..1622f7c 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/app.component.ts @@ -18,6 +18,7 @@ import {Component} from '@angular/core'; import {TranslateService} from '@ngx-translate/core'; +import {AppStateService} from '@app/services/storage/app-state.service'; import {HttpClientService} from '@app/services/http-client.service'; @Component({ @@ -28,16 +29,17 @@ import {HttpClientService} from '@app/services/http-client.service'; export class AppComponent { - constructor(private httpClient: HttpClientService, private translate: TranslateService) { + constructor(private httpClient: HttpClientService, private translate: TranslateService, private appState: AppStateService) { + this.appState.getParameter('isAuthorized').subscribe(value => this.isAuthorized = value); + this.appState.setParameter('isInitialLoading', true); + this.httpClient.get('status').subscribe(() => this.appState.setParameters({ + isAuthorized: true, + isInitialLoading: false + }), () => this.appState.setParameter('isInitialLoading', false)); translate.setDefaultLang('en'); translate.use('en'); } - ngOnInit() { - this.httpClient.get('status'); - } + isAuthorized: boolean = false; - get isAuthorized() { - return this.httpClient.isAuthorized; - } } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/dropdown-list/dropdown-list.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/dropdown-list/dropdown-list.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/dropdown-list/dropdown-list.component.ts index 808fcf8..6426f6a 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/dropdown-list/dropdown-list.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/dropdown-list/dropdown-list.component.ts @@ -16,19 +16,14 @@ * limitations under the License. */ -import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; +import {Component, Input, Output, EventEmitter} from '@angular/core'; @Component({ selector: 'ul.dropdown-menu', templateUrl: './dropdown-list.component.html', styleUrls: ['./dropdown-list.component.less'] }) -export class DropdownListComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } +export class DropdownListComponent { @Input() items: any[]; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-button/filter-button.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-button/filter-button.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-button/filter-button.component.ts index 3da53ca..b529686 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-button/filter-button.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-button/filter-button.component.ts @@ -20,9 +20,12 @@ import {Component, Input, forwardRef} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR, FormGroup} from '@angular/forms'; import {ComponentActionsService} from '@app/services/component-actions.service'; import {FilteringService} from '@app/services/filtering.service'; -import {MenuButtonComponent, menuButtonComponentOptions} from '@app/components/menu-button/menu-button.component'; +import {MenuButtonComponent} from '@app/components/menu-button/menu-button.component'; -@Component(Object.assign({ +@Component({ + selector: 'filter-button', + templateUrl: '../menu-button/menu-button.component.html', + styleUrls: ['../menu-button/menu-button.component.less'], providers: [ { provide: NG_VALUE_ACCESSOR, @@ -30,9 +33,7 @@ import {MenuButtonComponent, menuButtonComponentOptions} from '@app/components/m multi: true } ] -}, menuButtonComponentOptions, { - selector: 'filter-button', -})) +}) export class FilterButtonComponent extends MenuButtonComponent implements ControlValueAccessor { constructor(protected actions: ComponentActionsService, private filtering: FilteringService) { @@ -41,7 +42,7 @@ export class FilterButtonComponent extends MenuButtonComponent implements Contro ngAfterViewInit() { const callback = this.customOnChange ? - (value => this.customOnChange(value)) : (() => this.filtering.filteringSubject.next(null)); + (value => this.actions[this.customOnChange](value)) : (() => this.filtering.filteringSubject.next(null)); this.form.controls[this.filterName].valueChanges.subscribe(callback); } @@ -49,7 +50,7 @@ export class FilterButtonComponent extends MenuButtonComponent implements Contro filterName: string; @Input() - customOnChange: (value: any) => void; + customOnChange: string; @Input() form: FormGroup; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts index 9f4522b..f6d1294 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts @@ -24,6 +24,7 @@ import {TranslateHttpLoader} from '@ngx-translate/http-loader'; import {StoreModule} from '@ngrx/store'; import {AppSettingsService, appSettings} from '@app/services/storage/app-settings.service'; import {FilteringService} from '@app/services/filtering.service'; +import {ComponentActionsService} from '@app/services/component-actions.service'; import {FilterDropdownComponent} from './filter-dropdown.component'; @@ -69,7 +70,8 @@ describe('FilterDropdownComponent', () => { { provide: FilteringService, useValue: filtering - } + }, + ComponentActionsService ], schemas: [NO_ERRORS_SCHEMA] }) http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.ts index 84210dc..1cf7d41 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-dropdown/filter-dropdown.component.ts @@ -18,6 +18,7 @@ import {Component, AfterViewInit, Input, forwardRef} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR, FormGroup} from '@angular/forms'; import {FilteringService} from '@app/services/filtering.service'; +import {ComponentActionsService} from '@app/services/component-actions.service'; @Component({ selector: 'filter-dropdown', @@ -33,12 +34,12 @@ import {FilteringService} from '@app/services/filtering.service'; }) export class FilterDropdownComponent implements AfterViewInit, ControlValueAccessor { - constructor(private filtering: FilteringService) { + constructor(private filtering: FilteringService, private actions: ComponentActionsService) { } ngAfterViewInit() { const callback = this.customOnChange ? - (value => this.customOnChange(value)) : (() => this.filtering.filteringSubject.next(null)); + (value => this.actions[this.customOnChange](value)) : (() => this.filtering.filteringSubject.next(null)); this.form.controls[this.filterName].valueChanges.subscribe(callback); } @@ -46,7 +47,7 @@ export class FilterDropdownComponent implements AfterViewInit, ControlValueAcces options: any[]; @Input() - customOnChange: (value: any) => void; + customOnChange: string; @Input() form: FormGroup; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.spec.ts index 740593f..9123969 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.spec.ts @@ -24,6 +24,7 @@ import {TranslateHttpLoader} from '@ngx-translate/http-loader'; import {StoreModule} from '@ngrx/store'; import {AppSettingsService, appSettings} from '@app/services/storage/app-settings.service'; import {FilteringService} from '@app/services/filtering.service'; +import {ComponentActionsService} from '@app/services/component-actions.service'; import {FilterTextFieldComponent} from './filter-text-field.component'; @@ -59,7 +60,8 @@ describe('FilterTextFieldComponent', () => { { provide: FilteringService, useValue: filtering - } + }, + ComponentActionsService ], schemas: [CUSTOM_ELEMENTS_SCHEMA] }) http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.ts index 857b511..b05000b 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filter-text-field/filter-text-field.component.ts @@ -19,6 +19,7 @@ import {Component, AfterViewInit, Input, forwardRef} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR, FormGroup} from '@angular/forms'; import 'rxjs/add/operator/debounceTime'; import {FilteringService} from '@app/services/filtering.service'; +import {ComponentActionsService} from '@app/services/component-actions.service'; @Component({ selector: 'filter-text-field', @@ -34,12 +35,12 @@ import {FilteringService} from '@app/services/filtering.service'; }) export class FilterTextFieldComponent implements AfterViewInit, ControlValueAccessor { - constructor(private filtering: FilteringService) { + constructor(private filtering: FilteringService, private actions: ComponentActionsService) { } ngAfterViewInit() { const callback = this.customOnChange ? - (value => this.customOnChange(value)) : (() => this.filtering.filteringSubject.next(null)); + (value => this.actions[this.customOnChange](value)) : (() => this.filtering.filteringSubject.next(null)); this.form.controls[this.filterName].valueChanges.debounceTime(this.debounceInterval).subscribe(callback); } @@ -47,7 +48,7 @@ export class FilterTextFieldComponent implements AfterViewInit, ControlValueAcce filterName: string; @Input() - customOnChange: (value: any) => void; + customOnChange: string; @Input() form: FormGroup; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.html b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.html index 256b547..450ce5a 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.html +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.html @@ -25,7 +25,7 @@ formControlName="timeRange" [form]="filtersForm"></filter-dropdown> <filter-dropdown [(ngModel)]="filters.timeZone.selectedValue" [filterName]="'timeZone'" formControlName="timeZone" [form]="filtersForm" - [customOnChange]="setTimeZone"></filter-dropdown> + [customOnChange]="'setTimeZone'"></filter-dropdown> <!--button class="btn btn-success" type="button"> <span class="fa fa-search"></span> </button--> http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.ts index b2ae9b0..652b864 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/filters-panel/filters-panel.component.ts @@ -16,22 +16,18 @@ * limitations under the License. */ -import {Component, OnInit} from '@angular/core'; +import {Component} from '@angular/core'; import {FormControl, FormGroup} from '@angular/forms'; import {FilteringService} from '@app/services/filtering.service'; -import {AppSettingsService} from '@app/services/storage/app-settings.service'; @Component({ selector: 'filters-panel', templateUrl: './filters-panel.component.html', styleUrls: ['./filters-panel.component.less'] }) -export class FiltersPanelComponent implements OnInit { +export class FiltersPanelComponent { - constructor(private filtering: FilteringService, private appSettings: AppSettingsService) { - } - - ngOnInit() { + constructor(private filtering: FilteringService) { } get filters() { @@ -46,8 +42,4 @@ export class FiltersPanelComponent implements OnInit { filtersForm = new FormGroup(this.filtersFormItems); - setTimeZone(timeZone: string): void { - this.appSettings.setParameter('timeZone', timeZone); - } - } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.html b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.html index 37a96e9..a34cfb8 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.html +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.html @@ -26,7 +26,7 @@ <label for="password">{{'authorization.password' | translate}}</label> <input class="form-control" type="password" id="password" name="password" required [(ngModel)]="password"> </div> - <button class="btn btn-success" [disabled]="!loginForm.form.valid || isRequestInProgress"> + <button class="btn btn-success" [disabled]="!loginForm.form.valid || isLoginInProgress"> {{'authorization.signIn' | translate}} </button> </form> http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.spec.ts index 0498ee4..fd54fe6 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.spec.ts @@ -21,6 +21,8 @@ import {FormsModule} from '@angular/forms'; import {HttpModule, Http} from '@angular/http'; import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; import {TranslateHttpLoader} from '@ngx-translate/http-loader'; +import {StoreModule} from '@ngrx/store'; +import {AppStateService, appState} from '@app/services/storage/app-state.service'; import {HttpClientService} from '@app/services/http-client.service'; import {LoginFormComponent} from './login-form.component'; @@ -38,15 +40,10 @@ describe('LoginFormComponent', () => { }; const httpClient = { isAuthorized: true, - post: () => { + postFormData: () => { return { - finally: (callback: () => void) => { - callback(); - return { - subscribe: (success: () => void, error: () => void) => { - authMock.isError ? error() : success(); - } - } + subscribe: (success: () => void, error: () => void) => { + authMock.isError ? error() : success(); } } } @@ -62,9 +59,13 @@ describe('LoginFormComponent', () => { provide: TranslateLoader, useFactory: HttpLoaderFactory, deps: [Http] + }), + StoreModule.provideStore({ + appState }) ], providers: [ + AppStateService, { provide: HttpClientService, useValue: httpClient @@ -111,9 +112,9 @@ describe('LoginFormComponent', () => { expect(component.isLoginAlertDisplayed).toEqual(test.isLoginAlertDisplayed); }); - it('isRequestInProgress', () => { - expect(component.isRequestInProgress).toEqual(false); - }) + it('isLoginInProgress', () => { + expect(component.isLoginInProgress).toEqual(false); + }); }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.ts index 2a93775..62c71f1 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/login-form/login-form.component.ts @@ -16,21 +16,20 @@ * limitations under the License. */ -import {Component, OnInit} from '@angular/core'; +import {Component} from '@angular/core'; import 'rxjs/add/operator/finally'; import {HttpClientService} from '@app/services/http-client.service'; +import {AppStateService} from '@app/services/storage/app-state.service'; @Component({ selector: 'login-form', templateUrl: './login-form.component.html', styleUrls: ['./login-form.component.less'] }) -export class LoginFormComponent implements OnInit { +export class LoginFormComponent { - constructor(private httpClient: HttpClientService) { - } - - ngOnInit() { + constructor(private httpClient: HttpClientService, private appState: AppStateService) { + this.appState.getParameter('isLoginInProgress').subscribe(value => this.isLoginInProgress = value); } username: string; @@ -39,22 +38,22 @@ export class LoginFormComponent implements OnInit { isLoginAlertDisplayed: boolean; - isRequestInProgress: boolean; + isLoginInProgress: boolean; + + private setIsAuthorized(value: boolean): void { + this.appState.setParameters({ + isAuthorized: value, + isLoginInProgress: false + }); + this.isLoginAlertDisplayed = !value; + } login() { - this.isRequestInProgress = true; - this.httpClient.post('login', { + this.appState.setParameter('isLoginInProgress', true); + this.httpClient.postFormData('login', { username: this.username, password: this.password - }).finally(() => { - this.isRequestInProgress = false; - }).subscribe(() => { - this.isLoginAlertDisplayed = false; - this.httpClient.isAuthorized = true; - }, () => { - this.isLoginAlertDisplayed = true; - this.httpClient.isAuthorized = false; - }); + }).subscribe(() => this.setIsAuthorized(true), () => this.setIsAuthorized(false)); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.html b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.html index df72502..09b2e1e 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.html +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.html @@ -21,7 +21,7 @@ <div [ngClass]="'col-md-1 log-status ' + log.className">{{log.level}}</div> <div class="col-md-3"> <div class="log-type">{{log.type}}</div> - <time class="log-time">{{log.time | amTz: filtering.timeZone | amDateFormat: timeFormat}}</time> + <time class="log-time">{{log.time | amTz: timeZone | amDateFormat: timeFormat}}</time> </div> <div class="col-md-6 log-content-wrapper"> <div class="collapse log-actions" [attr.id]="'details-' + i"> http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.ts index efa05e4..5cfe4cc 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/logs-list/logs-list.component.ts @@ -19,7 +19,6 @@ import {Component, OnInit, Input} from '@angular/core'; import 'rxjs/add/operator/map'; import {HttpClientService} from '@app/services/http-client.service'; import {ServiceLogsService} from '@app/services/storage/service-logs.service'; -import {AppSettingsService} from '@app/services/storage/app-settings.service'; import {FilteringService} from '@app/services/filtering.service'; @Component({ @@ -29,7 +28,7 @@ import {FilteringService} from '@app/services/filtering.service'; }) export class LogsListComponent implements OnInit { - constructor(private httpClient: HttpClientService, private serviceLogsStorage: ServiceLogsService, private appSettings: AppSettingsService, private filtering: FilteringService) { + constructor(private httpClient: HttpClientService, private serviceLogsStorage: ServiceLogsService, private filtering: FilteringService) { this.filtering.filteringSubject.subscribe(this.loadLogs.bind(this)); } @@ -62,6 +61,10 @@ export class LogsListComponent implements OnInit { }); }); + get timeZone(): string { + return this.filtering.timeZone; + } + private loadLogs(): void { this.httpClient.get(this.logsArrayId, this.getParams()).subscribe(response => { this.serviceLogsStorage.clear(); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.html ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.html b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.html index 61d1b93..97ed1ce 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.html +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.html @@ -15,6 +15,9 @@ limitations under the License. --> -<login-form *ngIf="!isAuthorized"></login-form> +<div *ngIf="isInitialLoading" class="text-center"> + <span class="fa fa-spinner fa-spin"></span> +</div> +<login-form *ngIf="!isInitialLoading && !isAuthorized"></login-form> <filters-panel *ngIf="isAuthorized" class="row"></filters-panel> <logs-list *ngIf="isAuthorized" [logsArrayId]="'serviceLogs'"></logs-list> http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.spec.ts index 536f1ef..fa8954c 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.spec.ts @@ -19,6 +19,8 @@ import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {HttpModule} from '@angular/http'; +import {StoreModule} from '@ngrx/store'; +import {AppStateService, appState} from '@app/services/storage/app-state.service'; import {HttpClientService} from '@app/services/http-client.service'; import {MainContainerComponent} from './main-container.component'; @@ -30,9 +32,17 @@ describe('MainContainerComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MainContainerComponent], - imports: [HttpModule], + imports: [ + HttpModule, + StoreModule.provideStore({ + appState + }) + ], schemas: [CUSTOM_ELEMENTS_SCHEMA], - providers: [HttpClientService] + providers: [ + AppStateService, + HttpClientService + ] }) .compileComponents(); })); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.ts index bac39ec..b279cf5 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/main-container/main-container.component.ts @@ -16,22 +16,22 @@ * limitations under the License. */ -import {Component, OnInit} from '@angular/core'; -import {HttpClientService} from '@app/services/http-client.service'; +import {Component} from '@angular/core'; +import {AppStateService} from '@app/services/storage/app-state.service'; @Component({ selector: 'main-container', templateUrl: './main-container.component.html' }) -export class MainContainerComponent implements OnInit { +export class MainContainerComponent { - constructor(private httpClient: HttpClientService) {} - - ngOnInit() { + constructor(private appState: AppStateService) { + this.appState.getParameter('isAuthorized').subscribe(value => this.isAuthorized = value); + this.appState.getParameter('isInitialLoading').subscribe(value => this.isInitialLoading = value); } - get isAuthorized() { - return this.httpClient.isAuthorized; - } + isAuthorized: boolean = false; + + isInitialLoading: boolean = false; } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.spec.ts index d53677d..6c9e021 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.spec.ts @@ -21,6 +21,8 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {Http} from '@angular/http'; import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; import {TranslateHttpLoader} from '@ngx-translate/http-loader'; +import {StoreModule} from '@ngrx/store'; +import {AppSettingsService, appSettings} from '@app/services/storage/app-settings.service'; import {ComponentActionsService} from '@app/services/component-actions.service'; import {FilteringService} from '@app/services/filtering.service'; @@ -38,12 +40,17 @@ describe('MenuButtonComponent', () => { TestBed.configureTestingModule({ declarations: [MenuButtonComponent], imports: [ + StoreModule.provideStore({ + appSettings + }), TranslateModule.forRoot({ provide: TranslateLoader, useFactory: HttpLoaderFactory, deps: [Http] - })], + }) + ], providers: [ + AppSettingsService, ComponentActionsService, FilteringService ], http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.ts index 08b555c..0c1f840 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/components/menu-button/menu-button.component.ts @@ -20,13 +20,11 @@ import {Component, AfterViewInit, Input, ViewChild, ElementRef} from '@angular/c import {ComponentActionsService} from '@app/services/component-actions.service'; import * as $ from 'jquery'; -export const menuButtonComponentOptions = { +@Component({ selector: 'menu-button', templateUrl: './menu-button.component.html', styleUrls: ['./menu-button.component.less'] -} - -@Component(menuButtonComponentOptions) +}) export class MenuButtonComponent implements AfterViewInit { constructor(protected actions: ComponentActionsService) { http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/models/app-state.model.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/models/app-state.model.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/models/app-state.model.ts new file mode 100644 index 0000000..bedcfef --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/models/app-state.model.ts @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http; //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface AppState { + isAuthorized: boolean; + isInitialLoading: boolean; + isLoginInProgress: boolean; +} + +export const initialState: AppState = { + isAuthorized: false, + isInitialLoading: false, + isLoginInProgress: false +} http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/models/store.model.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/models/store.model.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/models/store.model.ts index c169c1b..d5f8881 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/models/store.model.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/models/store.model.ts @@ -16,9 +16,10 @@ * limitations under the License. */ -import {AppSettings} from '@app/models/app-settings.model'; import {Observable} from 'rxjs/Observable'; import {Store, Action} from '@ngrx/store'; +import {AppSettings} from '@app/models/app-settings.model'; +import {AppState} from '@app/models/app-state.model'; import {AuditLog} from '@app/models/audit-log.model'; import {ServiceLog} from '@app/models/service-log.model'; import {BarGraph} from '@app/models/bar-graph.model'; @@ -36,6 +37,7 @@ export const storeActions = { export interface AppStore { appSettings: AppSettings; + appState: AppState; auditLogs: AuditLog[]; serviceLogs: ServiceLog[]; barGraphs: BarGraph[]; @@ -92,6 +94,10 @@ export class CollectionModelService extends ModelService { export class ObjectModelService extends ModelService { + getParameter(key: string): Observable<any> { + return this.store.select(this.modelName, key); + } + setParameter(key: string, value: any): void { let payload = {}; payload[key] = value; @@ -107,7 +113,7 @@ export class ObjectModelService extends ModelService { } -export function collectionReducer(state: any, action: Action): any { +export function collectionReducer(state: any[] = [], action: Action): any { switch (action.type) { case storeActions.ADD: return [...state, ...action.payload]; @@ -122,7 +128,7 @@ export function collectionReducer(state: any, action: Action): any { } } -export function objectReducer(state: any, action: Action): any { +export function objectReducer(state: any = {}, action: Action): any { switch (action.type) { case storeActions.SET: return Object.assign({}, state, action.payload); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.spec.ts index 303fdab..ff0ee37 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.spec.ts @@ -17,13 +17,23 @@ */ import {TestBed, inject} from '@angular/core/testing'; +import {StoreModule} from '@ngrx/store'; +import {AppSettingsService, appSettings} from '@app/services/storage/app-settings.service'; import {ComponentActionsService} from './component-actions.service'; describe('ComponentActionsService', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [ComponentActionsService] + imports: [ + StoreModule.provideStore({ + appSettings + }) + ], + providers: [ + AppSettingsService, + ComponentActionsService + ] }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.ts index 4cde0a0..512b4f3 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/component-actions.service.ts @@ -17,11 +17,12 @@ */ import {Injectable} from '@angular/core'; +import {AppSettingsService} from '@app/services/storage/app-settings.service'; @Injectable() export class ComponentActionsService { - constructor() { + constructor(private appSettings: AppSettingsService) { } //TODO implement actions @@ -38,4 +39,8 @@ export class ComponentActionsService { openHistory() { } + setTimeZone(timeZone: string): void { + this.appSettings.setParameter('timeZone', timeZone); + } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/filtering.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/filtering.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/filtering.service.ts index 9f6b7dc..ce451d3 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/filtering.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/filtering.service.ts @@ -25,7 +25,7 @@ import {AppSettingsService} from '@app/services/storage/app-settings.service'; export class FilteringService { constructor(private appSettings: AppSettingsService) { - this.appSettings.getAll().subscribe(settings => this.timeZone = settings.timeZone); + this.appSettings.getParameter('timeZone').subscribe(value => this.timeZone = value); } timeZone: string; http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.spec.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.spec.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.spec.ts index 083ea23..0dfb0f3 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.spec.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.spec.ts @@ -18,13 +18,23 @@ import {TestBed, inject} from '@angular/core/testing'; import {HttpModule, Request} from '@angular/http'; +import {StoreModule} from '@ngrx/store'; +import {AppStateService, appState} from '@app/services/storage/app-state.service'; import {HttpClientService} from './http-client.service'; describe('HttpClientService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [HttpModule], - providers: [HttpClientService] + imports: [ + HttpModule, + StoreModule.provideStore({ + appState + }) + ], + providers: [ + HttpClientService, + AppStateService + ] }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.ts index cef6696..4ab85e5 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/http-client.service.ts @@ -18,16 +18,17 @@ import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/Observable'; -import {Http, XHRBackend, Request, RequestOptions, RequestOptionsArgs, Response} from '@angular/http'; +import {Http, XHRBackend, Request, RequestOptions, RequestOptionsArgs, Response, Headers, URLSearchParams} from '@angular/http'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import {AuditLogsQueryParams} from '@app/classes/queries/audit-logs-query-params.class'; import {ServiceLogsQueryParams} from '@app/classes/queries/service-logs-query-params.class'; +import {AppStateService} from '@app/services/storage/app-state.service'; @Injectable() export class HttpClientService extends Http { - constructor(backend: XHRBackend, defaultOptions: RequestOptions) { + constructor(backend: XHRBackend, defaultOptions: RequestOptions, private appState: AppStateService) { super(backend, defaultOptions); } @@ -49,14 +50,12 @@ export class HttpClientService extends Http { private readonly unauthorizedStatuses = [401, 403, 419]; - isAuthorized: boolean; - - generateUrlString(url: string): string { + private generateUrlString(url: string): string { const preset = this.endPoints[url]; return preset ? `${this.apiPrefix}${preset.url}` : url; } - generateUrl(request: string | Request): string | Request { + private generateUrl(request: string | Request): string | Request { if (typeof request === 'string') { return this.generateUrlString(request); } @@ -66,23 +65,35 @@ export class HttpClientService extends Http { } } - generateOptions(url: string, params: {[key: string]: string}): RequestOptionsArgs { - const preset = this.endPoints[url]; - return { - params: preset && preset.params ? preset.params(params) : params - }; + private generateOptions(url: string, params: {[key: string]: string}): RequestOptionsArgs { + const preset = this.endPoints[url], + rawParams = preset && preset.params ? preset.params(params) : params; + if (rawParams) { + const paramsString = Object.keys(rawParams).map(key => `${key}=${rawParams[key]}`).join('&'), + urlParams = new URLSearchParams(paramsString, { + encodeKey: key => key, + encodeValue: value => encodeURIComponent(value) + }); + return { + params: urlParams + }; + } else { + return { + params: rawParams + }; + } } - handleError(request: Observable<Response>): void { + private handleError(request: Observable<Response>): void { request.subscribe(null, (error: any) => { if (this.unauthorizedStatuses.indexOf(error.status) > -1) { - this.isAuthorized = false; + this.appState.setParameter('isAuthorized', false); } }); } request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> { - let req = super.request(this.generateUrl(url), options); + let req = super.request(this.generateUrl(url), options).share(); this.handleError(req); return req; } @@ -91,4 +102,18 @@ export class HttpClientService extends Http { return super.get(this.generateUrlString(url), this.generateOptions(url, params)); } + postFormData(url: string, params: {[key: string]: string}, options?: RequestOptionsArgs): Observable<Response> { + const encodedParams = this.generateOptions(url, params).params; + let body; + if (encodedParams && encodedParams instanceof URLSearchParams) { + body = encodedParams.rawParams; + } + let requestOptions = Object.assign({}, options); + if (!requestOptions.headers) { + requestOptions.headers = new Headers(); + } + requestOptions.headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); + return super.post(url, body, requestOptions); + } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/mock-api-data.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/mock-api-data.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/mock-api-data.service.ts index 757f68d..40645f0 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/mock-api-data.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/mock-api-data.service.ts @@ -62,7 +62,10 @@ export class mockApiDataService implements InMemoryDbService { parseUrl(url: string): any { const urlLocation = mockBackendService.prototype.getLocation(url), - query = urlLocation.search && new URLSearchParams(urlLocation.search.substr(1)), + query = urlLocation.search && new URLSearchParams(urlLocation.search.substr(1), { + encodeKey: key => key, + encodeValue: value => value + }), splitUrl = urlLocation.pathname.substr(1).split('/'), urlPartsCount = splitUrl.length, collectionName = splitUrl[urlPartsCount - 1], @@ -104,8 +107,8 @@ export class mockApiDataService implements InMemoryDbService { const collection = allData[filterMapItem.pathToCollection], filteredCollection = collection.filter(item => { let result = true; - query.paramsMap.forEach((value, key) => { - const paramValue = value[0], // TODO implement multiple conditions + query.paramsMap.forEach((value, key) => { + const paramValue = decodeURIComponent(value[0]), // TODO implement multiple conditions paramFilter = filterMapItem.filters[key]; if (paramFilter && ((paramFilter.filterFunction && !paramFilter.filterFunction(item[paramFilter.key], paramValue)) || http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-settings.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-settings.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-settings.service.ts index 1c87a3c..faed254 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-settings.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-settings.service.ts @@ -17,7 +17,7 @@ */ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {AppSettings, defaultSettings} from '@app/models/app-settings.model'; import {AppStore, ObjectModelService, objectReducer} from '@app/models/store.model'; @@ -28,6 +28,6 @@ export class AppSettingsService extends ObjectModelService { } } -export const appSettings: ActionReducer<AppSettings> = (state: AppSettings = defaultSettings, action: Action) => { +export function appSettings(state: AppSettings = defaultSettings, action: Action): any { return objectReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-state.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-state.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-state.service.ts new file mode 100644 index 0000000..49dfa77 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/app-state.service.ts @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http; //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {Injectable} from '@angular/core'; +import {Action, Store} from '@ngrx/store'; +import {AppState, initialState} from '@app/models/app-state.model'; +import {AppStore, ObjectModelService, objectReducer} from '@app/models/store.model'; + +@Injectable() +export class AppStateService extends ObjectModelService { + constructor(store: Store<AppStore>) { + super('appState', store); + } +} + +export function appState(state: AppState = initialState, action: Action): any { + return objectReducer(state, action); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/audit-logs.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/audit-logs.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/audit-logs.service.ts index 7c322ed..a50c68d 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/audit-logs.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/audit-logs.service.ts @@ -17,7 +17,7 @@ */ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {AuditLog} from '@app/models/audit-log.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -28,6 +28,6 @@ export class AuditLogsService extends CollectionModelService { } } -export const auditLogs: ActionReducer<AuditLog[]> = (state: AuditLog[] = [], action: Action) => { +export function auditLogs(state: AuditLog[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/bar-graphs.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/bar-graphs.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/bar-graphs.service.ts index 0109409..b3b955a 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/bar-graphs.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/bar-graphs.service.ts @@ -17,7 +17,7 @@ */ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {BarGraph} from '@app/models/bar-graph.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -28,6 +28,6 @@ export class BarGraphsService extends CollectionModelService { } } -export const barGraphs: ActionReducer<BarGraph[]> = (state: BarGraph[] = [], action: Action) => { +export function barGraphs(state: BarGraph[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/filters.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/filters.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/filters.service.ts index b8748e9..a06852c 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/filters.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/filters.service.ts @@ -18,7 +18,7 @@ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {Filter} from '@app/models/filter.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -29,6 +29,6 @@ export class FiltersService extends CollectionModelService { } } -export const filters: ActionReducer<Filter[]> = (state: Filter[] = [], action: Action) => { +export function filters(state: Filter[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/graphs.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/graphs.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/graphs.service.ts index eda04ee..0abd910 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/graphs.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/graphs.service.ts @@ -18,7 +18,7 @@ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {Graph} from '@app/models/graph.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -29,6 +29,6 @@ export class GraphsService extends CollectionModelService { } } -export const graphs: ActionReducer<Graph[]> = (state: Graph[] = [], action: Action) => { +export function graphs(state: Graph[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/nodes.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/nodes.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/nodes.service.ts index 7b2e6e9..4e47609 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/nodes.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/nodes.service.ts @@ -18,7 +18,7 @@ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {Node} from '@app/models/node.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -29,6 +29,6 @@ export class NodesService extends CollectionModelService { } } -export const nodes: ActionReducer<Node[]> = (state: Node[] = [], action: Action) => { +export function nodes(state: Node[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/service-logs.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/service-logs.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/service-logs.service.ts index ba277c4..ab77138 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/service-logs.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/service-logs.service.ts @@ -18,7 +18,7 @@ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {ServiceLog} from '@app/models/service-log.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -29,6 +29,6 @@ export class ServiceLogsService extends CollectionModelService { } } -export const serviceLogs: ActionReducer<ServiceLog[]> = (state: ServiceLog[] = [], action: Action) => { +export function serviceLogs(state: ServiceLog[] = [], action: Action): any { return collectionReducer(state, action); } http://git-wip-us.apache.org/repos/asf/ambari/blob/9a45ef6c/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/user-configs.service.ts ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/user-configs.service.ts b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/user-configs.service.ts index b26485d..36cfd5f 100644 --- a/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/user-configs.service.ts +++ b/ambari-logsearch/ambari-logsearch-web-new/src/app/services/storage/user-configs.service.ts @@ -18,7 +18,7 @@ import {Injectable} from '@angular/core'; -import {Action, ActionReducer, Store} from '@ngrx/store'; +import {Action, Store} from '@ngrx/store'; import {UserConfig} from '@app/models/user-config.model'; import {AppStore, CollectionModelService, collectionReducer} from '@app/models/store.model'; @@ -29,6 +29,6 @@ export class UserConfigsService extends CollectionModelService { } } -export const userConfigs: ActionReducer<UserConfig[]> = (state: UserConfig[] = [], action: Action) => { +export function userConfigs(state: UserConfig[] = [], action: Action): any { return collectionReducer(state, action); }