ramda#path TypeScript Examples

The following examples show how to use ramda#path. 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: content-type.controller.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Get('/overview')
	public async findByPermissions(
		@Query('page') page: number,
		@Query('pagesize') pagesize: number,
		@Query('all') all: string,
		@Request() req,
	): Promise<Paginated<any>> {
		const permissions = await this.permissionService.getPermissions(req.user?.uuid);
		const contentPermissions = [...new Set(permissions.filter(x => x.startsWith('content')).map(x => path([1])(x.split('/'))))] as string[];
		
		if (all === "true") {
			// Don't judge haha
			return this.contentTypeService.findByUuids(1, 5000, contentPermissions);
		}

		return this.contentTypeService.findByUuids(page, pagesize, contentPermissions);
	}
Example #2
Source File: page-type.controller.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Get('/overview')
	public async findByPermissions(
		@Query('page') page: number,
		@Query('pagesize') pagesize: number,
		@Query('all') all: string,
		@Request() req,
	): Promise<Paginated<any>> {
		const permissions = await this.permissionService.getPermissions(req.user?.uuid);
		const contentPermissions = [...new Set(permissions.filter(x => x.startsWith('pages')).map(x => path([1])(x.split('/'))))] as string[];
		
		if (all === "true") {
			// Don't judge haha
			return this.pageTypeService.findByUuids(1, 5000, contentPermissions);
		}

		return this.pageTypeService.findByUuids(page, pagesize, contentPermissions);
	}
Example #3
Source File: entry-create.page.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public ngOnInit(): void {
		this.formService.fetchOne(this.activatedRoute.snapshot.params.formUuid)
			.pipe(
				first()
			).subscribe();
		this.form$ = this.formQuery.selectEntity(this.activatedRoute.snapshot.params.formUuid)
			.pipe(
				tap((form) => {
					if (!form) {
						return;
					}

					const fields = form.fields.reduce((acc, field) => ({
						...acc,
						[field.slug]: ['']
					}), {});

					this.form = this.formBuilder.group({
						name: ['', Validators.required],
						slug: ['', Validators.required],
						state: [path(['workflow', 'initial'])(form), Validators.required],
						fields: this.formBuilder.group(fields)
					});

					this.form.get('name').valueChanges
						.pipe(
							takeUntil(this.componentDestroyed$)
						).subscribe((value) => this.form.patchValue({
							slug: slugify(value).toLowerCase()
						}));
				})
			);
	}
Example #4
Source File: data-input.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public doSearch(searchString = '') {
		this.dynamicInputService.fetchData(this.endpoint, { name: searchString, pagesize: 500 })
			.pipe(
				first(),
				map((item) => {
					return item.map((item) => ({
						value: path(this.itemValue)(item),
						label: path(this.itemLabel)(item)
					}));
				})
			)
			.subscribe(data => this.data = data);
	}
Example #5
Source File: data-input.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public writeValue(value: any) {
		if (!value) {
			return;
		}

		this.dynamicInputService.fetchData(this.endpoint)
			.pipe(first())
			.subscribe(data => {
				if (!this.multiple) {
					return setTimeout(() => this.control.setValue({
						value,
						label: path(this.itemLabel)(data.find((contentItem) => path(this.itemValue)(contentItem) === value))
					}));
				}

				const mappedValue = value.map((item) => ({
					value: item,
					label: path(this.itemLabel)(data.find((contentItem) => path(this.itemValue)(contentItem) === item))
				}));
				this.control.setValue(mappedValue);
			});
	}
Example #6
Source File: table-cell.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public ngOnChanges(changes: SimpleChanges) {
		if (changes.component?.currentValue) {
			this.loadComponent();
		}

		if (changes.column || changes.item || changes.index) {
			this.value = this.formatValue(
				path(['column', 'currentValue'], changes),
				path(['item', 'currentValue'], changes),
				path(['index', 'currentValue'], changes)
			);

			if (this.componentRef) {
				this.updateInstanceValues();
				this.componentRef.changeDetectorRef.detectChanges();
			}
		}

		this.ready = true;
	}
Example #7
Source File: table-cell.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
public formatValue(column: TableColumn, item: any, index: number): any {
		if (!column) {
			return null;
		}

		const value = path(column.value.split('.'), item);

		return column.format
			? column.format(value, column.value, item, index)
			: value == null
			? '-'
			: value;
	}
