-
Notifications
You must be signed in to change notification settings - Fork 33
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
TAN-3586 Add matrix field #10095
Closed
sebastienhoorens
wants to merge
41
commits into
matrix-question-feature-branch
from
TAN-3586-add-matrix-field
Closed
TAN-3586 Add matrix field #10095
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
77f54f9
added matrix_linear_scale and statements
sebastienhoorens 97448a4
green pipeline + fix offenses
sebastienhoorens 6c7c28d
factory for matrix field + statements
sebastienhoorens 0673b11
fix generate_key tidying
sebastienhoorens 426486a
fix offenses
sebastienhoorens d763e41
Merge branch 'TAN-3501-add-ranking-field' into TAN-3586-add-matrix-field
sebastienhoorens 86ab7e2
statements -> matrix_statements
sebastienhoorens b0c24b7
statements -> matrix_statements
sebastienhoorens eca85d7
statements -> matrix_statements
sebastienhoorens 69a63a4
first version update_all for matrix
sebastienhoorens bdca1f9
fix offenses
sebastienhoorens 0f2c0e8
fix merge conflict
sebastienhoorens ef64c18
fix merge conflicts...
sebastienhoorens 7cef983
matrix with linear scale labels
sebastienhoorens 0075bce
statements sidefx
sebastienhoorens e461f6f
spec for inserting, updating and deleting statements
sebastienhoorens bf05d57
fix offenses
sebastienhoorens ed212c4
json schema for matrix field
sebastienhoorens a6ff3e7
json and ui schemas
sebastienhoorens 22c6d04
fix offense
sebastienhoorens 9eb003a
initial version for survey results
sebastienhoorens 183a653
tidying matrix statements survey results
sebastienhoorens 17c54e4
initial statements endpoint to get one
sebastienhoorens e143520
matrix statements endpoint: get one + index
sebastienhoorens eaa1b62
a bit more tidying: remove dead code and move private method
sebastienhoorens 964f600
refactoring: stop passing around the group field
sebastienhoorens c23b8ed
towards grouped matrix results
sebastienhoorens 9865cc1
xlsx for matrix fields: stuck on weird bug
sebastienhoorens 62160f4
xlsx for matrix fields: << instead of += super weird
sebastienhoorens 43555ee
spec for matrix fields in prompts + tidying: extract ranking_field_value
sebastienhoorens be2e5f0
implemented matrix_linear_scale_field_value and refactored input_fiel…
sebastienhoorens af17a36
Merge branch 'TAN-3501-add-ranking-field' into TAN-3586-add-matrix-field
sebastienhoorens 38ec61a
green xlsx specs
sebastienhoorens 18d7b66
fix offenses
sebastienhoorens ad6a830
disable form sync for matrix fields (for now) and forgot to substitut…
sebastienhoorens ef91326
forgot geojson_supported_fields
sebastienhoorens 3d14eb2
Merge branch 'master' into TAN-3586-add-matrix-field
amanda-anderson cd15c7b
removed in progress group support for matrix
sebastienhoorens e4b0254
forgot to implement supports_geojson?
sebastienhoorens 2d2da99
requested: remove commented line + rename other_option + revert accid…
sebastienhoorens 42f3099
support matrix statements when copying fields
sebastienhoorens 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
27 changes: 27 additions & 0 deletions
27
back/app/controllers/web_api/v1/custom_field_matrix_statements_controller.rb
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class WebApi::V1::CustomFieldMatrixStatementsController < ApplicationController | ||
before_action :set_statement, only: %i[show] | ||
before_action :set_custom_field, only: %i[index] | ||
skip_before_action :authenticate_user | ||
|
||
def index | ||
@statements = policy_scope(CustomFieldMatrixStatement).where(custom_field: @custom_field).order(:ordering) | ||
render json: WebApi::V1::CustomFieldMatrixStatementSerializer.new(@statements, params: jsonapi_serializer_params).serializable_hash | ||
end | ||
|
||
def show | ||
render json: WebApi::V1::CustomFieldMatrixStatementSerializer.new(@statement, params: jsonapi_serializer_params).serializable_hash | ||
end | ||
|
||
private | ||
|
||
def set_custom_field | ||
@custom_field = CustomField.find(params[:custom_field_id]) | ||
end | ||
|
||
def set_statement | ||
@statement = CustomFieldMatrixStatement.find(params[:id]) | ||
authorize @statement | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# == Schema Information | ||
# | ||
# Table name: custom_field_matrix_statements | ||
# | ||
# id :uuid not null, primary key | ||
# custom_field_id :uuid not null | ||
# title_multiloc :jsonb not null | ||
# key :string not null | ||
# ordering :integer not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_custom_field_matrix_statements_on_custom_field_id (custom_field_id) | ||
# index_custom_field_matrix_statements_on_key (key) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (custom_field_id => custom_fields.id) | ||
# | ||
class CustomFieldMatrixStatement < ApplicationRecord | ||
# non-persisted attribute to enable form copying | ||
attribute :temp_id, :string, default: nil | ||
|
||
belongs_to :custom_field | ||
|
||
before_validation :generate_key, on: :create | ||
acts_as_list column: :ordering, top_of_list: 0, scope: :custom_field | ||
|
||
validates :title_multiloc, presence: true, multiloc: { presence: true } | ||
validates :key, presence: true, uniqueness: { scope: [:custom_field_id] }, | ||
format: { with: /\A[\w-]+\z/ } # Can only consist of word characters or dashes | ||
validates :custom_field, presence: true | ||
|
||
private | ||
|
||
def generate_key | ||
title = title_multiloc.values.first | ||
self.key ||= title && CustomFieldService.new.generate_key(title) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CustomFieldMatrixStatementPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope | ||
end | ||
end | ||
|
||
def show? | ||
true | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
back/app/serializers/web_api/v1/custom_field_matrix_statement_serializer.rb
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,7 @@ | ||
class WebApi::V1::CustomFieldMatrixStatementSerializer < WebApi::V1::BaseSerializer | ||
attributes :key, :title_multiloc, :ordering, :created_at, :updated_at | ||
|
||
attribute :temp_id, if: proc { |object| | ||
object.temp_id.present? | ||
} | ||
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
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
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
24 changes: 24 additions & 0 deletions
24
back/app/services/side_fx_custom_field_matrix_statement_service.rb
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class SideFxCustomFieldMatrixStatementService | ||
include SideFxHelper | ||
|
||
def after_create(statement, current_user) | ||
LogActivityJob.perform_later(statement, 'created', current_user, statement.created_at.to_i) | ||
end | ||
|
||
def after_update(statement, current_user) | ||
LogActivityJob.perform_later(statement, 'changed', current_user, statement.updated_at.to_i) | ||
end | ||
|
||
def after_destroy(frozen_statement, current_user) | ||
serialized_statement = clean_time_attributes(frozen_statement.attributes) | ||
LogActivityJob.perform_later( | ||
encode_frozen_resource(frozen_statement), | ||
'deleted', | ||
current_user, | ||
Time.now.to_i, | ||
payload: { custom_field_matrix_statement: serialized_statement } | ||
) | ||
end | ||
end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we including this in all the controller queries too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesspeake Yes, they're included in idea_custom_fields_controller.rb:97. I didn't spot other endpoints where we might want to include them as well?