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

-<% content_for :footer_scripts do %>
-<%= javascript_include_tag 'jquery-sortable' %>
-  
-<% end %>
+        
+        
+          <%= pp.name %>
+        
+      
+    <% end %>
+  
+
diff --git a/app/views/admin/all_page/index.html.erb b/app/views/admin/all_page/index.html.erb
index 5ab286d..f82d5db 100644
--- a/app/views/admin/all_page/index.html.erb
+++ b/app/views/admin/all_page/index.html.erb
@@ -12,7 +12,6 @@
     
   
 
-<% if false %>
 
@@ -21,10 +20,9 @@
-
+
<%= render 'published_pages_priority' %>
-<% end %> diff --git a/app/views/admin/all_page/pp_priority_down.js.erb b/app/views/admin/all_page/pp_priority_down.js.erb new file mode 100644 index 0000000..246f178 --- /dev/null +++ b/app/views/admin/all_page/pp_priority_down.js.erb @@ -0,0 +1 @@ +$('#pp_priority').html('<%= escape_javascript(render('/admin/all_page/published_pages_priority')) %>'); diff --git a/app/views/admin/all_page/pp_priority_up.js.erb b/app/views/admin/all_page/pp_priority_up.js.erb new file mode 100644 index 0000000..246f178 --- /dev/null +++ b/app/views/admin/all_page/pp_priority_up.js.erb @@ -0,0 +1 @@ +$('#pp_priority').html('<%= escape_javascript(render('/admin/all_page/published_pages_priority')) %>'); diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb index 60cf235..28be1ec 100644 --- a/app/views/admin/home/index.html.erb +++ b/app/views/admin/home/index.html.erb @@ -1 +1,44 @@ -

ToDo - Zmiana hasła, do logowania

+
+ +
+ +
+
+

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/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 78ac487..2b189f7 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -3,7 +3,7 @@ Ubezpieczenie - Należności - Panel Administracyjny <%= csrf_meta_tags %> - <%= favicon_link_tag %> + <%= stylesheet_link_tag 'application','bootstrap_lte' , 'font-awesome' , media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'AdminLTE', 'skin-blue', 'summernote' %> @@ -41,11 +41,6 @@ <%= current_admin.email %>