Example #8
Source File: population.service.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
private createPopulateMap(
		contentFields: Record<string, unknown>,
		contentTypeFields: ContentTypeField[] | PageTypeField[],
		parentFields: (string | number)[] = []
	): { fieldPath: string; contentUuid: string, type: 'content' | 'page' }[] {
		return (contentTypeFields as any[] || []).reduce((acc, field: ContentTypeField | PageTypeField) => {
			const fieldPath = [...parentFields, field.slug]

			if (field.fieldType === 'content-input' && path([...fieldPath])(contentFields)) {
				return [
					...acc,
					{
						contentUuid: path([...fieldPath])(contentFields),
						fieldPath,
						type: 'content'
					}
				]
			}

			if (field.fieldType === 'page-input' && path([...fieldPath])(contentFields)) {
				return [
					...acc,
					{
						contentUuid: path([...fieldPath])(contentFields),
						fieldPath,
						type: 'page'
					}
				]
			}

			if (field.fieldType === 'repeater') {
				return [
					...acc,
					...(pathOr<any[]>([], [...fieldPath])(contentFields) || []).reduce((subFieldAcc, _, i: number) => ([
						...subFieldAcc,
						...this.createPopulateMap(contentFields, field.subfields, [...fieldPath, i])
					]), [])
				]
			}

			return acc;
		}, [])
	}
