Sha256: eff7b77b9541d451aeab6757ab2563490fdc749328d0760647f510201032967c
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true # Admin::BookmarksController module Admin class BookmarksController < Admin::AdminController before_action :set_document, only: %i[create destroy] # GET /bookmarks # GET /bookmarks.json def index @pagy, @bookmarks = pagy(current_user.bookmarks.where(document_type: "Kithe::Model")) respond_to do |format| format.html { render :index } # B1G CSV format.csv { send_data collect_csv(current_user.bookmarks), filename: "documents-#{Time.zone.today}.csv" } end end # POST /bookmarks # POST /bookmarks.json def create @bookmark = Admin::Bookmark.find_or_create_by(user: current_user, document: @document) respond_to do |format| if @bookmark.save format.html { redirect_to admin_bookmarks_url, notice: "Bookmark was successfully created." } format.js else format.html { render :index, status: :unprocessable_entity } format.json { render json: @bookmark.errors, status: :unprocessable_entity } end end end # DELETE /bookmarks/1 # DELETE /bookmarks/1.json def destroy Admin::Bookmark.destroy_by(user: current_user, document: @document) respond_to do |format| format.html { redirect_to admin_bookmarks_url, notice: "Bookmark was successfully destroyed." } format.js end end private def set_document @document = Document.find_by(friendlier_id: params["document"]) end # Only allow a list of trusted parameters through. def bookmark_params params.fetch(:bookmark, {}) end def collect_csv(bookmarks) CSV.generate(headers: true) do |csv| csv << GeoblacklightAdmin::Schema.instance.importable_fields.map { |k, _v| k.to_s } bookmarks.map do |bookmark| csv << bookmark.document.to_csv end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geoblacklight_admin-0.5.1 | app/controllers/admin/bookmarks_controller.rb |