I used rxjs-tslint tool to automatically update most of the necessary code.
I added a new package, rxjs-compat, to maintain the compatibility
of external plugins that are still using RxJS v5.X.
Signed-off-by: Tiago Melo <tmelo@suse.com>
"ng2-charts": "^1.6.0",
"ng2-toastr": "4.1.2",
"ngx-bootstrap": "^2.0.1",
- "rxjs": "^5.5.2",
+ "rxjs": "^6.2.0",
+ "rxjs-compat": "^6.2.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
import { FormGroup } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap';
-import { Subject } from 'rxjs/Subject';
+import { Subject } from 'rxjs';
@Component({
selector: 'cd-flatten-confimation-modal',
styleUrls: ['./flatten-confimation-modal.component.scss']
})
export class FlattenConfirmationModalComponent implements OnInit {
-
child: string;
parent: string;
import { BsDropdownModule, TabsModule } from 'ngx-bootstrap';
import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { RbdMirroringService } from '../../../shared/api/rbd-mirroring.service';
import { SharedModule } from '../../../shared/shared.module';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { PoolService } from '../../../shared/api/pool.service';
import { RbdService } from '../../../shared/api/rbd.service';
subscribe: (name, metadata, onTaskFinished: (finishedTask: any) => any) => {
return null;
},
- defaultFeatures: () => Observable.of([]),
+ defaultFeatures: () => observableOf([]),
list: (attrs = []) => {
return new Promise(function(resolve, reject) {
return;
TabsModule,
TooltipModule
} from 'ngx-bootstrap';
-import 'rxjs/add/observable/throw';
-import { Observable } from 'rxjs/Observable';
+import { throwError as observableThrowError } from 'rxjs';
import { RbdService } from '../../../shared/api/rbd.service';
import { ComponentsModule } from '../../../shared/components/components.module';
null,
null
);
- spyOn(rbdService, 'delete').and.returnValue(Observable.throw({ status: 500 }));
+ spyOn(rbdService, 'delete').and.returnValue(observableThrowError({ status: 500 }));
spyOn(notificationService, 'notifyTask').and.stub();
component.modalRef = new BsModalRef();
component.modalRef.content = {
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap';
-import { Subject } from 'rxjs/Subject';
+import { Subject } from 'rxjs';
import { RbdService } from '../../../shared/api/rbd.service';
import { FinishedTask } from '../../../shared/models/finished-task';
import { ToastModule } from 'ng2-toastr';
import { BsModalRef, ModalModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs/Observable';
+import { throwError as observableThrowError } from 'rxjs';
import { ApiModule } from '../../../shared/api/api.module';
import { RbdService } from '../../../shared/api/rbd.service';
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ RbdSnapshotListComponent ],
+ declarations: [RbdSnapshotListComponent],
imports: [
DataTableModule,
ComponentsModule,
HttpClientTestingModule,
RouterTestingModule
],
- providers: [ AuthStorageService ]
- })
- .compileComponents();
+ providers: [AuthStorageService]
+ }).compileComponents();
}));
beforeEach(() => {
called = false;
rbdService = new RbdService(null);
notificationService = new NotificationService(null, null);
- component = new RbdSnapshotListComponent(null, null, null, rbdService, null, null,
- notificationService);
- spyOn(rbdService, 'deleteSnapshot').and.returnValue(Observable.throw({status: 500}));
+ component = new RbdSnapshotListComponent(
+ null,
+ null,
+ null,
+ rbdService,
+ null,
+ null,
+ notificationService
+ );
+ spyOn(rbdService, 'deleteSnapshot').and.returnValue(observableThrowError({ status: 500 }));
spyOn(notificationService, 'notifyTask').and.stub();
component.modalRef = new BsModalRef();
component.modalRef.content = {
- stopLoadingSpinner: () => called = true
+ stopLoadingSpinner: () => (called = true)
};
});
import { FormGroup } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap';
-import { Subject } from 'rxjs/Subject';
+import { Subject } from 'rxjs';
@Component({
selector: 'cd-rollback-confimation-modal',
import { RouterTestingModule } from '@angular/router/testing';
import { BsDropdownModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { CephfsService } from '../../../shared/api/cephfs.service';
import { SharedModule } from '../../../shared/shared.module';
import { ChartsModule } from 'ng2-charts/ng2-charts';
import { BsDropdownModule, ProgressbarModule, TabsModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { CephfsService } from '../../../shared/api/cephfs.service';
import { SharedModule } from '../../../shared/shared.module';
import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
import * as _ from 'lodash';
+import { Subscription } from 'rxjs';
import { CephfsService } from '../../../shared/api/cephfs.service';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { Component, Input } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { CephfsService } from '../../../shared/api/cephfs.service';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { FormsModule } from '@angular/forms';
import { TabsModule } from 'ngx-bootstrap/tabs/tabs.module';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { ConfigurationService } from '../../../shared/api/configuration.service';
import { SharedModule } from '../../../shared/shared.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { DashboardService } from '../../../shared/api/dashboard.service';
import { SharedModule } from '../../../shared/shared.module';
const fakeService = {
getHealth: () => {
- return Observable.of({
+ return observableOf({
health: {},
df: {
stats: {}
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
import { RgwUserService } from '../../../shared/api/rgw-user.service';
class MockRgwBucketService extends RgwBucketService {
enumerate() {
- return Observable.of(queryResult);
+ return observableOf(queryResult);
}
}
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap';
-import 'rxjs/add/observable/forkJoin';
-import { Observable } from 'rxjs/Observable';
-import { Subscriber } from 'rxjs/Subscriber';
+import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
import { DeletionModalComponent } from '../../../shared/components/deletion-modal/deletion-modal.component';
deletionObserver: (): Observable<any> => {
return new Observable((observer: Subscriber<any>) => {
// Delete all selected data table rows.
- Observable.forkJoin(
+ observableForkJoin(
this.selection.selected.map((bucket: any) => {
return this.rgwBucketService.delete(bucket.bucket);
})
import { RouterTestingModule } from '@angular/router/testing';
import { BsModalService } from 'ngx-bootstrap/modal';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { RgwUserService } from '../../../shared/api/rgw-user.service';
import { SharedModule } from '../../../shared/shared.module';
class MockRgwUserService extends RgwUserService {
enumerate() {
- return Observable.of(queryResult);
+ return observableOf(queryResult);
}
}
import * as _ from 'lodash';
import { BsModalService } from 'ngx-bootstrap';
-import 'rxjs/add/observable/forkJoin';
-import { Observable } from 'rxjs/Observable';
+import { forkJoin as observableForkJoin, Observable } from 'rxjs';
import { RgwUserService } from '../../../shared/api/rgw-user.service';
import { FormatterService } from '../../../shared/services/formatter.service';
const observables = [];
observables.push(this.rgwUserService.get(params.uid));
observables.push(this.rgwUserService.getQuota(params.uid));
- Observable.forkJoin(observables).subscribe(
+ observableForkJoin(observables).subscribe(
(resp: any[]) => {
this.loading = false;
// Get the default values.
this.submitObservables.push(this.rgwUserService.putQuota(bucketQuotaArgs));
}
// Finally execute all observables.
- Observable.forkJoin(this.submitObservables).subscribe(
+ observableForkJoin(this.submitObservables).subscribe(
() => {
this.goToListView();
},
import { Router } from '@angular/router';
import { BsModalService } from 'ngx-bootstrap';
-import 'rxjs/add/observable/forkJoin';
-import { Observable } from 'rxjs/Observable';
-import { Subscriber } from 'rxjs/Subscriber';
+import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
import { RgwUserService } from '../../../shared/api/rgw-user.service';
import { DeletionModalComponent } from '../../../shared/components/deletion-modal/deletion-modal.component';
deletionObserver: (): Observable<any> => {
return new Observable((observer: Subscriber<any>) => {
// Delete all selected data table rows.
- Observable.forkJoin(
+ observableForkJoin(
this.selection.selected.map((user: any) => {
return this.rgwUserService.delete(user.user_id);
})
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
+import { mergeMap } from 'rxjs/operators';
@Injectable()
export class PerformanceCounterService {
-
private url = 'api/perf_counters';
constructor(private http: HttpClient) {}
get(service_type: string, service_id: string) {
const serviceType = service_type.replace('-', '_');
- return this.http.get(`${this.url}/${serviceType}/${service_id}`)
- .flatMap((resp) => {
- return Observable.of(resp['counters']);
- });
+ return this.http.get(`${this.url}/${serviceType}/${service_id}`).pipe(
+ mergeMap((resp) => {
+ return observableOf(resp['counters']);
+ })
+ );
}
}
import { Injectable } from '@angular/core';
import * as _ from 'lodash';
-import 'rxjs/add/observable/forkJoin';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { forkJoin as observableForkJoin, of as observableOf } from 'rxjs';
+import { mergeMap } from 'rxjs/operators';
@Injectable()
export class RgwBucketService {
* @return {Observable<Object[]>}
*/
list() {
- return this.enumerate().flatMap((buckets: string[]) => {
- if (buckets.length > 0) {
- return Observable.forkJoin(
- buckets.map((bucket: string) => {
- return this.get(bucket);
- })
- );
- }
- return Observable.of([]);
- });
+ return this.enumerate().pipe(
+ mergeMap((buckets: string[]) => {
+ if (buckets.length > 0) {
+ return observableForkJoin(
+ buckets.map((bucket: string) => {
+ return this.get(bucket);
+ }));
+ }
+ return observableOf([]);
+ }));
}
/**
* @return {Observable<boolean>}
*/
exists(bucket: string) {
- return this.enumerate().flatMap((resp: string[]) => {
- const index = _.indexOf(resp, bucket);
- return Observable.of(-1 !== index);
- });
+ return this.enumerate().pipe(
+ mergeMap((resp: string[]) => {
+ const index = _.indexOf(resp, bucket);
+ return observableOf(-1 !== index);
+ }));
}
}
import { Injectable } from '@angular/core';
import * as _ from 'lodash';
-import 'rxjs/add/observable/forkJoin';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import {forkJoin as observableForkJoin, of as observableOf } from 'rxjs';
+import { mergeMap } from 'rxjs/operators';
@Injectable()
export class RgwUserService {
* @return {Observable<Object[]>}
*/
list() {
- return this.enumerate().flatMap((uids: string[]) => {
- if (uids.length > 0) {
- return Observable.forkJoin(
- uids.map((uid: string) => {
- return this.get(uid);
- })
- );
- }
- return Observable.of([]);
- });
+ return this.enumerate().pipe(
+ mergeMap((uids: string[]) => {
+ if (uids.length > 0) {
+ return observableForkJoin(
+ uids.map((uid: string) => {
+ return this.get(uid);
+ }));
+ }
+ return observableOf([]);
+ }));
}
/**
* @return {Observable<boolean>}
*/
exists(uid: string) {
- return this.enumerate().flatMap((resp: string[]) => {
- const index = _.indexOf(resp, uid);
- return Observable.of(-1 !== index);
- });
+ return this.enumerate().pipe(
+ mergeMap((resp: string[]) => {
+ const index = _.indexOf(resp, uid);
+ return observableOf(-1 !== index);
+ }));
}
}
import { ReactiveFormsModule } from '@angular/forms';
import { BsModalRef, BsModalService, ModalModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs/Observable';
-import { Subscriber } from 'rxjs/Subscriber';
+import { Observable, Subscriber, timer as observableTimer } from 'rxjs';
import { ModalComponent } from '../modal/modal.component';
import { DeletionModalComponent } from './deletion-modal.component';
fakeDelete() {
return (): Observable<any> => {
return new Observable((observer: Subscriber<any>) => {
- Observable.timer(100).subscribe(() => {
+ observableTimer(100).subscribe(() => {
observer.next(this.finish());
observer.complete();
});
}
fakeDeleteController() {
- Observable.timer(100).subscribe(() => {
+ observableTimer(100).subscribe(() => {
this.finish();
this.ctrlRef.hide();
});
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap';
-import { Observable } from 'rxjs/Observable';
+import { Observable } from 'rxjs';
import { SubmitButtonComponent } from '../submit-button/submit-button.component';
TemplateRef,
ViewChild
} from '@angular/core';
+
import {
DatatableComponent,
SortDirection,
SortPropDir,
TableColumnProp
} from '@swimlane/ngx-datatable';
-
import * as _ from 'lodash';
-import 'rxjs/add/observable/timer';
-import { Observable } from 'rxjs/Observable';
+import { Observable, timer as observableTimer } from 'rxjs';
import { CellTemplate } from '../../enum/cell-template.enum';
import { CdTableColumn } from '../../models/cd-table-column';
// Each item -> { prop: 'attribute name', dir: 'asc'||'desc'}
@Input() sorts?: SortPropDir[];
// Method used for setting column widths.
- @Input() columnMode ?= 'flex';
+ @Input() columnMode? = 'flex';
// Display the tool header, including reload button, pagination and search fields?
- @Input() toolHeader ?= true;
+ @Input() toolHeader? = true;
// Display the table header?
- @Input() header ?= true;
+ @Input() header? = true;
// Display the table footer?
- @Input() footer ?= true;
+ @Input() footer? = true;
// Page size to show. Set to 0 to show unlimited number of rows.
- @Input() limit ?= 10;
+ @Input() limit? = 10;
/**
* Auto reload time in ms - per default every 5s
tableColumns: CdTableColumn[];
cellTemplates: {
- [key: string]: TemplateRef<any>
+ [key: string]: TemplateRef<any>;
} = {};
search = '';
rows = [];
const exists = _.findIndex(this.columns, ['prop', this.identifier]) !== -1;
// Auto-build the sorting configuration. If the specified identifier doesn't exist,
// then use the property of the first column.
- this.sorts = this.createSortingDefinition(exists ?
- this.identifier : this.columns[0].prop + '');
+ this.sorts = this.createSortingDefinition(
+ exists ? this.identifier : this.columns[0].prop + ''
+ );
// If the specified identifier doesn't exist and it is not forced to use it anyway,
// then use the property of the first column.
if (!exists && !this.forceIdentifier) {
}
}
this.initUserConfig();
- this.columns.forEach(c => {
+ this.columns.forEach((c) => {
if (c.cellTransformation) {
c.cellTemplate = this.cellTemplates[c.cellTransformation];
}
if (this.fetchData.observers.length > 0) {
this.loadingIndicator = true;
}
- if (_.isInteger(this.autoReload) && (this.autoReload > 0)) {
+ if (_.isInteger(this.autoReload) && this.autoReload > 0) {
this.ngZone.runOutsideAngular(() => {
- this.reloadSubscriber = Observable.timer(0, this.autoReload).subscribe(x => {
+ this.reloadSubscriber = observableTimer(0, this.autoReload).subscribe((x) => {
this.ngZone.run(() => {
return this.reloadData();
});
}
}
- initUserConfig () {
+ initUserConfig() {
if (this.autoSave) {
this.tableName = this._calculateUniqueTableName(this.columns);
this._loadUserConfig();
}
}
- _calculateUniqueTableName (columns) {
+ _calculateUniqueTableName(columns) {
const stringToNumber = (s) => {
if (!_.isString(s)) {
return 0;
}
return result;
};
- return columns.reduce((result, value, index) =>
- ((stringToNumber(value.prop) + stringToNumber(value.name)) * (index + 1)) + result,
- 0).toString();
+ return columns
+ .reduce(
+ (result, value, index) =>
+ (stringToNumber(value.prop) + stringToNumber(value.name)) * (index + 1) + result,
+ 0
+ )
+ .toString();
}
- _loadUserConfig () {
+ _loadUserConfig() {
const loaded = this.localStorage.getItem(this.tableName);
if (loaded) {
this.userConfig = JSON.parse(loaded);
this.saveSubscriber = source.subscribe(this._saveUserConfig.bind(this));
}
- _initUserConfigProxy (observer) {
+ _initUserConfigProxy(observer) {
this.userConfig = new Proxy(this.userConfig, {
set(config, prop, value) {
config[prop] = value;
});
}
- _saveUserConfig (config) {
+ _saveUserConfig(config) {
this.localStorage.setItem(this.tableName, JSON.stringify(config));
}
- updateUserColumns () {
- this.userConfig.columns = this.columns.map(c => ({
+ updateUserColumns() {
+ this.userConfig.columns = this.columns.map((c) => ({
prop: c.prop,
name: c.name,
isHidden: !!c.isHidden
}));
}
- filterHiddenColumns () {
- this.tableColumns = this.columns.filter(c => !c.isHidden);
+ filterHiddenColumns() {
+ this.tableColumns = this.columns.filter((c) => !c.isHidden);
}
ngOnDestroy() {
}
}
- refreshBtn () {
+ refreshBtn() {
this.loadingIndicator = true;
this.reloadData();
}
this.updateColumns();
}
- updateColumns () {
+ updateColumns() {
this.updateUserColumns();
this.filterHiddenColumns();
const sortProp = this.userConfig.sorts[0].prop;
if (!_.find(this.tableColumns, (c: CdTableColumn) => c.prop === sortProp)) {
this.userConfig.sorts = this.createSortingDefinition(this.tableColumns[0].prop);
- this.table.onColumnSort({sorts: this.userConfig.sorts});
+ this.table.onColumnSort({ sorts: this.userConfig.sorts });
}
this.table.recalculate();
}
- createSortingDefinition (prop: TableColumnProp): SortPropDir[] {
+ createSortingDefinition(prop: TableColumnProp): SortPropDir[] {
return [
{
prop: prop,
];
}
- changeSorting ({sorts}) {
+ changeSorting({ sorts }) {
this.userConfig.sorts = sorts;
}
this.search = '';
}
let search = this.search.toLowerCase().replace(/,/g, '');
- const columns = this.columns.filter(c => c.cellTransformation !== CellTemplate.sparkline);
+ const columns = this.columns.filter((c) => c.cellTransformation !== CellTemplate.sparkline);
if (search.match(/['"][^'"]+['"]/)) {
search = search.replace(/['"][^'"]+['"]/g, (match: string) => {
return match.replace(/(['"])([^'"]+)(['"])/g, '$2').replace(/ /g, '+');
});
}
// update the rows
- this.rows = this.subSearch(this.data, search.split(' ').filter(s => s.length > 0), columns);
+ this.rows = this.subSearch(this.data, search.split(' ').filter((s) => s.length > 0), columns);
// Whenever the filter changes, always go back to the first page
this.table.offset = 0;
}
- subSearch (data: any[], currentSearch: string[], columns: CdTableColumn[]) {
+ subSearch(data: any[], currentSearch: string[], columns: CdTableColumn[]) {
if (currentSearch.length === 0 || data.length === 0) {
return data;
}
- const searchTerms: string[] = currentSearch.pop().replace('+', ' ').split(':');
+ const searchTerms: string[] = currentSearch
+ .pop()
+ .replace('+', ' ')
+ .split(':');
const columnsClone = [...columns];
const dataClone = [...data];
const filterColumns = (columnName: string) =>
if (searchTerm.length === 0) {
return data;
}
- return data.filter(d => {
- return columns.filter(c => {
- let cellValue: any = _.get(d, c.prop);
- if (!_.isUndefined(c.pipe)) {
- cellValue = c.pipe.transform(cellValue);
- }
- if (_.isUndefined(cellValue)) {
- return;
- }
- if (_.isArray(cellValue)) {
- cellValue = cellValue.join(' ');
- } else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) {
- cellValue = cellValue.toString();
- }
- return cellValue.toLowerCase().indexOf(searchTerm) !== -1;
- }).length > 0;
+ return data.filter((d) => {
+ return (
+ columns.filter((c) => {
+ let cellValue: any = _.get(d, c.prop);
+ if (!_.isUndefined(c.pipe)) {
+ cellValue = c.pipe.transform(cellValue);
+ }
+ if (_.isUndefined(cellValue)) {
+ return;
+ }
+ if (_.isArray(cellValue)) {
+ cellValue = cellValue.join(' ');
+ } else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) {
+ cellValue = cellValue.toString();
+ }
+ return cellValue.toLowerCase().indexOf(searchTerm) !== -1;
+ }).length > 0
+ );
});
}
import { Router } from '@angular/router';
import * as _ from 'lodash';
-import 'rxjs/add/observable/throw';
-import 'rxjs/add/operator/catch';
-import { Observable } from 'rxjs/Observable';
+import { Observable, throwError as observableThrowError } from 'rxjs';
+import { catchError } from 'rxjs/operators';
import { NotificationType } from '../enum/notification-type.enum';
import { FinishedTask } from '../models/finished-task';
@Injectable()
export class ApiInterceptorService implements HttpInterceptor {
-
- constructor(private router: Router,
- private authStorageService: AuthStorageService,
- public notificationService: NotificationService) {}
+ constructor(
+ private router: Router,
+ private authStorageService: AuthStorageService,
+ public notificationService: NotificationService
+ ) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
- return next.handle(request).catch((resp) => {
- if (resp instanceof HttpErrorResponse) {
- let showNotification = true;
- switch (resp.status) {
- case 400:
- const finishedTask = new FinishedTask();
+ return next.handle(request).pipe(
+ catchError((resp) => {
+ if (resp instanceof HttpErrorResponse) {
+ let showNotification = true;
+ switch (resp.status) {
+ case 400:
+ const finishedTask = new FinishedTask();
- const task = resp.error.task;
- if (_.isPlainObject(task)) {
- task.metadata.component = task.metadata.component || resp.error.component;
+ const task = resp.error.task;
+ if (_.isPlainObject(task)) {
+ task.metadata.component = task.metadata.component || resp.error.component;
- finishedTask.name = task.name;
- finishedTask.metadata = task.metadata;
- } else {
- finishedTask.metadata = resp.error;
- }
+ finishedTask.name = task.name;
+ finishedTask.metadata = task.metadata;
+ } else {
+ finishedTask.metadata = resp.error;
+ }
- finishedTask.success = false;
- finishedTask.exception = resp.error;
- this.notificationService.notifyTask(finishedTask);
- showNotification = false;
- break;
- case 401:
- this.authStorageService.remove();
- this.router.navigate(['/login']);
- break;
- case 404:
- this.router.navigate(['/404']);
- break;
- }
+ finishedTask.success = false;
+ finishedTask.exception = resp.error;
+ this.notificationService.notifyTask(finishedTask);
+ showNotification = false;
+ break;
+ case 401:
+ this.authStorageService.remove();
+ this.router.navigate(['/login']);
+ break;
+ case 404:
+ this.router.navigate(['/404']);
+ break;
+ }
- let timeoutId;
- if (showNotification) {
- timeoutId = this.notificationService.show(NotificationType.error,
- resp.error.detail || '',
- `${resp.status} - ${resp.statusText}`);
- }
+ let timeoutId;
+ if (showNotification) {
+ timeoutId = this.notificationService.show(
+ NotificationType.error,
+ resp.error.detail || '',
+ `${resp.status} - ${resp.statusText}`
+ );
+ }
- /**
- * Decorated preventDefault method (in case error previously had
- * preventDefault method defined). If called, it will prevent a
- * notification to be shown.
- */
- resp['preventDefault'] = () => {
- this.notificationService.cancel(timeoutId);
- };
+ /**
+ * Decorated preventDefault method (in case error previously had
+ * preventDefault method defined). If called, it will prevent a
+ * notification to be shown.
+ */
+ resp['preventDefault'] = () => {
+ this.notificationService.cancel(timeoutId);
+ };
- /**
- * If called, it will prevent a notification for the specific status code.
- * @param {number} status The status code to be ignored.
- */
- resp['ignoreStatusCode'] = function(status: number) {
- if (this.status === status) {
- this.preventDefault();
- }
- };
- }
- // Return the error to the method that called it.
- return Observable.throw(resp);
- });
+ /**
+ * If called, it will prevent a notification for the specific status code.
+ * @param {number} status The status code to be ignored.
+ */
+ resp['ignoreStatusCode'] = function(status: number) {
+ if (this.status === status) {
+ this.preventDefault();
+ }
+ };
+ }
+ // Return the error to the method that called it.
+ return observableThrowError(resp);
+ })
+ );
}
}
import { ActivatedRouteSnapshot, Router, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { ModuleStatusGuardService } from './module-status-guard.service';
}
};
const httpClient = TestBed.get(HttpClient);
- spyOn(httpClient, 'get').and.returnValue(Observable.of({ available: true, message: 'foo' }));
+ spyOn(httpClient, 'get').and.returnValue(observableOf({ available: true, message: 'foo' }));
service.canActivate(route, null).subscribe((resp) => {
result = resp;
});
};
const httpClient = TestBed.get(HttpClient);
const router = TestBed.get(Router);
- spyOn(httpClient, 'get').and.returnValue(Observable.of({ available: false, message: null }));
+ spyOn(httpClient, 'get').and.returnValue(observableOf({ available: false, message: null }));
service.canActivateChild(route, null).subscribe((resp) => {
result = resp;
});
};
const httpClient = TestBed.get(HttpClient);
const router = TestBed.get(Router);
- spyOn(httpClient, 'get').and.returnValue(Observable.of(null));
+ spyOn(httpClient, 'get').and.returnValue(observableOf(null));
service.canActivateChild(route, null).subscribe((resp) => {
result = resp;
});
RouterStateSnapshot
} from '@angular/router';
-import 'rxjs/add/observable/of';
-import 'rxjs/add/operator/catch';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
+import { catchError, map } from 'rxjs/operators';
/**
* This service checks if a route can be activated by executing a
private doCheck(route: ActivatedRouteSnapshot) {
const config = route.data['moduleStatusGuardConfig'];
- return this.http
- .get(`/api/${config.apiPath}/status`)
- .map((resp: any) => {
+ return this.http.get(`/api/${config.apiPath}/status`).pipe(
+ map((resp: any) => {
if (!resp.available) {
this.router.navigate([config.redirectTo, resp.message || '']);
}
return resp.available;
- })
- .catch(() => {
+ }),
+ catchError(() => {
this.router.navigate([config.redirectTo]);
- return Observable.of(false);
- });
+ return observableOf(false);
+ })
+ );
}
}
import * as _ from 'lodash';
import { ToastsManager } from 'ng2-toastr';
-import { BehaviorSubject } from 'rxjs/BehaviorSubject';
+import { BehaviorSubject } from 'rxjs';
import { NotificationType } from '../enum/notification-type.enum';
import { CdNotification } from '../models/cd-notification';
import { HttpClient } from '@angular/common/http';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
-import 'rxjs/add/observable/of';
-import { Observable } from 'rxjs/Observable';
+import { of as observableOf } from 'rxjs';
import { AuthStorageService } from './auth-storage.service';
import { SummaryService } from './summary.service';
const httpClientSpy = {
get: () =>
- Observable.of({
+ observableOf({
executing_tasks: [],
health_status: 'HEALTH_OK',
mgr_id: 'x',
expect(summaryService).toBeTruthy();
});
- it('should call refresh', fakeAsync(() => {
- authStorageService.set('foobar');
- let result = false;
- summaryService.refresh();
- summaryService.summaryData$.subscribe((res) => {
- result = true;
- });
- tick(5000);
- spyOn(summaryService, 'refresh').and.callFake(() => true);
- tick(5000);
- expect(result).toEqual(true);
- }));
+ it(
+ 'should call refresh',
+ fakeAsync(() => {
+ authStorageService.set('foobar');
+ let result = false;
+ summaryService.refresh();
+ summaryService.summaryData$.subscribe((res) => {
+ result = true;
+ });
+ tick(5000);
+ spyOn(summaryService, 'refresh').and.callFake(() => true);
+ tick(5000);
+ expect(result).toEqual(true);
+ })
+ );
it('should get summary', () => {
expect(summaryService.get()).toEqual(jasmine.any(Object));
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
-import { Subject } from 'rxjs/Subject';
+import { Subject } from 'rxjs';
import { AuthStorageService } from './auth-storage.service';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import * as _ from 'lodash';
-import 'rxjs/add/observable/of';
-import { Subject } from 'rxjs/Subject';
+import { Subject } from 'rxjs';
import { SummaryService } from './summary.service';
import { TaskManagerService } from './task-manager.service';
import 'jest-preset-angular';
import 'jest-zone-patch';
-// common rxjs imports
-import 'rxjs/add/observable/throw';
-import 'rxjs/add/operator/catch';
-import 'rxjs/add/operator/do';
-import 'rxjs/add/operator/map';
-import 'rxjs/add/operator/switchMap';
-// ...
-
import './jestGlobalMocks';
"curly": true,
"eofline": true,
"forin": true,
- "import-blacklist": [true, "rxjs", "rxjs/Rx"],
+ "import-blacklist": [
+ true,
+ "rxjs/Rx"
+ ],
"import-spacing": true,
"indent": [true, "spaces"],
"interface-over-type-literal": true,