diff --git a/app/controllers/admin/home_controller.rb b/app/controllers/admin/home_controller.rb index e7c2745..15d2b93 100644 --- a/app/controllers/admin/home_controller.rb +++ b/app/controllers/admin/home_controller.rb @@ -3,10 +3,12 @@ class Admin::HomeController < ApplicationController layout 'admin' def index @admin = current_admin + pp_pages_get end def change_pass @admin = current_admin + pp_pages_get if params[:admin][:password].blank? params[:admin].delete(:password) params[:admin].delete(:password_confirmation) @@ -19,6 +21,12 @@ class Admin::HomeController < ApplicationController end end + def pp_pages_get + @published_pages = PublishedPage.where('type_of = 1 OR type_of = 2').order('priority ASC') + @pp = PublishedPage.where('type_of = 1 OR type_of = 2').order('number_of_views DESC').first + @sc_setting = ScSetting.first + end + private def admin_params diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index dc78abf..e111fbf 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -2,18 +2,55 @@ class SiteController < ApplicationController #include RecaptchaVerifier def index @pages = PublishedPage.where('type_of != 3').order('priority ASC') - @adm = Admin.all + @ss = ScSetting.first + pg_name = 'index' + if cookies.encrypted[:visited].blank? + cookies.encrypted[:visited] = JSON.generate([pg_name]) + @ss.increment!(:index_number_of_views) + else + arr = JSON.parse(cookies.encrypted[:visited]) + if !arr.include?(pg_name) + arr << pg_name + cookies.encrypted[:visited] = JSON.generate(arr) + @ss.increment!(:index_number_of_views) + end + end end def show pages_get @page = PublishedPage.where('id = ? OR slug = ?',params[:id],params[:id]).first + if cookies.encrypted[:visited].blank? + cookies.encrypted[:visited] = JSON.generate([@page.id]) + @page.increment!(:number_of_views) + else + arr = JSON.parse(cookies.encrypted[:visited]) + if !arr.include?(@page.id) + arr << @page.id + cookies.encrypted[:visited] = JSON.generate(arr) + @page.increment!(:number_of_views) + end + end + if @page.blank? redirect_to '/404.html' end end def kontakt + @ss = ScSetting.first + pg_name = 'kontakt' + if cookies.encrypted[:visited].blank? + cookies.encrypted[:visited] = JSON.generate([pg_name]) + @ss.increment!(:contact_number_of_views) + else + arr = JSON.parse(cookies.encrypted[:visited]) + if !arr.include?(pg_name) + arr << pg_name + cookies.encrypted[:visited] = JSON.generate(arr) + @ss.increment!(:contact_number_of_views) + end + end pages_get end diff --git a/app/models/admin.rb b/app/models/admin.rb index ee11a20..ffb5bbc 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -1,6 +1,6 @@ class Admin < ApplicationRecord # Include default devise modules. Others available are: - # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, + # :confirmable, :lockable, :timeoutable and :omniauthable, :registerable, + devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable end diff --git a/app/models/sc_setting.rb b/app/models/sc_setting.rb new file mode 100644 index 0000000..4b9b3b0 --- /dev/null +++ b/app/models/sc_setting.rb @@ -0,0 +1,3 @@ +class ScSetting < ApplicationRecord + +end diff --git a/app/views/admin/all_page/_all_pages.html.erb b/app/views/admin/all_page/_all_pages.html.erb index 867c754..5c3fa1f 100644 --- a/app/views/admin/all_page/_all_pages.html.erb +++ b/app/views/admin/all_page/_all_pages.html.erb @@ -11,6 +11,7 @@ Nazwa Publiczna/Aktualna Tytuł + Wyświetleń Rodzaj Data utworzenia Akcje @@ -20,6 +21,7 @@ <%= ap.name %> <%= link_to raw(ap.published_page ? 'Tak' : 'Nie'), (ap.published_page ? {controller: '/admin/all_page', action: 'unpublish', id: ap.id} : {controller: '/admin/all_page', action: 'publish', id: ap.id}), remote: true %>/<%= raw(ap.published.eql?(true) ? 'Tak' : 'Nie') %> <%= ap.title %> + <%= ap.published_page ? ap.published_page.number_of_views : '-' %> <%= AllPage::PAGE_TYPES[ap.type_of] %> <%= ap.updated_at %> diff --git a/app/views/admin/articles/all_page/_all_pages.html.erb b/app/views/admin/articles/all_page/_all_pages.html.erb index 97a2014..c7ef623 100644 --- a/app/views/admin/articles/all_page/_all_pages.html.erb +++ b/app/views/admin/articles/all_page/_all_pages.html.erb @@ -11,6 +11,7 @@ Nazwa Publiczna/Aktualna Tytuł + Wyświetleń Rodzaj Data utworzenia Akcje @@ -20,6 +21,7 @@ <%= ap.name %> <%= link_to raw(ap.published_page ? 'Tak' : 'Nie'), (ap.published_page ? {controller: '/admin/all_page', action: 'unpublish', id: ap.id} : {controller: '/admin/all_page', action: 'publish', id: ap.id}), remote: true %>/<%= raw(ap.published.eql?(true) ? 'Tak' : 'Nie') %> <%= ap.title %> + <%= ap.published_page ? ap.published_page.number_of_views : '-' %> <%= AllPage::PAGE_TYPES[ap.type_of] %> <%= ap.updated_at %> diff --git a/app/views/admin/home/_dashboard.html.erb b/app/views/admin/home/_dashboard.html.erb new file mode 100644 index 0000000..6a771ef --- /dev/null +++ b/app/views/admin/home/_dashboard.html.erb @@ -0,0 +1,26 @@ +
+
+

