Skip to content

Commit

Permalink
Merge pull request #206 from tosdr/enh/issue-204-wikipedia-link
Browse files Browse the repository at this point in the history
adding the new column, the view and correcting previous view on servi…
  • Loading branch information
piks3l authored Dec 23, 2017
2 parents df30b0e + c4ab2ff commit 5ddd200
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 96 deletions.
2 changes: 1 addition & 1 deletion app/views/services/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="form-inputs col-xs-12">
<%= f.input :name, placeholder: "Service name" %>
<%= f.input :url, placeholder: "Address of the service"%>
<%= f.input :privacy_related, as: :boolean, label: :'privacy related' %>
<%= f.input :wikipedia, placeholder: "Wikipedia link" %>
</div>
<div class="form-actions col-xs-4 col-sm-2 col-md-2">
<%= link_to "Back", :back, class: "btn btn-default" %>
Expand Down
196 changes: 102 additions & 94 deletions app/views/services/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,66 @@
<h1 class="fw2 mv3">
<%= @service.name %>
</h1>
<p class="fw2 mt0 lh-copy">
<%= link_to "Website", service_path(@service.url) %>
<% if @service.wikipedia? %>
<%= link_to "Wikipedia", service_path(@service.wikipedia) %>
<% else %>
Wikipedia
<% end %>
</p>

<p>
<button class="btn btn-success" id="orderByPoint"> order by Rating </button>

<%= javascript_tag do %>
document.getElementById('orderByPoint').addEventListener("click", (event) => {
let elems = document.querySelectorAll(".card-point");
// convert nodelist to array
var array = [];
for (var i = elems.length >>> 0; i--;) {
array[i] = elems[i];
}
// perform sort depending on classname
if(event.currentTarget.className=="btn btn-success"){
array.sort(function(a, b) {
return a.dataset.rating - b.dataset.rating;
});
event.currentTarget.classList.remove("btn-success");
event.currentTarget.classList.add("btn-danger");
}
else if(event.currentTarget.className== "btn btn-danger"){
array.sort(function(a, b) {
return b.dataset.rating - a.dataset.rating;
});
event.currentTarget.classList.remove("btn-danger");
event.currentTarget.classList.add("btn-success");
}
// join the array back into HTML
var output = "";
for (var i = 0; i < array.length; i++) {
output += array[i].outerHTML;
}
// append output to div 'points-table-container'
document.getElementById('points-table-container').innerHTML = output;
});
<% end %>
let elems = document.querySelectorAll(".card-point");
// convert nodelist to array
var array = [];
for (var i = elems.length >>> 0; i--;) {
array[i] = elems[i];
}
// perform sort depending on classname
if(event.currentTarget.className=="btn btn-success"){
array.sort(function(a, b) {
return a.dataset.rating - b.dataset.rating;
});
event.currentTarget.classList.remove("btn-success");
event.currentTarget.classList.add("btn-danger");
}
else if(event.currentTarget.className== "btn btn-danger"){
array.sort(function(a, b) {
return b.dataset.rating - a.dataset.rating;
});
event.currentTarget.classList.remove("btn-danger");
event.currentTarget.classList.add("btn-success");
}
// join the array back into HTML
var output = "";
for (var i = 0; i < array.length; i++) {
output += array[i].outerHTML;
}
// append output to div 'points-table-container'
document.getElementById('points-table-container').innerHTML = output;
});
<% end %>
<% if current_user %>

<% if current_user.curator? %>
<%= link_to 'Edit Service', edit_service_path, class: 'btn btn-primary' %>
<%= link_to 'Delete Service', @service, method: :delete, class: 'btn btn-danger' %>
<% end %>
<% if current_user.curator? %>
<%= link_to 'Edit Service', edit_service_path, class: 'btn btn-primary' %>
<%= link_to 'Delete Service', @service, method: :delete, class: 'btn btn-danger' %>
<% end %>

</p>
</p>

<div id="custom-search-input">
<div class="input-group col-xs-12 mb15">
<%= form_tag(service_path(@service), method: :get) do %>
<%= collection_select :topic, :id , Topic.all, :id, :title, {prompt: "Select a Topic"} %>
<%= collection_select :topic, :id , Topic.all, :id, :title, {prompt: "Select a Topic"} %>

<%= submit_tag 'Search', class: "btn btn-default" %>
<%= link_to "Reset", service_path(@service), class: "btn btn-default" %>
<%= submit_tag 'Search', class: "btn btn-default" %>
<%= link_to "Reset", service_path(@service), class: "btn btn-default" %>

<% end %>
</div>
Expand Down Expand Up @@ -95,46 +103,46 @@
<% @points.each do |p| %>
<div class="card-point" data-rating="<%= p.rating %>">

