Skip to content

Commit

Permalink
fix: Icon selector
Browse files Browse the repository at this point in the history
  • Loading branch information
SenexCrenshaw committed Feb 29, 2024
1 parent 72921ea commit aee88ca
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 375 deletions.
9 changes: 8 additions & 1 deletion StreamMaster.API/Controllers/IconsController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;

using StreamMaster.Application.Icons;
using StreamMaster.Application.Icons.Commands;
using StreamMaster.Application.Icons.Queries;
using StreamMaster.Domain.Dto;
using StreamMaster.Domain.Pagination;

namespace StreamMaster.API.Controllers;
Expand Down Expand Up @@ -47,4 +47,11 @@ public async Task<ActionResult<IEnumerable<IconFileDto>>> GetIconsSimpleQuery([F
IEnumerable<IconFileDto> result = await Mediator.Send(new GetIconsSimpleQuery(iconFileParameters)).ConfigureAwait(false);
return Ok(result);
}

[HttpGet]
[Route("[action]")]
public async Task<ActionResult<List<IconFileDto>>> GetIcons()
{
return await Mediator.Send(new GetIcons());
}
}
5 changes: 5 additions & 0 deletions StreamMaster.Application/Icons/Hub/StreamMasterHub.Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public async Task<IEnumerable<IconFileDto>> GetIconsSimpleQuery(IconFileParamete
IEnumerable<IconFileDto> data = await mediator.Send(new GetIconsSimpleQuery(iconFileParameters)).ConfigureAwait(false);
return data;
}

public async Task<List<IconFileDto>> GetIcons()
{
return await mediator.Send(new GetIcons()).ConfigureAwait(false);
}
}
2 changes: 2 additions & 0 deletions StreamMaster.Application/Icons/IIconInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace StreamMaster.Application.Icons;

