Skip to content

Commit

Permalink
Merge pull request #74 from TarteelAI/fix-login-popup
Browse files Browse the repository at this point in the history
Fix login popup when visitor try to download resource
  • Loading branch information
naveed-ahmad authored Aug 24, 2024
2 parents 12a757f + 10e9d0d commit 00a82a5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 61 deletions.
8 changes: 6 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class ApplicationController < ActionController::Base
include Pagy::Backend

rescue_from ActionController::RoutingError, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: ->(exception) { render_error 404, exception }
rescue_from ActionController::UnknownFormat,
ActionController::RoutingError,
::AbstractController::ActionNotFound,
ActiveRecord::RecordNotFound,
with: ->(exception) { render_error 404, exception }

protect_from_forgery with: :exception
before_action :set_paper_trail_whodunnit
Expand Down Expand Up @@ -44,7 +48,7 @@ def access_denied_for_admin_resource(exception)
def render_error(_status, exception)
# raise exception if Rails.env.development?

render 'shared/not_found'
render 'shared/not_found', formats: [:html], status: 404
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module ApplicationHelper
include Pagy::Frontend

def is_current_page?(controller:, action: nil)
controller_name == controller && (action.nil? || action_name == action)
end

def set_page_title(title, data_options = {})
content_for :title, title
options = data_options.map do |key, value|
Expand Down
2 changes: 1 addition & 1 deletion app/views/landing/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<footer class="flex-column flex-md-row py-4 align-items-end gap-2 <%= 'credits-container' if current_page?(controller: "community", action: "credits") %>">
<footer class="flex-column flex-md-row py-4 align-items-end gap-2 <%= 'credits-container' if is_current_page?(controller: "community", action: "credits") %>">
<div class="d-flex flex-column gap-3 justify-content-between">

<div class="left">
Expand Down
4 changes: 2 additions & 2 deletions app/views/landing/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<header class="header py-2 py-md-3 py-lg-4 <%= 'credits-container container-lg' if current_page?(controller: "community", action: "credits") %>">
<header class="header py-2 py-md-3 py-lg-4 <%= 'credits-container container-lg' if is_current_page?(controller: "community", action: "credits") %>">
<div class="qul-logo">
<%= link_to root_path, class: 'text-dark' do %>
<svg width="32" height="40" viewBox="0 0 32 40" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand Down Expand Up @@ -80,4 +80,4 @@
</div>
</div>
</div>
</nav>
</header>
17 changes: 9 additions & 8 deletions app/views/learning_activities/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<%
tarteel_link = 'https://tarteel.go.link/?adj_t=1foxrfdy&adj_engagement_type=fallback_click&adj_fallback=https%3A%2F%2Fwww.tarteel.ai&adj_redirect_macos=https%3A%2F%2Fwww.tarteel.ai'
activity = (params[:activity] || params[:id]).presence.to_s.downcase
%>
<div class="quiz-container overflow-auto py-5 px-3">
<div class="box">
<% if valid_activity?(params[:id]) %>
<%= set_page_title "#{params[:id].humanize} - Quranic quiz" %>
<%= render params[:id] %>
<% if valid_activity?(activity) %>
<%= set_page_title "#{activity.humanize} - Quranic quiz" %>
<%= render activity %>

<div class="result my-5" id="quiz-result">
<div class="text-danger d-none" id="incorrect-message">
Expand All @@ -24,7 +25,7 @@

<div class="more-activities d-flex justify-content-center gap-2 mt-4 d-none">
<%= link_to 'Learn more about this ayah', '#_', class: 'btn btn-outline-success me-3 ayah-info', data: { controller: 'ajax-modal', url: '/ayah/1:1', css_class: 'modal-lg', use_turbo: true} %>
<%= link_to 'Try another', url_for, class: 'btn btn-outline-dark me-3' %>
<%= link_to 'Try another', learning_activity_path(activity), class: 'btn btn-outline-dark me-3' %>
<%= link_to 'More learning activities', learning_activities_path, class: 'btn btn-outline-dark' %>
</div>
<% else %>
Expand All @@ -33,17 +34,17 @@
</div>

<ol class="list-group text-start">
<% learning_activities.each do |activity| %>
<% learning_activities.each do |item| %>
<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto">
<div class="fw-bold">
<%= activity.title %>
<%= item.title %>
</div>
<%= activity.description %>
<%= item.description %>
</div>

<span>
<%= link_to 'Try', activity.url, class: 'btn btn-success' %>
<%= link_to 'Try', item.url, class: 'btn btn-success' %>
</span>
</li>
<% end %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/resources/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@

<div class="card-container gap-4">
<% @resources.each do |resource| %>
<div class="resource-card tool-card-with-bg pattern<%= patterns.sample %>" data-search="<%= resource.name.to_s.downcase %> <%= resource.resource_type.to_s.downcase %> <%= resource.tags.to_s.downcase %> <%= resource.humanize_cardinality_type.to_s.downcase %>">
<div
class="resource-card tool-card-with-bg pattern<%= patterns.sample %>"
data-search="<%= resource.name.to_s.downcase %> <%= resource.resource_type.to_s.downcase %> <%= resource.tags.to_s.downcase %> <%= resource.humanize_cardinality_type.to_s.downcase %>"
id="<%= dom_id resource %>"
>
<div class="p-3 gap-4 h-100 d-flex flex-column justify-content-between">
<div class="text-white">
<h3 class="mb-0">
Expand Down
6 changes: 3 additions & 3 deletions app/views/shared/not_found.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
Let's turn this detour into a chance to learn more about the Quran!
</div>

<% activities = ['ayah_mastery', 'complete_the_ayah'] %>
<%= render "learning_activities/#{activities.sample}" %>
<% activity = ['ayah_mastery', 'complete_the_ayah'].sample %>
<%= render "learning_activities/#{activity}" %>

<div class="result my-5" id="quiz-result">
<div class="text-danger d-none" id="incorrect-message">
Expand All @@ -30,7 +30,7 @@

<div class="more-activities d-flex justify-content-center gap-2 mt-4 d-none">
<%= link_to 'Learn more about this ayah', '#_', class: 'btn btn-outline-success me-3 ayah-info', data: { controller: 'ajax-modal', url: '/ayah/1:1', css_class: 'modal-lg', use_turbo: true} %>
<%= link_to 'Try another', url_for, class: 'btn btn-outline-dark me-3' %>
<%= link_to 'Try another', learning_activity_path(activity), class: 'btn btn-outline-dark me-3' %>
<%= link_to 'More learning activities', learning_activities_path, class: 'btn btn-outline-dark' %>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions db/migrate/20240808134403_rename_topic_children_column.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
class RenameTopicChildrenColumn < ActiveRecord::Migration[7.0]
def change
c = Topic.connection
c.rename_column :topics, :childen_count, :children_count

add_column :users, :role, :integer, default: 0
if c.column_exists? :topics, :childen_count
c.rename_column :topics, :childen_count, :children_count
end

add_column :users, :role, :integer, default: 0, if_not_exists: true
end
end
Loading

0 comments on commit 00a82a5

Please sign in to comment.