Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotwire...! #870

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ gem 'angular-rails-templates', '>= 1.0.0.beta'
gem 'apipie-rails', '~> 1.2'
gem 'bcrypt', '~> 3.1.7'
gem 'sassc-rails', '~> 2.1'
gem 'turbolinks', '~> 5'
gem 'colorize', require: false
gem 'cookies_eu'
gem 'devise', '>= 4.6.2'
Expand Down Expand Up @@ -93,3 +92,8 @@ group :test do
gem 'capybara'
gem 'selenium-webdriver'
end

gem "turbo-rails", "~> 1.5"

gem "jsbundling-rails", "~> 1.2"
gem "stimulus-rails", "~> 1.3"
15 changes: 11 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ GEM
railties (>= 3.2.16)
js_cookie_rails (2.2.0)
railties (>= 3.1)
jsbundling-rails (1.2.1)
railties (>= 6.0.0)
json (2.6.3)
json-jwt (1.16.3)
activesupport (>= 4.2)
Expand Down Expand Up @@ -407,14 +409,17 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
stimulus-rails (1.3.0)
railties (>= 6.0.0)
terser (1.1.18)
execjs (>= 0.3.0, < 3)
thor (1.2.2)
tilt (2.3.0)
timeout (0.4.0)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
turbo-rails (1.5.0)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
Expand Down Expand Up @@ -468,6 +473,7 @@ DEPENDENCIES
jbuilder (~> 2.7)
jquery-rails
jquery-ui-rails
jsbundling-rails (~> 1.2)
letter_opener
listen (~> 3.3)
memory_profiler
Expand Down Expand Up @@ -501,8 +507,9 @@ DEPENDENCIES
selenium-webdriver
sidekiq
simplecov
stimulus-rails (~> 1.3)
terser
turbolinks (~> 5)
turbo-rails (~> 1.5)
vega (~> 0.3.0)
web-console
webmock
Expand Down
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e development -C config/sidekiq.yml -q default
js: yarn build --watch
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= link_tree ../images
//= link application.js
//= link 'application.css'
//= link_tree ../builds/
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@

//= require codemirror/lib/codemirror
//= require codemirror/mode/javascript/javascript

// HUMMM>>>>> = require turbo
9 changes: 8 additions & 1 deletion app/assets/javascripts/components/export_case/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ <h3 class="modal-title">Export Case: <span class="modal-case">{{ ctrl.theCase.ca
</span>
</div>
<hr/>
<div class="form-group">
<input type="radio" id="rre" name="exportSelection" value="quepid" ng-model="ctrl.options.which">
<label for="quepid">Quepid</label>
<span class="help-block">
Need to move a Case between different Quepids?
</span>
</div>
<div class="form-group">
<input type="radio" id="rre" name="exportSelection" value="rre" ng-model="ctrl.options.which">
<label for="rre">Rated Ranking Evaluator</label>
Expand All @@ -99,7 +106,7 @@ <h3 class="modal-title">Export Case: <span class="modal-case">{{ ctrl.theCase.ca
<div class="form-group">
<label for="ltr">Quepid API</label>
<span class="help-block">
Quepid has a API that you can export data in the JSON format via. Append the parameter <code>?shallow=true</code> to return a smaller dataset.
Quepid <a ng-href="apipie" target="_blank">has an API</a> that you can export data in the JSON format via. Append the parameter <code>?shallow=true</code> to return a smaller dataset.
</span>

Retrieve the <a ng-href="api/cases/{{ctrl.theCase.caseNo}}.json?shallow=false" target="_blank">Case</a>, <a ng-href="api/cases/{{ctrl.theCase.caseNo}}/queries.json?shallow=false" target="_blank">Queries</a>, <a ng-href="api/cases/{{ctrl.theCase.caseNo}}/annotations.json" target="_blank">Annotations</a>, <a ng-href="api/cases/{{ctrl.theCase.caseNo}}/scores.json" target="_blank">Scores</a>, <a ng-href="api/export/ratings/{{ctrl.theCase.caseNo}}.json" target="_blank">Ratings</a>, or a Snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ angular.module('QuepidApp')
}

}
else if ( options.which === 'quepid' ) {
$log.info('Selected "quepid" as export option.');
caseCSVSvc.exportQuepidFormat(ctrl.theCase);
}
else if ( options.which === 'rre' ) {
$log.info('Selected "rre" as export option.');
caseCSVSvc.exportRREFormat(ctrl.theCase);
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/components/import_to_cases/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
<h3 class="modal-title">Import Snapshot</h3>
</div>
<div class="modal-body">

<div >

<div >
<ng-include src="'http://localhost:3000/home/bob'"></ng-include>
<!--iframe src="http://localhost:3000/test.html" title="description"></iframe-->
<iframe width="100%" src="http://localhost:3000/home/bob" title="description"></iframe>
</div>
</div>

<p>Importing snapshots lets you bring in a view of search that you might have created externally, for example if you are working
with a legacy search engine. Just create a Snapshot file in the below format, and you can compare your current search engine
to a previous search engine!
Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/services/caseCSVSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
self.exportBasicFormatSnapshot = exportBasicFormatSnapshot;
self.exportTrecFormat = exportTrecFormat;
self.exportTrecFormatSnapshot = exportTrecFormatSnapshot;
self.exportQuepidFormat = exportQuepidFormat;
self.exportRREFormat = exportRREFormat;
self.exportLTRFormat = exportLTRFormat;
self.exportInformationNeed = exportInformationNeed;
Expand Down Expand Up @@ -250,7 +251,18 @@
});
}