public interface IIconController
{
Task<ActionResult<List<IconFileDto>>> GetIcons();
Task<ActionResult> AutoMatchIconToStreams(AutoMatchIconToStreamsRequest request);

Task<ActionResult<IconFileDto>> GetIconFromSource(GetIconFromSourceRequest request);
Expand All @@ -21,6 +22,7 @@ public interface IIconDB

public interface IIconHub
{
Task<List<IconFileDto>> GetIcons();
Task AutoMatchIconToStreams(AutoMatchIconToStreamsRequest request);
Task<IconFileDto?> GetIconFromSource(GetIconFromSourceRequest request);

Expand Down
13 changes: 13 additions & 0 deletions StreamMaster.Application/Icons/Queries/GetIcons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace StreamMaster.Application.Icons.Queries;
public record GetIcons() : IRequest<List<IconFileDto>>;

internal class GetIconsHandler(ILogger<GetIcons> logger, IIconService iconService)
: IRequestHandler<GetIcons, List<IconFileDto>>
{
public Task<List<IconFileDto>> Handle(GetIcons request, CancellationToken cancellationToken)
{
List<IconFileDto> icons = iconService.GetIcons();

return Task.FromResult(icons);
}
}
13 changes: 10 additions & 3 deletions StreamMaster.Domain/Helpers/DirectoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ public static class DirectoryHelper
private static bool setupDirectories = false;
private static void Log(string format, params object[] args)
{
string message = string.Format(format, args);
string message = string.Format(format, args);
Console.WriteLine(message);
Debug.WriteLine(message);
}

public static void RenameDirectory(string oldName, string newName)
{
if (Directory.Exists(oldName))
try
{
if (Directory.Exists(oldName))
{
Directory.Move(oldName, newName);
}
}
catch (Exception ex)
{
Directory.Move(oldName, newName);
Log($"Failed to rename directory: {oldName} to {newName} {ex.InnerException}");
}
}

Expand Down
39 changes: 39 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@ check_files_ready_for_restore() {
return $file_found
}

rename_directory() {
local src="$1"
local dest="$2"

# Check if the source directory exists
if [ ! -d "$src" ]; then
echo "Source directory does not exist: $src"
return 1
fi

# Check for case sensitivity and existence of the destination directory
if [ "$src" = "$dest" ]; then
#echo "Source and destination are the same in a case-insensitive filesystem."
return 1
elif [ -d "$dest" ]; then
#echo "Destination directory already exists: $dest"
return 1
fi

# Perform the rename
mv "$src" "$dest"
if [ $? -eq 0 ]; then
echo "Directory renamed successfully from $src to $dest"
else
echo "Failed to rename directory from $src to $dest"
return 1
fi
}



wait_for_postgres() {
local host="$1"
local port="$2"
Expand Down Expand Up @@ -80,15 +111,23 @@ if [ "$PGID" -ne 0 ]; then
fi
fi

if [ ]

rm -rf /config/hls

mkdir -p /config/Cache
mkdir -p /config/DB
mkdir -p /config/Logs
mkdir -p /config/PlayLists/EPG
mkdir -p /config/PlayLists/M3U
mkdir -p /config/HLS
mkdir -p $BACKUP_DIR
mkdir -p $RESTORE_DIR
mkdir -p $PGDATA

rename_directory /config/settings /config/Settings
rename_directory /config/backups /config/Backups

# Change ownership of the /app directory
if [ "$PUID" -ne 0 ] || [ "$PGID" -ne 0 ]; then
echo "Changing ownership of /app to ${PUID:-0}:${PGID:-0}"
Expand Down
9 changes: 8 additions & 1 deletion streammasterwebui/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import SettingsEditor from '@features/settings/SettingsEditor';
import StreamGroupEditor from '@features/streamGroupEditor/StreamGroupEditor';
import StreamingStatus from '@features/streamingStatus/StreamingStatus';
import VideoPlayer from '@features/videoPlayer/VideoPlayer';
import { IconFileDto, StationChannelName, useEpgFilesGetEpgColorsQuery, useSchedulesDirectGetStationChannelNamesQuery } from '@lib/iptvApi';
import {
IconFileDto,
StationChannelName,
useEpgFilesGetEpgColorsQuery,
useIconsGetIconsQuery,
useSchedulesDirectGetStationChannelNamesQuery
} from '@lib/iptvApi';
import MessagesEn from '@lib/locales/MessagesEn';
import { CacheProvider } from '@lib/redux/CacheProvider';
import { SignalRConnection } from '@lib/signalr/SignalRConnection';
Expand Down Expand Up @@ -72,6 +78,7 @@ const App = (): JSX.Element => {
);
useSchedulesDirectGetStationChannelNamesQuery();
useEpgFilesGetEpgColorsQuery();
useIconsGetIconsQuery();

return (
<IntlProvider locale={locale} messages={messages}>
Expand Down
94 changes: 59 additions & 35 deletions streammasterwebui/components/epg/EPGSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import EditButton from '@components/buttons/EditButton';
import PopUpStringEditor from '@components/inputs/PopUpStringEditor';
import AddButton from '@components/buttons/AddButton';
import StringEditorBodyTemplate from '@components/inputs/StringEditorBodyTemplate';
import { EpgColorDto, StationChannelName, useEpgFilesGetEpgColorsQuery, useSchedulesDirectGetStationChannelNamesQuery } from '@lib/iptvApi';
import { Dropdown } from 'primereact/dropdown';
import { ProgressSpinner } from 'primereact/progressspinner';
import { classNames } from 'primereact/utils';
import React, { useEffect, useState } from 'react';

Expand All @@ -17,22 +18,19 @@ const EPGSelector = ({ enableEditMode = true, value, disabled, editable, onChang
const [colors, setColors] = useState<EpgColorDto[]>([]);
const [checkValue, setCheckValue] = useState<string | undefined>(undefined);
const [stationChannelName, setStationChannelName] = useState<StationChannelName | undefined>(undefined);
const [visible, setVisible] = useState<boolean>(false);
const [input, setInput] = useState<string | undefined>(undefined);

const query = useSchedulesDirectGetStationChannelNamesQuery();
const colorsQuery = useEpgFilesGetEpgColorsQuery();

useEffect(() => {
console.log('EPGSelector', value, input);
if (value && !input) {
setInput(value);
}
}, [value, input]);

useEffect(() => {
if (checkValue === undefined && query.isSuccess && input) {
console.log('checkValue', input);
setCheckValue(input);
const entry = query.data?.find((x) => x.channel === input);
if (entry && entry.id !== stationChannelName?.id) {
Expand Down Expand Up @@ -87,6 +85,56 @@ const EPGSelector = ({ enableEditMode = true, value, disabled, editable, onChang
);
};

const handleOnChange = (channel: string) => {
if (!channel) {
return;
}

const entry = query.data?.find((x) => x.channel === channel);
if (entry && entry.channel !== stationChannelName?.channel) {
setStationChannelName(entry);
} else {
setStationChannelName(undefined);
}

setInput(channel);
onChange && onChange(channel);
};

const panelTemplate = (option: any) => {
return (
<div className="flex grid col-12 m-0 p-0 justify-content-between align-items-center">
<div className="col-11 m-0 p-0 pl-2">
<StringEditorBodyTemplate
disableDebounce={true}
placeholder="Custom URL"
value={input}
onChange={(value) => {
if (value) {
setInput(value);
}
}}
/>
</div>
<div className="col-1 m-0 p-0">
<AddButton
tooltip="Add Custom URL"
iconFilled={false}
onClick={(e) => {
if (input) {
handleOnChange(input);
}
}}
style={{
width: 'var(--input-height)',
height: 'var(--input-height)'
}}
/>
</div>
</div>
);
};

const className = classNames('BaseSelector align-contents-center p-0 m-0 max-w-full w-full epgSelector', {
'p-disabled': disabled
});
Expand All @@ -97,28 +145,26 @@ const EPGSelector = ({ enableEditMode = true, value, disabled, editable, onChang

const loading = !query.isSuccess || query.isFetching || query.isLoading || !query.data;

if (loading) {
return <ProgressSpinner />;
}

return (
<div className="BaseSelector flex align-contents-center w-full min-w-full">
<Dropdown
className={className}
disabled={loading}
editable={editable}
filter
filterBy="displayName"
itemTemplate={itemTemplate}
loading={loading}
onChange={(e) => {
if (e?.value?.id) {
setInput(e.value.id);
setStationChannelName(e.value);
if (onChange) {
onChange(e.value.id);
}
}
handleOnChange(e?.value?.id);
}}
onHide={() => {}}
optionLabel="displayName"
options={query.data}
panelFooterTemplate={panelTemplate}
placeholder="placeholder"
resetFilterOnHide
showFilterClear
Expand All @@ -133,28 +179,6 @@ const EPGSelector = ({ enableEditMode = true, value, disabled, editable, onChang
}
}}
/>
<div>
<PopUpStringEditor
value={input}
visible={visible}
onClose={(value) => {
console.log(value);
setVisible(false);
if (value) {
setCheckValue(undefined);
setInput(value);
onChange && onChange(value);
}
}}
/>
<EditButton
tooltip="Custom ID"
iconFilled={false}
onClick={(e) => {
setVisible(true);
}}
/>
</div>
</div>
);
};
Expand Down
Loading

0 comments on commit aee88ca

Please sign in to comment.