Example #9
Source File: serviceResponseMapper.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
manualSearchMapper = (service: "deezer" | "spotify", response: any): Partial<Song>[] => {
	if (service === "spotify") {
		const tracks = pathOr<any[]>(null, ['tracks', 'items'])(response);

		return tracks.map(track => ({
			title: prop('name')(track),
			artist: path<string>(['artists', 0, 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'name'])(track),
			graphic: {
				large: pathOr(null, ['album', 'images', 0, 'url'])(track),
				medium: pathOr(null, ['album', 'images', 1, 'url'])(track),
				small: pathOr(null, ['album', 'images', 2, 'url'])(track),
			},
			extraInfo: {
				album: pick(['album_type', 'external_urls', 'href', 'id', 'release_date', 'release_date_precision', 'total_tracks', 'uri'])(propOr({}, 'album')(track)),
				artist: pick(['id', 'name', 'uri', 'href'])(pathOr({}, ['artists', 0])(track)),
				track: pick(['href', 'external_urls', 'uri', 'explicit', 'id'])(track)
			},
			previewUrl: pathOr(null, ['preview_url'])(track),
			releaseDate: pathOr(new Date(), ['album', 'release_date'])(track),
			durationMs: pathOr(1000, ['duration_ms'])(track),
		}));
	}

	if (service === "deezer") {
		const tracks = pathOr<any[]>(null, ['data'])(response);

		return tracks.map(track => ({
			title: prop('title')(track),
			artist: path<string>(['artist', 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'title'])(track),
			graphic: {
				large: pathOr(null, ['album', 'cover_xl'])(track),
				medium: pathOr(null, ['album', 'cover_big'])(track),
				small: pathOr(null, ['album', 'cover_medium'])(track),
			},
			previewUrl: pathOr(null, ['preview'])(track),
			releaseDate: new Date(),
			durationMs: pathOr(1000, ['duration'])(track),
		}));
	}

	if (service === "apple-music") {
		const tracks = pathOr<any[]>(null, ['results'])(response);

		return tracks.map(track => ({
			title: prop('trackName')(track),
			artist: path<string>(['artistName'])(track),
			album: pathOr('Unknown Album', ['collectionName'])(track),
			graphic: {
				large: pathOr(null, ['artworkUrl100'])(track)?.replace('100x100bb', '640x640bb'),
				medium: pathOr(null, ['artworkUrl60'])(track)?.replace('60x60bb', '300x300bb'),
				small: pathOr(null, ['artworkUrl30'])(track)?.replace('30x30bb', '64x64bb'),
			},
			extraInfo: {
				albumUrl: pathOr(null, ['collectionViewUrl'])(track),
				trackUrl: pathOr(null, ['trackViewUrl'])(track),
				artistUrl: pathOr(null, ['artistViewUrl'])(track),
				primaryGenreName: pathOr(null, ['primaryGenreName'])(track),
				albumPrice: pathOr(null, ['collectionPrice'])(track),
				trackPrice: pathOr(null, ['trackPrice'])(track),
				currency: pathOr(null, ['currency'])(track),
				country: pathOr(null, ['country'])(track),
			},
			previewUrl: pathOr(null, ['previewUrl'])(track),
			releaseDate: pathOr(null, ['releaseDate'])(track),
			durationMs: pathOr(1000, ['trackTimeMillis'])(track),
		}));
	}
}
Example #10
Source File: songFetcher.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
fetchSongData = async (streamUrl: string, streamType: string) => {
	const userAgent = new UserAgent();
	if(streamType == "icecast"){
		const radioServerResponse = await got.get(streamUrl ,{
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch((e) => {});

		if (Array.isArray(path(['icestats', 'source'])(radioServerResponse))) {
			const source = mergeAll<any>(path<object[]>(['icestats', 'source'])(radioServerResponse));
			return (prop('title')(source) as string);
		} else {
			return pathOr('', ['icestats', 'source', 'title'])(radioServerResponse);
		}
	};

	if(streamType == "shoutcast"){
		const radioServerResponse = await got.get(streamUrl ,{
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch(() => {});

		return pathOr('', ['songtitle'])(radioServerResponse);
	};

	if(streamType == "zeno"){
		const radioServerResponse = await got.get(streamUrl, {
			resolveBodyOnly: true,
			responseType: 'json',
			timeout: 5000,
			headers: {
				'User-Agent': userAgent.toString()
			}
		}).catch(() => {});

		return pathOr('', ['artist'])(radioServerResponse) + ' - ' + pathOr('', ['title'])(radioServerResponse);
	};
}
Example #11
Source File: timetable.page.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
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 #12
Source File: serviceResponseMapper.ts    From radiopanel with GNU General Public License v3.0 4 votes vote down vote up
serviceResponseMapper = (originalTitle: string, service: "deezer" | "spotify", response: any): Partial<Song> => {
	if (service === "spotify") {
		const track = pathOr(null, ['tracks', 'items', 0])(response);

		return {
			uuid: uuid.v4(),
			externalId: md5(originalTitle),
			title: propOr(path([1])(originalTitle.split('-')) || "", 'name')(track),
			artist: pathOr(path<string>([0])(originalTitle.split('-')), ['artists', 0, 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'name'])(track),
			graphic: {
				large: pathOr(null, ['album', 'images', 0, 'url'])(track),
				medium: pathOr(null, ['album', 'images', 1, 'url'])(track),
				small: pathOr(null, ['album', 'images', 2, 'url'])(track),
			},
			previewUrl: pathOr(null, ['preview_url'])(track),
			releaseDate: pathOr(new Date(), ['album', 'release_date'])(track),
			durationMs: pathOr(1000, ['duration_ms'])(track),
			originalTitle,
			extraInfo: {
				album: pick(['album_type', 'external_urls', 'href', 'id', 'release_date', 'release_date_precision', 'total_tracks', 'uri'])(propOr({}, 'album')(track)),
				artist: pick(['id', 'name', 'uri', 'href'])(pathOr({}, ['artists', 0])(track)),
				track: pick(['href', 'external_urls', 'uri', 'explicit', 'id'])(track || {})
			},
			updatedAt: new Date(),
			createdAt: new Date()
		};
	}

	if (service === "deezer") {
		const track = pathOr(null, ['data', 0])(response);

		return {
			uuid: uuid.v4(),
			externalId: md5(originalTitle),
			title: propOr(path([1])(originalTitle.split('-')) || "", 'title')(track),
			artist: pathOr(path<string>([0])(originalTitle.split('-')), ['artist', 'name'])(track),
			album: pathOr('Unknown Album', ['album', 'title'])(track),
			graphic: {
				large: pathOr(null, ['album', 'cover_xl'])(track),
				medium: pathOr(null, ['album', 'cover_big'])(track),
				small: pathOr(null, ['album', 'cover_medium'])(track),
			},
			previewUrl: pathOr(null, ['preview'])(track),
			releaseDate: new Date(),
			durationMs: pathOr(1000, ['duration'])(track),
			originalTitle,
			extraInfo: {},
			updatedAt: new Date(),
			createdAt: new Date()
		};
	}

	if (service === "apple-music") {
		const track = pathOr(null, ['results', 0])(response);

		return {
			uuid: uuid.v4(),
			externalId: md5(originalTitle),
			title: propOr(path([1])(originalTitle.split('-')) || "", 'trackName')(track),
			artist: pathOr(path<string>([0])(originalTitle.split('-')), ['artistName'])(track),
			album: pathOr('Unknown Album', ['collectionName'])(track),
			graphic: {
				large: pathOr(null, ['artworkUrl100'])(track)?.replace('100x100bb', '640x640bb'),
				medium: pathOr(null, ['artworkUrl60'])(track)?.replace('60x60bb', '300x300bb'),
				small: pathOr(null, ['artworkUrl30'])(track)?.replace('30x30bb', '64x64bb'),
			},
			extraInfo: {
				albumUrl: pathOr(null, ['collectionViewUrl'])(track),
				trackUrl: pathOr(null, ['trackViewUrl'])(track),
				artistUrl: pathOr(null, ['artistViewUrl'])(track),
				primaryGenreName: pathOr(null, ['primaryGenreName'])(track),
				albumPrice: pathOr(null, ['collectionPrice'])(track),
				trackPrice: pathOr(null, ['trackPrice'])(track),
				currency: pathOr(null, ['currency'])(track),
				country: pathOr(null, ['country'])(track),
			},
			previewUrl: pathOr(null, ['previewUrl'])(track),
			releaseDate: pathOr(null, ['releaseDate'])(track),
			durationMs: pathOr(1000, ['trackTimeMillis'])(track),
			originalTitle,
			updatedAt: new Date(),
			createdAt: new Date()
		};
	}
}