diff --git a/README.md b/README.md index 9efcfbf4..2d3eaed9 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ Checklist - [ ] Modify the remaining rails templates into JSX templates - [x] notifications list - [x] notification page - - [ ] list metacodes + - [x] list metacodes - [ ] new metacode - [ ] edit metacode - - [ ] list metacode_sets + - [x] list metacode_sets - [ ] new metacode set - [ ] edit metacode set - [ ] authorized apps diff --git a/src/Metamaps/DataFetcher.js b/src/Metamaps/DataFetcher.js index 4b60c0f8..6ebad3b7 100644 --- a/src/Metamaps/DataFetcher.js +++ b/src/Metamaps/DataFetcher.js @@ -16,6 +16,12 @@ async function getMetacodes() { return data } +async function getMetacodeSets() { + const res = await fetchWithCookies('/metacode_sets.json') + const data = await res.json() + return data +} + async function getCurrentUser() { const res = await fetchWithCookies('/users/current.json') const data = await res.json() @@ -39,6 +45,7 @@ async function requestAccess(mapId) { module.exports = { getMetacodes, + getMetacodeSets, getCurrentUser, approveAccessRequest, denyAccessRequest, diff --git a/src/Metamaps/GlobalUI/ReactApp.js b/src/Metamaps/GlobalUI/ReactApp.js index aa115425..5c7ec981 100644 --- a/src/Metamaps/GlobalUI/ReactApp.js +++ b/src/Metamaps/GlobalUI/ReactApp.js @@ -112,7 +112,8 @@ const ReactApp = { markAsRead: apply(Notifications.markAsRead, ReactApp.render), markAsUnread: apply(Notifications.markAsUnread, ReactApp.render), denyAccessRequest: DataFetcher.denyAccessRequest, - approveAccessRequest: DataFetcher.approveAccessRequest + approveAccessRequest: DataFetcher.approveAccessRequest, + metacodes: DataModel.Metacodes.toJSON() }, self.getMapProps(), self.getTopicProps(), diff --git a/src/Metamaps/index.js b/src/Metamaps/index.js index a5bae1cf..77774e93 100644 --- a/src/Metamaps/index.js +++ b/src/Metamaps/index.js @@ -89,6 +89,9 @@ document.addEventListener('DOMContentLoaded', async function() { const metacodes = await DataFetcher.getMetacodes() Metamaps.ServerData.Metacodes = metacodes + const metacodeSets = await DataFetcher.getMetacodeSets() + Metamaps.ServerData.metacodeSets = metacodeSets + const activeMapper = await DataFetcher.getCurrentUser() if (activeMapper) { Metamaps.ServerData.ActiveMapper = activeMapper diff --git a/src/routes/Admin.js b/src/routes/Admin/AdminHeader.js similarity index 70% rename from src/routes/Admin.js rename to src/routes/Admin/AdminHeader.js index f715aa1c..8e1510c4 100644 --- a/src/routes/Admin.js +++ b/src/routes/Admin/AdminHeader.js @@ -1,8 +1,8 @@ import React, { Component } from 'react' -import NavBar from '../components/NavBar' -import NavBarLink from '../components/NavBarLink' +import NavBar from '../../components/NavBar' +import NavBarLink from '../../components/NavBarLink' -class Admin extends Component { +class AdminHeader extends Component { render = () => { return ( @@ -15,4 +15,4 @@ class Admin extends Component { } } -export default Admin +export default AdminHeader diff --git a/src/routes/Admin/EditMetacode.js b/src/routes/Admin/EditMetacode.js new file mode 100644 index 00000000..036286c4 --- /dev/null +++ b/src/routes/Admin/EditMetacode.js @@ -0,0 +1,14 @@ +import React, { Component } from 'react' +import AdminHeader from './AdminHeader' + +class Metacodes extends Component { + render = () => { + return ( +
+ +
+ ) + } +} + +export default Metacodes \ No newline at end of file diff --git a/src/routes/Admin/EditMetacodeSet.js b/src/routes/Admin/EditMetacodeSet.js new file mode 100644 index 00000000..036286c4 --- /dev/null +++ b/src/routes/Admin/EditMetacodeSet.js @@ -0,0 +1,14 @@ +import React, { Component } from 'react' +import AdminHeader from './AdminHeader' + +class Metacodes extends Component { + render = () => { + return ( +
+ +
+ ) + } +} + +export default Metacodes \ No newline at end of file diff --git a/src/routes/Admin/MetacodeSets.js b/src/routes/Admin/MetacodeSets.js new file mode 100644 index 00000000..6abb55e0 --- /dev/null +++ b/src/routes/Admin/MetacodeSets.js @@ -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 ( +
+
+
+
+ + + + + + + + {metacodeSets.filter(m => m.id).map((metacodeSet, i) => { + return + })} + +
NameDescriptionMetacodes
+
+
+ +
+ ) + } +} + +class MetacodeSetRow extends Component { + render = () => { + const { metacodeSet, metacodes } = this.props + return ( + + + {metacodeSet.name} +
+ Edit +
+ Delete + + + {metacodeSet.description} + + + {metacodeSet.metacodes.map((mId, index) => { + const metacode = metacodes.find(m => m.id === mId) + return ( + + + {(index+1) % 4 === 0 &&
} +
+ ) + })} +
+ + + ) + } +} + +export default MetacodeSets \ No newline at end of file diff --git a/src/routes/Admin/Metacodes.js b/src/routes/Admin/Metacodes.js new file mode 100644 index 00000000..f821f7c8 --- /dev/null +++ b/src/routes/Admin/Metacodes.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react' +import { Link } from 'react-router' +import AdminHeader from './AdminHeader' + +class Metacodes extends Component { + render = () => { + return ( +
+
+
+
+ + + + + + + + + + {this.props.metacodes.map(metacode => { + return ( + + + + {metacode.color && } + {!metacode.color && } + + + + ) + })} + +
NameIconColor
{metacode.name}{metacode.icon}{metacode.color}metacode imageEdit
+
+
+ +
+ ) + } +} + +export default Metacodes \ No newline at end of file diff --git a/src/routes/Admin/NewMetacode.js b/src/routes/Admin/NewMetacode.js new file mode 100644 index 00000000..036286c4 --- /dev/null +++ b/src/routes/Admin/NewMetacode.js @@ -0,0 +1,14 @@ +import React, { Component } from 'react' +import AdminHeader from './AdminHeader' + +class Metacodes extends Component { + render = () => { + return ( +
+ +
+ ) + } +} + +export default Metacodes \ No newline at end of file diff --git a/src/routes/Admin/NewMetacodeSet.js b/src/routes/Admin/NewMetacodeSet.js new file mode 100644 index 00000000..036286c4 --- /dev/null +++ b/src/routes/Admin/NewMetacodeSet.js @@ -0,0 +1,14 @@ +import React, { Component } from 'react' +import AdminHeader from './AdminHeader' + +class Metacodes extends Component { + render = () => { + return ( +
+ +
+ ) + } +} + +export default Metacodes \ No newline at end of file diff --git a/src/routes/makeRoutes.js b/src/routes/makeRoutes.js index 428da21d..cc2ca429 100644 --- a/src/routes/makeRoutes.js +++ b/src/routes/makeRoutes.js @@ -1,10 +1,15 @@ import React from 'react' import { Route, IndexRoute } from 'react-router' -import Admin from './Admin' import App from './App' import Apps from './Apps' import Maps from './Maps' 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 NotificationPage from './Notifications/NotificationPage' import TopicView from './TopicView' @@ -50,14 +55,14 @@ export default function makeRoutes (currentUser) { - - - + + + - - - + + + diff --git a/views/metacode_sets/index.js b/views/metacode_sets/index.js deleted file mode 100644 index f1045489..00000000 --- a/views/metacode_sets/index.js +++ /dev/null @@ -1,46 +0,0 @@ -import React, { Component } from react - -class MyComponent extends Component { - render = () => { - return ( -
-
-
- - - - - - - - { @metacode_sets.each do |metacode_set| } - - - - - - { end } -
NameDescriptionMetacodes
- { metacode_set.name }
- { link_to 'Edit', - edit_metacode_set_path(metacode_set) } -
- { link_to 'Delete', - metacode_set, method: :delete, - data: { confirm: 'Are you sure?' } } -
{ metacode_set.desc } - { metacode_set.metacodes.each_with_index do |metacode, index| } - - { if (index+1)%4 == 0 } -
- { end } - { end } -
-
-
-
- ) - } -} - -export default MyComponent diff --git a/views/metacodes/index.js b/views/metacodes/index.js deleted file mode 100644 index da269782..00000000 --- a/views/metacodes/index.js +++ /dev/null @@ -1,40 +0,0 @@ -import React, { Component } from react - -class MyComponent extends Component { - render = () => { - return ( -
-
-
- - - - - - - - - - { @metacodes.each do |metacode| } - - - - { if metacode.color } - - { else } - - { end } - - - - { end } -
NameIconColor
{ metacode.name }{ metacode.icon } - { metacode.color } - { image_tag metacode.icon, width: 40 }{ link_to 'Edit', edit_metacode_path(metacode) }
-
-
- ) - } -} - -export default MyComponent