list metacodes and metacode setssssssssssssssssssssssssssssssss

This commit is contained in:
Connor Turland 2018-03-08 13:15:33 -05:00
parent 7ee822cb80
commit 7cfb830870
14 changed files with 194 additions and 100 deletions

View file

@ -51,10 +51,10 @@ Checklist
- [ ] Modify the remaining rails templates into JSX templates - [ ] Modify the remaining rails templates into JSX templates
- [x] notifications list - [x] notifications list
- [x] notification page - [x] notification page
- [ ] list metacodes - [x] list metacodes
- [ ] new metacode - [ ] new metacode
- [ ] edit metacode - [ ] edit metacode
- [ ] list metacode_sets - [x] list metacode_sets
- [ ] new metacode set - [ ] new metacode set
- [ ] edit metacode set - [ ] edit metacode set
- [ ] authorized apps - [ ] authorized apps

View file

@ -16,6 +16,12 @@ async function getMetacodes() {
return data return data
} }
async function getMetacodeSets() {
const res = await fetchWithCookies('/metacode_sets.json')
const data = await res.json()
return data
}
async function getCurrentUser() { async function getCurrentUser() {
const res = await fetchWithCookies('/users/current.json') const res = await fetchWithCookies('/users/current.json')
const data = await res.json() const data = await res.json()
@ -39,6 +45,7 @@ async function requestAccess(mapId) {
module.exports = { module.exports = {
getMetacodes, getMetacodes,
getMetacodeSets,
getCurrentUser, getCurrentUser,
approveAccessRequest, approveAccessRequest,
denyAccessRequest, denyAccessRequest,

View file

@ -112,7 +112,8 @@ const ReactApp = {
markAsRead: apply(Notifications.markAsRead, ReactApp.render), markAsRead: apply(Notifications.markAsRead, ReactApp.render),
markAsUnread: apply(Notifications.markAsUnread, ReactApp.render), markAsUnread: apply(Notifications.markAsUnread, ReactApp.render),
denyAccessRequest: DataFetcher.denyAccessRequest, denyAccessRequest: DataFetcher.denyAccessRequest,
approveAccessRequest: DataFetcher.approveAccessRequest approveAccessRequest: DataFetcher.approveAccessRequest,
metacodes: DataModel.Metacodes.toJSON()
}, },
self.getMapProps(), self.getMapProps(),
self.getTopicProps(), self.getTopicProps(),

View file

@ -89,6 +89,9 @@ document.addEventListener('DOMContentLoaded', async function() {
const metacodes = await DataFetcher.getMetacodes() const metacodes = await DataFetcher.getMetacodes()
Metamaps.ServerData.Metacodes = metacodes Metamaps.ServerData.Metacodes = metacodes
const metacodeSets = await DataFetcher.getMetacodeSets()
Metamaps.ServerData.metacodeSets = metacodeSets
const activeMapper = await DataFetcher.getCurrentUser() const activeMapper = await DataFetcher.getCurrentUser()
if (activeMapper) { if (activeMapper) {
Metamaps.ServerData.ActiveMapper = activeMapper Metamaps.ServerData.ActiveMapper = activeMapper

View file

@ -1,8 +1,8 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import NavBar from '../components/NavBar' import NavBar from '../../components/NavBar'
import NavBarLink from '../components/NavBarLink' import NavBarLink from '../../components/NavBarLink'
class Admin extends Component { class AdminHeader extends Component {
render = () => { render = () => {
return ( return (
<NavBar> <NavBar>
@ -15,4 +15,4 @@ class Admin extends Component {
} }
} }
export default Admin export default AdminHeader

View file

@ -0,0 +1,14 @@
import React, { Component } from 'react'
import AdminHeader from './AdminHeader'
class Metacodes extends Component {
render = () => {
return (
<div>
<AdminHeader />
</div>
)
}
}
export default Metacodes

View file

@ -0,0 +1,14 @@
import React, { Component } from 'react'
import AdminHeader from './AdminHeader'
class Metacodes extends Component {
render = () => {
return (
<div>
<AdminHeader />
</div>
)
}
}
export default Metacodes

View file

@ -0,0 +1,65 @@
import React, { Component } from 'react'
import { Link } from 'react-router'
import AdminHeader from './AdminHeader'
class MetacodeSets extends Component {
render = () => {
const { metacodeSets, metacodes } = this.props
return (
<div>
<div id="yield">
<div className="centerContent">
<br />
<table>
<tbody>
<tr>
<th>Name</th>
<th>Description</th>
<th>Metacodes</th>
</tr>
{metacodeSets.filter(m => m.id).map((metacodeSet, i) => {
return <MetacodeSetRow key={i} metacodeSet={metacodeSet} metacodes={metacodes} />
})}
</tbody>
</table>
</div>
</div>
<AdminHeader />
</div>
)
}
}
class MetacodeSetRow extends Component {
render = () => {
const { metacodeSet, metacodes } = this.props
return (
<tr>
<td>
{metacodeSet.name}
<br />
<Link to={`/metacode_sets/${metacodeSet.id}/edit`}>Edit</Link>
<br />
<a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href={`/metacode_sets/${metacodeSet.id}`}>Delete</a>
</td>
<td className="metacodeSetDesc">
{metacodeSet.description}
</td>
<td>
{metacodeSet.metacodes.map((mId, index) => {
const metacode = metacodes.find(m => m.id === mId)
return (
<span key={index}>
<img className="metacodeSetImage" src={metacode.icon} />
{(index+1) % 4 === 0 && <div className='clearfloat'></div>}
</span>
)
})}
<div className='clearfloat'></div>
</td>
</tr>
)
}
}
export default MetacodeSets

View file

@ -0,0 +1,43 @@
import React, { Component } from 'react'
import { Link } from 'react-router'
import AdminHeader from './AdminHeader'
class Metacodes extends Component {
render = () => {
return (
<div>
<div id="yield">
<div className="centerContent">
<br />
<table>
<tbody>
<tr>
<th>Name</th>
<th>Icon</th>
<th>Color</th>
<th></th>
<th></th>
</tr>
{this.props.metacodes.map(metacode => {
return (
<tr key={metacode.id}>
<td>{metacode.name}</td>
<td className="iconURL">{metacode.icon}</td>
{metacode.color && <td className="iconColor" style={{backgroundColor: metacode.color}}>{metacode.color}</td>}
{!metacode.color && <td></td>}
<td><img width="40" src={metacode.icon} alt="metacode image" /></td>
<td><Link to={`/metacodes/${metacode.id}/edit`}>Edit</Link></td>
</tr>
)
})}
</tbody>
</table>
</div>
</div>
<AdminHeader />
</div>
)
}
}
export default Metacodes

View file

@ -0,0 +1,14 @@
import React, { Component } from 'react'
import AdminHeader from './AdminHeader'
class Metacodes extends Component {
render = () => {
return (
<div>
<AdminHeader />
</div>
)
}
}
export default Metacodes

View file

@ -0,0 +1,14 @@
import React, { Component } from 'react'
import AdminHeader from './AdminHeader'
class Metacodes extends Component {
render = () => {
return (
<div>
<AdminHeader />
</div>
)
}
}
export default Metacodes

View file

@ -1,10 +1,15 @@
import React from 'react' import React from 'react'
import { Route, IndexRoute } from 'react-router' import { Route, IndexRoute } from 'react-router'
import Admin from './Admin'
import App from './App' import App from './App'
import Apps from './Apps' import Apps from './Apps'
import Maps from './Maps' import Maps from './Maps'
import MapView from './MapView' import MapView from './MapView'
import Metacodes from './Admin/Metacodes'
import NewMetacode from './Admin/NewMetacode'
import EditMetacode from './Admin/EditMetacode'
import MetacodeSets from './Admin/MetacodeSets'
import NewMetacodeSet from './Admin/NewMetacodeSet'
import EditMetacodeSet from './Admin/EditMetacodeSet'
import Notifications from './Notifications/Notifications' import Notifications from './Notifications/Notifications'
import NotificationPage from './Notifications/NotificationPage' import NotificationPage from './Notifications/NotificationPage'
import TopicView from './TopicView' import TopicView from './TopicView'
@ -50,14 +55,14 @@ export default function makeRoutes (currentUser) {
<Route path="password/edit" component={nullComponent} /> <Route path="password/edit" component={nullComponent} />
</Route> </Route>
<Route path="metacodes"> <Route path="metacodes">
<IndexRoute component={Admin} /> <IndexRoute component={Metacodes} />
<Route path="new" component={Admin} /> <Route path="new" component={NewMetacode} />
<Route path=":id/edit" component={Admin} /> <Route path=":id/edit" component={EditMetacode} />
</Route> </Route>
<Route path="metacode_sets"> <Route path="metacode_sets">
<IndexRoute component={Admin} /> <IndexRoute component={MetacodeSets} />
<Route path="new" component={Admin} /> <Route path="new" component={NewMetacodeSet} />
<Route path=":id/edit" component={Admin} /> <Route path=":id/edit" component={EditMetacodeSet} />
</Route> </Route>
<Route path="oauth"> <Route path="oauth">
<Route path="token/info" component={Apps} /> <Route path="token/info" component={Apps} />

View file

@ -1,46 +0,0 @@
import React, { Component } from react
class MyComponent extends Component {
render = () => {
return (
<div id="yield">
<div className='centerContent'>
<br />
<table>
<tr>
<th>Name</th>
<th className='metacodeSetsDescription'>Description</th>
<th>Metacodes</th>
</tr>
{ @metacode_sets.each do |metacode_set| }
<tr>
<td>
{ metacode_set.name }<br />
{ link_to 'Edit',
edit_metacode_set_path(metacode_set) }
<br />
{ link_to 'Delete',
metacode_set, method: :delete,
data: { confirm: 'Are you sure?' } }
</td>
<td className='metacodeSetDesc'>{ metacode_set.desc }</td>
<td>
{ metacode_set.metacodes.each_with_index do |metacode, index| }
<img className='metacodeSetImage' src='{ asset_path metacode.icon }' />
{ if (index+1)%4 == 0 }
<div className='clearfloat'></div>
{ end }
{ end }
<div className='clearfloat'></div>
</td>
</tr>
{ end }
</table>
</div>
</div>
)
}
}
export default MyComponent

View file

@ -1,40 +0,0 @@
import React, { Component } from react
class MyComponent extends Component {
render = () => {
return (
<div id="yield">
<div className='centerContent'>
<br />
<table>
<tr>
<th>Name</th>
<th>Icon</th>
<th>Color</th>
<th></th>
<th></th>
</tr>
{ @metacodes.each do |metacode| }
<tr>
<td>{ metacode.name }</td>
<td className="iconURL">{ metacode.icon }</td>
{ if metacode.color }
<td className="iconColor" style="background-color: { metacode.color }">
{ metacode.color }
</td>
{ else }
<td></td>
{ end }
<td>{ image_tag metacode.icon, width: 40 }</td>
<td>{ link_to 'Edit', edit_metacode_path(metacode) }</td>
</tr>
{ end }
</table>
</div>
</div>
)
}
}
export default MyComponent