Skip to content
Snippets Groups Projects
Commit 937384f1 authored by smayer's avatar smayer
Browse files

Add bugfix for named_entities_for_docs in catalog_controller.rb, move sessions...

Add bugfix for named_entities_for_docs in catalog_controller.rb, move sessions fully to cookie store, remove all /en/tools/newspapers-platform paths
parent c8ad6e4c
No related branches found
No related tags found
1 merge request!2Merging development into onb as preparation for Annolyzer release
......@@ -53,20 +53,20 @@ class CatalogController < ApplicationController
# Display an issue
def show
@issue = Issue.from_solr params[:id], with_pages = true, with_articles = true
session["named_entities"] = Issue.named_entities @issue.id
session["named_entities_labels"] = helpers.get_linked_entities session["named_entities"].map { |k, v| v.keys }.flatten.uniq
# puts session.inspect
end
##
# Retrieve named entities for a list of documents (issue and/or articles)
def named_entities_for_docs
named_entities = { LOC: {}, PER: {}, ORG: {}, HumanProd: {} }
linked_entities = {}
params[:docs_ids].each do |doc_id|
if doc_id.index("_article_").nil?
doc_named_entities = session["named_entities"]
if doc_id.index("_article_").nil? # if issue, get named entities from Issue
doc_named_entities = Issue.named_entities doc_id
else # if article, filter stored list
doc_named_entities = session["named_entities"].map { |ne_type, ne_list|
issue_id = doc_id.split(/_article_/, 2).first
doc_named_entities = Issue.named_entities issue_id
doc_named_entities = doc_named_entities.map { |ne_type, ne_list|
[ne_type, ne_list.select { |linked_id, namedentities|
namedentities.any? { |ne|
ne["article_id_ssi"] == doc_id
......@@ -86,8 +86,10 @@ class CatalogController < ApplicationController
named_entities[:HumanProd] = named_entities[:HumanProd].merge(doc_named_entities[:HumanProd]) do |key, oldval, newval|
oldval.concat newval
end
doc_named_entities_labels = helpers.get_linked_entities(doc_named_entities.map { |k, v| v.keys }.flatten.uniq)
linked_entities.merge(doc_named_entities_labels)
end
render partial: "named_entities/named_entities", locals: { named_entities: named_entities, linked_entities: session["named_entities_labels"] }
render partial: "named_entities/named_entities", locals: { named_entities: named_entities, linked_entities: linked_entities }
end
##
......
......@@ -73,7 +73,7 @@ export class SearchAPI {
static confirm_compond_creation(article_parts, callback) {
$.ajax({
type: "POST",
url: `/en/tool/newspapers-platform/catalog/confirm_compound_creation`,
url: addPrefixURL() + "/catalog/confirm_compound_creation",
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
......@@ -89,7 +89,7 @@ export class SearchAPI {
static create_compound(title, all_text, issue_id, article_parts_ids, callback) {
$.ajax({
type: "POST",
url: `/en/tool/newspapers-platform/catalog/create_compound`,
url: addPrefixURL() + "/catalog/create_compound",
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
......@@ -108,7 +108,7 @@ export class SearchAPI {
static delete_compound_article(compound_id, callback) {
$.ajax({
type: "POST",
url: `/en/tool/newspapers-platform/catalog/delete_compound`,
url: addPrefixURL() + "/catalog/delete_compound",
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
......@@ -124,7 +124,7 @@ export class SearchAPI {
static random_sample(callback) {
$.ajax({
type: "POST",
url: `/en/tool/newspapers-platform/catalog/random_sample`,
url: addPrefixURL() + "/catalog/random_sample",
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
......
......@@ -5,11 +5,11 @@
<h5>
<%
if doc.is_a?(Article)
url = "/en/tool/newspapers-platform/catalog/#{doc.issue_id}?selected=#{doc.id}"
url = "/catalog/#{doc.issue_id}?selected=#{doc.id}"
elsif doc.is_a?(CompoundArticle)
url = "/en/tool/newspapers-platform/catalog/#{doc.issue_id}?selected_compound=#{doc.id}"
url = "/catalog/#{doc.issue_id}?selected_compound=#{doc.id}"
else
url = "/en/tool/newspapers-platform/catalog/#{doc.id}"
url = "/catalog/#{doc.id}"
end
%>
<a href="<%= url %>">
......
......@@ -23,7 +23,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
database: db_test
production:
<<: *default
......
......@@ -74,8 +74,8 @@ Rails.application.configure do
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# Allow Action Cable access from any origin.
config.action_cable.url = ENV['NEP_CABLE_URL'] || "http://127.0.0.1:3000/cable"
config.action_cable.disable_request_forgery_protection = true
config.action_cable.url = ENV['NEP_CABLE_URL'] || 'http://127.0.0.1:3000/cable'
config.action_cable.allowed_request_origins = [ENV['NEP_LABS_DOMAIN'], 'http://127.0.0.1:8001']
# Allow XHR/Ajax requests from different origin
config.action_controller.forgery_protection_origin_check = false
end
class AddSessionsTable < ActiveRecord::Migration[6.1]
def change
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id, :unique => true
add_index :sessions, :updated_at
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_12_02_095539) do
ActiveRecord::Schema.define(version: 2021_11_23_112405) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -45,7 +45,7 @@ ActiveRecord::Schema.define(version: 2021_12_02_095539) do
create_table "experiments", force: :cascade do |t|
t.string "title"
t.bigint "user_id"
t.jsonb "description", default: { "children" => [] }
t.jsonb "description", default: {"children"=>[]}
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["title", "user_id"], name: "index_experiments_on_title_and_user_id", unique: true
......@@ -61,15 +61,6 @@ ActiveRecord::Schema.define(version: 2021_12_02_095539) do
t.index ["user_id"], name: "index_notifications_on_user_id"
end
create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false
t.text "data"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["session_id"], name: "index_sessions_on_session_id", unique: true
t.index ["updated_at"], name: "index_sessions_on_updated_at"
end
create_table "tools", force: :cascade do |t|
t.bigint "experiment_id"
t.bigint "parent_id"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment