Skip to content

Commit

Permalink
feat: player CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Mar 17, 2020
1 parent 353c48d commit 4518011
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
Expand Up @@ -32,9 +32,13 @@ create table player
client varchar not null,
ip_address varchar,
last_seen timestamp,
transcoding_id varchar, -- todo foreign key
max_bit_rate int default 0,
unique (name)
transcoding_id varchar,
unique (name),
foreign key (transcoding_id)
references transcoding(id)
on update restrict
on delete restrict
);
`)
return err
Expand Down
8 changes: 8 additions & 0 deletions ui/src/App.js
Expand Up @@ -6,6 +6,7 @@ import polyglotI18nProvider from 'ra-i18n-polyglot'
import messages from './i18n'
import { DarkTheme, Layout, Login } from './layout'
import transcoding from './transcoding'
import player from './player'
import user from './user'
import song from './song'
import album from './album'
Expand Down Expand Up @@ -48,6 +49,13 @@ const App = () => {
permissions === 'admin' ? (
<Resource name="user" {...user} options={{ subMenu: 'settings' }} />
) : null,
permissions === 'admin' ? (
<Resource
name="player"
{...player}
options={{ subMenu: 'settings' }}
/>
) : null,
permissions === 'admin' ? (
<Resource
name="transcoding"
Expand Down
52 changes: 52 additions & 0 deletions ui/src/player/PlayerEdit.js
@@ -0,0 +1,52 @@
import React from 'react'
import {
TextInput,
TextField,
Edit,
required,
SimpleForm,
SelectInput,
ReferenceInput
} from 'react-admin'
import { Title } from '../common'

const PlayerTitle = ({ record }) => {
return <Title subTitle={`Player ${record ? record.name : ''}`} />
}

const PlayerEdit = (props) => (
<Edit title={<PlayerTitle />} {...props}>
<SimpleForm>
<TextInput source="name" validate={[required()]} />
<ReferenceInput
label="Transcoding"
source="transcodingId"
reference="transcoding"
sort={{ field: 'name', order: 'ASC' }}
>
<SelectInput source="name" resettable />
</ReferenceInput>
<SelectInput
source="maxBitRate"
choices={[
{ id: 32, name: '32' },
{ id: 48, name: '48' },
{ id: 64, name: '64' },
{ id: 80, name: '80' },
{ id: 96, name: '96' },
{ id: 112, name: '112' },
{ id: 128, name: '128' },
{ id: 160, name: '160' },
{ id: 192, name: '192' },
{ id: 256, name: '256' },
{ id: 320, name: '320' },
{ id: 0, name: 'Unlimited' }
]}
/>
<TextField source="client" />
<TextField source="userName" />
</SimpleForm>
</Edit>
)

export default PlayerEdit
33 changes: 33 additions & 0 deletions ui/src/player/PlayerList.js
@@ -0,0 +1,33 @@
import React from 'react'
import {
Datagrid,
List,
TextField,
DateField,
FunctionField,
ReferenceField
} from 'react-admin'
import { Title } from '../common'

const PlayerList = (props) => (
<List title={<Title subTitle={'Players'} />} exporter={false} {...props}>
<Datagrid rowClick="edit">
<TextField source="name" />
<ReferenceField
label="Transcoding"
source="transcodingId"
reference="transcoding"
>
<TextField source="name" />
</ReferenceField>
<FunctionField
label="MaxBitRate"
source="maxBitRate"
render={(r) => (r.maxBitRate ? r.maxBitRate : 'Unlimited')}
/>
<DateField source="lastSeen" showTime />
</Datagrid>
</List>
)

export default PlayerList
9 changes: 9 additions & 0 deletions ui/src/player/index.js
@@ -0,0 +1,9 @@
import RadioIcon from '@material-ui/icons/Radio'
import PlayerList from './PlayerList'
import PlayerEdit from './PlayerEdit'

export default {
list: PlayerList,
edit: PlayerEdit,
icon: RadioIcon
}

0 comments on commit 4518011

Please sign in to comment.