ramda#pathOr TypeScript Examples
The following examples show how to use
ramda#pathOr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: error.interceptor.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
catchError((error: HttpErrorResponse) => {
this.toastr.error(pathOr('Something went wrong while trying to do that', ['error', 'message'])(error), 'Error');
return throwError(error);
})
);
}
Example #2
Source File: category-input.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnInit() {
this.doSearch();
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
if (!this.multiple) {
return this.propagateChange(pathOr(value, ['value'])(value));
}
this.propagateChange((value || []).map((roleItem) => pathOr(roleItem, ['value'])(roleItem)));
});
}
Example #3
Source File: event.modal.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private ensureNoIssues(): void {
this.slotService.verify({
...this.form.value,
uuid: pathOr(null, ['event', 'uuid'])(this.data),
start: moment(this.form.value.start).unix(),
end: moment(this.form.value.end).unix(),
})
.toPromise()
.then((slots) => this.validationInfo = slots);
}
Example #4
Source File: data-input.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnInit() {
this.doSearch();
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
if (!this.multiple) {
return this.propagateChange(pathOr(value, ['value'])(value));
}
this.propagateChange((value || []).map((roleItem) => pathOr(roleItem, ['value'])(roleItem)));
});
}
Example #5
Source File: slot-fields.page.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
subfields: this.formBuilder.array(this.buildFieldsArray(field.subfields || []))
});
if (!field.slug) {
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
}
return fieldForm;
});
}
Example #6
Source File: dynamic-input.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public writeValue(value: any) {
this.originalValue = value;
if (this.multiLanguage) {
return setTimeout(() => this.control.setValue(pathOr('', [this.language])(value)));
}
setTimeout(() => this.control.setValue(value));
}
Example #7
Source File: profile-fields.page.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
});
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
return fieldForm;
});
}
Example #8
Source File: detail.page.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnInit(): void {
this.form = this.formBuilder.group({
name: ['', Validators.required],
description: ['', Validators.required],
color: ['', Validators.required],
});
this.slotTypeService.fetchOne(this.activatedRoute.snapshot.params.id)
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((user) => {
this.form.patchValue({
...user,
role: pathOr(null, ['role', 'uuid'])(user)
});
});
}
Example #9
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
subfields: this.formBuilder.array(this.buildFieldsArray(field.subfields || []))
});
if (!field.slug) {
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
}
return fieldForm;
});
}
Example #10
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnChanges(changes: any) {
if (!changes.entityType) {
return;
}
const entityType = changes.entityType.currentValue;
this.form.patchValue({
...entityType,
workflow: pathOr('', ['workflow', 'uuid'])(entityType)
});
const fieldsGroup = this.form.get('fields') as FormArray;
this.buildFieldsArray((propOr([], 'fields')(entityType) as any[])).map((formGroup) => {
fieldsGroup.push(formGroup);
});
}
Example #11
Source File: role-input.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnInit() {
this.doSearch();
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
if (!this.multiple) {
return this.propagateChange(pathOr(value, ['value'])(value));
}
this.propagateChange((value || []).map((roleItem) => pathOr(roleItem, ['value'])(roleItem)));
});
}
Example #12
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
subfields: this.formBuilder.array(this.buildFieldsArray(field.subfields || []))
});
if (!field.slug) {
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
}
return fieldForm;
});
}
Example #13
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnChanges(changes: any) {
if (!changes.entityType) {
return;
}
const entityType = changes.entityType.currentValue;
this.form.patchValue({
...entityType,
workflow: pathOr('', ['workflow', 'uuid'])(entityType)
});
const fieldsGroup = this.form.get('fields') as FormArray;
this.buildFieldsArray((propOr([], 'fields')(entityType) as any[])).map((formGroup) => {
fieldsGroup.push(formGroup);
});
}
Example #14
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
subfields: this.formBuilder.array(this.buildFieldsArray(field.subfields || []))
});
if (!field.slug) {
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
}
return fieldForm;
});
}
Example #15
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnChanges(changes: any) {
if (!changes.entityType) {
return;
}
const entityType = changes.entityType.currentValue;
this.form.patchValue({
...entityType,
workflow: pathOr('', ['workflow', 'uuid'])(entityType)
});
const fieldsGroup = this.form.get('fields') as FormArray;
this.buildFieldsArray((propOr([], 'fields')(entityType) as any[])).map((formGroup) => {
fieldsGroup.push(formGroup);
});
}
Example #16
Source File: tenant-input.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnInit() {
this.doSearch();
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
if (!this.multiple) {
return this.propagateChange(pathOr(value, ['value'])(value));
}
this.propagateChange((value || []).map((tenantItem) => pathOr(tenantItem, ['value'])(tenantItem)));
});
}
Example #17
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public ngOnChanges(changes: any) {
if (!changes.entityType) {
return;
}
const entityType = changes.entityType.currentValue;
this.form.patchValue({
...entityType,
workflow: pathOr('', ['workflow', 'uuid'])(entityType)
});
const fieldsGroup = this.form.get('fields') as FormArray;
this.buildFieldsArray((propOr([], 'fields')(entityType) as any[])).map((formGroup) => {
fieldsGroup.push(formGroup);
});
}
Example #18
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
private buildFieldsArray(fields) {
return fields.map((field) => {
const fieldConfiguration = this.findFieldConfiguration(field.fieldType);
const config = fieldConfiguration.config.reduce((acc, fieldConfig) => ({
...acc,
[fieldConfig.identifier]: [pathOr(null, ['config', fieldConfig.identifier])(field)]
}), {});
const fieldForm = this.formBuilder.group({
uuid: [field.uuid],
name: [field.name],
slug: [field.slug],
showOnOverview: [field.showOnOverview],
multiLanguage: [field.multiLanguage],
fieldType: [field.fieldType],
config: this.formBuilder.group(config),
subfields: this.formBuilder.array(this.buildFieldsArray(field.subfields || []))
});
if (!field.slug) {
fieldForm.get('name').valueChanges
.pipe(
takeUntil(this.componentDestroyed$)
).subscribe((value) => fieldForm.patchValue({
slug: camelCase(value)
}));
}
return fieldForm;
});
}
Example #19
Source File: slot.controller.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
@Get('/previous')
@Permissions('timetable/read')
public async findPrevious(
@Query('populate') populate = false,
): Promise<any> {
const [{ _embedded: slots }, tenant] = await Promise.all([
this.slotService.find(moment().add(1, 'days').unix().toString(), moment().subtract(7, 'days').unix().toString()),
this.tenantService.findOne()
]);
const currentUnixTime = moment().unix();
const foundSlots = slots.filter((slot: Slot) => slot.end < currentUnixTime);
const slot = pathOr(null, [foundSlots.length - 1])(foundSlots)
if (!slot) {
return null;
}
if (!populate || !tenant.slotFields || !tenant.slotFields.length) {
return slot;
}
return {
...slot,
customData: await this.populateService.populateContent(slot.customData, tenant.slotFields),
}
}
Example #20
Source File: slot.controller.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
@Get('/later')
@Permissions('timetable/read')
public async findLater(
@Query('populate') populate = false,
): Promise<any> {
const [{ _embedded: slots }, tenant] = await Promise.all([
this.slotService.find(moment().add(7, 'days').unix().toString(), moment().subtract(1, 'days').unix().toString()),
this.tenantService.findOne()
]);
const currentUnixTime = moment().unix()
const slot = pathOr(null, [1])(slots.filter((slot: Slot) => slot.start > currentUnixTime))
if (!slot) {
return null;
}
if (!populate || !tenant.slotFields || !tenant.slotFields.length) {
return slot;
}
return {
...slot,
customData: await this.populateService.populateContent(slot.customData, tenant.slotFields),
}
}
Example #21
Source File: slot.controller.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
@Get('next-hours/:hour')
@Permissions('timetable/read')
public async findInHour(
@Query('populate') populate = false,
@Param('hour') hour: string,
): Promise<any> {
const [{ _embedded: slots }, tenant] = await Promise.all([
this.slotService.find(moment().add(7, 'days').unix().toString(), moment().subtract(1, 'days').unix().toString()),
this.tenantService.findOne(),
]);
const startOfHour = moment().add(Number(hour), 'hour').startOf('hour').unix();
const endOfHour = moment().add(Number(hour), 'hour').endOf('hour').unix();
const slot = pathOr(null, [0])(slots.filter((slot: Slot) => slot.start >= startOfHour && slot.start < endOfHour))
if (!slot) {
return null;
}
if (!populate || !tenant.slotFields || !tenant.slotFields.length) {
return slot;
}
return {
...slot,
customData: await this.populateService.populateContent(slot.customData, tenant.slotFields),
}
}
Example #22
Source File: user.service.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public async findOne(search: any): Promise<any> {
const query = this.userRepository.createQueryBuilder('User');
if (search.uuid) {
query.andWhere('User.uuid = :uuid', { uuid: search.uuid })
}
if (search.email) {
query.andWhere('User.email = :email', { email: search.email })
}
if (search.authenticationMethodUuid) {
query.andWhere('User.authenticationMethodUuid = :authenticationMethodUuid', { authenticationMethodUuid: search.authenticationMethodUuid })
}
const [user, userMeta] = await Promise.all([
query.getOne(),
this.getMeta(search.uuid)
]);
if (!user) {
return null;
}
const customData = userMeta.find((x) => x.key === "customData");
return {
...user,
...(pathOr(null, ['value'])(customData) && { customData: pathOr(null, ['value'])(customData) }),
};
}
Example #23
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public toggleFieldExpansion(i: number) {
this.openFields[i] = !pathOr(false, [i])(this.openFields);
}
Example #24
Source File: song-input.component.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public ngOnInit() {
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
this.propagateChange(pathOr(value, ['value'])(value));
});
}
Example #25
Source File: tag-input.component.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public ngOnInit() {
this.control.valueChanges.pipe(
takeUntil(this.componentDestroyed$),
).subscribe((value) => {
return this.propagateChange(pathOr(value, ['value'])(value));
});
}
Example #26
Source File: repeater-config.component.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public toggleSubfieldExpansion(i: number) {
this.openFields[i] = !pathOr(false, [i])(this.openFields);
}
Example #27
Source File: entity-type-form.component.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public toggleFieldExpansion(i: number) {
this.openFields[i] = !pathOr(false, [i])(this.openFields);
}
Example #28
Source File: timetable.page.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public ngOnInit(): void {
this.fetchData();
this.socketService.socket.on('timetable-updated', () => {
this.fetchData();
});
// TODO: add takeUntill
this.sessionQuery.user$.subscribe((user) => this.user = user);
this.sessionQuery.permissions$.subscribe((permissions) => this.permissions = permissions);
this.slotTypeService
.fetch()
.pipe(first())
.subscribe();
this.slotQuery.selectAll()
.pipe(
map(slots => {
return slots.map((slot) => ({
...slot,
id: (slot as any).uuid,
start: moment.unix(Number(slot.start)).toDate(),
end: moment.unix(Number(slot.end) - 1).toDate(),
color: {
primary: pathOr('#000', ['slotType', 'color'])(slot),
secondary: pathOr('#000', ['slotType', 'color'])(slot)
},
meta: {
...(slot as any).user,
originalTimings: {
start: moment.unix(Number(slot.start)).toDate(),
end: moment.unix(Number(slot.end)).toDate(),
},
editable: this.permissions.includes('timetable/update-other')
|| path(['user', 'uuid'])(slot) === prop('uuid')(this.user)
}
}));
})
).subscribe((slots) => {
this.slots = slots;
this.refresh();
});
}
Example #29
Source File: slot-fields.page.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public toggleFieldExpansion(i: number) {
this.openFields[i] = !pathOr(false, [i])(this.openFields);
}