Compare commits

...

1 Commits

10 changed files with 66 additions and 17 deletions

View File

@ -74,6 +74,7 @@ func getSettingsFromDB() {
TVShowPath string TVShowPath string
TVShowEnabled bool TVShowEnabled bool
FullDeleteEnabled bool FullDeleteEnabled bool
RandomNR uint32
} }
regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}") regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}")
@ -90,6 +91,7 @@ func getSettingsFromDB() {
TVShowPath: serverTVShowPath, TVShowPath: serverTVShowPath,
TVShowEnabled: !config.GetConfig().Features.DisableTVSupport, TVShowEnabled: !config.GetConfig().Features.DisableTVSupport,
FullDeleteEnabled: config.GetConfig().Features.FullyDeletableVideos, FullDeleteEnabled: config.GetConfig().Features.FullyDeletableVideos,
RandomNR: sett.RandomNR,
} }
context.Json(res) context.Json(res)
@ -127,12 +129,13 @@ func saveSettingsToDB() {
password=?, password=?,
mediacenter_name=?, mediacenter_name=?,
TMDB_grabbing=?, TMDB_grabbing=?,
DarkMode=? DarkMode=?,
random_nr=?
WHERE 1` WHERE 1`
// todo avoid conversion // todo avoid conversion
context.Text(string(database.SuccessQuery(query, context.Text(string(database.SuccessQuery(query,
args.VideoPath, args.EpisodePath, args.Password, args.VideoPath, args.EpisodePath, args.Password,
args.MediacenterName, args.TMDBGrabbing, args.DarkMode))) args.MediacenterName, args.TMDBGrabbing, args.DarkMode, args.RandomNR)))
}) })
} }

View File

@ -48,6 +48,7 @@ type SettingsType struct {
PasswordEnabled bool PasswordEnabled bool
TMDBGrabbing bool TMDBGrabbing bool
DarkMode bool DarkMode bool
RandomNR uint32
} }
type SettingsSizeType struct { type SettingsSizeType struct {

View File

@ -126,7 +126,7 @@ func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.Se
SELECT COUNT(*) SELECT COUNT(*)
FROM video_tags FROM video_tags
) AS tagsadded, ) AS tagsadded,
video_path, episode_path, password, mediacenter_name, TMDB_grabbing, DarkMode video_path, episode_path, password, mediacenter_name, TMDB_grabbing, DarkMode, random_nr
FROM settings FROM settings
LIMIT 1`, DBName) LIMIT 1`, DBName)
@ -134,7 +134,7 @@ func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.Se
var TMDBGrabbing int var TMDBGrabbing int
err := QueryRow(query).Scan(&sizes.VideoNr, &sizes.DBSize, &sizes.DifferentTags, &sizes.TagsAdded, err := QueryRow(query).Scan(&sizes.VideoNr, &sizes.DBSize, &sizes.DifferentTags, &sizes.TagsAdded,
&result.VideoPath, &result.EpisodePath, &result.Password, &result.MediacenterName, &TMDBGrabbing, &DarkMode) &result.VideoPath, &result.EpisodePath, &result.Password, &result.MediacenterName, &TMDBGrabbing, &DarkMode, &result.RandomNR)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())

View File

@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
alter table settings
add random_nr int default 3 null;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
alter table settings
drop random_nr;
-- +goose StatementEnd

View File

