mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-10 00:18:57 +00:00
@@ -1,8 +1,8 @@
|
||||
import { CustomDatePipe } from './custom-date.pipe';
|
||||
import { CustomDatePipe } from './custom-date.pipe'
|
||||
|
||||
describe('CustomDatePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new CustomDatePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const pipe = new CustomDatePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,32 +1,47 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core';
|
||||
import { SettingsService, SETTINGS_KEYS } from '../services/settings.service';
|
||||
import { DatePipe } from '@angular/common'
|
||||
import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core'
|
||||
import { SettingsService, SETTINGS_KEYS } from '../services/settings.service'
|
||||
|
||||
const FORMAT_TO_ISO_FORMAT = {
|
||||
"longDate": "y-MM-dd",
|
||||
"mediumDate": "y-MM-dd",
|
||||
"shortDate": "y-MM-dd"
|
||||
longDate: 'y-MM-dd',
|
||||
mediumDate: 'y-MM-dd',
|
||||
shortDate: 'y-MM-dd',
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'customDate'
|
||||
name: 'customDate',
|
||||
})
|
||||
export class CustomDatePipe implements PipeTransform {
|
||||
|
||||
private defaultLocale: string
|
||||
|
||||
constructor(@Inject(LOCALE_ID) locale: string, private datePipe: DatePipe, private settings: SettingsService) {
|
||||
constructor(
|
||||
@Inject(LOCALE_ID) locale: string,
|
||||
private datePipe: DatePipe,
|
||||
private settings: SettingsService
|
||||
) {
|
||||
this.defaultLocale = locale
|
||||
}
|
||||
|
||||
transform(value: any, format?: string, timezone?: string, locale?: string): string | null {
|
||||
let l = locale || this.settings.get(SETTINGS_KEYS.DATE_LOCALE) || this.defaultLocale
|
||||
transform(
|
||||
value: any,
|
||||
format?: string,
|
||||
timezone?: string,
|
||||
locale?: string
|
||||
): string | null {
|
||||
let l =
|
||||
locale ||
|
||||
this.settings.get(SETTINGS_KEYS.DATE_LOCALE) ||
|
||||
this.defaultLocale
|
||||
let f = format || this.settings.get(SETTINGS_KEYS.DATE_FORMAT)
|
||||
if (l == "iso-8601") {
|
||||
if (l == 'iso-8601') {
|
||||
return this.datePipe.transform(value, FORMAT_TO_ISO_FORMAT[f], timezone)
|
||||
} else {
|
||||
return this.datePipe.transform(value, format || this.settings.get(SETTINGS_KEYS.DATE_FORMAT), timezone, l)
|
||||
return this.datePipe.transform(
|
||||
value,
|
||||
format || this.settings.get(SETTINGS_KEYS.DATE_FORMAT),
|
||||
timezone,
|
||||
l
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { DocumentTitlePipe } from './document-title.pipe';
|
||||
import { DocumentTitlePipe } from './document-title.pipe'
|
||||
|
||||
describe('DocumentTitlePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new DocumentTitlePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const pipe = new DocumentTitlePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'documentTitle'
|
||||
name: 'documentTitle',
|
||||
})
|
||||
export class DocumentTitlePipe implements PipeTransform {
|
||||
|
||||
transform(value: string): string {
|
||||
if (value) {
|
||||
return value
|
||||
@@ -12,5 +11,4 @@ export class DocumentTitlePipe implements PipeTransform {
|
||||
return $localize`(no title)`
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { FileSizePipe } from './file-size.pipe';
|
||||
import { FileSizePipe } from './file-size.pipe'
|
||||
|
||||
describe('FileSizePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new FileSizePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const pipe = new FileSizePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -22,12 +22,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
type unit = 'bytes' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB';
|
||||
type unit = 'bytes' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB'
|
||||
type unitPrecisionMap = {
|
||||
[u in unit]: number;
|
||||
};
|
||||
[u in unit]: number
|
||||
}
|
||||
|
||||
const defaultPrecisionMap: unitPrecisionMap = {
|
||||
bytes: 0,
|
||||
@@ -35,8 +35,8 @@ const defaultPrecisionMap: unitPrecisionMap = {
|
||||
MB: 1,
|
||||
GB: 1,
|
||||
TB: 2,
|
||||
PB: 2
|
||||
};
|
||||
PB: 2,
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert bytes into largest possible unit.
|
||||
@@ -55,23 +55,26 @@ const defaultPrecisionMap: unitPrecisionMap = {
|
||||
*/
|
||||
@Pipe({ name: 'fileSize' })
|
||||
export class FileSizePipe implements PipeTransform {
|
||||
private readonly units: unit[] = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
private readonly units: unit[] = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']
|
||||
|
||||
transform(bytes: number = 0, precision: number | unitPrecisionMap = defaultPrecisionMap): string {
|
||||
if (isNaN(parseFloat(String(bytes))) || !isFinite(bytes)) return '?';
|
||||
transform(
|
||||
bytes: number = 0,
|
||||
precision: number | unitPrecisionMap = defaultPrecisionMap
|
||||
): string {
|
||||
if (isNaN(parseFloat(String(bytes))) || !isFinite(bytes)) return '?'
|
||||
|
||||
let unitIndex = 0;
|
||||
let unitIndex = 0
|
||||
|
||||
while (bytes >= 1024) {
|
||||
bytes /= 1024;
|
||||
unitIndex++;
|
||||
bytes /= 1024
|
||||
unitIndex++
|
||||
}
|
||||
|
||||
const unit = this.units[unitIndex];
|
||||
const unit = this.units[unitIndex]
|
||||
|
||||
if (typeof precision === 'number') {
|
||||
return `${bytes.toFixed(+precision)} ${unit}`;
|
||||
return `${bytes.toFixed(+precision)} ${unit}`
|
||||
}
|
||||
return `${bytes.toFixed(precision[unit])} ${unit}`;
|
||||
return `${bytes.toFixed(precision[unit])} ${unit}`
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,20 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { MatchingModel } from '../data/matching-model';
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { MatchingModel } from '../data/matching-model'
|
||||
|
||||
@Pipe({
|
||||
name: 'filter'
|
||||
name: 'filter',
|
||||
})
|
||||
export class FilterPipe implements PipeTransform {
|
||||
transform(items: MatchingModel[], searchText: string): MatchingModel[] {
|
||||
if (!items) return [];
|
||||
if (!searchText) return items;
|
||||
if (!items) return []
|
||||
if (!searchText) return items
|
||||
|
||||
return items.filter(item => {
|
||||
return Object.keys(item).some(key => {
|
||||
return String(item[key]).toLowerCase().includes(searchText.toLowerCase());
|
||||
});
|
||||
});
|
||||
}
|
||||
return items.filter((item) => {
|
||||
return Object.keys(item).some((key) => {
|
||||
return String(item[key])
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase())
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { SafePipe } from './safe.pipe';
|
||||
import { SafePipe } from './safe.pipe'
|
||||
|
||||
describe('SafePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new SafePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const pipe = new SafePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,19 +1,17 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { DomSanitizer } from '@angular/platform-browser'
|
||||
|
||||
@Pipe({
|
||||
name: 'safe'
|
||||
name: 'safe',
|
||||
})
|
||||
export class SafePipe implements PipeTransform {
|
||||
|
||||
constructor(private sanitizer: DomSanitizer) { }
|
||||
constructor(private sanitizer: DomSanitizer) {}
|
||||
|
||||
transform(url) {
|
||||
if (url == null) {
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl("")
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl('')
|
||||
} else {
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(url)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { YesNoPipe } from './yes-no.pipe';
|
||||
import { YesNoPipe } from './yes-no.pipe'
|
||||
|
||||
describe('YesNoPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new YesNoPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const pipe = new YesNoPipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,12 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'yesno'
|
||||
name: 'yesno',
|
||||
})
|
||||
export class YesNoPipe implements PipeTransform {
|
||||
|
||||
transform(value: boolean): unknown {
|
||||
return value ? $localize`Yes` : $localize`No`
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user