Browse Source

Merge pull request #4364 from abpframework/refactor/remove-deprecateds

Removed deprecateds in Angular UI packages
pull/4415/head
Levent Arman Özak 6 years ago
committed by GitHub
parent
commit
6964be4aa0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 5
      npm/ng-packs/packages/core/src/lib/models/common.ts
  3. 115
      npm/ng-packs/packages/core/src/lib/services/lazy-load.service.ts
  4. 94
      npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts
  5. 1
      npm/ng-packs/packages/theme-shared/src/lib/components/index.ts
  6. 38
      npm/ng-packs/packages/theme-shared/src/lib/components/pagination/pagination.component.html
  7. 55
      npm/ng-packs/packages/theme-shared/src/lib/components/pagination/pagination.component.ts
  8. 2
      npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-default.directive.ts
  9. 6
      npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts
  10. 9
      npm/ng-packs/packages/theme-shared/src/lib/models/toaster.ts
  11. 3
      npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts
  12. 4
      npm/ng-packs/packages/theme-shared/src/lib/tests/table.component.spec.ts
  13. 3
      npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts

2
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -117,6 +117,7 @@ export class BaseCoreModule {}
NgxsModule.forFeature([ReplaceableComponentsState, ProfileState, SessionState, ConfigState]),
NgxsRouterPluginModule.forRoot(),
NgxsStoragePluginModule.forRoot({ key: ['SessionState'] }),
OAuthModule.forRoot(),
],
})
export class RootCoreModule {}
@ -195,7 +196,6 @@ export class CoreModule {
deps: [LocalizationService],
useFactory: noop,
},
...OAuthModule.forRoot().providers,
{ provide: OAuthStorage, useFactory: storageFactory },
],
};

5
npm/ng-packs/packages/core/src/lib/models/common.ts

