Compare commits
1 Commits
master
...
settings_r
Author | SHA1 | Date | |
---|---|---|---|
7cd9cd7d89 |
@ -74,6 +74,7 @@ func getSettingsFromDB() {
|
||||
TVShowPath string
|
||||
TVShowEnabled 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}")
|
||||
@ -90,6 +91,7 @@ func getSettingsFromDB() {
|
||||
TVShowPath: serverTVShowPath,
|
||||
TVShowEnabled: !config.GetConfig().Features.DisableTVSupport,
|
||||
FullDeleteEnabled: config.GetConfig().Features.FullyDeletableVideos,
|
||||
RandomNR: sett.RandomNR,
|
||||
}
|
||||
|
||||
context.Json(res)
|
||||
@ -127,12 +129,13 @@ func saveSettingsToDB() {
|
||||
password=?,
|
||||
mediacenter_name=?,
|
||||
TMDB_grabbing=?,
|
||||
DarkMode=?
|
||||
DarkMode=?,
|
||||
random_nr=?
|
||||
WHERE 1`
|
||||
// todo avoid conversion
|
||||
context.Text(string(database.SuccessQuery(query,
|
||||
args.VideoPath, args.EpisodePath, args.Password,
|
||||
args.MediacenterName, args.TMDBGrabbing, args.DarkMode)))
|
||||
args.MediacenterName, args.TMDBGrabbing, args.DarkMode, args.RandomNR)))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ type SettingsType struct {
|
||||
PasswordEnabled bool
|
||||
TMDBGrabbing bool
|
||||
DarkMode bool
|
||||
RandomNR uint32
|
||||
}
|
||||
|
||||
type SettingsSizeType struct {
|
||||
|
@ -126,7 +126,7 @@ func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.Se
|
||||
SELECT COUNT(*)
|
||||
FROM video_tags
|
||||
) 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
|
||||
LIMIT 1`, DBName)
|
||||
|
||||
@ -134,7 +134,7 @@ func GetSettings() (result types.SettingsType, PathPrefix string, sizes types.Se
|
||||
var TMDBGrabbing int
|
||||
|
||||
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 {
|
||||
fmt.Println(err.Error())
|
||||
|
11
apiGo/database/migrations/20220505195845_randomnr.sql
Normal file
11
apiGo/database/migrations/20220505195845_randomnr.sql
Normal 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
|
@ -20,15 +20,16 @@ type SettingsType struct {
|
||||
MediacenterName string
|
||||
VideoPath string
|
||||
TVShowPath string
|
||||
RandomNR uint32
|
||||
}
|
||||
|
||||
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{}
|
||||
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 {
|
||||
fmt.Println("error while parsing db data: " + err.Error())
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler';
|
||||
import {IconButton} from '../../elements/GPElements/Button';
|
||||
import {faPlusCircle} from '@fortawesome/free-solid-svg-icons';
|
||||
import AddTagPopup from '../../elements/Popups/AddTagPopup/AddTagPopup';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
|
||||
interface state {
|
||||
videos: VideoTypes.VideoUnloadedType[];
|
||||
@ -28,8 +29,6 @@ interface GetRandomMoviesType {
|
||||
* Randompage shuffles random viedeopreviews and provides a shuffle btn
|
||||
*/
|
||||
class RandomPage extends React.Component<{}, state> {
|
||||
readonly LoadNR = 3;
|
||||
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
|
||||
@ -46,7 +45,7 @@ class RandomPage extends React.Component<{}, state> {
|
||||
componentDidMount(): void {
|
||||
addKeyHandler(this.keypress);
|
||||
|
||||
this.loadShuffledvideos(this.LoadNR);
|
||||
this.loadShuffledvideos();
|
||||
}
|
||||
|
||||
componentWillUnmount(): void {
|
||||
@ -56,7 +55,7 @@ class RandomPage extends React.Component<{}, state> {
|
||||
render(): JSX.Element {
|
||||
return (
|
||||
<div>
|
||||
<PageTitle title='Random Videos' subtitle='4pc' />
|
||||
<PageTitle title='Random Videos' subtitle={GlobalInfos.getRandomNR() + 'pc'} />
|
||||
|
||||
<SideBar>
|
||||
<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>}
|
||||
<div className={style.Shufflebutton}>
|
||||
<button onClick={(): void => this.loadShuffledvideos(this.LoadNR)} className={style.btnshuffle}>
|
||||
<button onClick={(): void => this.loadShuffledvideos()} className={style.btnshuffle}>
|
||||
Shuffle
|
||||
</button>
|
||||
</div>
|
||||
@ -88,7 +87,7 @@ class RandomPage extends React.Component<{}, state> {
|
||||
onHide={(): void => this.setState({addTagPopup: false})}
|
||||
submit={(tagId: number, tagName: string): 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
|
||||
* @param nr number of videos to load
|
||||
*/
|
||||
loadShuffledvideos(nr: number): void {
|
||||
loadShuffledvideos(): void {
|
||||
callAPI<GetRandomMoviesType>(
|
||||
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) => {
|
||||
this.setState({videos: []}); // needed to trigger rerender of main videoview
|
||||
this.setState({
|
||||
@ -122,7 +124,7 @@ class RandomPage extends React.Component<{}, state> {
|
||||
private keypress(event: KeyboardEvent): void {
|
||||
// bind s to shuffle
|
||||
if (event.key === 's') {
|
||||
this.loadShuffledvideos(4);
|
||||
this.loadShuffledvideos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ class GeneralSettings extends React.Component<Props, state> {
|
||||
Password: '',
|
||||
PasswordEnabled: false,
|
||||
TMDBGrabbing: false,
|
||||
VideoPath: ''
|
||||
VideoPath: '',
|
||||
RandomNR: 3
|
||||
},
|
||||
sizes: {
|
||||
DBSize: 0,
|
||||
@ -199,6 +200,23 @@ class GeneralSettings extends React.Component<Props, state> {
|
||||
/>
|
||||
</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'>
|
||||
Submit
|
||||
</Button>
|
||||
|
@ -40,6 +40,7 @@ export namespace SettingsTypes {
|
||||
TVShowPath: string;
|
||||
TVShowEnabled: boolean;
|
||||
FullDeleteEnabled: boolean;
|
||||
RandomNR: number;
|
||||
}
|
||||
|
||||
export interface SettingsType {
|
||||
@ -50,6 +51,7 @@ export namespace SettingsTypes {
|
||||
PasswordEnabled: boolean;
|
||||
TMDBGrabbing: boolean;
|
||||
DarkMode: boolean;
|
||||
RandomNR: number;
|
||||
}
|
||||
|
||||
export interface SizesType {
|
||||
|
@ -11,6 +11,7 @@ class StaticInfos {
|
||||
private tvshowpath: string = '';
|
||||
private TVShowsEnabled: boolean = false;
|
||||
private fullDeleteable: boolean = false;
|
||||
private RandomNR: number = 3;
|
||||
|
||||
/**
|
||||
* check if the current theme is the dark theme
|
||||
@ -44,6 +45,7 @@ class StaticInfos {
|
||||
}
|
||||
|
||||
handlers: (() => void)[] = [];
|
||||
|
||||
onThemeChange(func: () => void): void {
|
||||
this.handlers.push(func);
|
||||
}
|
||||
@ -71,6 +73,14 @@ class StaticInfos {
|
||||
getTVShowPath(): string {
|
||||
return this.tvshowpath;
|
||||
}
|
||||
|
||||
setRandomNR(nr: number): void {
|
||||
this.RandomNR = nr;
|
||||
}
|
||||
|
||||
getRandomNR(): number {
|
||||
return this.RandomNR;
|
||||
}
|
||||
}
|
||||
|
||||
export default new StaticInfos();
|
||||
|
@ -32,6 +32,7 @@ export const LoginContextProvider: FunctionComponent = (props): JSX.Element => {
|
||||
GlobalInfos.enableDarkTheme(result.DarkMode);
|
||||
|
||||
GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath);
|
||||
GlobalInfos.setRandomNR(result.RandomNR);
|
||||
|
||||
features.setTVShowEnabled(result.TVShowEnabled);
|
||||
features.setVideosFullyDeleteable(result.FullDeleteEnabled);
|
||||
|
Loading…
Reference in New Issue
Block a user