mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-7597] Convert Core pipes to Standalone # (#9560)
This commit is contained in:
@@ -18,7 +18,10 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
import { addMinutes, fromUnixTime, parse } from 'date-fns';
|
import { addMinutes, fromUnixTime, parse } from 'date-fns';
|
||||||
|
|
||||||
@Pipe({ name: 'adfDateTime' })
|
@Pipe({
|
||||||
|
name: 'adfDateTime',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class DateTimePipe implements PipeTransform {
|
export class DateTimePipe implements PipeTransform {
|
||||||
transform(value: string | Date | number, dateFormat: string): Date {
|
transform(value: string | Date | number, dateFormat: string): Date {
|
||||||
let parsedValue: Date;
|
let parsedValue: Date;
|
||||||
|
@@ -25,7 +25,8 @@ import { takeUntil } from 'rxjs/operators';
|
|||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'adfDecimalNumber',
|
name: 'adfDecimalNumber',
|
||||||
pure: false
|
pure: false,
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class DecimalNumberPipe implements PipeTransform, OnDestroy {
|
export class DecimalNumberPipe implements PipeTransform, OnDestroy {
|
||||||
static DEFAULT_LOCALE = 'en-US';
|
static DEFAULT_LOCALE = 'en-US';
|
||||||
|
@@ -20,12 +20,11 @@ import { TranslationService } from '../translation/translation.service';
|
|||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'adfFileSize',
|
name: 'adfFileSize',
|
||||||
pure: false
|
pure: false,
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class FileSizePipe implements PipeTransform {
|
export class FileSizePipe implements PipeTransform {
|
||||||
|
constructor(private translation: TranslationService) {}
|
||||||
constructor(private translation: TranslationService) {
|
|
||||||
}
|
|
||||||
|
|
||||||
transform(paramByte: any, decimals: number = 2): string {
|
transform(paramByte: any, decimals: number = 2): string {
|
||||||
if (paramByte == null) {
|
if (paramByte == null) {
|
||||||
@@ -49,5 +48,4 @@ export class FileSizePipe implements PipeTransform {
|
|||||||
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + i18nSize;
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + i18nSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,12 +19,11 @@ import { PipeTransform, Pipe } from '@angular/core';
|
|||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'fileType',
|
name: 'fileType',
|
||||||
pure: true
|
pure: true,
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class FileTypePipe implements PipeTransform {
|
export class FileTypePipe implements PipeTransform {
|
||||||
|
|
||||||
transform(value: string) {
|
transform(value: string) {
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
@@ -32,5 +31,4 @@ export class FileTypePipe implements PipeTransform {
|
|||||||
return fileInfo.split('_').pop();
|
return fileInfo.split('_').pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,12 @@
|
|||||||
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({ name: 'filterOutEvery' })
|
@Pipe({
|
||||||
|
name: 'filterOutEvery',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class FilterOutArrayObjectsByPropPipe<T> implements PipeTransform {
|
export class FilterOutArrayObjectsByPropPipe<T> implements PipeTransform {
|
||||||
transform(values: T[], filterKey: string, filterValue: any): T[] {
|
transform(values: T[], filterKey: string, filterValue: any): T[] {
|
||||||
return (values ?? []).filter(value => value[filterKey] !== filterValue);
|
return (values ?? []).filter((value) => value[filterKey] !== filterValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({ name: 'filterString' })
|
@Pipe({
|
||||||
|
name: 'filterString',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class FilterStringPipe implements PipeTransform {
|
export class FilterStringPipe implements PipeTransform {
|
||||||
|
|
||||||
transform(value: string = '', filterBy: string = ''): string {
|
transform(value: string = '', filterBy: string = ''): string {
|
||||||
const testResult = filterBy ?
|
const testResult = filterBy ? value.toLowerCase().indexOf(filterBy.toLowerCase()) > -1 : true;
|
||||||
value.toLowerCase().indexOf(filterBy.toLowerCase()) > -1 :
|
|
||||||
true;
|
|
||||||
|
|
||||||
return testResult ? value : '';
|
return testResult ? value : '';
|
||||||
}
|
}
|
||||||
|
@@ -18,17 +18,17 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'formatSpace'
|
name: 'formatSpace',
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class FormatSpacePipe implements PipeTransform {
|
export class FormatSpacePipe implements PipeTransform {
|
||||||
|
|
||||||
transform(inputValue: string, replaceChar: string = '_', lowerCase: boolean = true): string {
|
transform(inputValue: string, replaceChar: string = '_', lowerCase: boolean = true): string {
|
||||||
let transformedString = '';
|
let transformedString = '';
|
||||||
if (inputValue) {
|
if (inputValue) {
|
||||||
transformedString = lowerCase ? inputValue.trim().split(' ').join(replaceChar).toLocaleLowerCase() :
|
transformedString = lowerCase
|
||||||
inputValue.trim().split(' ').join(replaceChar);
|
? inputValue.trim().split(' ').join(replaceChar).toLocaleLowerCase()
|
||||||
|
: inputValue.trim().split(' ').join(replaceChar);
|
||||||
}
|
}
|
||||||
return transformedString;
|
return transformedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,9 +18,11 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
import { UserLike } from './user-like.interface';
|
import { UserLike } from './user-like.interface';
|
||||||
|
|
||||||
@Pipe({ name: 'fullName' })
|
@Pipe({
|
||||||
|
name: 'fullName',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class FullNamePipe implements PipeTransform {
|
export class FullNamePipe implements PipeTransform {
|
||||||
|
|
||||||
transform(user: UserLike): string {
|
transform(user: UserLike): string {
|
||||||
return this.buildFullName(user) ? this.buildFullName(user) : this.buildFromUsernameOrEmail(user);
|
return this.buildFullName(user) ? this.buildFullName(user) : this.buildFromUsernameOrEmail(user);
|
||||||
}
|
}
|
||||||
|
@@ -19,11 +19,11 @@ import { Pipe, PipeTransform } from '@angular/core';
|
|||||||
import { TranslationService } from '../translation/translation.service';
|
import { TranslationService } from '../translation/translation.service';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'adfLocalizedRole'
|
name: 'adfLocalizedRole',
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class LocalizedRolePipe implements PipeTransform {
|
export class LocalizedRolePipe implements PipeTransform {
|
||||||
constructor(private translationService: TranslationService) {
|
constructor(private translationService: TranslationService) {}
|
||||||
}
|
|
||||||
|
|
||||||
transform(value: string): any {
|
transform(value: string): any {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
@@ -19,10 +19,10 @@ import { Pipe, PipeTransform } from '@angular/core';
|
|||||||
import { ThumbnailService } from '../common/services/thumbnail.service';
|
import { ThumbnailService } from '../common/services/thumbnail.service';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'adfMimeTypeIcon'
|
name: 'adfMimeTypeIcon',
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class MimeTypeIconPipe implements PipeTransform {
|
export class MimeTypeIconPipe implements PipeTransform {
|
||||||
|
|
||||||
constructor(private thumbnailService: ThumbnailService) {}
|
constructor(private thumbnailService: ThumbnailService) {}
|
||||||
|
|
||||||
transform(text: string): string {
|
transform(text: string): string {
|
||||||
|
@@ -22,7 +22,10 @@ declare let moment: any;
|
|||||||
/**
|
/**
|
||||||
* @deprecated this pipe is deprecated and should no longer be used
|
* @deprecated this pipe is deprecated and should no longer be used
|
||||||
*/
|
*/
|
||||||
@Pipe({ name: 'adfMomentDate' })
|
@Pipe({
|
||||||
|
name: 'adfMomentDate',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class MomentDatePipe implements PipeTransform {
|
export class MomentDatePipe implements PipeTransform {
|
||||||
transform(value: any, dateFormat: string): any {
|
transform(value: any, dateFormat: string): any {
|
||||||
return moment(value, dateFormat);
|
return moment(value, dateFormat);
|
||||||
|
@@ -21,7 +21,10 @@ declare let moment: any;
|
|||||||
/**
|
/**
|
||||||
* @deprecated this pipe is deprecated and should no longer be used
|
* @deprecated this pipe is deprecated and should no longer be used
|
||||||
*/
|
*/
|
||||||
@Pipe({ name: 'adfMomentDateTime' })
|
@Pipe({
|
||||||
|
name: 'adfMomentDateTime',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class MomentDateTimePipe implements PipeTransform {
|
export class MomentDateTimePipe implements PipeTransform {
|
||||||
transform(value: any, dateFormat: string): any {
|
transform(value: any, dateFormat: string): any {
|
||||||
return moment(value, dateFormat).add(moment(value, dateFormat).utcOffset(), 'minutes');
|
return moment(value, dateFormat).add(moment(value, dateFormat).utcOffset(), 'minutes');
|
||||||
|
@@ -18,18 +18,13 @@
|
|||||||
import { MultiValuePipe } from './multi-value.pipe';
|
import { MultiValuePipe } from './multi-value.pipe';
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
|
|
||||||
describe('FullNamePipe', () => {
|
|
||||||
|
|
||||||
|
describe('MultiValuePipe', () => {
|
||||||
let pipe: MultiValuePipe;
|
let pipe: MultiValuePipe;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [CoreTestingModule, MultiValuePipe]
|
||||||
TranslateModule.forRoot(),
|
|
||||||
CoreTestingModule
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
pipe = TestBed.inject(MultiValuePipe);
|
pipe = TestBed.inject(MultiValuePipe);
|
||||||
});
|
});
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({ name: 'multiValue' })
|
@Pipe({
|
||||||
|
name: 'multiValue',
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
export class MultiValuePipe implements PipeTransform {
|
export class MultiValuePipe implements PipeTransform {
|
||||||
|
|
||||||
static DEFAULT_SEPARATOR = ', ';
|
static DEFAULT_SEPARATOR = ', ';
|
||||||
|
|
||||||
transform(values: any | any[], valueSeparator: string = MultiValuePipe.DEFAULT_SEPARATOR): string {
|
transform(values: any | any[], valueSeparator: string = MultiValuePipe.DEFAULT_SEPARATOR): string {
|
||||||
|
|
||||||
if (values && values instanceof Array) {
|
if (values && values instanceof Array) {
|
||||||
return values.join(valueSeparator);
|
return values.join(valueSeparator);
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
import { FileSizePipe } from './file-size.pipe';
|
import { FileSizePipe } from './file-size.pipe';
|
||||||
@@ -30,43 +29,19 @@ import { MultiValuePipe } from './multi-value.pipe';
|
|||||||
import { LocalizedDatePipe } from './localized-date.pipe';
|
import { LocalizedDatePipe } from './localized-date.pipe';
|
||||||
import { DecimalNumberPipe } from './decimal-number.pipe';
|
import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||||
import { LocalizedRolePipe } from './localized-role.pipe';
|
import { LocalizedRolePipe } from './localized-role.pipe';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { MomentDatePipe } from './moment-date.pipe';
|
import { MomentDatePipe } from './moment-date.pipe';
|
||||||
import { MomentDateTimePipe } from './moment-datetime.pipe';
|
import { MomentDateTimePipe } from './moment-datetime.pipe';
|
||||||
import { FilterStringPipe } from './filter-string.pipe';
|
import { FilterStringPipe } from './filter-string.pipe';
|
||||||
import { FilterOutArrayObjectsByPropPipe } from './filter-out-every-object-by-prop.pipe';
|
import { FilterOutArrayObjectsByPropPipe } from './filter-out-every-object-by-prop.pipe';
|
||||||
import { DateTimePipe } from './date-time.pipe';
|
import { DateTimePipe } from './date-time.pipe';
|
||||||
|
|
||||||
@NgModule({
|
export const CORE_PIPES = [
|
||||||
imports: [
|
|
||||||
CommonModule,
|
|
||||||
TranslateModule,
|
|
||||||
LocalizedDatePipe,
|
LocalizedDatePipe,
|
||||||
TimeAgoPipe
|
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
FileSizePipe,
|
|
||||||
HighlightPipe,
|
|
||||||
MimeTypeIconPipe,
|
|
||||||
InitialUsernamePipe,
|
|
||||||
FullNamePipe,
|
|
||||||
FormatSpacePipe,
|
|
||||||
FileTypePipe,
|
|
||||||
MultiValuePipe,
|
|
||||||
DecimalNumberPipe,
|
|
||||||
LocalizedRolePipe,
|
|
||||||
MomentDatePipe,
|
|
||||||
MomentDateTimePipe,
|
|
||||||
DateTimePipe,
|
|
||||||
FilterStringPipe,
|
|
||||||
FilterOutArrayObjectsByPropPipe
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
FileSizePipe,
|
|
||||||
HighlightPipe,
|
|
||||||
TimeAgoPipe,
|
TimeAgoPipe,
|
||||||
|
FileSizePipe,
|
||||||
|
HighlightPipe,
|
||||||
MimeTypeIconPipe,
|
MimeTypeIconPipe,
|
||||||
InitialUsernamePipe,
|
FullNamePipe,
|
||||||
FormatSpacePipe,
|
FormatSpacePipe,
|
||||||
FileTypePipe,
|
FileTypePipe,
|
||||||
MultiValuePipe,
|
MultiValuePipe,
|
||||||
@@ -77,26 +52,16 @@ import { DateTimePipe } from './date-time.pipe';
|
|||||||
DateTimePipe,
|
DateTimePipe,
|
||||||
FilterStringPipe,
|
FilterStringPipe,
|
||||||
FilterOutArrayObjectsByPropPipe,
|
FilterOutArrayObjectsByPropPipe,
|
||||||
LocalizedDatePipe
|
InitialUsernamePipe
|
||||||
],
|
] as const;
|
||||||
exports: [
|
|
||||||
FileSizePipe,
|
/**
|
||||||
HighlightPipe,
|
* @deprecated this Module is deprecated and should no longer be used.
|
||||||
TimeAgoPipe,
|
* Consider importing CORE_PIPES or individual pipes directly.
|
||||||
MimeTypeIconPipe,
|
*/
|
||||||
InitialUsernamePipe,
|
@NgModule({
|
||||||
FullNamePipe,
|
imports: [...CORE_PIPES],
|
||||||
FormatSpacePipe,
|
providers: [...CORE_PIPES],
|
||||||
FileTypePipe,
|
exports: [...CORE_PIPES]
|
||||||
MultiValuePipe,
|
|
||||||
DecimalNumberPipe,
|
|
||||||
LocalizedRolePipe,
|
|
||||||
MomentDatePipe,
|
|
||||||
MomentDateTimePipe,
|
|
||||||
DateTimePipe,
|
|
||||||
FilterStringPipe,
|
|
||||||
FilterOutArrayObjectsByPropPipe
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
export class PipeModule {
|
export class PipeModule {}
|
||||||
}
|
|
||||||
|
@@ -19,10 +19,10 @@ import { Pipe, PipeTransform } from '@angular/core';
|
|||||||
import { HighlightTransformService, HighlightTransformResult } from '../common/services/highlight-transform.service';
|
import { HighlightTransformService, HighlightTransformResult } from '../common/services/highlight-transform.service';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'highlight'
|
name: 'highlight',
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class HighlightPipe implements PipeTransform {
|
export class HighlightPipe implements PipeTransform {
|
||||||
|
|
||||||
constructor(private highlightTransformService: HighlightTransformService) {}
|
constructor(private highlightTransformService: HighlightTransformService) {}
|
||||||
|
|
||||||
transform(text: string, search: string): string {
|
transform(text: string, search: string): string {
|
||||||
|
@@ -20,12 +20,11 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
|||||||
import { UserLike } from './user-like.interface';
|
import { UserLike } from './user-like.interface';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'usernameInitials'
|
name: 'usernameInitials',
|
||||||
|
standalone: true
|
||||||
})
|
})
|
||||||
export class InitialUsernamePipe implements PipeTransform {
|
export class InitialUsernamePipe implements PipeTransform {
|
||||||
|
constructor(private sanitized: DomSanitizer) {}
|
||||||
constructor(private sanitized: DomSanitizer) {
|
|
||||||
}
|
|
||||||
|
|
||||||
transform(user: UserLike & { displayName?: string }, className: string = '', delimiter: string = ''): SafeHtml {
|
transform(user: UserLike & { displayName?: string }, className: string = '', delimiter: string = ''): SafeHtml {
|
||||||
let safeHtml: SafeHtml = '';
|
let safeHtml: SafeHtml = '';
|
||||||
@@ -42,8 +41,8 @@ export class InitialUsernamePipe implements PipeTransform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getInitialUserName(firstName: string, lastName: string, delimiter: string): string {
|
getInitialUserName(firstName: string, lastName: string, delimiter: string): string {
|
||||||
firstName = (firstName ? firstName[0] : '');
|
firstName = firstName ? firstName[0] : '';
|
||||||
lastName = (lastName ? lastName[0] : '');
|
lastName = lastName ? lastName[0] : '';
|
||||||
return firstName + delimiter + lastName;
|
return firstName + delimiter + lastName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user