Added projects. Part 1
This commit is contained in:
18
app.rb
18
app.rb
@@ -15,6 +15,7 @@ require_relative "classes/gitinfo"
|
|||||||
require_relative "classes/db"
|
require_relative "classes/db"
|
||||||
require_relative "classes/systeminfo"
|
require_relative "classes/systeminfo"
|
||||||
require_relative "classes/utilities"
|
require_relative "classes/utilities"
|
||||||
|
require_relative "classes/projects"
|
||||||
|
|
||||||
def print_error_page(error_status, error_meaasge)
|
def print_error_page(error_status, error_meaasge)
|
||||||
@page_name = "Ошибка выполнения"
|
@page_name = "Ошибка выполнения"
|
||||||
@@ -35,13 +36,19 @@ get "/" do
|
|||||||
repo = GitRepo.new(cfg.get_repo, db)
|
repo = GitRepo.new(cfg.get_repo, db)
|
||||||
if repo.path.nil?
|
if repo.path.nil?
|
||||||
print_error_page(503, "Путь к репозиториям не существует")
|
print_error_page(503, "Путь к репозиториям не существует")
|
||||||
|
else
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
else
|
else
|
||||||
repo_data = repo.getrepos
|
repo_data = repo.getrepos
|
||||||
@repos_number = repo_data.length
|
@repos_number = repo_data.length
|
||||||
@rcp_number = db.get_recips.length
|
@rcp_number = db.get_recips.length
|
||||||
|
@prj_number = prj.get_projects.length
|
||||||
erb :index
|
erb :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get "/repos/:reponame/:branch" do
|
get "/repos/:reponame/:branch" do
|
||||||
@page_name = params["reponame"]
|
@page_name = params["reponame"]
|
||||||
@@ -283,6 +290,17 @@ get "/bldcfginfo" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/projs" do
|
||||||
|
@page_name = "Список проектов"
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
@prj_list = prj.get_projects
|
||||||
|
erb :prjlist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
not_found do
|
not_found do
|
||||||
status 404
|
status 404
|
||||||
@page_name = "Кто-то потерялся"
|
@page_name = "Кто-то потерялся"
|
||||||
|
|||||||
@@ -54,4 +54,12 @@ class IniConfig
|
|||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_projects_path()
|
||||||
|
unless @config["projects"]["path"].nil?
|
||||||
|
@config["projects"]["path"].to_s
|
||||||
|
else
|
||||||
|
"projects"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ end
|
|||||||
class RepocRecips < Sequel::Model(:repos_recips)
|
class RepocRecips < Sequel::Model(:repos_recips)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Projects < Sequel::Model(:projects)
|
||||||
|
end
|
||||||
|
|
||||||
|
class ReposProjects < Sequel::Model(:repos_projects)
|
||||||
|
end
|
||||||
|
|
||||||
class DBase
|
class DBase
|
||||||
attr :error, :last_id
|
attr :error, :last_id
|
||||||
|
|
||||||
@@ -108,4 +114,8 @@ class DBase
|
|||||||
RepocRecips.where(recip_id: id.to_i).delete
|
RepocRecips.where(recip_id: id.to_i).delete
|
||||||
Recips.where(id: id.to_i).delete
|
Recips.where(id: id.to_i).delete
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def proj_list
|
||||||
|
Projects.order(:id).all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
30
classes/projects.rb
Normal file
30
classes/projects.rb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
require_relative "db"
|
||||||
|
|
||||||
|
class ProjectsActions
|
||||||
|
attr :path, :error, :db
|
||||||
|
|
||||||
|
def initialize(path, db)
|
||||||
|
@path = nil
|
||||||
|
@error = nil
|
||||||
|
@db = db
|
||||||
|
if File.absolute_path?(path)
|
||||||
|
if File.exist?(path)
|
||||||
|
@path = path
|
||||||
|
end
|
||||||
|
else
|
||||||
|
apath = File.realpath(path)
|
||||||
|
if File.exist?(apath)
|
||||||
|
@path = apath
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_projects
|
||||||
|
prj = []
|
||||||
|
File.open("locks/prjcreate", "r") do |f|
|
||||||
|
f.flock(File::LOCK_SH)
|
||||||
|
prj = @db.proj_list
|
||||||
|
end
|
||||||
|
prj
|
||||||
|
end
|
||||||
|
end
|
||||||
0
locks/prjcreate
Normal file
0
locks/prjcreate
Normal file
@@ -8,7 +8,7 @@
|
|||||||
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115l.094-.319z"></path>
|
<path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115l.094-.319z"></path>
|
||||||
</svg></div>
|
</svg></div>
|
||||||
<div class="px-3">
|
<div class="px-3">
|
||||||
<h2 class="fw-bold mb-0">5</h2>
|
<h2 class="fw-bold mb-0"><%= @prj_number %></h2>
|
||||||
<p class="mb-0">Проектов</p>
|
<p class="mb-0">Проектов</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
35
views/prjlist.erb
Normal file
35
views/prjlist.erb
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<%= erb :header %>
|
||||||
|
<div class="container py-4 py-xl-5">
|
||||||
|
<div class="row pb-5">
|
||||||
|
<div class="col-md-8 col-xl-6 text-center mx-auto">
|
||||||
|
<h2>Существующие проекты</h2>
|
||||||
|
<p class="w-lg-50">Страница управления проектами</p>
|
||||||
|
<div>
|
||||||
|
<div class="px-3"><a href="/prjcreate"><svg xmlns="http://www.w3.org/2000/svg" width="1em"
|
||||||
|
height="1em" fill="currentColor" viewBox="0 0 16 16"
|
||||||
|
class="bi bi-plus-circle text-primary" style="font-size: 29px;">
|
||||||
|
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"></path>
|
||||||
|
<path
|
||||||
|
d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z">
|
||||||
|
</path>
|
||||||
|
</svg> Добавить проект</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container text-center">
|
||||||
|
<div class="row gy-3">
|
||||||
|
<% @prj_list.each do |item| %>
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="card text-bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><%= item[:projname] %></h5>
|
||||||
|
<p class="card-text"><%= item[:descr] %></p>
|
||||||
|
<a href="/prjedit/<%= ERB::Util.url_encode(item[:id]) %>" class="card-link link-light">Редактировать</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<%= erb :footer %>
|
||||||
Reference in New Issue
Block a user