diff --git a/app/controllers/admin/all_page_controller.rb b/app/controllers/admin/all_page_controller.rb index 5a9f9a3..bc7e392 100644 --- a/app/controllers/admin/all_page_controller.rb +++ b/app/controllers/admin/all_page_controller.rb @@ -3,7 +3,7 @@ class Admin::AllPageController < ApplicationController layout 'admin' def index @all_pages = AllPage.where('type_of != 3') - @published_pages = PublishedPage.where('type_of = 1 OR type_of = 2').order('priority ASC') + get_pp_pages end def show @@ -64,8 +64,27 @@ class Admin::AllPageController < ApplicationController redirect_to action: 'index' end - def change_priority + def pp_priority_up + pp_this = PublishedPage.find(params[:id]) + pp_this_prio = pp_this.priority + pp_last = PublishedPage.where('(type_of = 1 OR type_of = 2) AND priority < ?', pp_this_prio).order('priority DESC').first + pp_this.priority = pp_last.priority + pp_this.save + pp_last.priority = pp_this_prio + pp_last.save + get_pp_pages + end + + def pp_priority_down + pp_this = PublishedPage.find(params[:id]) + pp_this_prio = pp_this.priority + pp_last = PublishedPage.where('(type_of = 1 OR type_of = 2) AND priority > ?', pp_this_prio).order('priority ASC').first + pp_this.priority = pp_last.priority + pp_this.save + pp_last.priority = pp_this_prio + pp_last.save + get_pp_pages end def publish @@ -121,6 +140,12 @@ class Admin::AllPageController < ApplicationController end end + def get_pp_pages + @published_pages = PublishedPage.where('type_of = 1 OR type_of = 2').order('priority ASC') + @pp_first = PublishedPage.where('type_of = 1 OR type_of = 2').order('priority ASC').first + @pp_last = PublishedPage.where('type_of = 1 OR type_of = 2').order('priority DESC').first + end + private def all_page_params params.require(:all_page).permit(:name, :article_id, :title, :type_of, :full_text) diff --git a/app/controllers/admin/home_controller.rb b/app/controllers/admin/home_controller.rb index 0dcd677..e7c2745 100644 --- a/app/controllers/admin/home_controller.rb +++ b/app/controllers/admin/home_controller.rb @@ -2,6 +2,26 @@ class Admin::HomeController < ApplicationController before_action :authenticate_admin! layout 'admin' def index - @adm = Admin.all + @admin = current_admin + end + + def change_pass + @admin = current_admin + if params[:admin][:password].blank? + params[:admin].delete(:password) + params[:admin].delete(:password_confirmation) + end + if @admin.update(admin_params) + bypass_sign_in(@admin) + redirect_to action: 'index' + else + render "index" + end + end + + private + + def admin_params + params.require(:admin).permit(:description, :password, :password_confirmation) end end diff --git a/app/models/all_page.rb b/app/models/all_page.rb index df2ea4b..e58ca4f 100644 --- a/app/models/all_page.rb +++ b/app/models/all_page.rb @@ -5,7 +5,11 @@ class AllPage < ApplicationRecord belongs_to :article, optional: true has_one :published_page before_destroy :b_destroy - + + def should_generate_new_friendly_id? + slug.blank? || title_changed? + end + PAGE_TYPES = { 1 => 'Strona zwykła', 2 => 'Strona z listą wpisów', diff --git a/app/models/published_page.rb b/app/models/published_page.rb index f75cd26..fb3f835 100644 --- a/app/models/published_page.rb +++ b/app/models/published_page.rb @@ -4,11 +4,17 @@ class PublishedPage < ApplicationRecord belongs_to :all_page belongs_to :article, optional: true + + def should_generate_new_friendly_id? + slug.blank? || title_changed? + end + def published true end def created_name - Admin.find(self.created_by).description + admin = Admin.find(self.created_by) + admin.blank? ? 'nieznany' : admin.description end def created_date diff --git a/app/views/admin/all_page/_published_pages_priority.html.erb b/app/views/admin/all_page/_published_pages_priority.html.erb index 6a1dcfe..5ea46ae 100644 --- a/app/views/admin/all_page/_published_pages_priority.html.erb +++ b/app/views/admin/all_page/_published_pages_priority.html.erb @@ -1,31 +1,29 @@ -
ToDo - Zmiana hasła, do logowania
+