added sortable

This commit is contained in:
Adrian Hinz 2022-06-28 14:56:01 +02:00
parent 24f8743ee6
commit a86b2b8995
20 changed files with 223 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -62,6 +62,20 @@ class CompanyActivitiesController < ApplicationController
end end
end end
def chg_prio
par = params[:ord].tr('sort_', '')
parray = par.split(',')
temp_i = 1
parray.each do |pa|
exp = CompanyActivity.where(id: pa).first
next if exp.blank?
exp.prio = temp_i
exp.save
temp_i += 1
end
end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

View File

@ -62,6 +62,20 @@ class CompanySizesController < ApplicationController
end end
end end
def chg_prio
par = params[:ord].tr('sort_', '')
parray = par.split(',')
temp_i = 1
parray.each do |pa|
exp = CompanySize.where(id: pa).first
next if exp.blank?
exp.prio = temp_i
exp.save
temp_i += 1
end
end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

View File

@ -62,6 +62,20 @@ class ExpensesController < ApplicationController
end end
end end
def chg_prio
par = params[:ord].tr('sort_', '')
parray = par.split(',')
temp_i = 1
parray.each do |pa|
exp = Expense.where(id: pa).first
next if exp.blank?
exp.prio = temp_i
exp.save
temp_i += 1
end
end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

View File

@ -62,6 +62,20 @@ class ProjectsController < ApplicationController
end end
end end
def chg_prio
par = params[:ord].tr('sort_', '')
parray = par.split(',')
temp_i = 1
parray.each do |pa|
exp = Project.where(id: pa).first
next if exp.blank?
exp.prio = temp_i
exp.save
temp_i += 1
end
end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

View File

@ -2,6 +2,7 @@
# CompanyActivity # CompanyActivity
class CompanyActivity < ApplicationRecord class CompanyActivity < ApplicationRecord
default_scope { order(prio: :asc) }
# == Constants ============================================================ # == Constants ============================================================
# == Attributes =========================================================== # == Attributes ===========================================================

View File

@ -2,6 +2,7 @@
# Company Size # Company Size
class CompanySize < ApplicationRecord class CompanySize < ApplicationRecord
default_scope { order(prio: :asc) }
# == Constants ============================================================ # == Constants ============================================================
# == Attributes =========================================================== # == Attributes ===========================================================

View File

@ -2,7 +2,7 @@
# Expanse # Expanse
class Expense < ApplicationRecord class Expense < ApplicationRecord
default_scope { order(name: :asc) } default_scope { order(prio: :asc) }
# == Constants ============================================================ # == Constants ============================================================
# == Attributes =========================================================== # == Attributes ===========================================================

View File

@ -2,6 +2,7 @@
# Project # Project
class Project < ApplicationRecord class Project < ApplicationRecord
default_scope { order(prio: :asc) }
# == Constants ============================================================ # == Constants ============================================================
# == Attributes =========================================================== # == Attributes ===========================================================

View File

@ -10,15 +10,17 @@
<tr> <tr>
<th>Nazwa</th> <th>Nazwa</th>
<th>Opis</th> <th>Opis</th>
<th>Priorytet</th>
<th style="width: 200px">Akcje</th> <th style="width: 200px">Akcje</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="sortable_list">
<% @company_activities.each do |company_activity| %> <% @company_activities.each do |company_activity| %>
<tr> <tr id="sort_<%= company_activity.id %>">
<td><%= company_activity.name %></td> <td><%= company_activity.name %></td>
<td><%= company_activity.description %></td> <td><%= company_activity.description %></td>
<td><%= company_activity.prio %></td>
<td> <td>
<%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_company_activity_path(company_activity), class: 'btn-sm btn-info' %> <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_company_activity_path(company_activity), class: 'btn-sm btn-info' %>
<%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), company_activity, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), company_activity, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
@ -27,5 +29,20 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% content_for :foot_scripts do %>
$( function() {
$( "#sortable_list" ).sortable({
update: function( event, ui ) {
var str = "";
$('#sortable_list > tr').each(function(index, tr) {
str += tr.id + ",";
});
$.post( "/company_activities/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
window.location.reload(true);
});
}
});
$( "tbody" ).disableSelection();
} );
<% end %>
<% end %> <% end %>

View File