@ -20,15 +20,16 @@ type SettingsType struct {
MediacenterName string MediacenterName string
VideoPath string VideoPath string
TVShowPath string TVShowPath string
RandomNR uint32
} }
func LoadSettings() *SettingsType { func LoadSettings() *SettingsType {
query := "SELECT DarkMode, password, mediacenter_name, video_path, episode_path from settings" query := "SELECT DarkMode, password, mediacenter_name, video_path, episode_path, random_nr from settings"
result := SettingsType{} result := SettingsType{}
var darkmode uint8 var darkmode uint8
err := database.QueryRow(query).Scan(&darkmode, &result.Pasword, &result.MediacenterName, &result.VideoPath, &result.TVShowPath) err := database.QueryRow(query).Scan(&darkmode, &result.Pasword, &result.MediacenterName, &result.VideoPath, &result.TVShowPath, &result.RandomNR)
if err != nil { if err != nil {
fmt.Println("error while parsing db data: " + err.Error()) fmt.Println("error while parsing db data: " + err.Error())
} }

View File

@ -11,6 +11,7 @@ import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler';
import {IconButton} from '../../elements/GPElements/Button'; import {IconButton} from '../../elements/GPElements/Button';
import {faPlusCircle} from '@fortawesome/free-solid-svg-icons'; import {faPlusCircle} from '@fortawesome/free-solid-svg-icons';
import AddTagPopup from '../../elements/Popups/AddTagPopup/AddTagPopup'; import AddTagPopup from '../../elements/Popups/AddTagPopup/AddTagPopup';
import GlobalInfos from '../../utils/GlobalInfos';
interface state { interface state {
videos: VideoTypes.VideoUnloadedType[]; videos: VideoTypes.VideoUnloadedType[];
@ -28,8 +29,6 @@ interface GetRandomMoviesType {
* Randompage shuffles random viedeopreviews and provides a shuffle btn * Randompage shuffles random viedeopreviews and provides a shuffle btn
*/ */
class RandomPage extends React.Component<{}, state> { class RandomPage extends React.Component<{}, state> {
readonly LoadNR = 3;
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
@ -46,7 +45,7 @@ class RandomPage extends React.Component<{}, state> {
componentDidMount(): void { componentDidMount(): void {
addKeyHandler(this.keypress); addKeyHandler(this.keypress);
this.loadShuffledvideos(this.LoadNR); this.loadShuffledvideos();
} }
componentWillUnmount(): void { componentWillUnmount(): void {
@ -56,7 +55,7 @@ class RandomPage extends React.Component<{}, state> {
render(): JSX.Element { render(): JSX.Element {
return ( return (
<div> <div>
<PageTitle title='Random Videos' subtitle='4pc' /> <PageTitle title='Random Videos' subtitle={GlobalInfos.getRandomNR() + 'pc'} />
<SideBar> <SideBar>
<SideBarTitle>Visible Tags:</SideBarTitle> <SideBarTitle>Visible Tags:</SideBarTitle>
@ -79,7 +78,7 @@ class RandomPage extends React.Component<{}, state> {
{this.state.videos.length !== 0 ? <VideoContainer data={this.state.videos} /> : <div>No Data found!</div>} {this.state.videos.length !== 0 ? <VideoContainer data={this.state.videos} /> : <div>No Data found!</div>}
<div className={style.Shufflebutton}> <div className={style.Shufflebutton}>
<button onClick={(): void => this.loadShuffledvideos(this.LoadNR)} className={style.btnshuffle}> <button onClick={(): void => this.loadShuffledvideos()} className={style.btnshuffle}>
Shuffle Shuffle
</button> </button>
</div> </div>
@ -88,7 +87,7 @@ class RandomPage extends React.Component<{}, state> {
onHide={(): void => this.setState({addTagPopup: false})} onHide={(): void => this.setState({addTagPopup: false})}
submit={(tagId: number, tagName: string): void => { submit={(tagId: number, tagName: string): void => {
this.setState({filterTags: [...this.state.filterTags, {TagId: tagId, TagName: tagName}]}, (): void => { this.setState({filterTags: [...this.state.filterTags, {TagId: tagId, TagName: tagName}]}, (): void => {
this.loadShuffledvideos(this.LoadNR); this.loadShuffledvideos();
}); });
}} }}
/> />
@ -99,12 +98,15 @@ class RandomPage extends React.Component<{}, state> {
/** /**
* load random videos from backend * load random videos from backend
* @param nr number of videos to load
*/ */
loadShuffledvideos(nr: number): void { loadShuffledvideos(): void {
callAPI<GetRandomMoviesType>( callAPI<GetRandomMoviesType>(
APINode.Video, APINode.Video,
{action: 'getRandomMovies', Number: nr, TagFilter: this.state.filterTags.map((t) => t.TagId)}, {
action: 'getRandomMovies',
Number: GlobalInfos.getRandomNR(),
TagFilter: this.state.filterTags.map((t) => t.TagId)
},
(result) => { (result) => {
this.setState({videos: []}); // needed to trigger rerender of main videoview this.setState({videos: []}); // needed to trigger rerender of main videoview
this.setState({ this.setState({
@ -122,7 +124,7 @@ class RandomPage extends React.Component<{}, state> {
private keypress(event: KeyboardEvent): void { private keypress(event: KeyboardEvent): void {
// bind s to shuffle // bind s to shuffle
if (event.key === 's') { if (event.key === 's') {
this.loadShuffledvideos(4); this.loadShuffledvideos();
} }
} }
} }

View File

@ -33,7 +33,8 @@ class GeneralSettings extends React.Component<Props, state> {
Password: '', Password: '',
PasswordEnabled: false, PasswordEnabled: false,
TMDBGrabbing: false, TMDBGrabbing: false,
VideoPath: '' VideoPath: '',
RandomNR: 3
}, },
sizes: { sizes: {
DBSize: 0, DBSize: 0,
@ -199,6 +200,23 @@ class GeneralSettings extends React.Component<Props, state> {
/> />
</Form.Group> </Form.Group>
<Form.Group className={style.mediacenternameform} data-testid='randnrform'>
<Form.Label>Number of random videos on Random page</Form.Label>
<Form.Control
type='number'
placeholder='2'
value={this.state.generalSettings.RandomNR}
onChange={(e): void =>
this.setState({
generalSettings: {
...this.state.generalSettings,
RandomNR: parseInt(e.target.value, 10)
}
})
}
/>
</Form.Group>
<Button variant='primary' type='submit'> <Button variant='primary' type='submit'>
Submit Submit
</Button> </Button>

View File

@ -40,6 +40,7 @@ export namespace SettingsTypes {
TVShowPath: string; TVShowPath: string;
TVShowEnabled: boolean; TVShowEnabled: boolean;
FullDeleteEnabled: boolean; FullDeleteEnabled: boolean;
RandomNR: number;
} }
export interface SettingsType { export interface SettingsType {
@ -50,6 +51,7 @@ export namespace SettingsTypes {
PasswordEnabled: boolean; PasswordEnabled: boolean;
TMDBGrabbing: boolean; TMDBGrabbing: boolean;
DarkMode: boolean; DarkMode: boolean;
RandomNR: number;
} }
export interface SizesType { export interface SizesType {

View File

@ -11,6 +11,7 @@ class StaticInfos {
private tvshowpath: string = ''; private tvshowpath: string = '';
private TVShowsEnabled: boolean = false; private TVShowsEnabled: boolean = false;
private fullDeleteable: boolean = false; private fullDeleteable: boolean = false;
private RandomNR: number = 3;
/** /**
* check if the current theme is the dark theme * check if the current theme is the dark theme
@ -44,6 +45,7 @@ class StaticInfos {
} }
handlers: (() => void)[] = []; handlers: (() => void)[] = [];
onThemeChange(func: () => void): void { onThemeChange(func: () => void): void {
this.handlers.push(func); this.handlers.push(func);
} }
@ -71,6 +73,14 @@ class StaticInfos {
getTVShowPath(): string { getTVShowPath(): string {
return this.tvshowpath; return this.tvshowpath;
} }
setRandomNR(nr: number): void {
this.RandomNR = nr;
}
getRandomNR(): number {
return this.RandomNR;
}
} }
export default new StaticInfos(); export default new StaticInfos();

View File

@ -32,6 +32,7 @@ export const LoginContextProvider: FunctionComponent = (props): JSX.Element => {
GlobalInfos.enableDarkTheme(result.DarkMode); GlobalInfos.enableDarkTheme(result.DarkMode);
GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath); GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath);
GlobalInfos.setRandomNR(result.RandomNR);
features.setTVShowEnabled(result.TVShowEnabled); features.setTVShowEnabled(result.TVShowEnabled);
features.setVideosFullyDeleteable(result.FullDeleteEnabled); features.setVideosFullyDeleteable(result.FullDeleteEnabled);