function exportQuepidFormat(aCase) {
$http.get('api/export/cases/' + aCase.caseNo)
.then(function(response) {
var blob = new Blob([$filter('json')(response.data)], {
type: 'application/json'
});

/*global saveAs */
saveAs(blob, formatDownloadFileName(aCase.caseName + '_quepid.json'));
});
}

function exportRREFormat(aCase) {
$http.get('api/export/ratings/' + aCase.caseNo + '.json?file_format=rre')
.then(function(response) {
Expand Down
39 changes: 35 additions & 4 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class HomeController < ApplicationController
def show
# https://www.gamecreatures.com/blog/2023/03/07/rails-add-turbo-hotwire-to-existing-sprockets-application/
@turbo = true
# @cases = @current_user.cases.not_archived.includes([ :scores ])
@cases = @current_user.cases_involved_with.not_archived

Expand All @@ -21,10 +23,39 @@ def show

@most_recent_books.sort_by!(&:name)


end

def bob
@case = Case.new
render :layout => false
end

def cases
@cases = @current_user.cases_involved_with.not_archived
render :layout => false
end

def grouped_cases
@cases = @current_user.cases_involved_with.not_archived
# Homepage is too slow so we have to cut some stuff out ;-(
# candidate_cases = @cases.select { |kase| kase.scores.scored.count.positive? }
@cases
# @grouped_cases = candidate_cases.group_by { |kase| kase.case_name.split(':').first }
# @grouped_cases = @grouped_cases.select { |_key, value| value.count > 1 }
candidate_cases = @cases.select { |kase| kase.scores.scored.count.positive? }
@grouped_cases = candidate_cases.group_by { |kase| kase.case_name.split(':').first }
@grouped_cases = @grouped_cases.select { |_key, value| value.count > 1 }
render :layout => false
end

def youruncle

file = params[:case][:upload].read
data = JSON.parse(file)
puts data
#file_data = params[:case][:upload].tempfile
#File.read(file_data, 'r') do |file|
# person = JSON.parse(file)
# puts person
#end

redirect_to admin_users_url, notice: 'User account was successfully deleted.'
end
end
6 changes: 6 additions & 0 deletions app/javascript/app2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Entry point for the build script in your package.json

import { Turbo } from "@hotwired/turbo-rails"
window.Turbo = Turbo

import "./controllers"
8 changes: 8 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

//import { application } from "./application"

//import LegacyJsController from "./legacy_js_controller"
//application.register("legacy-js", LegacyJsController)
9 changes: 8 additions & 1 deletion app/views/home/_case.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
</td>
<% end %>

<td><%= link_to 'View', case_core_path(kase, kase.last_try_number), class: 'btn btn-sm btn-primary', role: 'button' %></td>
<td>
<%= link_to 'View',
case_core_path(kase, kase.last_try_number),
class: 'btn btn-sm btn-primary',
role: 'button',
data: { turbo_frame: "_top" }
%>
</td>
</tr>
26 changes: 26 additions & 0 deletions app/views/home/bob.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= form_for(@case, url: home_youruncle_path, class: 'form-horizontal') do |f| %>
<% if @case.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@case.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% @case.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>


<div class="form-group clearfix">
<%= f.label :upload, class: 'col-sm-2 control-label' %>
<div class="col-sm-10">
<%= f.file_field :upload, class: 'form-control' %>
</div>
</div>

<div class="form-group">
<button type="submit" class="btn btn-primary">Import Case</button>
</div>

<% end %>
14 changes: 14 additions & 0 deletions app/views/home/cases.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<turbo-frame id="cases">
<table class="table">
<tr>
<th scope="col">Case Title</th>
<th scope="col"># of Queries</th>
<th scope="col">Last Score</th>
<th scope="col">Last Run On</th>
<th scope="col">Last Run By</th>
<th scope="col"></th>
</tr>

<%= render partial: "case", collection: @cases, as: :kase %>
</table>
</turbo-frame>
5 changes: 5 additions & 0 deletions app/views/home/grouped_cases.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<turbo-frame id="grouped-cases">
<% @grouped_cases.keys[0..2].each do |key| %>
<%= render partial: "grouped_cases", locals: {grouped_cases_name: key, grouped_cases: @grouped_cases[key]}%>
<% end %>
</turbo-frame>
54 changes: 29 additions & 25 deletions app/views/home/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ https://getbootstrap.com/docs/5.2/examples/navbars-offcanvas/# for example of of
</div>

<div class="row my-4">
<% if false %>
<%= render partial: "case_summary", collection: @most_recent_cases, as: :kase %>
<% end %>
</div>

<div class="row my-4">
<%= render partial: "book_summary", collection: @most_recent_books, as: :book %>
</div>



<% if @cases.empty? && @most_recent_books.empty? %>
<div class="container my-5">
<div class="p-5 text-center bg-body-tertiary rounded-3">
Expand All @@ -39,40 +39,44 @@ https://getbootstrap.com/docs/5.2/examples/navbars-offcanvas/# for example of of
</div>
</div>
<% else %>


<div class="row">
<div class="col-12 col-xl-8 mb-4 mb-lg-0">
<div class="card">
<h5 class="card-header">Cases</h5>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Case Title</th>
<th scope="col"># of Queries</th>
<th scope="col">Last Score</th>
<th scope="col">Last Run On</th>
<th scope="col">Last Run By</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<%= render partial: "case", collection: @cases, as: :kase %>
</tbody>
</table>
<%= turbo_frame_tag "cases", src: home_cases_path do %>
<div>
Placeholder content
</div>
<% end %>
</div>
<%= link_to 'View all', cases_path(), class: 'btn btn-block btn-light', role: 'button' %>

<%= link_to 'View all', cases_path(), class: 'btn btn-block btn-light', role: 'button' %>
</div>
</div>
</div>
<div class="col-12 col-xl-4">
<% if true == false # disable%>
<% @grouped_cases.keys[0..2].each do |key| %>
<%= render partial: "grouped_cases", locals: {grouped_cases_name: key, grouped_cases: @grouped_cases[key]}%>
<% end %>
<% end %>

<%= turbo_frame_tag "grouped-cases", src: home_grouped_cases_path do %>

<div class="card" aria-hidden="true">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title placeholder-glow">
<span class="placeholder col-6"></span>
</h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-6"></span>
<span class="placeholder col-8"></span>
</p>
</div>
</div>

<% end %>
</div>
</div>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= csrf_meta_tags %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag "app2", defer: true %>

</head>

<body>
<body 'data-turbo'= <%= @turbo ? true : false %>' >

<%= render 'layouts/header' %>

Expand Down
2 changes: 2 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

Rails.application.config.assets.paths << Rails.root.join('spec/karma') if Rails.env.development? || Rails.env.test?

Rails.application.config.assets.paths << Rails.root.join('app/assets/builds')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
Expand Down
Loading