@ -10,15 +10,17 @@
<tr> <tr>
<th>Nazwa</th> <th>Nazwa</th>
<th>Opis</th> <th>Opis</th>
<th>Priorytet</th>
<th style="width: 200px">Akcje</th> <th style="width: 200px">Akcje</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="sortable_list">
<% @company_sizes.each do |company_size| %> <% @company_sizes.each do |company_size| %>
<tr> <tr id="sort_<%= company_size.id %>">
<td><%= company_size.name %></td> <td><%= company_size.name %></td>
<td><%= company_size.description %></td> <td><%= company_size.description %></td>
<td><%= company_size.prio %></td>
<td> <td>
<%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_company_size_path(company_size), class: 'btn-sm btn-info' %> <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_company_size_path(company_size), class: 'btn-sm btn-info' %>
<%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), company_size, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), company_size, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
@ -27,5 +29,20 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% content_for :foot_scripts do %>
$( function() {
$( "#sortable_list" ).sortable({
update: function( event, ui ) {
var str = "";
$('#sortable_list > tr').each(function(index, tr) {
str += tr.id + ",";
});
$.post( "/company_sizes/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
window.location.reload(true);
});
}
});
$( "tbody" ).disableSelection();
} );
<% end %>
<% end %> <% end %>

View File

@ -10,15 +10,17 @@
<tr> <tr>
<th>Nazwa</th> <th>Nazwa</th>
<th>Opis</th> <th>Opis</th>
<th>Priorytet</th>
<th style="width: 200px">Akcje</th> <th style="width: 200px">Akcje</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="sortable_list">
<% @expenses.each do |expense| %> <% @expenses.each do |expense| %>
<tr> <tr id="sort_<%= expense.id %>">
<td><%= expense.name %></td> <td><%= expense.name %></td>
<td><%= expense.description %></td> <td><%= expense.description %></td>
<td><%= expense.prio %></td>
<td> <td>
<%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_expense_path(expense), class: 'btn-sm btn-info' %> <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_expense_path(expense), class: 'btn-sm btn-info' %>
<%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), expense, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), expense, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
@ -27,5 +29,20 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% content_for :foot_scripts do %>
$( function() {
$( "#sortable_list" ).sortable({
update: function( event, ui ) {
var str = "";
$('#sortable_list > tr').each(function(index, tr) {
str += tr.id + ",";
});
$.post( "/expenses/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
window.location.reload(true);
});
}
});
$( "tbody" ).disableSelection();
} );
<% end %>
<% end %> <% end %>

View File

@ -11,7 +11,7 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'font_awesomeall', 'tempusdominus-bootstrap-4.min', 'select2.min', 'bootstrap-duallistbox.min', 'summernote-bs4', 'adminlte.min' %> <%= stylesheet_link_tag 'font_awesomeall', 'tempusdominus-bootstrap-4.min', 'select2.min', 'bootstrap-duallistbox.min', 'summernote-bs4', 'adminlte.min' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'tinymce/tinymce.min' %> <%= javascript_include_tag 'tinymce/tinymce.min', 'jquery-ui.min' %>
</head> </head>
<body class="hold-transition sidebar-mini"> <body class="hold-transition sidebar-mini">
@ -103,6 +103,9 @@
<!-- REQUIRED SCRIPTS --> <!-- REQUIRED SCRIPTS -->
<%= javascript_include_tag 'jquery.min', 'bootstrap.bundle.min', 'bs-custom-file-input.min', 'moment-with-locales.min', 'select2.full.min', 'jquery.bootstrap-duallistbox.min', 'tempusdominus-bootstrap-4.min', 'summernote-bs4', 'adminlte.min', 'bootstrap-switch.min', 'forms' %> <%= javascript_include_tag 'jquery.min', 'bootstrap.bundle.min', 'bs-custom-file-input.min', 'moment-with-locales.min', 'select2.full.min', 'jquery.bootstrap-duallistbox.min', 'tempusdominus-bootstrap-4.min', 'summernote-bs4', 'adminlte.min', 'bootstrap-switch.min', 'forms', 'jquery-ui.min' %>
<script type="text/javascript">
<%= yield :foot_scripts %>
</script>
</body> </body>
</html> </html>

View File

