Class: I18nProofreading::SuggestionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- I18nProofreading::SuggestionsController
- Defined in:
- app/controllers/i18n_proofreading/suggestions_controller.rb
Constant Summary collapse
- PER_PAGE =
50
Instance Method Summary collapse
-
#context ⇒ Object
Pending suggestions for one key/locale, shown as read-only context when the proofreader reopens the popover for a string someone already flagged.
- #create ⇒ Object
-
#index ⇒ Object
--- triage dashboard (admin) --------------------------------------------.
Instance Method Details
#context ⇒ Object
Pending suggestions for one key/locale, shown as read-only context when the proofreader reopens the popover for a string someone already flagged.
46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/i18n_proofreading/suggestions_controller.rb', line 46 def context suggestions = Suggestion .where(translation_key: params[:key], locale: params[:locale]) .status_pending .newest_first .limit(20) render json: suggestions.map { |suggestion| suggestion_json(suggestion) } end |
#create ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/i18n_proofreading/suggestions_controller.rb', line 56 def create suggestion = Suggestion.new(suggestion_params) (suggestion) if suggestion.save I18nProofreading.config.on_submit.call(suggestion) head :created else render json: { errors: suggestion.errors. }, status: :unprocessable_entity end end |
#index ⇒ Object
--- triage dashboard (admin) --------------------------------------------
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/i18n_proofreading/suggestions_controller.rb', line 28 def index @status = Suggestion::STATUSES.include?(params[:status]) ? params[:status] : 'pending' @locale = params[:locale].presence @counts = Suggestion.group(:status).count @locales = Suggestion.distinct.pluck(:locale).compact.sort scope = Suggestion.where(status: @status) scope = scope.where(locale: @locale) if @locale @page = [params[:page].to_i, 1].max rows = scope.newest_first.offset((@page - 1) * PER_PAGE).limit(PER_PAGE + 1).to_a @more = rows.size > PER_PAGE @suggestions = rows.first(PER_PAGE) end |