Skip to content

Commit f02d1d2

Browse files
authored
Merge pull request creativecommons#188 from pavitra14/master
GSoC project ideas page should allow selection of both difficulty level and a tool of choice
2 parents 6bd8893 + b620d0e commit f02d1d2

File tree

23 files changed

+150
-95
lines changed

23 files changed

+150
-95
lines changed

content/internships/project-ideas-collection/add-audio/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ skills_recommended: CSS, Django, Django REST Framework, HTML, JavaScript, Python
3333
mentors: Alden Page, Brent Moran, Anna Tumadóttir
3434
---
3535
difficulty: Medium
36+
---
37+
filter_value: difficulty-medium skill-javascript skill-python

content/internships/project-ideas-collection/catalog-expansion/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ skills_recommended: Python, JSON, Apache Airflow (optional)
2626
mentors: Brent Moran, Kriti Godey
2727
---
2828
difficulty: Easy
29+
---
30+
filter_value: difficulty-easy skill-python

content/internships/project-ideas-collection/cc-search-accessibility/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ skills_recommended: CSS, HTML, JavaScript, Vue.js
4444
mentors: Breno Ferreira, Ari Madian
4545
---
4646
difficulty: Medium
47+
---
48+
filter_value: difficulty-medium skill-javascript

content/internships/project-ideas-collection/legal-database/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ skills_recommended: CSS, Django, HTML, JavaScript, PHP, Python, WordPress (eithe
3838
mentors: Kriti Godey, Sarah Pearson, Timid Robot Zehta
3939
---
4040
difficulty: Medium
41+
---
42+
filter_value: difficulty-medium skill-javascript skill-python skill-wordpress

content/internships/project-ideas-collection/linked-commons/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ skills_recommended: JavaScript, Graph Theory
3232
mentors: Brent Moran, María Belén Guaranda Cabezas
3333
---
3434
difficulty: Easy
35+
---
36+
filter_value: difficulty-easy skill-javascript

content/internships/project-ideas-collection/metrics-dashboard/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ skills_recommended: CSS, design, HTML, Python, PostgreSQL
4040
mentors: Alden Page, Anna Tumadóttir
4141
---
4242
difficulty: Hard
43+
---
44+
filter_value: difficulty-hard skill-python

content/internships/project-ideas-collection/vocabulary-integration/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ skills_recommended: CSS, HTML, JavaScript, PHP, WordPress
3636
mentors: Dhruv Bhanushali, Hugo Solar
3737
---
3838
difficulty: Medium
39+
---
40+
filter_value: difficulty-medium skill-javascript skill-wordpress

content/internships/project-ideas-collection/web-monetization/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ skills_recommended: Research, Writing. In so far as the work is technical, it is
3737
mentors: Anna Tumadóttir, Sarah Pearson
3838
---
3939
difficulty: Easy
40+
---
41+
filter_value: difficulty-easy skill-writing

content/internships/project-ideas-collection/wp-plugin/contents.lr

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ skills_recommended: CSS, HTML, JavaScript, PHP, WordPress
3636
mentors: Hugo Solar, Timid Robot Zehta
3737
---
3838
difficulty: Medium
39+
---
40+
filter_value: difficulty-medium skill-javascript skill-wordpress

content/internships/project-ideas/all/contents.lr

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
_model: redirect
2-
---
3-
target: /internships/project-ideas/all/
4-
---
5-
_discoverable: no
1+
_model: project-ideas

content/internships/project-ideas/difficulty-easy/contents.lr

-9
This file was deleted.

content/internships/project-ideas/difficulty-hard/contents.lr

-9
This file was deleted.

content/internships/project-ideas/difficulty-medium/contents.lr

-9
This file was deleted.

content/internships/project-ideas/skill-javascript/contents.lr

-9
This file was deleted.

content/internships/project-ideas/skill-python/contents.lr

-9
This file was deleted.

content/internships/project-ideas/skill-wordpress/contents.lr

-9
This file was deleted.

content/internships/project-ideas/skill-writing/contents.lr

-9
This file was deleted.

models/project-idea.ini

+4
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ type = string
3838
[fields.difficulty]
3939
label = Difficulty
4040
type = string
41+
42+
[fields.filter_value]
43+
label = Filter Value
44+
type = string

models/project-ideas.ini

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ order_by = title
1212
label = Filter Navigation Label
1313
type = string
1414

15+
[fields.filter_label]
16+
label = Filter Label
17+
type = string
18+
1519
[fields.field]
1620
label = Filter Field
1721
type = string

templates/project-ideas.html

+27-17
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,47 @@
33

44
{% block header %}Open Source Internships: Project Ideas{% endblock %}
55
{% block body %}
6+
67
<p class="lead">This is the project idea list for the <strong><a href="/internships">current round of open source internships at Creative Commons</a></strong>.</p>
78
<hr/>
89
<!-- We display all ideas by default. -->
910
{% set ideas = site.query('/internships/project-ideas-collection').include_undiscoverable(true) %}
10-
{% set filters = site.query('/internships/project-ideas').include_undiscoverable(true).order_by('order') %}
11-
{% set current_filter = filters.filter(F._slug == this._slug).first() %}
12-
<!-- The following code filters the ideas to display based on the current URL. -->
13-
{% if current_filter.field == 'difficulty' %}
14-
{% set ideas = ideas.filter(F.difficulty == current_filter.value) %}
15-
{% elif current_filter.field == 'recommended_skill' %}
16-
{% set ideas = ideas.filter(F.skills_recommended.contains(current_filter.value).or(F.skills_recommended.contains('depends'))) %}
17-
{% endif %}
1811
<div class="mt-4">
1912
<div>
20-
{% for filter in filters %}
21-
<a href="{{ filter.url_path }}">
22-
<button type="button" class="m-1 btn btn-sm {% if this._slug == filter._slug %}btn-dark{% else %}btn-primary{% endif %}" {% if this._slug == filter._slug %}disabled{% endif %}>
23-
{{ filter.nav_label }}
24-
</button>
25-
</a>
26-
{% endfor %}
13+
<button type="button" class="m-1 btn btn-sm btn-dark filter-btn" data-filter="all">
14+
All Projects
15+
</button>
16+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="difficulty-easy">
17+
Difficulty: Easy
18+
</button>
19+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="difficulty-medium">
20+
Difficulty: Medium
21+
</button>
22+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="difficulty-hard">
23+
Difficulty: Hard
24+
</button>
25+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="skill-javascript">
26+
Skill: JavaScript
27+
</button>
28+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="skill-python">
29+
Skill: Python
30+
</button>
31+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="skill-wordpress">
32+
Skill: WordPress
33+
</button>
34+
<button type="button" class="m-1 btn btn-sm btn-primary filter-btn" data-filter="skill-writing">
35+
Skill: Writing
36+
</button>
2737
<ul class="list-unstyled m-3">
2838
{% for idea in ideas %}
29-
<li class="my-2"><a href="#{{ idea._slug }}">{{ idea.title }}</a></li>
39+
<li class="my-2 filter filter-label {{ idea.filter_value }}"><a href="#{{ idea._slug }}">{{ idea.title }}</a></li>
3040
{% endfor %}
3141
<li class="my-2"><a href="#original-ideas">Original Ideas</a></li>
3242
</ul>
3343
</div>
3444
<hr/>
3545
{% for idea in ideas %}
36-
<div class="project-idea-card m-1 mb-4">
46+
<div class="project-idea-card m-1 mb-4 filter filter-block {{ idea.filter_value }}">
3747
<h2 class="card-header project-idea-header"><a name="{{ idea._slug }}">{{ idea.title }}</a></h5>
3848
<ul class="list-group list-group-flush">
3949
<li class="list-group-item"><strong>The Problem:</strong> {{ idea.problem }}</li>

webpack/js/ideas.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
$(document).ready(function(){
2+
// Class for active buttons
3+
const active_class = 'btn-dark';
4+
5+
// Class for inactive buttons
6+
const inactive_class = 'btn-primary';
7+
8+
// jQuery object containing all the filter buttons
9+
const filter_btn = $('.filter-btn');
10+
11+
// Animation delay for show() function
12+
const animation_delay = 100;
13+
14+
// List of Available filters
15+
const filters = [
16+
'all',
17+
'difficulty-easy',
18+
'difficulty-medium',
19+
'difficulty-hard',
20+
'skill-javascript',
21+
'skill-python',
22+
'skill-wordpress',
23+
'skill-writing'
24+
];
25+
26+
// Variable to hold selected filters
27+
var selected = [];
28+
29+
// To display selected filters
30+
function showIdeas(selected)
31+
{
32+
// If no filter is selected/show all
33+
if(selected.length == 0){
34+
$('.filter').show(animation_delay);
35+
return selected;
36+
}
37+
// Get filters which were not selected
38+
hidden = filters.filter(n => !selected.includes(n));
39+
40+
// Hide not selected
41+
for (const idea in hidden) {
42+
if (hidden.hasOwnProperty(idea)) {
43+
const element = hidden[idea];
44+
$('.filter.' + element).hide();
45+
}
46+
}
47+
// Show not selected
48+
for (const idea in selected) {
49+
if (selected.hasOwnProperty(idea)) {
50+
const element = selected[idea];
51+
$('.filter.' + element).show(animation_delay);
52+
}
53+
}
54+
return selected;
55+
}
56+
57+
// To reset the selected filters / All Projects button
58+
function resetFilters()
59+
{
60+
$('.filter-btn[data-filter="all"]').removeClass(inactive_class).addClass(active_class);
61+
return filter_btn.not('[data-filter="all"]').removeClass(active_class).addClass(inactive_class);
62+
}
63+
64+
// To toggle classes in filter buttons
65+
function toggleBtn(btn)
66+
{
67+
if(btn.hasClass(active_class)){
68+
return btn.removeClass(active_class).addClass(inactive_class);
69+
}
70+
return btn.removeClass(inactive_class).addClass(active_class);
71+
}
72+
73+
// Click event handler
74+
filter_btn.click(function() {
75+
var value = $(this).data('filter');
76+
// Reset all filters and show all
77+
if(value == 'all')
78+
{
79+
selected = [];
80+
resetFilters();
81+
return showIdeas(selected);
82+
}
83+
if(selected.indexOf(value) > -1)
84+
{
85+
// If the filter is already selected, remove it from selected and toggle buttons
86+
selected.splice(selected.indexOf(value), 1);
87+
}else if(filters.indexOf(value) > -1) {
88+
// If the filter is not selected, add it to the selected array and toggle buttons
89+
$('.filter-btn[data-filter="all"]').removeClass(active_class).addClass(inactive_class);
90+
selected.push(value);
91+
}
92+
toggleBtn($(this));
93+
return showIdeas(selected);
94+
});
95+
});

webpack/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22

33
module.exports = {
44
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
5-
entry: ['./js/main.js', './sass/main.scss'],
5+
entry: ['./js/main.js','./js/ideas.js', './sass/main.scss'],
66
output: {
77
path: path.resolve(__dirname, '../assets/static/gen'),
88
filename: 'script.js',

0 commit comments

Comments
 (0)