Wyświetlenia stron

+
+ + + + + + + + + + + + + + <% for p in @published_pages %> + + + + + <% end %> +
StronaIlość wyświetleń
Strona główna<%= @sc_setting.index_number_of_views %>
Kontakt<%= @sc_setting.contact_number_of_views %>
<%= p.name %><%= p.number_of_views %>
+ +
diff --git a/app/views/admin/home/_user_form.html.erb b/app/views/admin/home/_user_form.html.erb new file mode 100644 index 0000000..07a8fd5 --- /dev/null +++ b/app/views/admin/home/_user_form.html.erb @@ -0,0 +1,27 @@ +
+
+

Zmiana danych

+
+ <%= form_tag({controller: '/admin/home', action: :change_pass}) do %> +
+ <% if @admin.errors.any? %> + <%= raw errors_to_html(@admin.errors) %> + <% end %> +
+ + <%= text_field :admin, :description, class: "form-control", placeholder: 'Opis' %> +
+
+ + <%= password_field :admin, :password, class: "form-control", placeholder: 'Nowe Hasło' %> +
+
+ + <%= password_field :admin, :password_confirmation, class: "form-control", placeholder: 'Powtórz Nowe Hasło' %> +
+
+ + <% end %> +
diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb index 28be1ec..fec23e5 100644 --- a/app/views/admin/home/index.html.erb +++ b/app/views/admin/home/index.html.erb @@ -1,44 +1,45 @@
- -
- -
-
-

Zmiana danych

+
+
+
+

<%= @pp.number_of_views %>

+ +

Najwięcej wyświetleń:
<%= @pp.name %>

+
+
+
- - - <%= form_tag({controller: '/admin/home', action: :change_pass}) do %> -
- <% if @admin.errors.any? %> - <%= raw errors_to_html(@admin.errors) %> - <% end %> -
- - <%= text_field :admin, :description, class: "form-control", placeholder: 'Opis' %> -
-
- - <%= password_field :admin, :password, class: "form-control", placeholder: 'Nowe Hasło' %> -
-
- - <%= password_field :admin, :password_confirmation, class: "form-control", placeholder: 'Powtórz Nowe Hasło' %> -
-
- - - - <% end %>
- -
- - -
+
+
+
+

<%= @sc_setting.index_number_of_views %>

+

Wyświetleń dla:
Strona główna

+
+
+ +
+
+
+
+
+
+

<%= @sc_setting.contact_number_of_views %>

+

Wyświetleń dla:
Kontakt

+
+
+ +
+
+
+
+ +
+
+ <%= render 'dashboard' %> +
+
+ <%= render 'user_form' %>
-
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 441ad0a..4c41944 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -62,9 +62,9 @@