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