<% if p.rating.between?(7, 10)%>
<% if p.rating.between?(7, 10)%>
<% pointbox = "point-good" %>
<% elsif p.rating.between?(4,6) %>
<% elsif p.rating.between?(4,6) %>
<% pointbox = "point-neutral" %>
<% elsif p.rating.between?(2,3) %>
<% elsif p.rating.between?(2,3) %>
<% pointbox = "point-bad" %>
<% elsif p.rating.between?(0,2) %>
<% elsif p.rating.between?(0,2) %>
<% pointbox = "point-blocker" %>
<% end %>
<div class="card-inline">
<div class="card-inline-item card-inline-point ">
<%= p.title %>
</div>
<div class="card-inline-item card-inline-rating <%= pointbox %>">
<%= p.rating %>
</div>
<div class="card-inline-item card-inline-status">
<%= p.status %>
</div>
<div class="card-inline-item card-inline-topic">
<%= p.topic.title %>
</div>
<div class="card-inline-item card-inline-featured">
<% if p.is_featured? %>
<i class="fa fa-check" aria-hidden="true"></i>
<% else %>
<i class="fa fa-circle-o" aria-hidden="true"></i>
<% end %>
</div>
<div class="card-inline-item card-inline-options">
<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<% end %>
<div class="card-inline">
<div class="card-inline-item card-inline-point ">
<%= p.title %>
</div>
<div class="card-inline-item card-inline-rating <%= pointbox %>">
<%= p.rating %>
</div>
<div class="card-inline-item card-inline-status">
<%= p.status %>
</div>
<div class="card-inline-item card-inline-topic">
<%= p.topic.title %>
</div>
<div class="card-inline-item card-inline-featured">
<% if p.is_featured? %>
<i class="fa fa-check" aria-hidden="true"></i>
<% else %>
<i class="fa fa-circle-o" aria-hidden="true"></i>
<% end %>
</div>
<div class="card-inline-item card-inline-options">
<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
</div>
</div>
</div>
</div>

<!-- card-inline-END -->
<% end %>
</div>
<% end %>
</div>

</div>
</div>
Expand All @@ -146,48 +154,48 @@
<div id="custom-search-input">
<div class="input-group col-xs-12 mb15">
<%= form_tag(service_path(@service), method: :get) do %>
<%= collection_select :topic, :id , Topic.all, :id, :title, {prompt: "Select a Topic"}, class: "dropdown" %>
<%= collection_select :topic, :id , Topic.all, :id, :title, {prompt: "Select a Topic"}, class: "dropdown" %>
<%= submit_tag 'Search', class: "btn btn-default" %>
<%= link_to "Reset", service_path(@service), class: "btn btn-default" %>
<% end %>
</div>
</div>
<div id="points-table-container">

<% @points.each do |p| %>
<div class="card-point" data-rating="<%= p.rating %>">
<% @points.each do |p| %>
<div class="card-point" data-rating="<%= p.rating %>">

<% if p.rating.between?(7, 10)%>
<% if p.rating.between?(7, 10)%>
<% pointbox = "point-good" %>
<% elsif p.rating.between?(4,6) %>
<% pointbox = "point-neutral" %>
<% elsif p.rating.between?(2,3) %>
<% pointbox = "point-bad" %>
<% elsif p.rating.between?(0,2) %>
<% pointbox = "point-blocker" %>
<% end %>
<% end %>

<article class="holder">
<div class="header-holder">
<h1 class="article-header <%= pointbox %>">
<%= p.title %>
</h1>
</div>
<article class="holder">
<div class="header-holder">
<h1 class="article-header <%= pointbox %>">
<%= p.title %>
</h1>
</div>

<div class="article-text-holder">
<p class="article-text">
<%= p.analysis %>
</p>
</div>
<div class="article-text-holder">
<p class="article-text">
<%= p.analysis %>
</p>
</div>

<div class="article-text-holder">
<p class="article-text">
Topic: <%= p.topic.title %>
</p>
</div>
<div class="article-text-holder">
<p class="article-text">
Topic: <%= p.topic.title %>
</p>
</div>

</article>
</div>
</article>
</div>

<% end %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20171223161343_add_wikipedia_link_to_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWikipediaLinkToServices < ActiveRecord::Migration[5.1]
def change
add_column :services, :wikipedia, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171223151948) do
ActiveRecord::Schema.define(version: 20171223161343) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -87,6 +87,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "grade"
t.string "wikipedia"
end

create_table "topics", force: :cascade do |t|
Expand Down

0 comments on commit 5ddd200

Please sign in to comment.