@ -10,15 +10,17 @@
<tr> <tr>
<th>Nazwa</th> <th>Nazwa</th>
<th>Opis</th> <th>Opis</th>
<th>Priorytet</th>
<th style="width: 200px">Akcje</th> <th style="width: 200px">Akcje</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="sortable_list">
<% @projects.each do |project| %> <% @projects.each do |project| %>
<tr> <tr id="sort_<%= project.id %>">
<td><%= project.name %></td> <td><%= project.name %></td>
<td><%= project.description %></td> <td><%= project.description %></td>
<td><%= project.prio %></td>
<td> <td>
<%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_project_path(project), class: 'btn-sm btn-info' %> <%= link_to raw('<i class="fas fa-edit"></i> Edycja'), edit_project_path(project), class: 'btn-sm btn-info' %>
<%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), project, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %> <%= link_to raw('<i class="fas fa-trash-can"></i> Usuń'), project, class: 'btn-sm btn-danger', method: :delete, data: { confirm: 'Czy na pewno?' } %>
@ -27,5 +29,20 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% content_for :foot_scripts do %>
$( function() {
$( "#sortable_list" ).sortable({
update: function( event, ui ) {
var str = "";
$('#sortable_list > tr').each(function(index, tr) {
str += tr.id + ",";
});
$.post( "/projects/chg_prio", { authenticity_token: $('meta[name="csrf-token"]').attr("content"), ord: str }, function( data ) {
window.location.reload(true);
});
}
});
$( "tbody" ).disableSelection();
} );
<% end %>
<% end %> <% end %>

38
bin/init_prios.rb Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
# require 'mailman'
require 'mail'
require 'builder'
ENV['RAILS_ENV'] ||= 'development'
require File.dirname(__FILE__) + '/../config/environment'
prio = 1
Expense.all.each do |exp|
exp.prio = prio
exp.save
prio += 1
end
prio = 1
CompanyActivity.all.each do |exp|
exp.prio = prio
exp.save
prio += 1
end
prio = 1
Project.all.each do |exp|
exp.prio = prio
exp.save
prio += 1
end
prio = 1
CompanySize.all.each do |exp|
exp.prio = prio
exp.save
prio += 1
end

View File

@ -6,6 +6,7 @@ pl:
expense: expense:
name: "Nazwa" name: "Nazwa"
description: "Opis" description: "Opis"
prio: "Priorytet"
errors: errors:
models: models:
expense: expense:

View File

@ -13,10 +13,14 @@ Rails.application.routes.draw do
post 'home/order_meeting_save' post 'home/order_meeting_save'
resources :home, only: %i[index show] resources :home, only: %i[index show]
devise_for :users devise_for :users
post 'company_sizes/chg_prio'
resources :company_sizes resources :company_sizes
post 'expenses/chg_prio'
resources :expenses resources :expenses
resources :tags resources :tags
post 'company_activities/chg_prio'
resources :company_activities resources :company_activities
post 'projects/chg_prio'
resources :projects resources :projects
resources :partners resources :partners
resources :experts resources :experts

View File

@ -0,0 +1,12 @@
class AddPrioToExpenses < ActiveRecord::Migration[5.2]
def change
add_column :expenses, :prio, :integer, after: :description, default: 0
add_index :expenses, :prio
add_column :company_activities, :prio, :integer, after: :description, default: 0
add_index :company_activities, :prio
add_column :projects, :prio, :integer, after: :description, default: 0
add_index :projects, :prio
add_column :company_sizes, :prio, :integer, after: :description, default: 0
add_index :company_sizes, :prio
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_06_15_092725) do ActiveRecord::Schema.define(version: 2022_06_28_085754) do
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
@ -36,10 +36,12 @@ ActiveRecord::Schema.define(version: 2022_06_15_092725) do
create_table "company_activities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "company_activities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"
t.integer "prio", default: 0
t.integer "created_by" t.integer "created_by"
t.integer "updated_by" t.integer "updated_by"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["prio"], name: "index_company_activities_on_prio"
end end
create_table "company_activities_dotations", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "company_activities_dotations", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
@ -51,10 +53,12 @@ ActiveRecord::Schema.define(version: 2022_06_15_092725) do
create_table "company_sizes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "company_sizes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"
t.integer "prio", default: 0
t.integer "created_by" t.integer "created_by"
t.integer "updated_by" t.integer "updated_by"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["prio"], name: "index_company_sizes_on_prio"
end end
create_table "company_sizes_dotations", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "company_sizes_dotations", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
@ -164,10 +168,12 @@ ActiveRecord::Schema.define(version: 2022_06_15_092725) do
create_table "expenses", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "expenses", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"
t.integer "prio", default: 0
t.integer "created_by" t.integer "created_by"
t.integer "updated_by" t.integer "updated_by"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["prio"], name: "index_expenses_on_prio"
end end
create_table "experts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "experts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
@ -211,10 +217,12 @@ ActiveRecord::Schema.define(version: 2022_06_15_092725) do
create_table "projects", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "projects", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"
t.integer "prio", default: 0
t.integer "created_by" t.integer "created_by"
t.integer "updated_by" t.integer "updated_by"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["prio"], name: "index_projects_on_prio"
end end
create_table "roles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "roles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|