Skip to content

Commit

Permalink
Merge pull request #154 from aismail/f/#153-create-breadcrumbs-widget
Browse files Browse the repository at this point in the history
F/#153 create breadcrumbs widget
  • Loading branch information
Andrei-Adnan Ismail committed May 17, 2013
2 parents 1ee0168 + 2b0991d commit 41c6b7b
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/conf/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ App.the_modules = {
'widget/assignments': 'modules/assignments_list_widget',
'widget/submission_details': 'modules/submission_details_widget',
'widget/assignment_details': 'modules/assignment_details_widget',
'widget/breadcrumbs': 'modules/breadcrumbs_widget',

// Controllers
'widget/Dashboard': 'modules/dashboard_controller',
Expand Down
10 changes: 9 additions & 1 deletion app/modules/assignment_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define ['cs!controller'], (Controller) ->
class AssignmentController extends Controller
action: =>
[assignments] = Utils.newDataChannels('/assignments')
[subjects, assignments, submissions] = Utils.newDataChannels\
('/subjects', '/assignments', '/submissions')

params =
# Parameters passed to the assignment details widget.
Expand All @@ -10,6 +11,13 @@ define ['cs!controller'], (Controller) ->
'/assignments': assignments
'id': @params.url_params[0]

# Parameters passed to the breadcruds_widget.
breadcrumbs_params:
'channels':
'/subjects': subjects
'/assignments': assignments
'/submissions': submissions

@renderLayout(params)


47 changes: 47 additions & 0 deletions app/modules/breadcrumbs_widget.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
define ['cs!widget'], (Widget) ->
class BreadcrumbsWidget extends Widget
subscribed_channels: ['/subjects', '/assignments','/submissions']
template_name: 'templates/breadcrumbs_widget.hjs'

aggregated_channels:{get_subjects_and_assignments: ['/subjects', '/assignments',
'/submissions']}

get_subjects_and_assignments: (subjects_params, assignments_params, submissions_params) =>
base_url = Utils.current_url()
output = [ {url:base_url, name: "Dashboard"}]
current_url = window.location.href.split("/")
id = current_url[current_url.length - 1]
current_page = current_url[current_url.length - 2]
current_page = current_page.substr(1)
if current_page is "submissions"
aux = submissions_params.collection.get(id)
assignment_id = aux.attributes.assignment_id

if assignment_id
submission_id = id
id = assignment_id

if current_page is "assignments" or assignment_id
aux = assignments_params.collection.get(id)
assignment = aux.attributes.name
subject_id = aux.attributes.subject_id

if current_page is "subjects"
subject_id = id

if subject_id
aux = subjects_params.collection.get(subject_id)
subject = aux.attributes.name

if subject_id
output.push({url: base_url + "#subjects/" + subject_id,name: subject})

if assignment_id
output.push({url: base_url + "#assignments/" + assignment_id,name: assignment})

if submission_id
output.push({url: base_url + "#submissions/" + submission_id,name: "Submission"})

params=
output: output
@renderLayout(params, false)
8 changes: 7 additions & 1 deletion app/modules/dashboard_controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ define ['cs!controller'], (Controller) ->
# Create new data channels holding the Subjects and Usertosubjects
# mapping. The channel configuration can be found in datasource.js.

[subjects, userstosubjects] = Utils.newDataChannels('/subjects',
[subjects, assignments, submissions, userstosubjects] = \
Utils.newDataChannels('/subjects', '/assignments', '/submissions',
'/userstosubjects')

params =
Expand All @@ -17,6 +18,11 @@ define ['cs!controller'], (Controller) ->
'/items': userstosubjects
item: 'userstosubjects'
item_element: 'tr'
breadcrumbs_params:
'channels':
'/subjects': subjects
'/assignments': assignments
'/submissions': submissions

# Render the layout (dashboard_controller.hjs)
@renderLayout(params)
Expand Down
12 changes: 10 additions & 2 deletions app/modules/subject_controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ define ['cs!controller'], (Controller) ->
action: =>
channel_params =
'/subjects': {}
'/assignments':
'/assignments':
'subject_id': this.url_params[0]
'/submissions':{}

[subjects, assignments] = Utils.newDataChannels(channel_params)
[subjects, assignments, submissions] = Utils.newDataChannels(channel_params)

params =
# Parameters passed to the subject_details_widget.
Expand All @@ -17,6 +18,13 @@ define ['cs!controller'], (Controller) ->
'channels':
'/assignments': assignments

# Parameters passed to the breadcruds_widget.
breadcrumbs_params:
'channels':
'/subjects': subjects
'/assignments': assignments
'/submissions': submissions

# Render the layout (subject_controller.hjs)
@renderLayout(params)

11 changes: 9 additions & 2 deletions app/modules/submission_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define ['cs!controller'], (Controller) ->
class SubmissionController extends Controller
action: =>
# Create a new data channel holding the submissions.
[submissions] = Utils.newDataChannels('/submissions')
[subjects, assignments, submissions] = Utils.newDataChannels\
('/subjects', '/assignments', '/submissions')

params =
# Parameters passed to the submission_details_widget.
Expand All @@ -12,5 +12,12 @@ define ['cs!controller'], (Controller) ->
'channels':
'/submissions':submissions
'id': @params.url_params[0]

# Parameters passed to the breadcruds_widget.
breadcrumbs_params:
'channels':
'/subjects': subjects
'/assignments': assignments
'/submissions': submissions
@renderLayout(params)

1 change: 1 addition & 0 deletions app/templates/assignment_controller.hjs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div class="mozaic-widget" data-widget="breadcrumbs" data-params="{{breadcrumbs_params}}"></div>
<div class="mozaic-widget" data-widget="assignment_details" data-params="{{assignments_params}}"></div>
4 changes: 4 additions & 0 deletions app/templates/breadcrumbs_widget.hjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{#each output}}
<a href="{{url}}">{{name}}</a>
{{/each}}
<br>
3 changes: 1 addition & 2 deletions app/templates/dashboard_controller.hjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<h1>Dashboard</h1>
<div class="mozaic-widget" data-widget="breadcrumbs" data-params="{{breadcrumbs_params}}"></div>
<table class="mozaic-widget" data-widget="list" data-params="{{list_params}}"></table>


1 change: 1 addition & 0 deletions app/templates/subject_controller.hjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<div class="mozaic-widget" data-widget="breadcrumbs" data-params="{{breadcrumbs_params}}"></div>
<div class="mozaic-widget" data-widget="subject_details" data-params="{{subjects_params}}"></div>
<table class="mozaic-widget" data-widget="assignments" data-params="{{assignments_params}}"></table>
1 change: 1 addition & 0 deletions app/templates/submission_controller.hjs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div class="mozaic-widget" data-widget="breadcrumbs" data-params="{{breadcrumbs_params}}"></div>
<div class="mozaic-widget" data-widget="submission_details" data-params="{{submissions_params}}"></div>

0 comments on commit 41c6b7b

Please sign in to comment.