-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add entry request reviews and exports
- Loading branch information
1 parent
c9e2e13
commit 0094db9
Showing
27 changed files
with
567 additions
and
47 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
app/assets/javascripts/application/entry_request_review.js
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,53 @@ | ||
const entryRequestReviewUpdateSubjects = {} | ||
|
||
async function submitEntryRequestReview(id) { | ||
const statusIndicator = document.getElementById(`entry-request-${id}-status-indicator`) | ||
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), | ||
}); | ||
entryRequestReviewUpdateSubjects[id] = result | ||
} | ||
const subject = entryRequestReviewUpdateSubjects[id] | ||
subject.next() | ||
} | ||
|
||
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} | ||
}) | ||
try { | ||
const response = await fetch(`/entry_requests/${id}/update_review`, { | ||
method: 'put', | ||
body: JSON.stringify({ | ||
"entry_request": { | ||
"entry_type": entryType, | ||
"finalized": finalized, | ||
"justification": justification, | ||
}, | ||
"recommendations": recommendations | ||
}), | ||
headers: { | ||
'X-CSRF-TOKEN': getCsrfToken(), | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
statusIndicator.className = "uk-icon-check uk-float-right" | ||
} catch (error) { | ||
statusIndicator.className = "uk-icon-close uk-float-right" | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module EntryRequestHelper | ||
def resort_recommendations_tooltip(recommendations) | ||
result = [] | ||
|
||
recommendations_by_type = recommendations.sort_by { |resort_id, recommendation| recommendation} | ||
recommendations_by_type.each do |resort_id, recommendation| | ||
resort = @resorts.find{|r| r.id == resort_id.to_i} | ||
result << "#{Rails.configuration.x.entry_types[recommendation]} - #{resort.name}" | ||
end | ||
result.join("\n") | ||
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
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,19 @@ | ||
class EntryRequestPolicy < ApplicationPolicy | ||
def review? | ||
return false if SystemAttribute.offseason? | ||
|
||
pek_admin? || rvt_leader? || resort_leader? | ||
end | ||
|
||
alias update_review? review? | ||
|
||
private | ||
|
||
def rvt_leader? | ||
user.leader_of?(Group.rvt) | ||
end | ||
|
||
def resort_leader? | ||
Group.resorts.any? { |resort| user.leader_of?(resort) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class ExportActiveUsers | ||
attr_reader :semester | ||
|
||
def initialize(semester) | ||
@semester = semester | ||
end | ||
|
||
def self.call(semester) | ||
new(semester).call | ||
end | ||
|
||
def call | ||
result = [] | ||
result << ["Név","Email"] | ||
users = User.joins(:point_history).where("point_histories.point > 0") | ||
.where("point_histories.semester": [SystemAttribute.semester.previous.to_s, SystemAttribute.semester.to_s]) | ||
.order(:lastname).distinct | ||
|
||
users.each do |user| | ||
result << [user.full_name, user.email] | ||
end | ||
result | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class ExportUsersWithAb | ||
attr_reader :semester | ||
|
||
def initialize(semester) | ||
@semester = semester | ||
end | ||
|
||
def self.call(semester) | ||
new(semester).call | ||
end | ||
|
||
def call | ||
result = [] | ||
result << ["Név", "Email", "Kör", "Indoklás"] | ||
entry_requests = EntryRequest.includes({evaluation: :group},:user) | ||
.where("evaluations.semester": SystemAttribute.semester.to_s, | ||
"evaluations.entry_request_status": Evaluation::ACCEPTED, | ||
entry_type: "AB") | ||
.order("groups.name", "users.lastname") | ||
|
||
entry_requests.each do |entry_request| | ||
result << [entry_request.user.full_name, entry_request.user.email, entry_request.evaluation.group.name, entry_request.justification] | ||
end | ||
result | ||
end | ||
end |
Oops, something went wrong.