This commit is contained in:
Adrian Hinz 2018-02-03 21:24:36 +01:00
parent f400fb56ba
commit 32d73f5791
10 changed files with 150 additions and 44 deletions

View File

@ -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

View File

@ -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

View File

@ -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

3
app/models/sc_setting.rb Normal file
View File

@ -0,0 +1,3 @@
class ScSetting < ApplicationRecord
end

View File

@ -11,6 +11,7 @@
<th>Nazwa</th>
<th>Publiczna/Aktualna</th>
<th>Tytuł</th>
<th>Wyświetleń</th>
<th>Rodzaj</th>
<th>Data utworzenia</th>
<th style="width: 200px">Akcje</th>
@ -20,6 +21,7 @@
<td><%= ap.name %></td>
<td id="publish_<%= ap.id %>"><%= link_to raw(ap.published_page ? '<span class="badge bg-green" title="Zdejmij publikację">Tak</span>' : '<span class="badge bg-red" title="Opublikuj">Nie</span>'), (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) ? '<span class="badge bg-green">Tak</span>' : '<span class="badge bg-red">Nie</span>') %></td>
<td><%= ap.title %></td>
<th><%= ap.published_page ? ap.published_page.number_of_views : '-' %></th>
<td><%= AllPage::PAGE_TYPES[ap.type_of] %></td>
<td><%= ap.updated_at %></td>
<td>

View File

@ -11,6 +11,7 @@
<th>Nazwa</th>
<th>Publiczna/Aktualna</th>
<th>Tytuł</th>
<th>Wyświetleń</th>
<th>Rodzaj</th>
<th>Data utworzenia</th>
<th style="width: 200px">Akcje</th>
@ -20,6 +21,7 @@
<td><%= ap.name %></td>
<td id="publish_<%= ap.id %>"><%= link_to raw(ap.published_page ? '<span class="badge bg-green" title="Zdejmij publikację">Tak</span>' : '<span class="badge bg-red" title="Opublikuj">Nie</span>'), (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) ? '<span class="badge bg-green">Tak</span>' : '<span class="badge bg-red">Nie</span>') %></td>
<td><%= ap.title %></td>
<th><%= ap.published_page ? ap.published_page.number_of_views : '-' %></th>
<td><%= AllPage::PAGE_TYPES[ap.type_of] %></td>
<td><%= ap.updated_at %></td>
<td>

View File

@ -0,0 +1,26 @@
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">Wyświetlenia stron</h3>
</div>
<table class="table table-bordered">
<tr>
<th>Strona</th>
<th>Ilość wyświetleń</th>
</tr>
<tr>
<td>Strona główna</td>
<td><%= @sc_setting.index_number_of_views %></td>
</tr>
<tr>
<td>Kontakt</td>
<td><%= @sc_setting.contact_number_of_views %></td>
</tr>
<% for p in @published_pages %>
<tr>
<td><%= p.name %></td>
<td><%= p.number_of_views %></td>
</tr>
<% end %>
</table>
</div>

View File

@ -0,0 +1,27 @@
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Zmiana danych</h3>
</div>
<%= form_tag({controller: '/admin/home', action: :change_pass}) do %>
<div class="box-body">
<% if @admin.errors.any? %>
<%= raw errors_to_html(@admin.errors) %>
<% end %>
<div class="form-group">
<label>Opis</label>
<%= text_field :admin, :description, class: "form-control", placeholder: 'Opis' %>
</div>
<div class="form-group">
<label>Nowe Hasło</label>
<%= password_field :admin, :password, class: "form-control", placeholder: 'Nowe Hasło' %>
</div>
<div class="form-group">
<label>Powrtórz Nowe Hasło</label>
<%= password_field :admin, :password_confirmation, class: "form-control", placeholder: 'Powtórz Nowe Hasło' %>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Zapisz</button>
</div>
<% end %>
</div>

View File

@ -1,44 +1,45 @@
<div class="row">
<!-- left column -->
<div class="col-md-6">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Zmiana danych</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<%= form_tag({controller: '/admin/home', action: :change_pass}) do %>
<div class="box-body">
<% if @admin.errors.any? %>
<%= raw errors_to_html(@admin.errors) %>
<% end %>
<div class="form-group">
<label>Opis</label>
<%= text_field :admin, :description, class: "form-control", placeholder: 'Opis' %>
</div>
<div class="form-group">
<label>Nowe Hasło</label>
<%= password_field :admin, :password, class: "form-control", placeholder: 'Nowe Hasło' %>
</div>
<div class="form-group">
<label>Powrtórz Nowe Hasło</label>
<%= password_field :admin, :password_confirmation, class: "form-control", placeholder: 'Powtórz Nowe Hasło' %>
</div>
</div>
<!-- /.box-body -->
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h3><%= @pp.number_of_views %></h3>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Zapisz</button>
<p>Najwięcej wyświetleń: <br /><strong><%= @pp.name %></strong></p>
</div>
<div class="icon">
<i class="fa fa-eye"></i>
</div>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-green">
<div class="inner">
<h3><%= @sc_setting.index_number_of_views %></h3>
<p>Wyświetleń dla: <br /><strong>Strona główna</strong></p>
</div>
<div class="icon">
<i class="fa fa-home"></i>
</div>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-yellow">
<div class="inner">
<h3><%= @sc_setting.contact_number_of_views %></h3>
<p>Wyświetleń dla: <br /><strong>Kontakt</strong></p>
</div>
<div class="icon">
<i class="fa fa-envelope-o"></i>
</div>
</div>
</div>
<% end %>
</div>
<!-- /.box -->
</div>
<!--/.col (left) -->
<!-- right column -->
<div class="row">
<div class="col-md-6">
<%= render 'dashboard' %>
</div>
<div class="col-md-6">
<%= render 'user_form' %>
</div>
<!--/.col (right) -->
</div>

View File

@ -63,9 +63,9 @@
<!-- Sidebar Menu -->
<ul class="sidebar-menu" data-widget="tree">
<li class="header">MENU</li>
<li <%= raw controller_path.to_s.include?('admin/home') ? 'class="active"' : '' %>><a href="/admin"><i class="fa fa-home"></i> <span>Home</span></a></li>
<li <%= raw controller_path.to_s.include?('admin/all_page') ? 'class="active"' : '' %>><a href="/admin/all_page"><i class="fa fa-sitemap"></i> <span>Strony</span></a></li>
<li <%= raw controller_path.to_s.include?('admin/article') ? 'class="active"' : '' %>><a href="/admin/article"><i class="fa fa-pencil-square-o"></i> <span>Grupy Wpisów</span></a></li>
<li <%= raw controller_path.to_s.include?('admin/home') ? 'class="active"' : '' %>><a href="/admin"><i class="fa fa-home text-aqua"></i> <span>Home</span></a></li>
<li <%= raw controller_path.to_s.include?('admin/all_page') ? 'class="active"' : '' %>><a href="/admin/all_page"><i class="fa fa-sitemap text-yellow"></i> <span>Strony</span></a></li>
<li <%= raw controller_path.to_s.include?('admin/article') ? 'class="active"' : '' %>><a href="/admin/article"><i class="fa fa-pencil-square-o text-green"></i> <span>Grupy Wpisów</span></a></li>
</ul>
<!-- /.sidebar-menu -->
</section>