-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from xronos-ch/lod
Lod
- Loading branch information
Showing
44 changed files
with
1,047 additions
and
60 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,76 @@ | ||
class LodLinksController < ApplicationController | ||
load_and_authorize_resource | ||
|
||
before_action :set_lod_link, only: [:show, :edit, :update, :destroy] | ||
|
||
def show | ||
if source = "Wikidata" | ||
@wikidata_link.request_item | ||
if @wikidata_link.item.sitelink_title("enwiki").present? | ||
@wikidata_link.item.request_wikipedia_extract | ||
end | ||
end | ||
render partial: "lod_link" | ||
end | ||
|
||
def new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@lod_link = LodLink.new(lod_link_params) | ||
|
||
respond_to do |format| | ||
if @lod_link.save | ||
format.html { redirect_back fallback_location: root_path, notice: success_notice } | ||
format.json { render :show, status: :created, location: @lod_link } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @lod_link.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @lod_link.update(lod_link_params) | ||
format.html { redirect_back fallback_location: root_path, notice: success_notice } | ||
format.json { render :show, status: :ok, location: @lod_link } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @lod_link.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
end | ||
|
||
private | ||
|
||
def set_lod_link | ||
@lod_link = LodLink.find(params[:id]) | ||
@wikidata_link = LodLink.where(source: "Wikidata").find(params[:id]) | ||
end | ||
|
||
def lod_link_params | ||
params.require(:lod_link).permit([ | ||
:external_id, | ||
:source, | ||
:linkable_type, | ||
:linkable_id, | ||
:revision_comment, | ||
:status | ||
]) | ||
end | ||
|
||
def success_notice | ||
@lod_link.linkable_type + | ||
":" + | ||
@lod_link.linkable_id.to_s + | ||
" is now linked to Wikidata item Q" + | ||
@lod_link.external_id.to_s | ||
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,46 @@ | ||
class Lods::SitesController < LodsController | ||
load_and_authorize_resource | ||
|
||
# GET /issues/sites/:issue | ||
def index | ||
allowed_methods = lods | ||
if lod_param.present? && allowed_methods.include?(lod_param.to_sym) | ||
@sites = Site.public_send(lod_param) | ||
else | ||
@sites = Site.all | ||
end | ||
|
||
if params.has_key?(:search) | ||
@sites = @sites.search params[:search] | ||
end | ||
|
||
if params.has_key?(:sites_order_by) | ||
order = { params[:sites_order_by] => params.fetch(:sites_order, "asc") } | ||
else | ||
order = :id | ||
end | ||
@sites = @sites.reorder(order) | ||
|
||
@sites = @sites.with_counts | ||
|
||
respond_to do |format| | ||
format.html do | ||
@pagy, @sites = pagy(@sites) | ||
|
||
# Fetch and cache Wikidata matches for the current page | ||
@wikidata_matches = fetch_wikidata_matches(@sites) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def lods | ||
Site.lods | ||
end | ||
|
||
def fetch_wikidata_matches(sites) | ||
# Ensure Wikidata matches are always a hash | ||
Site.wikidata_match_candidates_batch(sites) || {} | ||
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 LodsController < ApplicationController | ||
include Pagy::Backend | ||
|
||
before_action :authenticate_user! | ||
|
||
layout "curate" | ||
|
||
def index | ||
end | ||
|
||
private | ||
|
||
def lods | ||
[:issues, :another_allowed_method] # Add all allowed methods here | ||
end | ||
|
||
def lod_param | ||
lod = params.fetch(:lod, nil) | ||
allowed_methods = lods.map(&:to_s) | ||
return lod.to_sym if lod.present? && allowed_methods.include?(lod) | ||
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,21 @@ | ||
module LodsHelper | ||
def lod_label(lod) | ||
lod.to_s.upcase | ||
end | ||
|
||
def lod_description(lod) | ||
case lod | ||
# Sites | ||
when :missing_wikidata_link | ||
"No Wikidata Link has yet been provided" | ||
else | ||
"" | ||
end | ||
end | ||
|
||
def lod_badge(lod) | ||
content_tag :span, title: lod_description(lod), class: "badge text-bg-warning" do | ||
lod_label(lod) | ||
end | ||
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,29 @@ | ||
module SimpleIconsHelper | ||
|
||
def simple_icon(slug) | ||
content_tag :span, class: "svg-icon svg-baseline" do | ||
embedded_svg "simple_icons/#{slug}.svg", width: 32, height: 32, role: "graphics-symbol", class: "simple-icon" | ||
end | ||
end | ||
|
||
# Embed SVGs directly | ||
# adapted from https://blog.cloud66.com/using-svgs-in-a-rails-stack | ||
def embedded_svg(filename, options = {}) | ||
assets = Rails.application.assets | ||
|
||
asset = assets.load_path.find(filename) | ||
|
||
if asset | ||
#file = asset.source.force_encoding("UTF-8") | ||
doc = Nokogiri::HTML::DocumentFragment.parse asset.content | ||
svg = doc.at_css "svg" | ||
options.each {|attr, value| svg[attr.to_s] = value} | ||
#svg["class"] = options[:class] if options[:class].present? | ||
else | ||
doc = "<!-- SVG #{filename} not found -->" | ||
end | ||
|
||
raw doc | ||
end | ||
|
||
end |
Oops, something went wrong.