From e09e2387dd157e05b8c6c10a8b4471f862ba3e9a Mon Sep 17 00:00:00 2001 From: JoshuaSaikali Date: Fri, 3 Dec 2021 12:44:23 -0500 Subject: [PATCH] Added labs page --- .../types/dynamic_topic_option_type.rb | 1 + api/app/services/fetch_dynamic_routes.rb | 2 +- .../components/ContentCard/ContentCard.svelte | 6 ++-- .../queries/DynamicRoutes/Routes.example.js | 9 ++++-- .../queries/DynamicRoutes/Routes.query.js | 1 + client/src/pages/Labs.svelte | 12 ++++---- dynamic/router.py | 29 +++++++++++++------ 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/api/app/graphql/types/dynamic_topic_option_type.rb b/api/app/graphql/types/dynamic_topic_option_type.rb index c5303bfa..bfdea759 100644 --- a/api/app/graphql/types/dynamic_topic_option_type.rb +++ b/api/app/graphql/types/dynamic_topic_option_type.rb @@ -3,5 +3,6 @@ class DynamicTopicOptionType < Types::BaseObject description 'A type that represents a options for generating a dynamic question.' field :name, String, null: false field :route, String, null: false + field :display_name, String, null: false end end diff --git a/api/app/services/fetch_dynamic_routes.rb b/api/app/services/fetch_dynamic_routes.rb index 2343a439..56d79f9f 100644 --- a/api/app/services/fetch_dynamic_routes.rb +++ b/api/app/services/fetch_dynamic_routes.rb @@ -8,7 +8,7 @@ def call(path = 'http://127.0.0.1:8000/api/') topics = [] data.each_key do |key| question_routes = data[key.to_s] - questions_list = question_routes.map { |k, v| OpenStruct.new(name: k, route: v) } + questions_list = question_routes.map { |k, v| OpenStruct.new(name: k, route: v['route'], display_name: v['display_name']) } topics << OpenStruct.new(name: key, options: questions_list) end topics diff --git a/client/src/components/ContentCard/ContentCard.svelte b/client/src/components/ContentCard/ContentCard.svelte index bd0dc0f3..f83c4234 100644 --- a/client/src/components/ContentCard/ContentCard.svelte +++ b/client/src/components/ContentCard/ContentCard.svelte @@ -13,7 +13,8 @@ faClipboard, //Test faPencilAlt, //Midterm faPenAlt, //Exam - faUser // Person + faUser, // Person + faVial // Test Tube } from '@fortawesome/free-solid-svg-icons'; const tagIcons = { @@ -30,7 +31,8 @@ Test: faQuestion, Midterm: faQuestion, Exam: faQuestion, - User: faUser + User: faUser, + Vial: faVial }; diff --git a/client/src/data/queries/DynamicRoutes/Routes.example.js b/client/src/data/queries/DynamicRoutes/Routes.example.js index dcbcd03d..2c322c63 100644 --- a/client/src/data/queries/DynamicRoutes/Routes.example.js +++ b/client/src/data/queries/DynamicRoutes/Routes.example.js @@ -16,15 +16,18 @@ const ROUTES_EXAMPLE_DATA = { options: [ { name: 'bitstrings-of-length', - route: '/comp2804/bitstrings-of-length' + route: '/comp2804/bitstrings-of-length', + displayName: 'Bitstrings of Length' }, { name: 'set-theory-question', - route: '/comp2804/set-theory' + route: '/comp2804/set-theory', + displayName: 'Set Theory' }, { name: 'num-of-functions', - route: '/comp2804/num-of-functions' + route: '/comp2804/num-of-functions', + displayName: 'Number of Functions' } ] } diff --git a/client/src/data/queries/DynamicRoutes/Routes.query.js b/client/src/data/queries/DynamicRoutes/Routes.query.js index 13800a84..a0cc4549 100644 --- a/client/src/data/queries/DynamicRoutes/Routes.query.js +++ b/client/src/data/queries/DynamicRoutes/Routes.query.js @@ -7,6 +7,7 @@ const ROUTES = gql` options { name route + displayName } } } diff --git a/client/src/pages/Labs.svelte b/client/src/pages/Labs.svelte index b07bb7ca..d165c767 100644 --- a/client/src/pages/Labs.svelte +++ b/client/src/pages/Labs.svelte @@ -3,7 +3,6 @@ import {ContentCard, CourseNavbar as Navbar, Loading} from '../components'; import {getRoutes} from '../data'; const response = getRoutes(); - console.log($response.data.dynamicRoutes.options) @@ -18,14 +17,13 @@ {#if !$response.loading && $response}
- - {#each $response.data.dynamicRoutes.options as routes} + {#each $response.data.dynamicRoutes[1].options as routes} {/each} diff --git a/dynamic/router.py b/dynamic/router.py index a9cc4871..613229f6 100644 --- a/dynamic/router.py +++ b/dynamic/router.py @@ -11,14 +11,25 @@ routes = { 'demo': { - 'graph_theory': "/demo/graph-theory" + 'graph_theory': { + 'display_name': "Graph Theory", + 'route': "/demo/graph-theory" + } }, 'comp2804': { - 'bitstrings-of-length': "/comp2804/bitstrings-of-length", - 'set-theory-question': "/comp2804/set-theory", - 'num-of-functions': "/comp2804/num-of-functions" + 'bitstrings-of-length': { + 'display_name': "Bitstrings of Length", + 'route': "/comp2804/bitstrings-of-length" + }, + 'set-theory-question': { + 'display_name': "Set Theory", + 'route': "/comp2804/set-theory" + }, + 'num-of-functions': { + 'display_name': "Number of Functions", + 'route': "/comp2804/num-of-functions" + } } - } @@ -27,23 +38,23 @@ async def get_generators(): return routes -@router.get(routes['demo']['graph_theory']) +@router.get(routes['demo']['graph_theory']['route']) async def generate_graph_theory_question(): return graph_theory_question_generator.call() -@router.get(routes['comp2804']['set-theory-question']) +@router.get(routes['comp2804']['set-theory-question']['route']) async def generate_set_theory_question(): return set_theory_question_generator.call() -@router.get(routes['comp2804']['num-of-functions']) +@router.get(routes['comp2804']['num-of-functions']['route']) async def generate_num_of_functions_question( lower_range: int = 0, upper_range: int = 10 ): return num_of_functions_generator.call(lower_range, upper_range) -@router.get(routes['comp2804']['bitstrings-of-length']) +@router.get(routes['comp2804']['bitstrings-of-length']['route']) async def bitstrings_of_length_question(): return bitstrings_of_length_generator.call()