Skip to content

Commit

Permalink
New: Command line arguments for Custom Scripts are no longer supported
Browse files Browse the repository at this point in the history
  • Loading branch information
markus101 authored and ta264 committed Jul 25, 2019
1 parent b8b8f06 commit b9d2409
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 126 deletions.
22 changes: 13 additions & 9 deletions frontend/src/Components/Form/DeviceInputConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { fetchDevices, clearDevices } from 'Store/Actions/deviceActions';
import { fetchOptions, clearOptions } from 'Store/Actions/providerOptionActions';
import DeviceInput from './DeviceInput';

function createMapStateToProps() {
return createSelector(
(state, { value }) => value,
(state) => state.devices,
(state) => state.providerOptions,
(value, devices) => {

return {
Expand Down Expand Up @@ -37,8 +37,8 @@ function createMapStateToProps() {
}

const mapDispatchToProps = {
dispatchFetchDevices: fetchDevices,
dispatchClearDevices: clearDevices
dispatchFetchOptions: fetchOptions,
dispatchClearOptions: clearOptions
};

class DeviceInputConnector extends Component {
Expand All @@ -51,7 +51,7 @@ class DeviceInputConnector extends Component {
}

componentWillUnmount = () => {
// this.props.dispatchClearDevices();
this.props.dispatchClearOptions();
}

//
Expand All @@ -61,10 +61,14 @@ class DeviceInputConnector extends Component {
const {
provider,
providerData,
dispatchFetchDevices
dispatchFetchOptions
} = this.props;

dispatchFetchDevices({ provider, providerData });
dispatchFetchOptions({
action: 'getDevices',
provider,
providerData
});
}

//
Expand Down Expand Up @@ -92,8 +96,8 @@ DeviceInputConnector.propTypes = {
providerData: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
dispatchFetchDevices: PropTypes.func.isRequired,
dispatchClearDevices: PropTypes.func.isRequired
dispatchFetchOptions: PropTypes.func.isRequired,
dispatchClearOptions: PropTypes.func.isRequired
};

export default connect(createMapStateToProps, mapDispatchToProps)(DeviceInputConnector);
13 changes: 11 additions & 2 deletions frontend/src/Components/Form/ProviderFieldFormGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getType(type) {
return inputTypes.NUMBER;
case 'path':
return inputTypes.PATH;
case 'filepath':
case 'filePath':
return inputTypes.PATH;
case 'select':
return inputTypes.SELECT;
Expand Down Expand Up @@ -60,6 +60,7 @@ function ProviderFieldFormGroup(props) {
value,
type,
advanced,
hidden,
pending,
errors,
warnings,
Expand All @@ -68,6 +69,13 @@ function ProviderFieldFormGroup(props) {
...otherProps
} = props;

if (
hidden === 'hidden' ||
(hidden === 'hiddenIfNotSet' && !value)
) {
return null;
}

return (
<FormGroup
advancedSettings={advancedSettings}
Expand All @@ -86,7 +94,7 @@ function ProviderFieldFormGroup(props) {
errors={errors}
warnings={warnings}
pending={pending}
includeFiles={type === 'filepath' ? true : undefined}
includeFiles={type === 'filePath' ? true : undefined}
onChange={onChange}
{...otherProps}
/>
Expand All @@ -108,6 +116,7 @@ ProviderFieldFormGroup.propTypes = {
value: PropTypes.any,
type: PropTypes.string.isRequired,
advanced: PropTypes.bool.isRequired,
hidden: PropTypes.string,
pending: PropTypes.bool.isRequired,
errors: PropTypes.arrayOf(PropTypes.object).isRequired,
warnings: PropTypes.arrayOf(PropTypes.object).isRequired,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/Store/Actions/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as addArtist from './addArtistActions';
import * as app from './appActions';
import * as blacklist from './blacklistActions';
import * as calendar from './calendarActions';
import * as captcha from './captchaActions';
import * as customFilters from './customFilterActions';
import * as devices from './deviceActions';
import * as calendar from './calendarActions';
import * as commands from './commandActions';
import * as albums from './albumActions';
import * as trackFiles from './trackFileActions';
Expand All @@ -16,6 +15,7 @@ import * as oAuth from './oAuthActions';
import * as organizePreview from './organizePreviewActions';
import * as retagPreview from './retagPreviewActions';
import * as paths from './pathActions';
import * as providerOptions from './providerOptionActions';
import * as queue from './queueActions';
import * as releases from './releaseActions';
import * as rootFolders from './rootFolderActions';
Expand All @@ -38,7 +38,6 @@ export default [
calendar,
commands,
customFilters,
devices,
albums,
trackFiles,
albumHistory,
Expand All @@ -49,6 +48,7 @@ export default [
organizePreview,
retagPreview,
paths,
providerOptions,
queue,
releases,
rootFolders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { set } from './baseActions';
//
// Variables

export const section = 'devices';
export const section = 'providerOptions';

//
// State
Expand All @@ -23,40 +23,35 @@ export const defaultState = {
//
// Actions Types

export const FETCH_DEVICES = 'devices/fetchDevices';
export const CLEAR_DEVICES = 'devices/clearDevices';
export const FETCH_OPTIONS = 'devices/fetchOptions';
export const CLEAR_OPTIONS = 'devices/clearOptions';

//
// Action Creators

export const fetchDevices = createThunk(FETCH_DEVICES);
export const clearDevices = createAction(CLEAR_DEVICES);
export const fetchOptions = createThunk(FETCH_OPTIONS);
export const clearOptions = createAction(CLEAR_OPTIONS);

//
// Action Handlers

export const actionHandlers = handleThunks({

[FETCH_DEVICES]: function(getState, payload, dispatch) {
const actionPayload = {
action: 'getDevices',
...payload
};

[FETCH_OPTIONS]: function(getState, payload, dispatch) {
dispatch(set({
section,
isFetching: true
}));

const promise = requestAction(actionPayload);
const promise = requestAction(payload);

promise.done((data) => {
dispatch(set({
section,
isFetching: false,
isPopulated: true,
error: null,
items: data.devices || []
items: data.options || []
}));
});

Expand All @@ -76,7 +71,7 @@ export const actionHandlers = handleThunks({

export const reducers = createHandleActions({

[CLEAR_DEVICES]: function(state) {
[CLEAR_OPTIONS]: function(state) {
return updateSectionState(state, section, defaultState);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Lidarr.Http/ClientSchema/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public class Field
public bool Advanced { get; set; }
public List<SelectOption> SelectOptions { get; set; }
public string Section { get; set; }
public string Hidden { get; set; }

public Field Clone()
{
return (Field) MemberwiseClone();
return (Field)MemberwiseClone();
}
}
}
33 changes: 20 additions & 13 deletions src/Lidarr.Http/ClientSchema/SchemaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public static List<Field> ToSchema(object model)

var mappings = GetFieldMappings(model.GetType());

var result = new List<Field>(mappings.Length);
var result = new List<Field>(mappings.Length);

foreach (var mapping in mappings)
{
var field = mapping.Field.Clone();
field.Value = mapping.GetterFunc(model);

result.Add(field);
result.Add(field);
}

return result.OrderBy(r => r.Order).ToList();
Expand All @@ -45,7 +45,7 @@ public static object ReadFromSchema(List<Field> fields, Type targetType)
{
var field = fields.Find(f => f.Name == mapping.Field.Name);

mapping.SetterFunc(target, field.Value);
mapping.SetterFunc(target, field.Value);
}

return target;
Expand All @@ -54,9 +54,10 @@ public static object ReadFromSchema(List<Field> fields, Type targetType)

public static T ReadFromSchema<T>(List<Field> fields)
{
return (T) ReadFromSchema(fields, typeof(T));
return (T)ReadFromSchema(fields, typeof(T));
}


// Ideally this function should begin a System.Linq.Expression expression tree since it's faster.
// But it's probably not needed till performance issues pop up.
public static FieldMapping[] GetFieldMappings(Type type)
Expand All @@ -74,11 +75,12 @@ public static FieldMapping[] GetFieldMappings(Type type)
result[i].Field.Order = i;
}

_mappings[type] = result;
_mappings[type] = result;
}
return result;
}
}

private static FieldMapping[] GetFieldMapping(Type type, string prefix, Func<object, object> targetSelector)
{
var result = new List<FieldMapping>();
Expand All @@ -97,7 +99,7 @@ private static FieldMapping[] GetFieldMapping(Type type, string prefix, Func<obj
HelpLink = fieldAttribute.HelpLink,
Order = fieldAttribute.Order,
Advanced = fieldAttribute.Advanced,
Type = fieldAttribute.Type.ToString().ToLowerInvariant(),
Type = fieldAttribute.Type.ToString().FirstCharToLower(),
Section = fieldAttribute.Section
};

Expand All @@ -106,9 +108,14 @@ private static FieldMapping[] GetFieldMapping(Type type, string prefix, Func<obj
field.SelectOptions = GetSelectOptions(fieldAttribute.SelectOptions);
}

if (fieldAttribute.Hidden != HiddenType.Visible)
{
field.Hidden = fieldAttribute.Hidden.ToString().FirstCharToLower();
}

var valueConverter = GetValueConverter(propertyInfo.PropertyType);

result.Add(new FieldMapping
result.Add(new FieldMapping
{
Field = field,
PropertyType = propertyInfo.PropertyType,
Expand Down Expand Up @@ -138,8 +145,10 @@ private static List<SelectOption> GetSelectOptions(Type selectOptions)
{
var options = from Enum e in Enum.GetValues(selectOptions)
select new SelectOption { Value = Convert.ToInt32(e), Name = e.ToString() };

return options.OrderBy(o => o.Value).ToList();
}

private static Func<object, object> GetValueConverter(Type propertyType)
{
if (propertyType == typeof(int))
Expand Down Expand Up @@ -178,13 +187,11 @@ private static List<SelectOption> GetSelectOptions(Type selectOptions)
{
if (fieldValue.GetType() == typeof(JArray))
{
return ((JArray) fieldValue).Select(s => s.Value<int>());
return ((JArray)fieldValue).Select(s => s.Value<int>());
}
else
{
return fieldValue.ToString().Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
.Select(s => Convert.ToInt32(s));
return fieldValue.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToInt32(s));
}
};
}
Expand All @@ -195,11 +202,11 @@ private static List<SelectOption> GetSelectOptions(Type selectOptions)
{
if (fieldValue.GetType() == typeof(JArray))
{
return ((JArray) fieldValue).Select(s => s.Value<string>());
return ((JArray)fieldValue).Select(s => s.Value<string>());
}
else
{
return fieldValue.ToString().Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
return fieldValue.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
};
}
Expand Down
31 changes: 31 additions & 0 deletions src/NzbDrone.Common/Disk/SystemFolders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;

namespace NzbDrone.Common.Disk
{
public static class SystemFolders
{
public static List<string> GetSystemFolders()
{
if (OsInfo.IsWindows)
{
return new List<string> { Environment.GetFolderPath(Environment.SpecialFolder.Windows) };
}

if (OsInfo.IsOsx)
{
return new List<string> { "/System" };
}

return new List<string>
{
"/bin",
"/boot",
"/lib",
"/sbin",
"/proc"
};
}
}
}
4 changes: 3 additions & 1 deletion src/NzbDrone.Common/NzbDrone.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Disk\RelativeFileSystemModel.cs" />
<Compile Include="Disk\FileSystemModel.cs" />
<Compile Include="Disk\FileSystemResult.cs" />
<Compile Include="Disk\SystemFolders.cs" />
<Compile Include="EnvironmentInfo\IOsVersionAdapter.cs" />
<Compile Include="EnvironmentInfo\IPlatformInfo.cs" />
<Compile Include="EnvironmentInfo\OsVersionModel.cs" />
Expand Down Expand Up @@ -259,6 +260,7 @@
<PackageReference Include="System.IO.Abstractions">
<Version>4.0.11</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand All @@ -268,4 +270,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit b9d2409

Please sign in to comment.