-
Notifications
You must be signed in to change notification settings - Fork 172
CRUD for Questionnaire #246
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
Open
21Tulasi
wants to merge
2
commits into
expertiza:main
Choose a base branch
from
21Tulasi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
| class ItemTypesController < ApplicationController | ||
| # GET /item_types | ||
| def index | ||
| item_types = ItemType.all | ||
| render json: item_types | ||
| end | ||
| end |
This file contains hidden or 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,16 @@ | ||
| # app/controllers/items_controller.rb | ||
| class ItemsController < ApplicationController | ||
| def index | ||
| questionnaire = Questionnaire.find(params[:questionnaire_id]) | ||
|
|
||
| Rails.logger.info "Items for Questionnaire #{questionnaire.id}:" | ||
| questionnaire.items.each do |item| | ||
| Rails.logger.info item.attributes.inspect | ||
| end | ||
|
|
||
| items_json = questionnaire.items.as_json | ||
| Rails.logger.info "JSON being rendered: #{items_json.inspect}" | ||
|
|
||
| render json: items_json | ||
| end | ||
| end |
This file contains hidden or 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,7 @@ | ||
| class QuestionnaireTypesController < ApplicationController | ||
| # GET /questionnaire_types | ||
| def index | ||
| questionnaire_types = QuestionnaireType.all | ||
| render json: questionnaire_types | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| class ItemType < ApplicationRecord | ||
| # Validations | ||
| validates :name, presence: true, uniqueness: true | ||
| end |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,13 +2,14 @@ | |
|
|
||
| class Questionnaire < ApplicationRecord | ||
| belongs_to :instructor | ||
| has_many :items, class_name: "Item", foreign_key: "questionnaire_id", dependent: :destroy # the collection of questions associated with this Questionnaire | ||
| has_many :items, -> { order(:seq) }, class_name: "Item", foreign_key: "questionnaire_id", dependent: :destroy # the collection of questions associated with this Questionnaire | ||
| accepts_nested_attributes_for :items, allow_destroy: true | ||
| before_destroy :check_for_question_associations | ||
|
|
||
| validate :validate_questionnaire | ||
| validates :name, presence: true | ||
| validates :max_question_score, :min_question_score, numericality: true | ||
|
|
||
|
|
||
| # after_initialize :post_initialization | ||
| # @print_name = 'Review Rubric' | ||
|
|
@@ -28,7 +29,7 @@ def symbol | |
| def get_assessments_for(participant) | ||
| participant.reviews | ||
| end | ||
|
|
||
| # validate the entries for this questionnaire | ||
| def validate_questionnaire | ||
| errors.add(:max_question_score, 'The maximum item score must be a positive integer.') if max_question_score < 1 | ||
|
|
@@ -64,9 +65,9 @@ def self.copy_questionnaire_details(params) | |
| questionnaire | ||
| end | ||
|
|
||
| # Check_for_question_associations checks if questionnaire has associated questions or not | ||
| # Check_for_question_associations checks if questionnaire has associated items or not | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check_for_item_associations |
||
| def check_for_question_associations | ||
| if questions.any? | ||
| if items.any? | ||
| raise ActiveRecord::DeleteRestrictionError.new( "Cannot delete record because dependent questions exist") | ||
| end | ||
| end | ||
|
|
@@ -82,4 +83,4 @@ def as_json(options = {}) | |
| hash['instructor'] ||= { id: nil, name: nil } | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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,7 @@ | ||
| class QuestionnaireType < ApplicationRecord | ||
| # Validations | ||
| validates :name, presence: true, uniqueness: true | ||
|
|
||
| # Associations (if any later) | ||
| # has_many :questionnaires, foreign_key: :questionnaire_type, primary_key: :name | ||
| end |
This file contains hidden or 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 hidden or 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,7 @@ | ||
| class AddTextareaWidthToItems < ActiveRecord::Migration[8.0] | ||
| def change | ||
| add_column :items, :textarea_width, :integer | ||
| add_column :items, :textarea_height, :integer | ||
| add_column :items, :textbox_width, :integer | ||
| end | ||
| end |
This file contains hidden or 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,6 @@ | ||
| class AddColsRowsToItems < ActiveRecord::Migration[8.0] | ||
| def change | ||
| add_column :items, :col_names, :string | ||
| add_column :items, :row_names, :string | ||
| end | ||
| end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20251230123456_rename_question_types_to_item_types.rb.rb
This file contains hidden or 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,5 @@ | ||
| class RenameQuestionTypesToItemTypes < ActiveRecord::Migration[8.0] | ||
| def change | ||
| rename_table :question_types, :item_types | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.