Skip to content

Commit

Permalink
Fix page saveing for next page logic
Browse files Browse the repository at this point in the history
  • Loading branch information
balen committed Dec 26, 2023
1 parent d68e3cc commit 4dea386
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/javascript/surveys/edit-survey-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</draggable>
<div v-if="!isLastPage(page.id)" class="mt-3">
After page {{i + 1}}
<next-page-picker :for-page="page.id" :id="pagePickerId" class="ml-1" v-model="page.next_page_id" @change="savePage()"></next-page-picker>
<next-page-picker :for-page="page.id" :id="pagePickerId" class="ml-1" v-model="page.next_page_id" @change="updatePage"></next-page-picker>
</div>
<b-modal v-if="isSelected" :id="deleteModalId" @ok="deletePage(page)" ok-title="Yes" cancel-variant="link" title="Delete page and questions?">
<p>{{SURVEY_CONFIRM_DELETE_PAGE_1}}</p>
Expand Down Expand Up @@ -97,6 +97,11 @@ export default {
}
},
methods: {
updatePage(arg) {
this.page.next_page_action = arg != -1 ? 'next_page' : 'submit'
this.page.next_page_id = arg
this.savePage(this.page)
},
mergePageUp() {
this.mergePage(this.page, this.getPreviousPage(this.page.id))
},
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/survey/page_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class Survey::PageSerializer
include JSONAPI::Serializer

attributes :id, :title, :next_page_id, :next_page_action,
attributes :id, :title, :next_page_action,
:sort_order, :created_at, :updated_at, :survey_id

# Because the DB can not set -1 for a UUID we fake it for the front end
attribute :next_page_id do |object|
object.next_page_action == 'submit' ? -1 : object.next_page_id
end

has_many :questions, serializer: Survey::QuestionSerializer,
links: {
Expand Down

0 comments on commit 4dea386

Please sign in to comment.