@ -7,11 +7,6 @@ import { Config } from './config';
export namespace ABP {
export interface Root {
environment: Partial<Config.Environment>;
/**
*
* @deprecated To be deleted in v3.0
*/
requirements?: Config.Requirements;
skipGetAppConfiguration?: boolean;
sendNullsAsQueryParam?: boolean;
}

115
npm/ng-packs/packages/core/src/lib/services/lazy-load.service.ts

@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { concat, Observable, of, ReplaySubject, throwError } from 'rxjs';
import { concat, Observable, of, throwError } from 'rxjs';
import { delay, retryWhen, shareReplay, take, tap } from 'rxjs/operators';
import { LoadingStrategy } from '../strategies';
import { uuid } from '../utils';
@Injectable({
providedIn: 'root',
@ -10,108 +9,20 @@ import { uuid } from '../utils';
export class LazyLoadService {
readonly loaded = new Map<string, HTMLScriptElement | HTMLLinkElement>();
loadedLibraries: { [url: string]: ReplaySubject<void> } = {};
load(strategy: LoadingStrategy, retryTimes?: number, retryDelay?: number): Observable<Event> {
if (this.loaded.has(strategy.path)) return of(new CustomEvent('load'));
load(strategy: LoadingStrategy, retryTimes?: number, retryDelay?: number): Observable<Event>;
/**
*
* @deprecated Use other overload that requires a strategy as first param
*/
load(
urlOrUrls: string | string[],
type: 'script' | 'style',
content?: string,
targetQuery?: string,
position?: InsertPosition,
): Observable<void>;
load(
strategyOrUrl: LoadingStrategy | string | string[],
retryTimesOrType?: number | 'script' | 'style',
retryDelayOrContent?: number | string,
targetQuery: string = 'body',
position: InsertPosition = 'beforeend',
): Observable<Event | void> {
if (strategyOrUrl instanceof LoadingStrategy) {
const strategy = strategyOrUrl;
const retryTimes = typeof retryTimesOrType === 'number' ? retryTimesOrType : 2;
const retryDelay = typeof retryDelayOrContent === 'number' ? retryDelayOrContent : 1000;
if (this.loaded.has(strategy.path)) return of(new CustomEvent('load'));
return strategy.createStream().pipe(
retryWhen(error$ =>
concat(
error$.pipe(delay(retryDelay), take(retryTimes)),
throwError(new CustomEvent('error')),
),
return strategy.createStream().pipe(
retryWhen(error$ =>
concat(
error$.pipe(delay(retryDelay), take(retryTimes)),
throwError(new CustomEvent('error')),
),
tap(() => this.loaded.set(strategy.path, strategy.element)),
delay(100),
shareReplay({ bufferSize: 1, refCount: true }),
);
}
let urlOrUrls = strategyOrUrl;
const content = (retryDelayOrContent as string) || '';
const type = retryTimesOrType as 'script' | 'style';
if (!urlOrUrls && !content) {
return throwError('Should pass url or content');
} else if (!urlOrUrls && content) {
urlOrUrls = [null];
}
if (!Array.isArray(urlOrUrls)) {
urlOrUrls = [urlOrUrls];
}
return new Observable(subscriber => {
(urlOrUrls as string[]).forEach((url, index) => {
const key = url ? url.slice(url.lastIndexOf('/') + 1) : uuid();
if (this.loadedLibraries[key]) {
subscriber.next();
subscriber.complete();
return;
}
this.loadedLibraries[key] = new ReplaySubject();
let library;
if (type === 'script') {
library = document.createElement('script');
library.type = 'text/javascript';
if (url) {
(library as HTMLScriptElement).src = url;
}
(library as HTMLScriptElement).text = content;
} else if (url) {
library = document.createElement('link');
library.type = 'text/css';
(library as HTMLLinkElement).rel = 'stylesheet';
if (url) {
(library as HTMLLinkElement).href = url;
}
} else {
library = document.createElement('style');
(library as HTMLStyleElement).textContent = content;
}
library.onload = () => {
this.loadedLibraries[key].next();
this.loadedLibraries[key].complete();
if (index === urlOrUrls.length - 1) {
subscriber.next();
subscriber.complete();
}
};
document.querySelector(targetQuery).insertAdjacentElement(position, library);
});
});
),
tap(() => this.loaded.set(strategy.path, strategy.element)),
delay(100),
shareReplay({ bufferSize: 1, refCount: true }),
);
}
remove(path: string): boolean {

94
npm/ng-packs/packages/core/src/lib/tests/lazy-load.service.spec.ts

@ -1,6 +1,5 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { of, throwError } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
import { switchMap } from 'rxjs/operators';
import { LazyLoadService } from '../services/lazy-load.service';
import { ScriptLoadingStrategy } from '../strategies';
@ -84,94 +83,3 @@ describe('LazyLoadService', () => {
});
});
});
describe('LazyLoadService (Deprecated)', () => {
let spectator: SpectatorService<LazyLoadService>;
let service: LazyLoadService;
const scriptElement = document.createElement('script');
const linkElement = document.createElement('link');
const styleElement = document.createElement('style');
const cloneDocument = { ...document };
const createService = createServiceFactory({ service: LazyLoadService });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
afterEach(() => (document = { ...cloneDocument }));
test('should load script with content just one time', done => {
const spy = jest.spyOn(document, 'createElement');
spy.mockReturnValue(scriptElement);
service.load('https://abp.io', 'script', 'test').subscribe(res => {
expect(
document.querySelector('script[src="https://abp.io"][type="text/javascript"]').textContent,
).toMatch('test');
});
scriptElement.onload(null);
service.load('https://abp.io', 'script', 'test').subscribe(res => {
expect(
document.querySelectorAll('script[src="https://abp.io"][type="text/javascript"]'),
).toHaveLength(1);
done();
});
});
test('should load style element', done => {
const spy = jest.spyOn(document, 'createElement');
spy.mockReturnValue(styleElement);
const content = '* { color: black; }';
service.load(null, 'style', content).subscribe(res => {
expect(document.querySelector('style').textContent).toMatch(content);
done();
});
styleElement.onload(null);
});
describe('style with url', () => {
beforeEach(() => {
const spy = jest.spyOn(document, 'createElement');
spy.mockReturnValue(linkElement);
});
test('should load an link element', done => {
service.load('https://abp.io', 'style').subscribe(res => {
expect(
document.querySelector('link[type="text/css"][rel="stylesheet"][href="https://abp.io"]'),
).toBeTruthy();
done();
});
linkElement.onload(null);
});
test('should load link elements', done => {
service.load(['https://abp.io', 'https://volosoft.com'], 'style').subscribe(res => {
expect(document.querySelector('link[href="https://volosoft.com"]')).toBeTruthy();
done();
});
linkElement.onload(null);
});
});
test('should throw error when required parameters are null', done => {
service
.load(null, 'style')
.pipe(
catchError(err => {
expect(err).toBeTruthy();
done();
return of(null);
}),
)
.subscribe();
});
});

1
npm/ng-packs/packages/theme-shared/src/lib/components/index.ts

@ -5,7 +5,6 @@ export * from './confirmation/confirmation.component';
export * from './loading/loading.component';
export * from './loader-bar/loader-bar.component';
export * from './modal/modal.component';
export * from './pagination/pagination.component';
export * from './sort-order-icon/sort-order-icon.component';
export * from './table-empty-message/table-empty-message.component';
export * from './table/table.component';

38
npm/ng-packs/packages/theme-shared/src/lib/components/pagination/pagination.component.html

@ -1,38 +0,0 @@
<div
class="ui-paginator-bottom ui-paginator ui-widget ui-widget-header ui-unselectable-text ui-helper-clearfix"
>
<a
class="ui-paginator-first ui-paginator-element ui-state-default ui-corner-all"
[class.ui-state-disabled]="value === 1"
tabindex="-1"
(click)="changePage(1)"
><span class="ui-paginator-icon pi pi-step-backward"></span></a
><a
class="ui-paginator-prev ui-paginator-element ui-state-default ui-corner-all"
[class.ui-state-disabled]="value === 1"
tabindex="-1"
(click)="changePage(value - 1)"
><span class="ui-paginator-icon pi pi-caret-left"></span></a
><span class="ui-paginator-pages"
><a
*ngFor="let page of pageArray; trackBy: trackByFn"
(click)="changePage(page)"
class="ui-paginator-page ui-paginator-element ui-state-default ui-corner-all"
[class.ui-state-active]="page === value"
tabindex="0"
>{{ page }}</a
></span
><a
class="ui-paginator-next ui-paginator-element ui-state-default ui-corner-all"
[class.ui-state-disabled]="value === totalPages"
tabindex="0"
(click)="changePage(value + 1)"
><span class="ui-paginator-icon pi pi-caret-right"></span></a
><a
class="ui-paginator-last ui-paginator-element ui-state-default ui-corner-all"
[class.ui-state-disabled]="value === totalPages"
tabindex="0"
(click)="changePage(totalPages)"
><span class="ui-paginator-icon pi pi-step-forward"></span
></a>
</div>

55
npm/ng-packs/packages/theme-shared/src/lib/components/pagination/pagination.component.ts

@ -1,55 +0,0 @@
import { Component, Input, OnInit, Output, EventEmitter, TrackByFunction } from '@angular/core';
@Component({
selector: 'abp-pagination',
templateUrl: 'pagination.component.html',
})
/**
* @deprecated
*/
export class PaginationComponent implements OnInit {
private _value = 1;
@Input()
get value(): number {
return this._value;
}
set value(newValue: number) {
if (this._value === newValue) return;
this._value = newValue;
this.valueChange.emit(newValue);
}
@Output()
readonly valueChange = new EventEmitter<number>();
@Input()
totalPages = 0;
get pageArray(): number[] {
const count = this.totalPages < 5 ? this.totalPages : 5;
if (this.value === 1 || this.value === 2) {
return Array.from(new Array(count)).map((_, index) => index + 1);
} else if (this.value === this.totalPages || this.value === this.totalPages - 1) {
return Array.from(new Array(count)).map((_, index) => this.totalPages - count + 1 + index);
} else {
return [this.value - 2, this.value - 1, this.value, this.value + 1, this.value + 2];
}
}
trackByFn: TrackByFunction<number> = (_, page) => page;
ngOnInit() {
if (!this.value || this.value < 1 || this.value > this.totalPages) {
this.value = 1;
}
}
changePage(page: number) {
if (page < 1) return;
else if (page > this.totalPages) return;
this.value = page;
}
}

2
npm/ng-packs/packages/theme-shared/src/lib/directives/ngx-datatable-default.directive.ts

@ -19,5 +19,7 @@ export class NgxDatatableDefaultDirective {
this.table.footerHeight = 50;
this.table.headerHeight = 50;
this.table.rowHeight = 'auto';
this.table.scrollbarH = true;
this.table.virtualization = false;
}
}

6
npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts

@ -10,12 +10,6 @@ export namespace Confirmation {
hideYesBtn?: boolean;
cancelText?: Config.LocalizationParam;
yesText?: Config.LocalizationParam;
/**
*
* @deprecated To be deleted in v2.9
*/
closable?: boolean;
}
export interface DialogData {

9
npm/ng-packs/packages/theme-shared/src/lib/models/toaster.ts

@ -20,13 +20,4 @@ export namespace Toaster {
}
export type Severity = 'neutral' | 'success' | 'info' | 'warning' | 'error';
/**
* @deprecated Status will be removed from toaster model in v3.0
*/
export enum Status {
confirm = 'confirm',
reject = 'reject',
dismiss = 'dismiss',
}
}

3
npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts

@ -2,7 +2,6 @@ import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator/je
import { TableSortDirective } from '../directives/table-sort.directive';
import { TableComponent } from '../components/table/table.component';
import { DummyLocalizationPipe } from './table.component.spec';
import { PaginationComponent } from '../components';
import { NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap';
describe('TableSortDirective', () => {
@ -10,7 +9,7 @@ describe('TableSortDirective', () => {
let directive: TableSortDirective;
const createDirective = createDirectiveFactory({
directive: TableSortDirective,
declarations: [TableComponent, DummyLocalizationPipe, PaginationComponent],
declarations: [TableComponent, DummyLocalizationPipe],
imports: [NgbPaginationModule],
});

4
npm/ng-packs/packages/theme-shared/src/lib/tests/table.component.spec.ts

@ -1,7 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap';
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest';
import { PaginationComponent, TableComponent } from '../components';
import { TableComponent } from '../components';
@Pipe({
name: 'abpLocalization',
@ -16,7 +16,7 @@ describe('TableComponent', () => {
let spectator: SpectatorHost<TableComponent>;
const createHost = createHostFactory({
component: TableComponent,
declarations: [PaginationComponent, DummyLocalizationPipe],
declarations: [DummyLocalizationPipe],
imports: [NgbPaginationModule],
});

3
npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts

@ -14,7 +14,6 @@ import { LoaderBarComponent } from './components/loader-bar/loader-bar.component
import { LoadingComponent } from './components/loading/loading.component';
import { ModalContainerComponent } from './components/modal/modal-container.component';
import { ModalComponent } from './components/modal/modal.component';
import { PaginationComponent } from './components/pagination/pagination.component';
import { SortOrderIconComponent } from './components/sort-order-icon/sort-order-icon.component';
import { TableEmptyMessageComponent } from './components/table-empty-message/table-empty-message.component';
import { TableComponent } from './components/table/table.component';
@ -59,7 +58,6 @@ export function ngxDatatableMessageFactory(store: Store) {
LoadingComponent,
ModalComponent,
ModalContainerComponent,
PaginationComponent,
TableComponent,
TableEmptyMessageComponent,
ToastComponent,
@ -80,7 +78,6 @@ export function ngxDatatableMessageFactory(store: Store) {
LoaderBarComponent,
LoadingComponent,
ModalComponent,
PaginationComponent,
TableComponent,
TableEmptyMessageComponent,
ToastComponent,

Loading…
Cancel
Save