mirror of https://github.com/morpheus65535/bazarr
Fix languages/providers filters issue in history stats
This commit is contained in:
parent
8d447453e9
commit
c21e501ebe
|
@ -54,7 +54,9 @@ from functools import wraps
|
|||
api_bp = Blueprint('api', __name__, url_prefix=base_url.rstrip('/') + '/api')
|
||||
api = Api(api_bp)
|
||||
|
||||
None_Keys = ['null', 'undefined', '']
|
||||
None_Keys = ['null', 'undefined', '', None]
|
||||
|
||||
False_Keys = ['False', 'false', '0']
|
||||
|
||||
|
||||
def authenticate(actual_method):
|
||||
|
@ -350,10 +352,14 @@ class Languages(Resource):
|
|||
@authenticate
|
||||
def get(self):
|
||||
history = request.args.get('history')
|
||||
if history and history not in ['False', 'false', '0']:
|
||||
if history and history not in False_Keys:
|
||||
languages = list(TableHistory.select(TableHistory.language).dicts())
|
||||
languages += list(TableHistoryMovie.select(TableHistoryMovie.language).dicts())
|
||||
languages_list = list(set([x['language'].split(':')[0] for x in languages]))
|
||||
languages_set = set()
|
||||
for l in languages:
|
||||
if l not in None_Keys and l['language'] not in None_Keys:
|
||||
languages_set.add(l['language'].split(':')[0])
|
||||
languages_list = list(languages_set)
|
||||
languages_dicts = []
|
||||
for language in languages_list:
|
||||
code2 = None
|
||||
|
@ -365,7 +371,9 @@ class Languages(Resource):
|
|||
if not any(x['code2'] == code2 for x in languages_dicts):
|
||||
languages_dicts.append({
|
||||
'code2': code2,
|
||||
'name': language_from_alpha2(language)
|
||||
'name': language_from_alpha2(language),
|
||||
# Compatibility: Use false temporarily
|
||||
'enabled': False
|
||||
})
|
||||
return jsonify(sorted(languages_dicts, key=itemgetter('name')))
|
||||
result = TableSettingsLanguages.select(TableSettingsLanguages.name,
|
||||
|
@ -1128,7 +1136,7 @@ class Providers(Resource):
|
|||
@authenticate
|
||||
def get(self):
|
||||
history = request.args.get('history')
|
||||
if history and history not in ['False', 'false', '0']:
|
||||
if history and history not in False_Keys:
|
||||
providers = list(TableHistory.select(TableHistory.provider)
|
||||
.where(TableHistory.provider != None)
|
||||
.dicts())
|
||||
|
@ -1139,7 +1147,9 @@ class Providers(Resource):
|
|||
providers_dicts = []
|
||||
for provider in providers_list:
|
||||
providers_dicts.append({
|
||||
'name': provider
|
||||
'name': provider,
|
||||
'status': 'History',
|
||||
'retry': '-'
|
||||
})
|
||||
return jsonify(data=sorted(providers_dicts, key=itemgetter('name')))
|
||||
|
||||
|
|
|
@ -12,8 +12,12 @@ import {
|
|||
XAxis,
|
||||
YAxis,
|
||||
} from "recharts";
|
||||
import { useLanguages, useSystemProviders } from "../../@redux/hooks";
|
||||
import { HistoryApi } from "../../apis";
|
||||
import {
|
||||
HistoryApi,
|
||||
ProvidersApi,
|
||||
SystemApi,
|
||||
useAsyncRequest,
|
||||
} from "../../apis";
|
||||
import {
|
||||
AsyncSelector,
|
||||
ContentHeader,
|
||||
|
@ -45,9 +49,12 @@ const SelectorContainer: FunctionComponent = ({ children }) => (
|
|||
);
|
||||
|
||||
const HistoryStats: FunctionComponent = () => {
|
||||
const [languages] = useLanguages(true);
|
||||
const [languages] = useAsyncRequest(() => SystemApi.languages(true), []);
|
||||
|
||||
const [providerList] = useSystemProviders();
|
||||
const [providerList] = useAsyncRequest(
|
||||
() => ProvidersApi.providers(true),
|
||||
[]
|
||||
);
|
||||
|
||||
const [timeframe, setTimeframe] = useState<History.TimeframeOptions>("month");
|
||||
const [action, setAction] = useState<Nullable<History.ActionOptions>>(null);
|
||||
|
@ -102,7 +109,7 @@ const HistoryStats: FunctionComponent = () => {
|
|||
<SelectorContainer>
|
||||
<LanguageSelector
|
||||
clearable
|
||||
options={languages}
|
||||
options={languages.data}
|
||||
value={lang}
|
||||
onChange={setLanguage}
|
||||
></LanguageSelector>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import { useCallback, useState } from "react";
|
||||
import { useDidMount } from "rooks";
|
||||
|
||||
type RequestReturn<F extends () => Promise<any>> = PromiseType<ReturnType<F>>;
|
||||
|
||||
export function useAsyncRequest<F extends () => Promise<any>>(
|
||||
request: F,
|
||||
defaultData: RequestReturn<F>
|
||||
): [AsyncState<RequestReturn<F>>, () => void] {
|
||||
const [state, setState] = useState<AsyncState<RequestReturn<F>>>({
|
||||
updating: true,
|
||||
data: defaultData,
|
||||
});
|
||||
const update = useCallback(() => {
|
||||
setState((s) => ({ ...s, updating: true }));
|
||||
request()
|
||||
.then((res) => setState({ updating: false, data: res }))
|
||||
.catch((err) => setState((s) => ({ ...s, updating: false, err })));
|
||||
}, [request]);
|
||||
|
||||
useDidMount(update);
|
||||
|
||||
return [state, update];
|
||||
}
|
|
@ -84,6 +84,7 @@ export { default as BadgesApi } from "./badges";
|
|||
export { default as EpisodesApi } from "./episodes";
|
||||
export { default as FilesApi } from "./files";
|
||||
export { default as HistoryApi } from "./history";
|
||||
export * from "./hooks";
|
||||
export { default as MoviesApi } from "./movies";
|
||||
export { default as ProvidersApi } from "./providers";
|
||||
export { default as SeriesApi } from "./series";
|
||||
|
|
|
@ -5,9 +5,9 @@ class ProviderApi extends BaseApi {
|
|||
super("/providers");
|
||||
}
|
||||
|
||||
async providers() {
|
||||
async providers(history: boolean = false) {
|
||||
return new Promise<Array<System.Provider>>((resolve, reject) => {
|
||||
this.get<DataWrapper<Array<System.Provider>>>("")
|
||||
this.get<DataWrapper<Array<System.Provider>>>("", { history })
|
||||
.then((result) => {
|
||||
resolve(result.data.data);
|
||||
})
|
||||
|
|
|
@ -57,9 +57,9 @@ class SystemApi extends BaseApi {
|
|||
});
|
||||
}
|
||||
|
||||
async languages() {
|
||||
async languages(history: boolean = false) {
|
||||
return new Promise<Array<ApiLanguage>>((resolve, reject) => {
|
||||
this.get<Array<ApiLanguage>>("/languages")
|
||||
this.get<Array<ApiLanguage>>("/languages", { history })
|
||||
.then((result) => {
|
||||
resolve(result.data);
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue