From 3250d30c07c05c9a81674df962a583ba5ee89e5a Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 14:16:19 +0700 Subject: [PATCH 01/52] Add vendor in gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index de0c54b..44e797f 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ yarn-error.log* /engines/*/Gemfile.lock .env + +# Add vendor +/vendor From ccfe931879e2ae04160e2265cbb997bc8e19d385 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 14:29:51 +0700 Subject: [PATCH 02/52] Show search stats in a table --- app/controllers/search_stats_controller.rb | 2 +- app/views/search_stats/_pagination.html.erb | 43 ++++++++++++++++++++ app/views/search_stats/_search_stat.html.erb | 39 ++++-------------- app/views/search_stats/index.html.erb | 26 +++++++++--- 4 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 app/views/search_stats/_pagination.html.erb diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index 59edf49..51ab5d9 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -3,6 +3,6 @@ class SearchStatsController < ApplicationController # GET /search_stats def index - @pagy, @search_stats = pagy(SearchStat.all) + @pagy, @search_stats = pagy(SearchStat.all, items: 8) end end diff --git a/app/views/search_stats/_pagination.html.erb b/app/views/search_stats/_pagination.html.erb new file mode 100644 index 0000000..8f09f7b --- /dev/null +++ b/app/views/search_stats/_pagination.html.erb @@ -0,0 +1,43 @@ +
+ +
diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index a4d591a..56f8244 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -1,31 +1,8 @@ -
-

- <%= I18n.t('search_stat.keyword')%>: - <%= search_stat.keyword %> -

- -

- <%= I18n.t('search_stat.ad_count')%>: - <%= search_stat.ad_count %> -

- -

- <%= I18n.t('search_stat.link_count')%>: - <%= search_stat.link_count %> -

- -

- <%= I18n.t('search_stat.total_result_count')%>: - <%= search_stat.total_result_count %> -

- -

- <%= I18n.t('search_stat.raw_response')%>: - <%= search_stat.raw_response %> -

- -

- <%= I18n.t('search_stat.user')%>: - <%= search_stat.user_id %> -

-
+ + <%= search_stat.keyword %> + <%= search_stat.ad_count %> + <%= search_stat.link_count %> + <%= search_stat.total_result_count %> + <%= search_stat.raw_response %> + <%= search_stat.user_id %> + diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index 9c24d8c..6e39492 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -1,7 +1,23 @@ -

<%= I18n.t('search_stat.title')%>

+
+

<%= I18n.t('search_stat.title') %>

-
- <%= render @search_stats %> -
+
+ + + + + + + + + + + + + <%= render @search_stats %> + +
<%= I18n.t('search_stat.keyword') %><%= I18n.t('search_stat.ad_count') %><%= I18n.t('search_stat.link_count') %><%= I18n.t('search_stat.total_result_count') %><%= I18n.t('search_stat.raw_response') %><%= I18n.t('search_stat.user') %>
+
-<%== pagy_nav(@pagy) if @pagy.pages > 1 %> + <%= render partial: 'pagination' %> +
From 09048a2eba5fbe21cb3119214a9fd79071454c42 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 17:17:22 +0700 Subject: [PATCH 03/52] [#14] Add search stat show page --- app/controllers/search_stats_controller.rb | 4 ++ app/views/search_stats/index.html.erb | 15 ++++++- app/views/search_stats/show.html.erb | 46 ++++++++++++++++++++++ config/routes.rb | 2 +- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 app/views/search_stats/show.html.erb diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index 51ab5d9..0fa26f2 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -5,4 +5,8 @@ class SearchStatsController < ApplicationController def index @pagy, @search_stats = pagy(SearchStat.all, items: 8) end + + def show + @search_stat = SearchStat.find(params[:id]) + end end diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index 6e39492..a9044f1 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -11,10 +11,23 @@ <%= I18n.t('search_stat.total_result_count') %> <%= I18n.t('search_stat.raw_response') %> <%= I18n.t('search_stat.user') %> + - <%= render @search_stats %> + <% @search_stats.each do |search_stat| %> + + <%= search_stat.keyword %> + <%= search_stat.ad_count %> + <%= search_stat.link_count %> + <%= search_stat.total_result_count %> + <%= search_stat.raw_response %> + <%= search_stat.user_id %> + + <%= link_to 'Show', search_stat_path(search_stat), class: 'btn btn-primary' %> + + + <% end %> diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb new file mode 100644 index 0000000..1bf2dee --- /dev/null +++ b/app/views/search_stats/show.html.erb @@ -0,0 +1,46 @@ +
+
+
+ <%= link_to search_stats_path, class: "btn btn-primary m-1" do %> + Back + <% end %> +
+

<%= I18n.t('search_stat.title') %>

+
+ +
+
+
Search Stat Details
+ +

+ <%= I18n.t('search_stat.keyword') %>: + <%= @search_stat.keyword %> +

+ +

+ <%= I18n.t('search_stat.ad_count') %>: + <%= @search_stat.ad_count %> +

+ +

+ <%= I18n.t('search_stat.link_count') %>: + <%= @search_stat.link_count %> +

+ +

+ <%= I18n.t('search_stat.total_result_count') %>: + <%= @search_stat.total_result_count %> +

+ +

+ <%= I18n.t('search_stat.raw_response') %>: + <%= @search_stat.raw_response %> +

+ +

+ <%= I18n.t('search_stat.user') %>: + <%= @search_stat.user_id %> +

+
+
+
diff --git a/config/routes.rb b/config/routes.rb index 81a3538..726b7c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ root "home#index" get "/health_check", to: 'health_check#health_check', as: :rails_health_check - resources :search_stats, only: [:index] + resources :search_stats, only: [:index, :show] end From 80f79ef8d5c0cc0658859dae71bea7cac84fd78c Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 18:25:54 +0700 Subject: [PATCH 04/52] [#14] Add list of url's for adword and non-adwords --- app/controllers/search_stats_controller.rb | 22 ++++ app/models/search_stat.rb | 1 + app/views/search_stats/show.html.erb | 111 +++++++++++++++------ config/locales/en.yml | 3 + 4 files changed, 104 insertions(+), 33 deletions(-) diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index 0fa26f2..fdb6532 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -8,5 +8,27 @@ def index def show @search_stat = SearchStat.find(params[:id]) + @search_stat.adwords_urls = retrieve_adwords_urls(@search_stat) + @search_stat.non_adwords_urls = retrieve_non_adwords_urls(@search_stat) + end + + private + + def retrieve_adwords_urls(_search_stat) + # Dummy array of Non AdWords URLs + [ + 'https://www.example.com/advertiser1', + 'https://www.example.com/advertiser2', + 'https://www.example.com/advertiser3' + ] + end + + def retrieve_non_adwords_urls(_search_stat) + # Dummy array of Non AdWords URLs + [ + 'https://www.example.com/advertiser1', + 'https://www.example.com/advertiser2', + 'https://www.example.com/advertiser3' + ] end end diff --git a/app/models/search_stat.rb b/app/models/search_stat.rb index f7835bf..58c46cd 100644 --- a/app/models/search_stat.rb +++ b/app/models/search_stat.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true class SearchStat < ApplicationRecord + attr_accessor :adwords_urls, :non_adwords_urls end diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 1bf2dee..c9f08f4 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -8,39 +8,84 @@

<%= I18n.t('search_stat.title') %>

-
-
-
Search Stat Details
- -

- <%= I18n.t('search_stat.keyword') %>: - <%= @search_stat.keyword %> -

- -

- <%= I18n.t('search_stat.ad_count') %>: - <%= @search_stat.ad_count %> -

- -

- <%= I18n.t('search_stat.link_count') %>: - <%= @search_stat.link_count %> -

- -

- <%= I18n.t('search_stat.total_result_count') %>: - <%= @search_stat.total_result_count %> -

- -

- <%= I18n.t('search_stat.raw_response') %>: - <%= @search_stat.raw_response %> -

- -

- <%= I18n.t('search_stat.user') %>: - <%= @search_stat.user_id %> -

+
+
+
<%= I18n.t('search_stat.details_title') %>
+
+
+

+ <%= I18n.t('search_stat.keyword') %>: + <%= @search_stat.keyword %> +

+ +

+ <%= I18n.t('search_stat.ad_count_top') %>: + <%= 1 %> +

+ +

+ <%= I18n.t('search_stat.ad_count') %>: + <%= @search_stat.ad_count %> +

+
+
+

+ <%= I18n.t('search_stat.non_ad_count') %>: + <%= @search_stat.ad_count %> +

+ +

+ <%= I18n.t('search_stat.link_count') %>: + <%= @search_stat.link_count %> +

+ +

+ <%= I18n.t('search_stat.total_result_count') %>: + <%= @search_stat.total_result_count %> +

+
+
+

+ <%= I18n.t('search_stat.raw_response') %>: + <%= @search_stat.raw_response %> +

+ +

+ <%= I18n.t('search_stat.user') %>: + <%= @search_stat.user_id %> +

+
+ + + +
+
+
List of URLs of AdWords Advertisers in Top Position
+
    + <% @search_stat.adwords_urls.each do |url| %> +
  • + <%= link_to url, url, target: "_blank" %> +
  • + <% end %> +
+
+
+ +
+
+
List of URLs of Non-AdWords Results on the Page
+
    + <% @search_stat.non_adwords_urls.each do |url| %> +
  • + <%= link_to url, url, target: "_blank" %> +
  • + <% end %> +
+
+
+ + +
diff --git a/config/locales/en.yml b/config/locales/en.yml index 0a7509c..92975d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -32,8 +32,11 @@ en: search_stat: ad_count: 'Ad count' + ad_count_top: 'Ad count top' + details_title: 'Search stat details' keyword: 'Keyword' link_count: 'Link count' + non_ad_count: 'Non ad count' raw_response: 'Raw response' title: 'Search stats' total_result_count: 'Total result count' From a8ab93880bc85433ed8ced8aba38f440bdf77149 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 19:22:29 +0700 Subject: [PATCH 05/52] Add default per page for pagy --- app/controllers/search_stats_controller.rb | 2 +- config/initializers/pagy.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 config/initializers/pagy.rb diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index fdb6532..1228622 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -3,7 +3,7 @@ class SearchStatsController < ApplicationController # GET /search_stats def index - @pagy, @search_stats = pagy(SearchStat.all, items: 8) + @pagy, @search_stats = pagy(SearchStat.all) end def show diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb new file mode 100644 index 0000000..138ed61 --- /dev/null +++ b/config/initializers/pagy.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require 'pagy/extras/bootstrap' + +# Override default options +Pagy::DEFAULT[:items] = 5 +Pagy::DEFAULT[:size] = [1, 2, 2, 1] +Pagy::DEFAULT[:overflow] = :empty_page From 6f2fc8aef52729522c22ba4f24e5e8bd174ca344 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 19:28:32 +0700 Subject: [PATCH 06/52] Use pagy default bootstrap pagination --- app/views/search_stats/_pagination.html.erb | 43 --------------------- app/views/search_stats/index.html.erb | 2 +- config/initializers/pagy.rb | 4 +- 3 files changed, 4 insertions(+), 45 deletions(-) delete mode 100644 app/views/search_stats/_pagination.html.erb diff --git a/app/views/search_stats/_pagination.html.erb b/app/views/search_stats/_pagination.html.erb deleted file mode 100644 index 8f09f7b..0000000 --- a/app/views/search_stats/_pagination.html.erb +++ /dev/null @@ -1,43 +0,0 @@ -
- -
diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index a9044f1..e70f9fb 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -32,5 +32,5 @@
- <%= render partial: 'pagination' %> + <%== pagy_bootstrap_nav(@pagy) %> diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index 138ed61..7b0ffe9 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -5,4 +5,6 @@ # Override default options Pagy::DEFAULT[:items] = 5 Pagy::DEFAULT[:size] = [1, 2, 2, 1] -Pagy::DEFAULT[:overflow] = :empty_page + +require 'pagy/extras/overflow' +Pagy::DEFAULT[:overflow] = :last_page From fb6c01cb6ea9a582bc8d214af9d1431acfd56a3d Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 29 May 2023 19:33:04 +0700 Subject: [PATCH 07/52] Add render to search stats --- app/views/search_stats/index.html.erb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index e70f9fb..dba1551 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -15,19 +15,7 @@ - <% @search_stats.each do |search_stat| %> - - <%= search_stat.keyword %> - <%= search_stat.ad_count %> - <%= search_stat.link_count %> - <%= search_stat.total_result_count %> - <%= search_stat.raw_response %> - <%= search_stat.user_id %> - - <%= link_to 'Show', search_stat_path(search_stat), class: 'btn btn-primary' %> - - - <% end %> + <%= render @search_stats %> From 39da3d2ab0adc0f5d96baef23ea32a5628333996 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 30 May 2023 16:48:24 +0700 Subject: [PATCH 08/52] [#14] Show rendered search stat raw response in modal --- .../search_stats/_raw_response_modal.html.erb | 41 ++++++ app/views/search_stats/_search_stat.html.erb | 16 ++- app/views/search_stats/index.html.erb | 4 +- app/views/search_stats/show.html.erb | 129 +++++++++--------- config/locales/en.yml | 2 +- 5 files changed, 121 insertions(+), 71 deletions(-) create mode 100644 app/views/search_stats/_raw_response_modal.html.erb diff --git a/app/views/search_stats/_raw_response_modal.html.erb b/app/views/search_stats/_raw_response_modal.html.erb new file mode 100644 index 0000000..59371f7 --- /dev/null +++ b/app/views/search_stats/_raw_response_modal.html.erb @@ -0,0 +1,41 @@ + + + diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index 56f8244..f378c40 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -3,6 +3,18 @@ <%= search_stat.ad_count %> <%= search_stat.link_count %> <%= search_stat.total_result_count %> - <%= search_stat.raw_response %> - <%= search_stat.user_id %> + + <%= button_to 'Show Details', search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %> + + + + diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index dba1551..a9a1db1 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -9,9 +9,7 @@ <%= I18n.t('search_stat.ad_count') %> <%= I18n.t('search_stat.link_count') %> <%= I18n.t('search_stat.total_result_count') %> - <%= I18n.t('search_stat.raw_response') %> - <%= I18n.t('search_stat.user') %> - + <%= I18n.t('search_stat.action') %> diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index c9f08f4..9f6315c 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -8,84 +8,83 @@

<%= I18n.t('search_stat.title') %>

-
-
-
<%= I18n.t('search_stat.details_title') %>
-
-
-

- <%= I18n.t('search_stat.keyword') %>: - <%= @search_stat.keyword %> -

+
+
+
<%= I18n.t('search_stat.details_title') %>
+
+
+

+ <%= I18n.t('search_stat.keyword') %>: + <%= @search_stat.keyword %> +

-

- <%= I18n.t('search_stat.ad_count_top') %>: - <%= 1 %> -

+

+ <%= I18n.t('search_stat.ad_count_top') %>: + <%= 1 %> +

-

- <%= I18n.t('search_stat.ad_count') %>: - <%= @search_stat.ad_count %> -

-
-
-

- <%= I18n.t('search_stat.non_ad_count') %>: - <%= @search_stat.ad_count %> -

+

+ <%= I18n.t('search_stat.ad_count') %>: + <%= @search_stat.ad_count %> +

+
+
+

+ <%= I18n.t('search_stat.non_ad_count') %>: + <%= @search_stat.ad_count %> +

-

- <%= I18n.t('search_stat.link_count') %>: - <%= @search_stat.link_count %> -

+

+ <%= I18n.t('search_stat.link_count') %>: + <%= @search_stat.link_count %> +

-

- <%= I18n.t('search_stat.total_result_count') %>: - <%= @search_stat.total_result_count %> -

-
-
-

- <%= I18n.t('search_stat.raw_response') %>: - <%= @search_stat.raw_response %> -

+

+ <%= I18n.t('search_stat.total_result_count') %>: + <%= @search_stat.total_result_count %> +

+
+
+

+ <%= button_tag 'View Raw Response', class: 'btn btn-primary', onclick: "openRawResponse('#{j @search_stat.raw_response}')"%> +

-

- <%= I18n.t('search_stat.user') %>: - <%= @search_stat.user_id %> -

+

+ <%= I18n.t('search_stat.user') %>: + <%= @search_stat.user_id %> +

+
-
-
-
-
List of URLs of AdWords Advertisers in Top Position
-
    - <% @search_stat.adwords_urls.each do |url| %> -
  • - <%= link_to url, url, target: "_blank" %> -
  • - <% end %> -
+
+
+
List of URLs of AdWords Advertisers in Top Position
+
    + <% @search_stat.adwords_urls.each do |url| %> +
  • + <%= link_to url, url, target: "_blank" %> +
  • + <% end %> +
+
-
-
-
-
List of URLs of Non-AdWords Results on the Page
-
    - <% @search_stat.non_adwords_urls.each do |url| %> -
  • - <%= link_to url, url, target: "_blank" %> -
  • - <% end %> -
+
+
+
List of URLs of Non-AdWords Results on the Page
+
    + <% @search_stat.non_adwords_urls.each do |url| %> +
  • + <%= link_to url, url, target: "_blank" %> +
  • + <% end %> +
+
-
- +<%= render 'raw_response_modal' %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 92975d0..51435c9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,13 +31,13 @@ en: search_stat: + action: "Action" ad_count: 'Ad count' ad_count_top: 'Ad count top' details_title: 'Search stat details' keyword: 'Keyword' link_count: 'Link count' non_ad_count: 'Non ad count' - raw_response: 'Raw response' title: 'Search stats' total_result_count: 'Total result count' user: 'User' From 58915f906e1fd29438131cfa0bdf3d543f9500b6 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 30 May 2023 18:48:01 +0700 Subject: [PATCH 09/52] [#11] Remove extra blank lines --- .gitignore | 1 - app/views/search_stats/show.html.erb | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index be71c07..44e797f 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,5 @@ yarn-error.log* .env - # Add vendor /vendor diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 9f6315c..13ac60f 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -46,7 +46,8 @@

- <%= button_tag 'View Raw Response', class: 'btn btn-primary', onclick: "openRawResponse('#{j @search_stat.raw_response}')"%> + <%= button_tag 'View Raw Response', class: 'btn btn-primary', + onclick: "openRawResponse('#{j @search_stat.raw_response}')"%>

@@ -58,8 +59,6 @@

- -
List of URLs of AdWords Advertisers in Top Position
From 6e67d7957c3a415c53047769fc50b51934acdb06 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Wed, 31 May 2023 10:47:00 +0700 Subject: [PATCH 10/52] [#11] Return search stats that belongs to user --- app/controllers/search_stats_controller.rb | 2 +- app/models/search_stat.rb | 1 + app/models/user.rb | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index 1228622..cea1e0f 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -3,7 +3,7 @@ class SearchStatsController < ApplicationController # GET /search_stats def index - @pagy, @search_stats = pagy(SearchStat.all) + @pagy, @search_stats = pagy(current_user.search_stats) end def show diff --git a/app/models/search_stat.rb b/app/models/search_stat.rb index 58c46cd..e456a13 100644 --- a/app/models/search_stat.rb +++ b/app/models/search_stat.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true class SearchStat < ApplicationRecord + belongs_to :user attr_accessor :adwords_urls, :non_adwords_urls end diff --git a/app/models/user.rb b/app/models/user.rb index 351e132..63b1a46 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,8 +4,12 @@ class User < ApplicationRecord include Authenticable PASSWORD_PATTERN = /(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}/ + has_many :search_stats, dependent: :destroy + before_validation :password_complexity, on: :create + private + def password_complexity return if password.match?(PASSWORD_PATTERN) From 4c766755a273b2033b95a7b6ad0cb5db882d5842 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Wed, 31 May 2023 10:59:38 +0700 Subject: [PATCH 11/52] [#11] Show search stat not found message --- app/views/search_stats/index.html.erb | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index a9a1db1..8523d9d 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -1,22 +1,28 @@

<%= I18n.t('search_stat.title') %>

-
- - - - - - - - - - - - <%= render @search_stats %> - -
<%= I18n.t('search_stat.keyword') %><%= I18n.t('search_stat.ad_count') %><%= I18n.t('search_stat.link_count') %><%= I18n.t('search_stat.total_result_count') %><%= I18n.t('search_stat.action') %>
-
+ <% if @search_stats.any? %> +
+ + + + + + + + + + + + <%= render @search_stats %> + +
<%= I18n.t('search_stat.keyword') %><%= I18n.t('search_stat.ad_count') %><%= I18n.t('search_stat.link_count') %><%= I18n.t('search_stat.total_result_count') %><%= I18n.t('search_stat.action') %>
+
- <%== pagy_bootstrap_nav(@pagy) %> + <%== pagy_bootstrap_nav(@pagy) %> + <% else %> +
+

No search stats found.

+
+ <% end %>
From d57f29ea8c651d9e272548d111fd9417d4059bfd Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 1 Jun 2023 17:24:39 +0700 Subject: [PATCH 12/52] [#40] Create separate model,migration, and seeder for result links --- app/models/result_link.rb | 9 +++++++++ app/models/search_stat.rb | 8 ++++---- db/migrate/20230601085414_create_result_links.rb | 16 ++++++++++++++++ db/schema.rb | 14 +++++++++++++- db/seeds.rb | 3 ++- spec/fabricators/result_link_fabricator.rb | 10 ++++++++++ spec/fabricators/search_stat_fabricator.rb | 6 +++++- 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 app/models/result_link.rb create mode 100644 db/migrate/20230601085414_create_result_links.rb create mode 100644 spec/fabricators/result_link_fabricator.rb diff --git a/app/models/result_link.rb b/app/models/result_link.rb new file mode 100644 index 0000000..313688e --- /dev/null +++ b/app/models/result_link.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ResultLink < ApplicationRecord + belongs_to :search_stat, inverse_of: :result_links + + enum link_type: { ads_top: 0, ads_page: 1, non_ads: 2 } + + validates :url, presence: true +end diff --git a/app/models/search_stat.rb b/app/models/search_stat.rb index 88a8fef..b3cb8cd 100644 --- a/app/models/search_stat.rb +++ b/app/models/search_stat.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class SearchStat < ApplicationRecord - belongs_to :user - attr_accessor :adwords_urls, :non_adwords_urls - - validates :keyword, presence: true + validates :keyword, presence: true, length: { maximum: 255 } validates :raw_response, presence: true + + belongs_to :user + has_many :result_links, inverse_of: :search_stat, dependent: :destroy end diff --git a/db/migrate/20230601085414_create_result_links.rb b/db/migrate/20230601085414_create_result_links.rb new file mode 100644 index 0000000..24ca656 --- /dev/null +++ b/db/migrate/20230601085414_create_result_links.rb @@ -0,0 +1,16 @@ +class CreateResultLinks < ActiveRecord::Migration[7.0] + def change + enable_extension 'citext' unless extension_enabled?('citext') + + create_table :result_links do |t| + t.references :search_stat, null: false, foreign_key: true + t.integer :link_type, null: false + t.citext :url, null: false + + t.timestamps default: -> { 'CURRENT_TIMESTAMP' } + end + + add_index :result_links, :link_type + add_index :result_links, :url + end +end diff --git a/db/schema.rb b/db/schema.rb index 67175ab..7770da1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,23 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_05_23_085326) do +ActiveRecord::Schema.define(version: 2023_06_01_085414) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "plpgsql" + create_table "result_links", force: :cascade do |t| + t.bigint "search_stat_id", null: false + t.integer "link_type", null: false + t.citext "url", null: false + t.datetime "created_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false + t.datetime "updated_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false + t.index ["link_type"], name: "index_result_links_on_link_type" + t.index ["search_stat_id"], name: "index_result_links_on_search_stat_id" + t.index ["url"], name: "index_result_links_on_url" + end + create_table "search_stats", force: :cascade do |t| t.string "keyword", null: false t.integer "ad_count", default: 0, null: false @@ -39,5 +50,6 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "result_links", "search_stats" add_foreign_key "search_stats", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 4ca4fbb..c87e52d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,5 +10,6 @@ # Generate dummy data for SearchStat 10.times do - Fabricate(:search_stat) + user = User.where(email: 'user@demo.com').first_or_create(Fabricate.attributes_for(:user, email: 'user@demo.com')) + Fabricate.times(100, :search_stat_parsed_with_links, user: user) end diff --git a/spec/fabricators/result_link_fabricator.rb b/spec/fabricators/result_link_fabricator.rb new file mode 100644 index 0000000..46a16cf --- /dev/null +++ b/spec/fabricators/result_link_fabricator.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +Fabricator(:result_link) do + link_type { FFaker.rand 3 } + url { FFaker::Internet.http_url } +end + +Fabricator(:result_link_with_search_stat, from: :result_link) do + search_stat { Fabricate(:search_stat) } +end diff --git a/spec/fabricators/search_stat_fabricator.rb b/spec/fabricators/search_stat_fabricator.rb index cf64d87..9986ac6 100644 --- a/spec/fabricators/search_stat_fabricator.rb +++ b/spec/fabricators/search_stat_fabricator.rb @@ -6,5 +6,9 @@ link_count { rand(1..10) } total_result_count { rand(1..100) } raw_response { FFaker::HTMLIpsum.body } - user_id { Fabricate(:user).id } + user { Fabricate(:user) } +end + +Fabricator(:search_stat_parsed_with_links, from: :search_stat) do + result_links(count: FFaker.rand(10) + 1) end From 888c0d57e17ccde6255e41b919e6097c0c503baf Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 1 Jun 2023 17:57:09 +0700 Subject: [PATCH 13/52] [#40] Show result links from db instead of dummy data --- app/controllers/search_stats_controller.rb | 24 +--------------------- app/views/search_stats/show.html.erb | 8 ++++---- config/initializers/pagy.rb | 2 +- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index cea1e0f..f426438 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -7,28 +7,6 @@ def index end def show - @search_stat = SearchStat.find(params[:id]) - @search_stat.adwords_urls = retrieve_adwords_urls(@search_stat) - @search_stat.non_adwords_urls = retrieve_non_adwords_urls(@search_stat) - end - - private - - def retrieve_adwords_urls(_search_stat) - # Dummy array of Non AdWords URLs - [ - 'https://www.example.com/advertiser1', - 'https://www.example.com/advertiser2', - 'https://www.example.com/advertiser3' - ] - end - - def retrieve_non_adwords_urls(_search_stat) - # Dummy array of Non AdWords URLs - [ - 'https://www.example.com/advertiser1', - 'https://www.example.com/advertiser2', - 'https://www.example.com/advertiser3' - ] + @search_stat = SearchStat.includes(:result_links).find(params[:id]) end end diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 13ac60f..3f78109 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -63,9 +63,9 @@
List of URLs of AdWords Advertisers in Top Position
    - <% @search_stat.adwords_urls.each do |url| %> + <% @search_stat.result_links.ads_top.or(@search_stat.result_links.ads_page).each do |result_link| %>
  • - <%= link_to url, url, target: "_blank" %> + <%= link_to result_link.url, result_link.url, target: "_blank" %>
  • <% end %>
@@ -76,9 +76,9 @@
List of URLs of Non-AdWords Results on the Page
    - <% @search_stat.non_adwords_urls.each do |url| %> + <% @search_stat.result_links.non_ads.each do |result_link| %>
  • - <%= link_to url, url, target: "_blank" %> + <%= link_to result_link.url, result_link.url, target: "_blank" %>
  • <% end %>
diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index 7b0ffe9..d64e859 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require 'pagy/extras/bootstrap' +require 'pagy/extras/overflow' # Override default options Pagy::DEFAULT[:items] = 5 Pagy::DEFAULT[:size] = [1, 2, 2, 1] -require 'pagy/extras/overflow' Pagy::DEFAULT[:overflow] = :last_page From 08016c12affb62f845af3765e908559edff28f8c Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 1 Jun 2023 18:25:38 +0700 Subject: [PATCH 14/52] [#41] Sort models --- app/models/result_link.rb | 4 ++-- app/models/search_stat.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/result_link.rb b/app/models/result_link.rb index 313688e..d642e68 100644 --- a/app/models/result_link.rb +++ b/app/models/result_link.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class ResultLink < ApplicationRecord - belongs_to :search_stat, inverse_of: :result_links - enum link_type: { ads_top: 0, ads_page: 1, non_ads: 2 } + belongs_to :search_stat, inverse_of: :result_links + validates :url, presence: true end diff --git a/app/models/search_stat.rb b/app/models/search_stat.rb index b3cb8cd..a83f577 100644 --- a/app/models/search_stat.rb +++ b/app/models/search_stat.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class SearchStat < ApplicationRecord + has_many :result_links, inverse_of: :search_stat, dependent: :destroy + belongs_to :user + validates :keyword, presence: true, length: { maximum: 255 } validates :raw_response, presence: true - - belongs_to :user - has_many :result_links, inverse_of: :search_stat, dependent: :destroy end From ad8a1a8163a030b7a14ce0b33a76f1a4c21f5b4c Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 6 Jun 2023 16:36:39 +0700 Subject: [PATCH 15/52] [#40] Remove ads_page link type from result link model --- app/models/result_link.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/result_link.rb b/app/models/result_link.rb index d642e68..6d1c1e6 100644 --- a/app/models/result_link.rb +++ b/app/models/result_link.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ResultLink < ApplicationRecord - enum link_type: { ads_top: 0, ads_page: 1, non_ads: 2 } + enum link_type: { ads_top: 0, non_ads: 2 } belongs_to :search_stat, inverse_of: :result_links From fcafc99269e9fec7419fe1ed3318ea0dd3ad7f2a Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 6 Jun 2023 18:04:47 +0700 Subject: [PATCH 16/52] Update db/migrate/20230601085414_create_result_links.rb Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- db/migrate/20230601085414_create_result_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20230601085414_create_result_links.rb b/db/migrate/20230601085414_create_result_links.rb index 24ca656..8ee357a 100644 --- a/db/migrate/20230601085414_create_result_links.rb +++ b/db/migrate/20230601085414_create_result_links.rb @@ -7,7 +7,7 @@ def change t.integer :link_type, null: false t.citext :url, null: false - t.timestamps default: -> { 'CURRENT_TIMESTAMP' } + t.timestamps end add_index :result_links, :link_type From 5af96b72520ce692c9f311821a09524102789f36 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 6 Jun 2023 18:05:48 +0700 Subject: [PATCH 17/52] Update db/seeds.rb Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- db/seeds.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index c87e52d..8996b03 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,7 +9,8 @@ require 'fabrication' # Generate dummy data for SearchStat +user = User.where(email: 'user@demo.com').first_or_create(Fabricate.attributes_for(:user, email: 'user@demo.com')) + 10.times do - user = User.where(email: 'user@demo.com').first_or_create(Fabricate.attributes_for(:user, email: 'user@demo.com')) Fabricate.times(100, :search_stat_parsed_with_links, user: user) end From 81f148c9cf1c4c1beeadf4b028ac234e873ecb0a Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 10:16:07 +0700 Subject: [PATCH 18/52] Update app/views/search_stats/show.html.erb Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- app/views/search_stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 3f78109..77a94a7 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -65,7 +65,7 @@
    <% @search_stat.result_links.ads_top.or(@search_stat.result_links.ads_page).each do |result_link| %>
  • - <%= link_to result_link.url, result_link.url, target: "_blank" %> + <%= link_to result_link.url, result_link.url %>
  • <% end %>
From 3613756ca31e9175e56145463256782eca10d535 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 10:24:46 +0700 Subject: [PATCH 19/52] [#40] Change type of link column in result_links table --- .../20230608032015_change_url_type_in_result_links.rb | 9 +++++++++ db/schema.rb | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230608032015_change_url_type_in_result_links.rb diff --git a/db/migrate/20230608032015_change_url_type_in_result_links.rb b/db/migrate/20230608032015_change_url_type_in_result_links.rb new file mode 100644 index 0000000..e82d677 --- /dev/null +++ b/db/migrate/20230608032015_change_url_type_in_result_links.rb @@ -0,0 +1,9 @@ +class ChangeUrlTypeInResultLinks < ActiveRecord::Migration[7.0] + def change + remove_index :result_links, :url + + change_column :result_links, :url, :string, null: false + + add_index :result_links, :url + end +end diff --git a/db/schema.rb b/db/schema.rb index 3f5b9d2..0989781 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_06_02_033657) do +ActiveRecord::Schema.define(version: 2023_06_08_032015) do # These are extensions that must be enabled in order to support this database enable_extension "citext" @@ -19,7 +19,7 @@ create_table "result_links", force: :cascade do |t| t.bigint "search_stat_id", null: false t.integer "link_type", null: false - t.citext "url", null: false + t.string "url", null: false t.datetime "created_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false t.datetime "updated_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false t.index ["link_type"], name: "index_result_links_on_link_type" From 57f9e8d07d421c1e3c03dee017e1cc9b1953a9b1 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 15:13:47 +0700 Subject: [PATCH 20/52] [#11] Use active record model attributes in search stats table --- app/views/search_stats/index.html.erb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index 75c09c8..d7ef5d2 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -1,15 +1,16 @@ -

<%= SearchStat.model_name.human %>

+
+

<%= SearchStat.model_name.human %>

<% if @search_stats.any? %>
- - - - - + + + + + From 393df1f7796e547d6165df9cfa8650ed9d825417 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 15:26:45 +0700 Subject: [PATCH 21/52] [#11] Add table for search stats --- app/views/search_stats/_search_stat.html.erb | 48 ++++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index f0eed2b..c3d3ca5 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -1,31 +1,19 @@ -
-

- <%= SearchStat.human_attribute_name(:keyword) %>: - <%= search_stat.keyword %> -

+
+ + + + + + -

- <%= SearchStat.human_attribute_name(:ad_count) %>: - <%= search_stat.ad_count %> -

- -

- <%= SearchStat.human_attribute_name(:link_count) %>: - <%= search_stat.link_count %> -

- -

- <%= SearchStat.human_attribute_name(:total_result_count) %>: - <%= search_stat.total_result_count %> -

- -

- <%= SearchStat.human_attribute_name(:raw_response) %>: - <%= search_stat.raw_response %> -

- -

- <%= SearchStat.human_attribute_name(:user_id) %>: - <%= search_stat.user_id %> -

- + From a8a2755e7ba312056a6ec1489a42104763cd0888 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 15:27:11 +0700 Subject: [PATCH 22/52] [#11] Add active record based translation in search stat show page --- app/views/search_stats/show.html.erb | 18 +++++++++--------- config/locales/en.yml | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 77a94a7..bb9193e 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -5,7 +5,7 @@ Back <% end %> -

<%= I18n.t('search_stat.title') %>

+

<%= SearchStat.model_name.human %>

@@ -14,33 +14,33 @@

- <%= I18n.t('search_stat.keyword') %>: + <%= SearchStat.human_attribute_name(:keyword) %>: <%= @search_stat.keyword %>

- <%= I18n.t('search_stat.ad_count_top') %>: + <%= SearchStat.human_attribute_name(:ad_count_top) %>: <%= 1 %>

- <%= I18n.t('search_stat.ad_count') %>: + <%= SearchStat.human_attribute_name(:ad_count) %>: <%= @search_stat.ad_count %>

- <%= I18n.t('search_stat.non_ad_count') %>: + <%= SearchStat.human_attribute_name(:non_ad_count) %>: <%= @search_stat.ad_count %>

- <%= I18n.t('search_stat.link_count') %>: + <%= SearchStat.human_attribute_name(:link_count) %>: <%= @search_stat.link_count %>

- <%= I18n.t('search_stat.total_result_count') %>: + <%= SearchStat.human_attribute_name(:total_result_count) %>: <%= @search_stat.total_result_count %>

@@ -51,7 +51,7 @@

- <%= I18n.t('search_stat.user') %>: + <%= SearchStat.human_attribute_name(:total_result_count) %>: <%= @search_stat.user_id %>

@@ -63,7 +63,7 @@
List of URLs of AdWords Advertisers in Top Position
    - <% @search_stat.result_links.ads_top.or(@search_stat.result_links.ads_page).each do |result_link| %> + <% @search_stat.result_links.ads_top.or(@search_stat.result_links.non_ads).each do |result_link| %>
  • <%= link_to result_link.url, result_link.url %>
  • diff --git a/config/locales/en.yml b/config/locales/en.yml index ce17548..fff2849 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -37,8 +37,10 @@ en: attributes: search_stat: ad_count: Ad count + ad_count_top: Ad count top keyword: Keyword link_count: Link count + non_ad_count: Non ad count raw_response: Raw response total_result_count: Total result count user_id: User From 3a7ee716f800c059a33e5045bc0333f0a46dfd80 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 15:31:54 +0700 Subject: [PATCH 23/52] [#11] Add search stat title --- app/views/search_stats/show.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index bb9193e..60e2930 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -5,12 +5,11 @@ Back <% end %>
-

<%= SearchStat.model_name.human %>

-
<%= I18n.t('search_stat.details_title') %>
+
<%= SearchStat.model_name.human %>

From 11daa76403744858bcda37bfac08f6a89d2ad74a Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 8 Jun 2023 15:32:40 +0700 Subject: [PATCH 24/52] [#11] Remove unnecessary code --- app/views/search_stats/_search_stat.html.erb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index c3d3ca5..4df7c31 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -7,13 +7,3 @@ <%= button_to 'Show Details', search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %> - - From bd74354cbef789bf45da8ffcb4f509763265ef01 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 18:14:32 +0700 Subject: [PATCH 25/52] [#11] Use js from app/javascript directory to show raw response --- app/javascript/application.js | 1 + .../components/raw_response_modal.js | 22 +++++++++++++++ .../search_stats/_raw_response_modal.html.erb | 28 ------------------- 3 files changed, 23 insertions(+), 28 deletions(-) create mode 100644 app/javascript/components/raw_response_modal.js diff --git a/app/javascript/application.js b/app/javascript/application.js index a90b449..cc40fe7 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -4,3 +4,4 @@ import './translations/translations'; import './initializers/'; import './screens/'; +import './components/raw_response_modal' diff --git a/app/javascript/components/raw_response_modal.js b/app/javascript/components/raw_response_modal.js new file mode 100644 index 0000000..8499c1f --- /dev/null +++ b/app/javascript/components/raw_response_modal.js @@ -0,0 +1,22 @@ +import { Modal } from 'bootstrap'; + +function openRawResponse(rawResponse) { + var modal = new Modal(document.getElementById('rawResponseModal')); + var iframe = document.getElementById('rawResponseIframe'); + iframe.srcdoc = rawResponse; + modal.show(); +} + +function closeRawResponse() { + var modal = Modal.getInstance(document.getElementById('rawResponseModal')); + + // Close the modal + if (modal) { + modal.hide(); + } +} + +var closeButton = document.querySelector('#rawResponseModal .btn-close'); +closeButton.addEventListener('click', closeRawResponse); + +window.openRawResponse = openRawResponse diff --git a/app/views/search_stats/_raw_response_modal.html.erb b/app/views/search_stats/_raw_response_modal.html.erb index 59371f7..c024036 100644 --- a/app/views/search_stats/_raw_response_modal.html.erb +++ b/app/views/search_stats/_raw_response_modal.html.erb @@ -11,31 +11,3 @@

- - From 89990de059fb7b5a80641fbc790f6877a0a6ba99 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 18:35:31 +0700 Subject: [PATCH 26/52] [#11] Add relation between search stat and user --- app/models/search_stat.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/search_stat.rb b/app/models/search_stat.rb index 2f1b0f7..283d0a6 100644 --- a/app/models/search_stat.rb +++ b/app/models/search_stat.rb @@ -2,7 +2,7 @@ class SearchStat < ApplicationRecord has_many :result_links, inverse_of: :search_stat, dependent: :destroy - belongs_to :user + belongs_to :user, inverse_of: :search_stats validates :keyword, presence: true, length: { maximum: 255 } validates :raw_response, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 63b1a46..bacbbce 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ApplicationRecord include Authenticable PASSWORD_PATTERN = /(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}/ - has_many :search_stats, dependent: :destroy + has_many :search_stats, inverse_of: :user, dependent: :destroy before_validation :password_complexity, on: :create From 3746cb939a50e7b6c7f3679fe8c23a947428adc1 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 19:12:18 +0700 Subject: [PATCH 27/52] [#11] Localise search stat details button --- app/views/search_stats/_search_stat.html.erb | 2 +- config/locales/en.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index 4df7c31..7d8c770 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -4,6 +4,6 @@
diff --git a/config/locales/en.yml b/config/locales/en.yml index fff2849..96e1ed0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,3 +44,5 @@ en: raw_response: Raw response total_result_count: Total result count user_id: User + buttons: + search_stat_details: Show Details From 9159302ce281393317c3d78af1c2caac13bc889f Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 19:13:50 +0700 Subject: [PATCH 28/52] [#11] Localise, remove dummy, and fix lint in search stat show page --- app/javascript/application.js | 2 +- app/javascript/components/raw_response_modal.js | 2 +- app/views/search_stats/show.html.erb | 8 ++++---- config/locales/en.yml | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/javascript/application.js b/app/javascript/application.js index cc40fe7..24b1354 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -4,4 +4,4 @@ import './translations/translations'; import './initializers/'; import './screens/'; -import './components/raw_response_modal' +import './components/raw_response_modal'; diff --git a/app/javascript/components/raw_response_modal.js b/app/javascript/components/raw_response_modal.js index 8499c1f..cf4aadb 100644 --- a/app/javascript/components/raw_response_modal.js +++ b/app/javascript/components/raw_response_modal.js @@ -19,4 +19,4 @@ function closeRawResponse() { var closeButton = document.querySelector('#rawResponseModal .btn-close'); closeButton.addEventListener('click', closeRawResponse); -window.openRawResponse = openRawResponse +window.openRawResponse = openRawResponse; diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 60e2930..79893f9 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -19,7 +19,7 @@

<%= SearchStat.human_attribute_name(:ad_count_top) %>: - <%= 1 %> + <%= @search_stat.top_ad_count %>

@@ -30,7 +30,7 @@

<%= SearchStat.human_attribute_name(:non_ad_count) %>: - <%= @search_stat.ad_count %> + <%= @search_stat.non_ad_count %>

@@ -45,10 +45,10 @@

- <%= button_tag 'View Raw Response', class: 'btn btn-primary', + <%= button_tag t('buttons.raw_response'), class: 'btn btn-primary', onclick: "openRawResponse('#{j @search_stat.raw_response}')"%>

- +

<%= SearchStat.human_attribute_name(:total_result_count) %>: <%= @search_stat.user_id %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 96e1ed0..3bf5b15 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -46,3 +46,4 @@ en: user_id: User buttons: search_stat_details: Show Details + raw_response: View Raw Response From d89551c2baf0587728497bdc2cfe9ab94c55db10 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 19:35:36 +0700 Subject: [PATCH 29/52] [#11] Change link type of result link model --- app/models/result_link.rb | 2 +- db/migrate/20230601085414_create_result_links.rb | 3 --- ...30612121926_change_link_type_to_string_in_result_links.rb | 5 +++++ db/schema.rb | 4 ++-- db/seeds.rb | 2 +- spec/fabricators/result_link_fabricator.rb | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20230612121926_change_link_type_to_string_in_result_links.rb diff --git a/app/models/result_link.rb b/app/models/result_link.rb index 6d1c1e6..04949c4 100644 --- a/app/models/result_link.rb +++ b/app/models/result_link.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ResultLink < ApplicationRecord - enum link_type: { ads_top: 0, non_ads: 2 } + enum link_type: { ads_top: 'ads_top', non_ads: 'non_ads' } belongs_to :search_stat, inverse_of: :result_links diff --git a/db/migrate/20230601085414_create_result_links.rb b/db/migrate/20230601085414_create_result_links.rb index 8ee357a..1b9d9b9 100644 --- a/db/migrate/20230601085414_create_result_links.rb +++ b/db/migrate/20230601085414_create_result_links.rb @@ -9,8 +9,5 @@ def change t.timestamps end - - add_index :result_links, :link_type - add_index :result_links, :url end end diff --git a/db/migrate/20230612121926_change_link_type_to_string_in_result_links.rb b/db/migrate/20230612121926_change_link_type_to_string_in_result_links.rb new file mode 100644 index 0000000..06ae3e4 --- /dev/null +++ b/db/migrate/20230612121926_change_link_type_to_string_in_result_links.rb @@ -0,0 +1,5 @@ +class ChangeLinkTypeToStringInResultLinks < ActiveRecord::Migration[7.0] + def change + change_column :result_links, :link_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0989781..5f377a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_06_08_032015) do +ActiveRecord::Schema.define(version: 2023_06_12_121926) do # These are extensions that must be enabled in order to support this database enable_extension "citext" @@ -18,7 +18,7 @@ create_table "result_links", force: :cascade do |t| t.bigint "search_stat_id", null: false - t.integer "link_type", null: false + t.string "link_type", null: false t.string "url", null: false t.datetime "created_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false t.datetime "updated_at", precision: 6, default: -> { "CURRENT_TIMESTAMP" }, null: false diff --git a/db/seeds.rb b/db/seeds.rb index 8996b03..5ebbdc8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -12,5 +12,5 @@ user = User.where(email: 'user@demo.com').first_or_create(Fabricate.attributes_for(:user, email: 'user@demo.com')) 10.times do - Fabricate.times(100, :search_stat_parsed_with_links, user: user) + Fabricate.times(100, :search_stat, user: user) end diff --git a/spec/fabricators/result_link_fabricator.rb b/spec/fabricators/result_link_fabricator.rb index 46a16cf..9e745b7 100644 --- a/spec/fabricators/result_link_fabricator.rb +++ b/spec/fabricators/result_link_fabricator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Fabricator(:result_link) do - link_type { FFaker.rand 3 } + link_type { ResultLink.link_types.keys.sample } url { FFaker::Internet.http_url } end From fc3e324ea6b1eac7254683bd63fa71cc1e5e6400 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 12 Jun 2023 19:37:08 +0700 Subject: [PATCH 30/52] [#11] Update config/initializers/pagy.rb Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- config/initializers/pagy.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index d64e859..b2b7b0b 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -6,5 +6,4 @@ # Override default options Pagy::DEFAULT[:items] = 5 Pagy::DEFAULT[:size] = [1, 2, 2, 1] - Pagy::DEFAULT[:overflow] = :last_page From 8730d24f608075e0a38eb61c9f9401edfe1ffaa1 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Fri, 16 Jun 2023 11:16:36 +0700 Subject: [PATCH 31/52] [#11] Add css :after for search stats details --- app/assets/stylesheets/application.scss | 2 +- .../stylesheets/components/search_stat_details.scss | 3 +++ app/views/search_stats/show.html.erb | 12 ++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 app/assets/stylesheets/components/search_stat_details.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b578cd7..5e3a681 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -14,5 +14,5 @@ // Layouts // Components - +@import './components/search_stat_details.scss' // Screens diff --git a/app/assets/stylesheets/components/search_stat_details.scss b/app/assets/stylesheets/components/search_stat_details.scss new file mode 100644 index 0000000..a55dbee --- /dev/null +++ b/app/assets/stylesheets/components/search_stat_details.scss @@ -0,0 +1,3 @@ +.title::after { + content: ":"; +} diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 79893f9..3a47c59 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -13,33 +13,33 @@

- <%= SearchStat.human_attribute_name(:keyword) %>: + <%= SearchStat.human_attribute_name(:keyword) %> <%= @search_stat.keyword %>

- <%= SearchStat.human_attribute_name(:ad_count_top) %>: + <%= SearchStat.human_attribute_name(:ad_count_top) %> <%= @search_stat.top_ad_count %>

- <%= SearchStat.human_attribute_name(:ad_count) %>: + <%= SearchStat.human_attribute_name(:ad_count) %> <%= @search_stat.ad_count %>

- <%= SearchStat.human_attribute_name(:non_ad_count) %>: + <%= SearchStat.human_attribute_name(:non_ad_count) %> <%= @search_stat.non_ad_count %>

- <%= SearchStat.human_attribute_name(:link_count) %>: + <%= SearchStat.human_attribute_name(:link_count) %> <%= @search_stat.link_count %>

- <%= SearchStat.human_attribute_name(:total_result_count) %>: + <%= SearchStat.human_attribute_name(:total_result_count) %> <%= @search_stat.total_result_count %>

From 9a8839b865a09c4a3415abfa228fbf8056d6acbf Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Fri, 16 Jun 2023 11:22:59 +0700 Subject: [PATCH 32/52] [#11] Fix style --- app/assets/stylesheets/application.scss | 2 +- app/assets/stylesheets/components/search_stat_details.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5e3a681..5ede441 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -14,5 +14,5 @@ // Layouts // Components -@import './components/search_stat_details.scss' +@import './components/search_stat_details' // Screens diff --git a/app/assets/stylesheets/components/search_stat_details.scss b/app/assets/stylesheets/components/search_stat_details.scss index a55dbee..94efd45 100644 --- a/app/assets/stylesheets/components/search_stat_details.scss +++ b/app/assets/stylesheets/components/search_stat_details.scss @@ -1,3 +1,3 @@ .title::after { - content: ":"; + content: ':'; } From f3170c0501d44d7457d6f3b1933a84dc503da118 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 11:33:39 +0700 Subject: [PATCH 33/52] [#11] Change style implementation for search stat detail --- .../components/search_stat_details.scss | 6 ++++-- app/views/search_stats/show.html.erb | 14 +++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/components/search_stat_details.scss b/app/assets/stylesheets/components/search_stat_details.scss index 94efd45..ed75ec1 100644 --- a/app/assets/stylesheets/components/search_stat_details.scss +++ b/app/assets/stylesheets/components/search_stat_details.scss @@ -1,3 +1,5 @@ -.title::after { - content: ':'; +.search_stat_detail { + &__title:after { + content: ':'; + } } diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 3a47c59..52923e2 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -7,39 +7,39 @@
-
+
<%= SearchStat.model_name.human %>

- <%= SearchStat.human_attribute_name(:keyword) %> + <%= SearchStat.human_attribute_name(:keyword) %> <%= @search_stat.keyword %>

- <%= SearchStat.human_attribute_name(:ad_count_top) %> + <%= SearchStat.human_attribute_name(:ad_count_top) %> <%= @search_stat.top_ad_count %>

- <%= SearchStat.human_attribute_name(:ad_count) %> + <%= SearchStat.human_attribute_name(:ad_count) %> <%= @search_stat.ad_count %>

- <%= SearchStat.human_attribute_name(:non_ad_count) %> + <%= SearchStat.human_attribute_name(:non_ad_count) %> <%= @search_stat.non_ad_count %>

- <%= SearchStat.human_attribute_name(:link_count) %> + <%= SearchStat.human_attribute_name(:link_count) %> <%= @search_stat.link_count %>

- <%= SearchStat.human_attribute_name(:total_result_count) %> + <%= SearchStat.human_attribute_name(:total_result_count) %> <%= @search_stat.total_result_count %>

From 3b2cf62318f19465106198b7ebbebc090ea135b7 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 11:50:32 +0700 Subject: [PATCH 34/52] [#11] Change case for search stat detail class name --- .../components/search_stat_details.scss | 4 ++-- app/views/search_stats/show.html.erb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/components/search_stat_details.scss b/app/assets/stylesheets/components/search_stat_details.scss index ed75ec1..2e8a5f3 100644 --- a/app/assets/stylesheets/components/search_stat_details.scss +++ b/app/assets/stylesheets/components/search_stat_details.scss @@ -1,5 +1,5 @@ -.search_stat_detail { - &__title:after { +.search-stat-detail { + &__title::after { content: ':'; } } diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 52923e2..12ab98e 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -7,39 +7,39 @@
-
+
<%= SearchStat.model_name.human %>

- <%= SearchStat.human_attribute_name(:keyword) %> + <%= SearchStat.human_attribute_name(:keyword) %> <%= @search_stat.keyword %>

- <%= SearchStat.human_attribute_name(:ad_count_top) %> + <%= SearchStat.human_attribute_name(:ad_count_top) %> <%= @search_stat.top_ad_count %>

- <%= SearchStat.human_attribute_name(:ad_count) %> + <%= SearchStat.human_attribute_name(:ad_count) %> <%= @search_stat.ad_count %>

- <%= SearchStat.human_attribute_name(:non_ad_count) %> + <%= SearchStat.human_attribute_name(:non_ad_count) %> <%= @search_stat.non_ad_count %>

- <%= SearchStat.human_attribute_name(:link_count) %> + <%= SearchStat.human_attribute_name(:link_count) %> <%= @search_stat.link_count %>

- <%= SearchStat.human_attribute_name(:total_result_count) %> + <%= SearchStat.human_attribute_name(:total_result_count) %> <%= @search_stat.total_result_count %>

From 807967188578112fd3049d50e048c99a83e2d62f Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 11:59:19 +0700 Subject: [PATCH 35/52] [#11] Move raw response modal js file location --- app/javascript/application.js | 2 +- .../{raw_response_modal.js => raw_response_modal/index.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename app/javascript/components/{raw_response_modal.js => raw_response_modal/index.js} (100%) diff --git a/app/javascript/application.js b/app/javascript/application.js index 24b1354..afd294f 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -4,4 +4,4 @@ import './translations/translations'; import './initializers/'; import './screens/'; -import './components/raw_response_modal'; +import './components/raw_response_modal/index'; diff --git a/app/javascript/components/raw_response_modal.js b/app/javascript/components/raw_response_modal/index.js similarity index 100% rename from app/javascript/components/raw_response_modal.js rename to app/javascript/components/raw_response_modal/index.js From 78e96e53bc4ca3a1177dd631c17def958195bbf7 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 12:04:35 +0700 Subject: [PATCH 36/52] [#11] Change button element type in search stats table --- app/views/search_stats/_search_stat.html.erb | 2 +- config/locales/en.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/search_stats/_search_stat.html.erb b/app/views/search_stats/_search_stat.html.erb index 7d8c770..1556e46 100644 --- a/app/views/search_stats/_search_stat.html.erb +++ b/app/views/search_stats/_search_stat.html.erb @@ -4,6 +4,6 @@
diff --git a/config/locales/en.yml b/config/locales/en.yml index 3bf5b15..73427d9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,5 +45,6 @@ en: total_result_count: Total result count user_id: User buttons: - search_stat_details: Show Details raw_response: View Raw Response + links: + search_stat_details: Show Details From f895479d94881f752f3ce49807f183db534ebc53 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 12:13:58 +0700 Subject: [PATCH 37/52] [#11] Remove wrapping p tag from raw response button --- app/views/search_stats/show.html.erb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 12ab98e..6fe7c93 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -44,11 +44,9 @@

-

- <%= button_tag t('buttons.raw_response'), class: 'btn btn-primary', - onclick: "openRawResponse('#{j @search_stat.raw_response}')"%> -

- + <%= button_tag t('buttons.raw_response'), class: 'btn btn-primary', + onclick: "openRawResponse('#{j @search_stat.raw_response}')"%> +

<%= SearchStat.human_attribute_name(:total_result_count) %>: <%= @search_stat.user_id %> From 055a969b21ebddfd965f767c79e02c0fdf7de979 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 12:30:43 +0700 Subject: [PATCH 38/52] [#11] Localise search stat ads and non ads title --- app/views/search_stats/show.html.erb | 4 ++-- config/locales/en.yml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 6fe7c93..3eebe2e 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -58,7 +58,7 @@

-
List of URLs of AdWords Advertisers in Top Position
+
<%=t('titles.top_ads')%>
    <% @search_stat.result_links.ads_top.or(@search_stat.result_links.non_ads).each do |result_link| %>
  • @@ -71,7 +71,7 @@
    -
    List of URLs of Non-AdWords Results on the Page
    +
    <%=t('titles.non_ads')%>
      <% @search_stat.result_links.non_ads.each do |result_link| %>
    • diff --git a/config/locales/en.yml b/config/locales/en.yml index 73427d9..d3a3ba1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,3 +48,6 @@ en: raw_response: View Raw Response links: search_stat_details: Show Details + titles: + top_ads: List of URLs of AdWords Advertisers in Top Position + non_ads: List of URLs of Non-AdWords Results on the Page From 51725d55ade6f598c7bab4067416eaaa18b32cca Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 12:57:45 +0700 Subject: [PATCH 39/52] [#11] Use bootstrap to show raw response modal --- app/views/search_stats/_raw_response_modal.html.erb | 5 +++-- app/views/search_stats/show.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/search_stats/_raw_response_modal.html.erb b/app/views/search_stats/_raw_response_modal.html.erb index c024036..a59c746 100644 --- a/app/views/search_stats/_raw_response_modal.html.erb +++ b/app/views/search_stats/_raw_response_modal.html.erb @@ -3,10 +3,11 @@
    diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 3eebe2e..a0f0304 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -44,9 +44,9 @@

    - <%= button_tag t('buttons.raw_response'), class: 'btn btn-primary', - onclick: "openRawResponse('#{j @search_stat.raw_response}')"%> - +

    <%= SearchStat.human_attribute_name(:total_result_count) %>: <%= @search_stat.user_id %> From 47dd383b55b4a7c6506b30bec693555d911e761a Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 12:58:13 +0700 Subject: [PATCH 40/52] [#11] Localise back button in search stat details page --- app/views/search_stats/show.html.erb | 2 +- config/locales/en.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index a0f0304..2a2234f 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -2,7 +2,7 @@

    <%= link_to search_stats_path, class: "btn btn-primary m-1" do %> - Back + <%= t('buttons.back') %> <% end %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index d3a3ba1..5aa11c7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -46,6 +46,7 @@ en: user_id: User buttons: raw_response: View Raw Response + back: Back links: search_stat_details: Show Details titles: From b390c72de2f1e2eae8cd20a23419a764b7f93fbf Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:01:20 +0700 Subject: [PATCH 41/52] [#11] Remove unnecessary js file --- app/javascript/application.js | 1 - .../components/raw_response_modal/index.js | 22 ------------------- 2 files changed, 23 deletions(-) delete mode 100644 app/javascript/components/raw_response_modal/index.js diff --git a/app/javascript/application.js b/app/javascript/application.js index afd294f..a90b449 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -4,4 +4,3 @@ import './translations/translations'; import './initializers/'; import './screens/'; -import './components/raw_response_modal/index'; diff --git a/app/javascript/components/raw_response_modal/index.js b/app/javascript/components/raw_response_modal/index.js deleted file mode 100644 index cf4aadb..0000000 --- a/app/javascript/components/raw_response_modal/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import { Modal } from 'bootstrap'; - -function openRawResponse(rawResponse) { - var modal = new Modal(document.getElementById('rawResponseModal')); - var iframe = document.getElementById('rawResponseIframe'); - iframe.srcdoc = rawResponse; - modal.show(); -} - -function closeRawResponse() { - var modal = Modal.getInstance(document.getElementById('rawResponseModal')); - - // Close the modal - if (modal) { - modal.hide(); - } -} - -var closeButton = document.querySelector('#rawResponseModal .btn-close'); -closeButton.addEventListener('click', closeRawResponse); - -window.openRawResponse = openRawResponse; From 5bf2a10213c512bb303f48d3fcc154488b9fa38c Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:06:04 +0700 Subject: [PATCH 42/52] [#11] Localise no search stat found message --- app/views/search_stats/index.html.erb | 2 +- config/locales/en.yml | 1 + db/schema.rb | 31 ++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/views/search_stats/index.html.erb b/app/views/search_stats/index.html.erb index d7ef5d2..15e5ffd 100644 --- a/app/views/search_stats/index.html.erb +++ b/app/views/search_stats/index.html.erb @@ -22,7 +22,7 @@ <%== pagy_bootstrap_nav(@pagy) %> <% else %>
    -

    No search stats found.

    +

    <%= t('titles.no_stats')%>

    <% end %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 5aa11c7..39c1572 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -52,3 +52,4 @@ en: titles: top_ads: List of URLs of AdWords Advertisers in Top Position non_ads: List of URLs of Non-AdWords Results on the Page + no_stats: No search stats found diff --git a/db/schema.rb b/db/schema.rb index 5f377a0..fd91cf5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,40 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_06_12_121926) do +ActiveRecord::Schema.define(version: 2023_06_15_070454) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "plpgsql" + create_table "oauth_access_tokens", force: :cascade do |t| + t.bigint "resource_owner_id" + t.bigint "application_id", null: false + t.string "token", null: false + t.string "refresh_token" + t.integer "expires_in" + t.string "scopes" + t.datetime "created_at", precision: 6, null: false + t.datetime "revoked_at", precision: 6 + t.string "previous_refresh_token", default: "", null: false + t.index ["application_id"], name: "index_oauth_access_tokens_on_application_id" + t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true + t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id" + t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true + end + + create_table "oauth_applications", force: :cascade do |t| + t.string "name", null: false + t.string "uid", null: false + t.string "secret", null: false + t.text "redirect_uri" + t.string "scopes", default: "", null: false + t.boolean "confidential", default: true, null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true + end + create_table "result_links", force: :cascade do |t| t.bigint "search_stat_id", null: false t.string "link_type", null: false @@ -54,6 +82,7 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id" add_foreign_key "result_links", "search_stats" add_foreign_key "search_stats", "users" end From 70600016a18c03971815b73f136cc111d85c7a65 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:10:16 +0700 Subject: [PATCH 43/52] [#11] Show only top ads in top ads section of search stat details --- app/views/search_stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 2a2234f..112007a 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -60,7 +60,7 @@
    <%=t('titles.top_ads')%>
      - <% @search_stat.result_links.ads_top.or(@search_stat.result_links.non_ads).each do |result_link| %> + <% @search_stat.result_links.ads_top.each do |result_link| %>
    • <%= link_to result_link.url, result_link.url %>
    • From af093c8f2503f953a2b61489de4b8028267e1e3c Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:12:58 +0700 Subject: [PATCH 44/52] [#11] Use single quote for rails string in detail page Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- app/views/search_stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index 112007a..e75d93f 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -75,7 +75,7 @@
        <% @search_stat.result_links.non_ads.each do |result_link| %>
      • - <%= link_to result_link.url, result_link.url, target: "_blank" %> + <%= link_to result_link.url, result_link.url, target: '_blank' %>
      • <% end %>
      From 7ea292090c3620e45e3159d7233806e5f545ec12 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:14:48 +0700 Subject: [PATCH 45/52] [#11] Sort en.yml in alphabetical order --- config/locales/en.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 39c1572..6c5868c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,11 +45,11 @@ en: total_result_count: Total result count user_id: User buttons: - raw_response: View Raw Response back: Back + raw_response: View Raw Response links: search_stat_details: Show Details titles: - top_ads: List of URLs of AdWords Advertisers in Top Position - non_ads: List of URLs of Non-AdWords Results on the Page no_stats: No search stats found + non_ads: List of URLs of Non-AdWords Results on the Page + top_ads: List of URLs of AdWords Advertisers in Top Position From d4b5083f5b15c30828b429d6c5b92292ed29e7ba Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 13:18:36 +0700 Subject: [PATCH 46/52] [#11] Create user explicitly in seeds.rb --- db/seeds.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index 5ebbdc8..72d0a27 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,7 +9,10 @@ require 'fabrication' # Generate dummy data for SearchStat -user = User.where(email: 'user@demo.com').first_or_create(Fabricate.attributes_for(:user, email: 'user@demo.com')) + +user = User.find_or_initialize_by(email: 'user@demo.com') do |user| + user.password = 'aaaaaaA1' +end 10.times do Fabricate.times(100, :search_stat, user: user) From 12b315e490ff562154aef727e72417f9ffb6f26f Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Mon, 19 Jun 2023 15:44:45 +0700 Subject: [PATCH 47/52] [#11] Sanitize raw response before showing in modal --- app/views/search_stats/_raw_response_modal.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/search_stats/_raw_response_modal.html.erb b/app/views/search_stats/_raw_response_modal.html.erb index a59c746..74d515f 100644 --- a/app/views/search_stats/_raw_response_modal.html.erb +++ b/app/views/search_stats/_raw_response_modal.html.erb @@ -6,7 +6,7 @@
From 57eeabf4618db0df33bbb75379122ac1af2677d0 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 20 Jun 2023 17:19:50 +0700 Subject: [PATCH 48/52] [#11] Update app/assets/stylesheets/application.scss Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- app/assets/stylesheets/application.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5ede441..d664df9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -15,4 +15,5 @@ // Components @import './components/search_stat_details' + // Screens From 0f869cce36093a1b67ef7167e4f8c28d33a06222 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Tue, 20 Jun 2023 17:20:46 +0700 Subject: [PATCH 49/52] [#11] Update app/controllers/search_stats_controller.rb Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- app/controllers/search_stats_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/search_stats_controller.rb b/app/controllers/search_stats_controller.rb index f426438..02d6557 100644 --- a/app/controllers/search_stats_controller.rb +++ b/app/controllers/search_stats_controller.rb @@ -7,6 +7,6 @@ def index end def show - @search_stat = SearchStat.includes(:result_links).find(params[:id]) + @search_stat = current_user.search_stats.includes(:result_links).find(params[:id]) end end From 7c64ab67da1bef63be96cb39f761931851712988 Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 22 Jun 2023 11:18:27 +0700 Subject: [PATCH 50/52] [#11] Add indentation in search stat details page --- app/views/search_stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/search_stats/show.html.erb b/app/views/search_stats/show.html.erb index e75d93f..3562b46 100644 --- a/app/views/search_stats/show.html.erb +++ b/app/views/search_stats/show.html.erb @@ -82,5 +82,5 @@
-<%= render 'raw_response_modal' %> + <%= render 'raw_response_modal' %> From e896cb48d93afc28206bab0f8931cdec86e3fcbb Mon Sep 17 00:00:00 2001 From: Md Mosharaf Hossan Date: Thu, 22 Jun 2023 12:23:47 +0700 Subject: [PATCH 51/52] [#11] Extract raw response modal iframe style to assets css --- app/assets/stylesheets/application.scss | 3 ++- app/assets/stylesheets/components/_raw-response-modal.scss | 7 +++++++ app/views/search_stats/_raw_response_modal.html.erb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/components/_raw-response-modal.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d664df9..4e020bf 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -14,6 +14,7 @@ // Layouts // Components -@import './components/search_stat_details' +@import './components/search_stat_details'; +@import './components/raw-response-modal'; // Screens diff --git a/app/assets/stylesheets/components/_raw-response-modal.scss b/app/assets/stylesheets/components/_raw-response-modal.scss new file mode 100644 index 0000000..314559f --- /dev/null +++ b/app/assets/stylesheets/components/_raw-response-modal.scss @@ -0,0 +1,7 @@ +.raw-response-modal { + iframe { + width: 100%; + height: 80vh; + border: none; + } +} diff --git a/app/views/search_stats/_raw_response_modal.html.erb b/app/views/search_stats/_raw_response_modal.html.erb index 74d515f..fa92bb8 100644 --- a/app/views/search_stats/_raw_response_modal.html.erb +++ b/app/views/search_stats/_raw_response_modal.html.erb @@ -1,4 +1,4 @@ -
<%= I18n.t('search_stat.keyword') %><%= I18n.t('search_stat.ad_count') %><%= I18n.t('search_stat.link_count') %><%= I18n.t('search_stat.total_result_count') %><%= I18n.t('search_stat.action') %><%= SearchStat.human_attribute_name(:keyword) %><%= SearchStat.human_attribute_name(:ad_count) %><%= SearchStat.human_attribute_name(:link_count) %><%= SearchStat.human_attribute_name(:total_result_count) %>
<%= search_stat.keyword %><%= search_stat.ad_count %><%= search_stat.link_count %><%= search_stat.total_result_count %> + <%= button_to 'Show Details', search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %> +
<%= search_stat.link_count %> <%= search_stat.total_result_count %> - <%= button_to 'Show Details', search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %> + <%= button_to t('buttons.search_stat_details'), search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %>
<%= search_stat.link_count %> <%= search_stat.total_result_count %> - <%= button_to t('buttons.search_stat_details'), search_stat_path(search_stat), method: :get, class: 'btn btn-primary' %> + <%= link_to t('links.search_stat_details'), search_stat_path(search_stat), class: 'btn btn-primary' %>