Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/controllers/ntriple_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# Controls the ntriple editing logic
class NtripleController < AdminController

def edit
@term = params[:term_id]
@file = File.open("#{Settings.cache_dir}/ns/#{params[:term_id]}.nt", 'r').read
end

def update
binding.pry
reader = RDF::Reader.for(:ntriples).new(params[params["id"]]["ntriples"])
reader = reader.validate!
if reader.valid?
PreloadCache.write_triples(params[params["id"]]["ntriples"], params["id"])
# Commit triples to file and to BG
flash[:success] = "NTriples for #{ params["id"] } has been updated successfully"
redirect_to '/'
else
# Redirect back to form
redirect_to "/ntriples/#{params["id"]}"
end
end
end
5 changes: 5 additions & 0 deletions app/services/preload_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def self.preload(term)
write("#{Settings.cache_dir}/ns/#{term.id}.jsonld", term.full_graph.dump(:jsonld, standard_prefixes: true))
end

def self.write_triples(triples, id)
FileUtils.mkdir_p("#{Settings.cache_dir}/ns/#{id}")
write("#{Settings.cache_dir}/ns/#{id}.nt", triples)
end

private

def self.write(path, content)
Expand Down
5 changes: 5 additions & 0 deletions app/views/ntriple/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= simple_form_for(@term, :url => update_ntriples_path(:id => @term)) do |f| %>
<%= f.input 'ntriples', as: :text, input_html: { cols: 150, rows: 30, value: @file } %>

<%= f.submit %>
<% end %>
1 change: 1 addition & 0 deletions app/views/terms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<%= link_to "Edit", edit_term_path(@term), { :class => 'btn btn-default' } %>
<% end %>
<%= link_to "Manage cache", cache_term_path(@term), { :class => 'btn btn-default' } %>
<%= link_to "Edit N-Triples", edit_ntriples_path(:term_id => @term.id), { :class => 'btn btn-default' } %>
</div>

<% if @term.term_id.hasParent? %>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
post 'predicates/*id/review_update', :to => "predicates#review_update", :as => "review_update_predicate"
patch 'predicates/*id', :to => "predicates#update", :as => "update_predicate"

get 'ntriples/*term_id', :to => "ntriple#edit", :as => "edit_ntriples"
post 'ntriples/*term_id/update', :to => "ntriple#update", :as => "update_ntriples"

resources :vocabularies, :only => [:index, :new, :create, :edit]
get '/vocabularies/*vocabulary_id/new', :to => "terms#new", :as => "new_term"
resources :predicates, :only => [:index, :new, :create, :edit]
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/ntriple_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe NtripleController, type: :controller do

end