Merge pull request #44 from KevinMidboe/client/admin-page

Client/admin page
This commit is contained in:
2017-10-21 09:50:32 +02:00
committed by GitHub
4 changed files with 29 additions and 11 deletions

View File

@@ -14,7 +14,7 @@ class Root extends Component {
<Router> <Router>
<Switch> <Switch>
<Route exact path='/' component={SearchRequest} /> <Route exact path='/' component={SearchRequest} />
<Route path='/admin/:search' component={AdminComponent} /> <Route path='/admin/:request' component={AdminComponent} />
<Route path='/admin' component={AdminComponent} /> <Route path='/admin' component={AdminComponent} />
</Switch> </Switch>
</Router> </Router>

View File

@@ -29,7 +29,7 @@ class AdminComponent extends React.Component {
fetchJSON('https://apollo.kevinmidboe.com/api/v1/plex/requests/all', 'GET') fetchJSON('https://apollo.kevinmidboe.com/api/v1/plex/requests/all', 'GET')
.then(result => { .then(result => {
this.setState({ this.setState({
requested_objects: result.requestedItems requested_objects: result.requestedItems.reverse()
}) })
}) })
} }
@@ -49,18 +49,25 @@ class AdminComponent extends React.Component {
return <LoginForm /> return <LoginForm />
} }
let display = undefined let selectedRequest = undefined;
if (this.props.match.params.search && this.state.requested_objects !== '') { let listItemSelected = undefined;
display = this.state.requested_objects[this.props.match.params.search]
const requestParam = this.props.match.params.request;
if (requestParam && this.state.requested_objects !== '') {
selectedRequest = this.state.requested_objects[requestParam]
listItemSelected = requestParam
} }
return ( return (
<div> <div>
<div style={adminComponentStyle.sidebar}> <div style={adminComponentStyle.sidebar}>
<Sidebar requested_objects={this.state.requested_objects} style={adminComponentStyle.sidebar}/> <Sidebar
requested_objects={this.state.requested_objects}
listItemSelected={listItemSelected}
style={adminComponentStyle.sidebar} />
</div> </div>
<div style={adminComponentStyle.selectedObjectPanel}> <div style={adminComponentStyle.selectedObjectPanel}>
<AdminRequestInfo display={display} /> <AdminRequestInfo selectedRequest={selectedRequest} />
</div> </div>
</div> </div>
) )

View File

@@ -35,7 +35,7 @@ class AdminRequestInfo extends Component {
minHeight: '450px', minHeight: '450px',
} }
} }
const request = this.props.display; const request = this.props.selectedRequest;
if (request) { if (request) {
return ( return (

View File

@@ -3,12 +3,23 @@ import { Link } from 'react-router-dom';
class SidebarComponent extends Component { class SidebarComponent extends Component {
generateListElements(index, item) {
if (index == this.props.listItemSelected)
return (
<td>{item.name}</td>
)
else
return (
<td><Link to={{ pathname: '/admin/'+String(index)}}>{item.name}</Link></td>
)
}
displayRequestedElementsInfo() { displayRequestedElementsInfo() {
if (this.props.requested_objects) { if (this.props.requested_objects) {
let element = this.props.requested_objects.map((item, index) => { let requestedElement = this.props.requested_objects.map((item, index) => {
return ( return (
<tr key={index}> <tr key={index}>
<td><Link to={{ pathname: '/admin/'+String(index)}}>{item.name}</Link></td> { this.generateListElements(index, item) }
<td>{item.status}</td> <td>{item.status}</td>
<td>{item.requested_date}</td> <td>{item.requested_date}</td>
</tr> </tr>
@@ -25,7 +36,7 @@ class SidebarComponent extends Component {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{element} {requestedElement}
</tbody> </tbody>
</table> </table>
) )