-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
113b7a6
commit 80383ae
Showing
15 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# TutorialsController | ||
class TutorialsController < ApplicationController | ||
before_action :set_tutorial, only: [:edit, :destroy, :update, :cancel_edit] | ||
authorize_resource | ||
|
||
def new | ||
@tutorial = Tutorial.new | ||
lecture = Lecture.find_by_id(params[:lecture_id]) | ||
@tutorial.lecture = lecture | ||
end | ||
|
||
def create | ||
@tutorial = Tutorial.new(tutorial_params) | ||
@tutorial.save | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@tutorial.update(tutorial_params) | ||
end | ||
|
||
def destroy | ||
@tutorial.destroy | ||
end | ||
|
||
def cancel_edit | ||
end | ||
|
||
private | ||
|
||
def set_tutorial | ||
@tutorial = Tutorial.find_by_id(params[:id]) | ||
return if @tutorial.present? | ||
redirect_to :root, alert: I18n.t('controllers.no_tutorial') | ||
end | ||
|
||
def tutorial_params | ||
params.require(:tutorial).permit(:title, :tutor_id, :lecture_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= form_with model: tutorial do |f| %> | ||
<div class="form-row tutorialRow py-2 mx-3 border" | ||
data-id="<%= tutorial.id.to_i %>"> | ||
<div class="form-group col-4"> | ||
<%= f.text_field :title, | ||
class: 'form-control' %> | ||
</div> | ||
<div class="form-group col-4"> | ||
<%= f.select :tutor_id, | ||
options_for_select(User.select_editors, tutorial.tutor_id), | ||
{}, | ||
{ class: 'form-control' } %> | ||
</div> | ||
<div class="form-group col-4"> | ||
<%= f.submit t('buttons.save'), | ||
class: 'btn btn-sm btn-primary ml-2' %> | ||
<% if tutorial.persisted? %> | ||
<%= link_to t('buttons.cancel'), | ||
cancel_edit_tutorial_path(tutorial), | ||
class: 'btn btn-sm btn-secondary', | ||
remote: true %> | ||
<% else %> | ||
<button class="btn btn-sm btn-secondary" | ||
id="cancelNewTutorial" | ||
role="button"> | ||
<%= t('buttons.cancel') %> | ||
</button> | ||
<% end %> | ||
</div> | ||
</div> | ||
<%= f.hidden_field :lecture_id, | ||
value: tutorial.lecture.id %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<div class="row tutorialRow py-2 mx-3 border" data-id="<%= tutorial.id.to_i %>"> | ||
<div class="col-4"> | ||
<%= tutorial.title %> | ||
</div> | ||
<div class="col-4"> | ||
<%= tutorial.tutor.name %> | ||
</div> | ||
<div class="col-4"> | ||
<%= link_to edit_tutorial_path(tutorial), | ||
class: 'text-dark', | ||
data: { toggle: 'tooltip', | ||
placement: 'botttom' }, | ||
style: 'text-decoration: none;', | ||
title: t('buttons.edit'), | ||
remote: true do %> | ||
<i class="far fa-lg fa-edit mr-2"> | ||
</i> | ||
<% end %> | ||
<%= link_to tutorial_path(tutorial), | ||
class: 'text-dark', | ||
data: { toggle: 'tooltip', | ||
placement: 'botttom', | ||
confirm: t('confirmation.generic') }, | ||
style: 'text-decoration: none;', | ||
title: t('buttons.delete'), | ||
method: :delete, | ||
remote: true do %> | ||
<i class="fas fa-lg fa-trash-alt"> | ||
</i> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.tutorialRow[data-id="<%= @tutorial.id %>') | ||
.replaceWith('<%= j render partial: "tutorials/row", | ||
locals: { tutorial: @tutorial } %>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.tutorialRow[data-id="0"') | ||
.replaceWith('<%= j render partial: "tutorials/row", | ||
locals: { tutorial: @tutorial } %>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('.tutorialRow[data-id="<%= @tutorial.id %>"').remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.tutorialRow[data-id="<%= @tutorial.id %>"') | ||
.replaceWith('<%= j render partial: "tutorials/form", | ||
locals: { tutorial: @tutorial } %>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('#tutorialListHeader') | ||
.after('<%= j render partial: "tutorials/form", | ||
locals: { tutorial: @tutorial } %>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.tutorialRow[data-id="<%= @tutorial.id %>') | ||
.replaceWith('<%= j render partial: "tutorials/row", | ||
locals: { tutorial: @tutorial } %>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters