Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labs page for dynamic questions #131

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/app/graphql/types/dynamic_topic_option_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion api/app/services/fetch_dynamic_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Home,
COMP1805Home,
COMP2804Home,
Labs,
NotFound,
Test
} from './pages';
Expand All @@ -33,6 +34,9 @@
// Test path
'/sessions/:id': CourseSession,

// Labs path
'/labs': Labs,

// Catch-all
'*': NotFound
};
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/ContentCard/ContentCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -30,7 +31,8 @@
Test: faQuestion,
Midterm: faQuestion,
Exam: faQuestion,
User: faUser
User: faUser,
Vial: faVial
};
</script>

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/CourseNavbar/CourseNavbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<a href="/" use:link>
<Fa icon={faQuestion} />
</a>
<a href="/" use:link>
<a href="/labs" use:link>
<Fa icon={faVial} />
</a>
<a href="/" use:link>
Expand Down
9 changes: 6 additions & 3 deletions client/src/data/queries/DynamicRoutes/Routes.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
]
}
Expand Down
1 change: 1 addition & 0 deletions client/src/data/queries/DynamicRoutes/Routes.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ROUTES = gql`
options {
name
route
displayName
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions client/src/pages/Labs.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script>
import {link} from 'svelte-spa-router';
import {ContentCard, CourseNavbar as Navbar, Loading} from '../components';
import {getRoutes} from '../data';
const response = getRoutes();
</script>

<Navbar />
<div class="course-page">
{#if $response.loading}
<div class="loading-wrap"><Loading /></div>
{/if}

{#if $response.error}
<div>ERROR: {$response.error.message}</div>
{/if}

{#if !$response.loading && $response}
<div class="content-container">
{#each $response.data.dynamicRoutes[1].options as routes}
<a href={'#/labs'}>
<ContentCard
title={routes.displayName}
info="Lab"
tag={'Lab'}
type="Vial"
/>
</a>
{/each}
</div>
{/if}
</div>

<style>
.content-container {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
margin-top: 3rem;
}

a {
text-decoration: none;
color: inherit;
}
</style>
1 change: 1 addition & 0 deletions client/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {default as About} from './About.svelte';
export {default as Course} from './Course.svelte';
export {default as Labs} from './Labs.svelte';
export {default as CourseSession} from './CourseSession.svelte';
export {default as Home} from './Home.svelte';
export {default as NotFound} from './NotFound.svelte';
Expand Down
65 changes: 44 additions & 21 deletions dynamic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,44 @@
)

routes = {
"demo": {"graph_theory": "/demo/graph-theory"},
"books_shelves": {
"books_shelves_0": "/books_shelves/books_shelves_0",
"books_shelves_1": "/books_shelves/books_shelves_1",
"books_shelves_2": "/books_shelves/books_shelves_2",
"books_shelves_3": "/books_shelves/books_shelves_3",
'books_shelves': {
"books_shelves_0": {
'display_name': "Book Shelves",
'route': "/books_shelves/books_shelves_0"
},
"books_shelves_1": {
'display_name': "Book Shelve",
'route': "/books_shelves/books_shelves_1"
},
"books_shelves_2": {
'display_name': "Book Shelve",
'route': "/books_shelves/books_shelves_2"
},
"books_shelves_3": {
'display_name': "Book Shelve",
'route': "/books_shelves/books_shelves_3"
},
},
"comp2804": {
"bitstrings-of-length": "/comp2804/bitstrings-of-length",
"set-theory-question": "/comp2804/set-theory",
"num-of-functions": "/comp2804/num-of-functions",
'demo': {
'graph_theory': {
'display_name': "Graph Theory",
'route': "/demo/graph-theory"
}
},
'comp2804': {
'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"
}
}
}


Expand All @@ -35,47 +61,44 @@ 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()


############___Books_Shelves_Questions___############
@router.get(routes["books_shelves"]["books_shelves_0"])
@router.get(routes["books_shelves"]["books_shelves_0"]['route'])
async def generate_books_shelves_0_question():
return books_shelves_0_generator.call()


@router.get(routes["books_shelves"]["books_shelves_1"])
@router.get(routes["books_shelves"]["books_shelves_1"]['route'])
async def generate_books_shelves_1_question():
return books_shelves_1_generator.call()


@router.get(routes["books_shelves"]["books_shelves_2"])
@router.get(routes["books_shelves"]["books_shelves_2"]['route'])
async def generate_books_shelves_2_question():
return books_shelves_2_generator.call()


@router.get(routes["books_shelves"]["books_shelves_3"])
@router.get(routes["books_shelves"]["books_shelves_3"]['route'])
async def generate_books_shelves_3_question():
return books_shelves_3_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()