Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.1)
base64 (0.3.0)
bcrypt (3.1.22)
bigdecimal (4.1.0)
bigdecimal (4.1.2)
bindata (2.5.1)
bindex (0.8.1)
bootsnap (1.18.6)
Expand Down Expand Up @@ -208,7 +208,7 @@ GEM
date (3.5.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (5.0.3)
devise (5.0.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 7.0)
Expand Down Expand Up @@ -279,7 +279,7 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.8.2)
irb (1.17.0)
irb (1.18.0)
pp (>= 0.6.0)
prism (>= 1.3.0)
rdoc (>= 4.0.0)
Expand All @@ -292,7 +292,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.19.3)
json (2.19.5)
json-jwt (1.17.0)
activesupport (>= 4.2)
aes_key_wrap
Expand Down Expand Up @@ -344,7 +344,7 @@ GEM
mini_magick (5.3.1)
logger
mini_mime (1.1.5)
minitest (6.0.3)
minitest (6.0.6)
drb (~> 2.0)
prism (~> 1.5)
msgpack (1.8.0)
Expand All @@ -353,7 +353,7 @@ GEM
bigdecimal (>= 3.1, < 5)
net-http (0.9.1)
uri (>= 0.11.1)
net-imap (0.6.3)
net-imap (0.6.4)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -365,21 +365,21 @@ GEM
newrelic_rpm (10.2.0)
logger
nio4r (2.7.5)
nokogiri (1.19.2-aarch64-linux-gnu)
nokogiri (1.19.3-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-aarch64-linux-musl)
nokogiri (1.19.3-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.19.2-arm-linux-gnu)
nokogiri (1.19.3-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-arm-linux-musl)
nokogiri (1.19.3-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.19.2-arm64-darwin)
nokogiri (1.19.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-darwin)
nokogiri (1.19.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-linux-gnu)
nokogiri (1.19.3-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.2-x86_64-linux-musl)
nokogiri (1.19.3-x86_64-linux-musl)
racc (~> 1.4)
oauth2 (2.0.14)
faraday (>= 0.17.3, < 4.0)
Expand Down Expand Up @@ -489,7 +489,7 @@ GEM
tsort (>= 0.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.3.1)
rake (13.4.2)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ support continuous improvement of public service delivery.

An example Touchpoints form that includes every input element
is available in this
[Kitchen Sink](https://touchpoints.app.cloud.gov/touchpoints/34d93e4e/submit)
[Kitchen Sink](https://touchpoints.app.cloud.gov/touchpoints/34d93e4e)
example.

Touchpoints is a web application
Expand All @@ -24,7 +24,7 @@ GSA's Federal Acquisition Service (FAS) is developing Touchpoints in-house by th
within the Technology Transformation Services'
[Data Portfolio](https://www.gsa.gov/about-us/organization/federal-acquisition-service/technology-transformation-services/tts-solutions#data).

Touchpoints is online at <https://touchpoints.digital.gov/>.
Touchpoints documentation is online at <https://touchpoints.digital.gov/>.

A Demo environment is online at <https://app-demo.touchpoints.digital.gov/>,
and government customers are [encouraged](https://github.com/GSA/touchpoints/wiki/Touchpoints-Demo-Environment/) to sign up and try it out.
Expand All @@ -37,7 +37,7 @@ For developers, the wiki contains a [developer guide](https://github.com/GSA/tou

## Team Process

The Touchpoints team tracks work in a [backlog](https://en.wikipedia.org/wiki/Kanban) board.
The Touchpoints team tracks work in a [backlog](https://github.com/orgs/GSA/projects/348) board.

Issues and ideas are also noted in GitHub [Issues](https://github.com/gsa/touchpoints/issues).

Expand Down
14 changes: 9 additions & 5 deletions app/controllers/admin/question_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Admin
class QuestionOptionsController < AdminController
before_action :set_question, only: %i[new create create_other show edit update destroy]
before_action :set_question, only: %i[new create create_other show edit update destroy sort]
before_action :set_question_option, only: %i[show edit update destroy]

def index
Expand All @@ -21,11 +21,15 @@ def edit
end

def sort
params[:question_option].each_with_index do |id, index|
QuestionOption.find(id).update(position: index + 1)
current_option_ids = @question.question_options.pluck(:id).map(&:to_s)
if current_option_ids.sort == params[:question_option].sort
params[:question_option].each_with_index do |id, index|
QuestionOption.find(id).update(position: index + 1)
end
head :ok
else
render json: { error: "All question options must be listed exactly once in reordering request" }, status: :unprocessable_content
end

head :ok
end

def update_title
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/questions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@

ele.html(resp);
ele.find(".question-option-edit").hide();
initializeSortableQuestionOptions(ele.find(".question-options"));
}
});
}
Expand All @@ -141,6 +142,7 @@

ele.html(resp);
ele.find(".question-option-edit").hide();
initializeSortableQuestionOptions(ele.find(".question-options"));
}
});
});
Expand Down
61 changes: 35 additions & 26 deletions app/views/components/forms/edit/_builder.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -274,33 +274,9 @@ $(function() {

// Initialize sortable for question options
try {
$(".question-options").sortable({
items: '.question-option',
handle: '.drag-handle',
placeholder: 'sort-placeholder',
update: function(e, ui) {
try {
var url = $(this).parent().data("url");
if (!url) {
console.error("Missing URL for question options sort");
return;
}
$.ajax({
url: url,
type: "PATCH",
data: $(this).sortable('serialize'),
error: function(xhr, status, error) {
console.error("Option sort update failed:", error);
ui.item.animate({ left: 0 }, 300);
}
});
} catch (err) {
console.error("Error during option sort update:", err);
}
}
}).disableSelection();
initializeSortableQuestionOptions($(".question-options"));
} catch (err) {
console.error("Failed to initialize option sortable:", err);
console.error("Failed to initialize question option sortable:", err);
}

// Initialize sortable for sections
Expand Down Expand Up @@ -446,6 +422,39 @@ function initializeSortableQuestions($questionContainer) {
}).disableSelection();
}

function initializeSortableQuestionOptions($questionOptionContainer) {
$questionOptionContainer.sortable({
items: '.question-option',
placeholder: 'sort-placeholder',
tolerance: 'pointer',
update: function(e, ui) {
try {
let url = $(this).parent().data("url") + "/sort";
let data = $(this).sortable('serialize');
if (!url) {
console.error("Missing URL for question options sort");
return;
}
if (!data) {
console.error("Failed to serialize sortable data");
return;
}
$.ajax({
url: url,
type: "PATCH",
data: data,
error: () => {
alert("Failed to update question option order");
$(this).sortable("cancel");
}
});
} catch (err) {
console.error("Error during option sort update:", err);
}
}
}).disableSelection();
}

document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".quill").forEach((wrapper) => {
const editorContainer = wrapper.querySelector(".editor");
Expand Down
8 changes: 3 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,16 @@
patch 'update_title', to: 'form_sections#update_title', as: :inline_update
end
resources :questions, except: :new do
member do
patch 'question_options', to: 'question_options#sort', as: :sort_question_options
collection do
patch 'sort', to: 'questions#sort', as: :sort_questions
end
resources :question_options, except: %i[index show] do
patch 'update_title', to: 'question_options#update_title', as: :inline_update
collection do
post 'create_other', to: 'question_options#create_other', as: :create_other
patch 'sort', to: 'question_options#sort', as: :sort_question_options
end
end
collection do
patch 'sort', to: 'questions#sort', as: :sort_questions
end
end
resources :submissions, only: %i[show update destroy] do
collection do
Expand Down
Loading