Skip to content

Commit

Permalink
send recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
SepsiLaszlo committed Dec 8, 2024
1 parent 5434614 commit 3283d38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 12 additions & 9 deletions app/assets/javascripts/application/entry_request_review.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
const entryRequestReviewUpdateSubjects = {}

async function submitEntryRequestReview(id) {
console.log(id + " " + event);
const statusIndicator = document.getElementById(`entry-request-${id}-status-indicator`)
statusIndicator.className = "uk-icon-cog uk-float-right"
if(!entryRequestReviewUpdateSubjects[id]){
const { Subject, debounceTime } = rxjs;
statusIndicator.className = "uk-icon-keyboard-o uk-float-right"
if (!entryRequestReviewUpdateSubjects[id]) {
const {Subject, debounceTime} = rxjs;
const subject = new Subject();
const result = subject.pipe(debounceTime(1000))
result.subscribe({
next: async () => await updateEntryRequestReview(id),
// next: () => { console.log(Math.random())}
});
entryRequestReviewUpdateSubjects[id] = result
}
const subject = entryRequestReviewUpdateSubjects[id]
subject.next()
}

async function updateEntryRequestReview(id){
async function updateEntryRequestReview(id) {
const statusIndicator = document.getElementById(`entry-request-${id}-status-indicator`)
statusIndicator.className = "uk-icon-cog uk-icon-spin uk-float-right"
const entryType = document.getElementById(`entry-request-${id}-entry-type`).value
const finalized = document.getElementById(`entry-request-${id}-finalized`).checked
const justification = document.getElementById(`entry-request-${id}-justification`).value
const recommendationElements = Array.from(document.getElementsByClassName(`entry-request-${id}-recommendation`))
const recommendations = recommendationElements.map((element) => {
return {"resort_id": element.getAttribute("data-resort-id"), "value": element.value}
})
console.log(entryType + finalized + justification)
const statusIndicator = document.getElementById(`entry-request-${id}-status-indicator`)
try {
const response = await fetch(`/entry_requests/${id}/update_review`, {
method: 'put',
body: JSON.stringify({
"entry_type": entryType,
"finalized": finalized,
"justification": justification,
"recommendations": recommendations
}),
headers: {
'X-CSRF-TOKEN': getCsrfToken(),
Expand All @@ -41,8 +45,7 @@ async function updateEntryRequestReview(id){
throw new Error(`HTTP error! status: ${response.status}`);
}
statusIndicator.className = "uk-icon-check uk-float-right"
}
catch(error) {
} catch (error) {
statusIndicator.className = "uk-icon-close uk-float-right"

}
Expand Down
4 changes: 3 additions & 1 deletion app/views/entry_requests/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<% if current_user.leader_of?(resort) %>
<div class="uk-form-row">
<%= form.label :recommendation, "Ajánlás (#{resort.name} Vezető)", class: "uk-form-label uk-text-bold" %>
<%= form.select :entry_type, Rails.configuration.x.entry_types.map { |k, v| [v, k] },{}, class: "uk-form-width-small" %>
<%= form.select :entry_type, Rails.configuration.x.entry_types.map { |k, v| [v, k] },{},
class: "uk-form-width-small entry-request-#{entry_request.id}-recommendation",
data: {"resort-id" => resort.id} %>
</div>
<% end %>
<% end %>
Expand Down

0 comments on commit 3283d38

Please sign in to comment.