Added project to project linking
This commit is contained in:
57
app.rb
57
app.rb
@@ -550,9 +550,6 @@ get "/prjgitf/:id/:git_id" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/gitbld/:id/:git_id" do
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/prjcfg/:id" do
|
get "/prjcfg/:id" do
|
||||||
unless session[:prjcfg_modal_text].nil?
|
unless session[:prjcfg_modal_text].nil?
|
||||||
@modal_info = session[:prjcfg_modal_info]
|
@modal_info = session[:prjcfg_modal_info]
|
||||||
@@ -684,6 +681,60 @@ post "/gitspec/:id/:git_id" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/prjaddrepo/:id" do
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
prj_info = prj.get_project(params["id"])
|
||||||
|
if prj_info.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
@page_name = "#{prj_info[:projname]} - добавить связанные проекты"
|
||||||
|
@proj_name = prj_info[:projname]
|
||||||
|
@proj_descr = prj_info[:descr]
|
||||||
|
@proj_id = prj_info[:id]
|
||||||
|
@projects_list = prj.get_related_projects_list(params["id"])
|
||||||
|
@all_projects = prj.get_projects
|
||||||
|
erb :prjprj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post "/prjaddrepo/:id" do
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
prj_info = prj.get_project(params["id"])
|
||||||
|
if prj_info.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
unless params["cancel"].nil?
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
else
|
||||||
|
if params["disableLinks"].nil?
|
||||||
|
list_id = params["prjlst"]
|
||||||
|
current_list = prj.get_related_projects_list(params["id"])
|
||||||
|
current_list_id = current_list.map { |item| item[:proj_id_repository] }
|
||||||
|
new_ids = list_id - current_list_id
|
||||||
|
removed_ids = current_list_id - list_id
|
||||||
|
prj.save_linked_projects(params["id"], new_ids, removed_ids)
|
||||||
|
prj.regenerate_linked_repos(params["id"])
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
else
|
||||||
|
prj.delete_linked_projects(params["id"])
|
||||||
|
prj.regenerate_linked_repos(params["id"])
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/gitbld/:id/:git_id" do
|
||||||
|
end
|
||||||
|
|
||||||
not_found do
|
not_found do
|
||||||
status 404
|
status 404
|
||||||
@page_name = "Кто-то потерялся"
|
@page_name = "Кто-то потерялся"
|
||||||
|
|||||||
@@ -188,4 +188,20 @@ class DBase
|
|||||||
def get_projects_links(prj_id)
|
def get_projects_links(prj_id)
|
||||||
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_linked_projects(prj_id)
|
||||||
|
ProjectsProjects.where(proj_id: prj_id.to_i).delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_linked_projects_with_id(prj_id, prj_id_link)
|
||||||
|
ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_linked_projects(prj_id, prj_id_link)
|
||||||
|
item = ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).first
|
||||||
|
if item.nil?
|
||||||
|
id = ProjectsProjects.insert(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i)
|
||||||
|
@last_id = id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
11
classes/mock.rb
Normal file
11
classes/mock.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class MockManager
|
||||||
|
attr :path, :error, :last_status, :last_pid
|
||||||
|
|
||||||
|
def initialize(path)
|
||||||
|
@error = nil
|
||||||
|
unless File.exist? (path)
|
||||||
|
Dir.mkdir(path)
|
||||||
|
end
|
||||||
|
@path = path
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -68,7 +68,7 @@ class ProjectsActions
|
|||||||
File.join(proj_path, PROJECTS_STRUCTURE[:SRC], gitname)
|
File.join(proj_path, PROJECTS_STRUCTURE[:SRC], gitname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_linked_repos(id, proj_path, proj_name)
|
def generate_linked_repos(id, proj_path, proj_name, linked_repo_tpl)
|
||||||
linked_prj = []
|
linked_prj = []
|
||||||
proj_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
proj_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||||
proj_repo = <<~PRJ_CFG
|
proj_repo = <<~PRJ_CFG
|
||||||
@@ -99,7 +99,17 @@ class ProjectsActions
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
File.open(prj_incl_path, "w") { |f| f << linked_prj.join("\n\n\n") }
|
File.open(linked_repo_tpl, "w") { |f| f << linked_prj.join("\n\n\n") }
|
||||||
|
end
|
||||||
|
|
||||||
|
def regenerate_linked_repos(id)
|
||||||
|
proj_path = get_project_path(id)
|
||||||
|
config_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS])
|
||||||
|
prj_incl_path = File.join(config_path, "repos_include.tpl")
|
||||||
|
prj_info = get_project(id)
|
||||||
|
unless prj_info.nil?
|
||||||
|
generate_linked_repos(id, proj_path, prj_info[:projname], prj_incl_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_config(id, configuration_path, proj_path, proj_name)
|
def generate_config(id, configuration_path, proj_path, proj_name)
|
||||||
@@ -107,7 +117,7 @@ class ProjectsActions
|
|||||||
conf_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS])
|
conf_path = File.join(proj_path, PROJECTS_STRUCTURE[:CONFIGS])
|
||||||
prj_incl_path = File.join(conf_path, "repos_include.tpl")
|
prj_incl_path = File.join(conf_path, "repos_include.tpl")
|
||||||
proj_config = <<~PRJ_CFG
|
proj_config = <<~PRJ_CFG
|
||||||
include("#{configuration}")
|
include("#{configuration_path}")
|
||||||
include("#{prj_incl_path}")
|
include("#{prj_incl_path}")
|
||||||
config_opts['plugin_conf']['ccache_enable'] = True
|
config_opts['plugin_conf']['ccache_enable'] = True
|
||||||
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
||||||
@@ -121,7 +131,7 @@ class ProjectsActions
|
|||||||
config_opts['plugin_conf']['yum_cache_enable'] = True
|
config_opts['plugin_conf']['yum_cache_enable'] = True
|
||||||
PRJ_CFG
|
PRJ_CFG
|
||||||
File.open(proj_conf_path, "w") { |f| f << proj_config }
|
File.open(proj_conf_path, "w") { |f| f << proj_config }
|
||||||
generate_linked_repos(id, proj_path, proj_name)
|
generate_linked_repos(id, proj_path, proj_name, prj_incl_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_project(name, description, configuration)
|
def create_project(name, description, configuration)
|
||||||
@@ -134,7 +144,7 @@ class ProjectsActions
|
|||||||
ret_val = 1
|
ret_val = 1
|
||||||
else
|
else
|
||||||
created = false
|
created = false
|
||||||
begin
|
#begin
|
||||||
Dir.mkdir(fname)
|
Dir.mkdir(fname)
|
||||||
PROJECTS_STRUCTURE.each_pair do |key, value|
|
PROJECTS_STRUCTURE.each_pair do |key, value|
|
||||||
new_path = File.join(fname, value)
|
new_path = File.join(fname, value)
|
||||||
@@ -153,10 +163,10 @@ class ProjectsActions
|
|||||||
ret_val = 1
|
ret_val = 1
|
||||||
@error = "Конфигурация #{configuration} не существует"
|
@error = "Конфигурация #{configuration} не существует"
|
||||||
end
|
end
|
||||||
rescue => e
|
#rescue => e
|
||||||
ret_val = 1
|
# ret_val = 1
|
||||||
@error = e.message
|
# @error = e.message
|
||||||
end
|
#end
|
||||||
unless created
|
unless created
|
||||||
FileUtils.rm_rf(fname, secure: true)
|
FileUtils.rm_rf(fname, secure: true)
|
||||||
end
|
end
|
||||||
@@ -199,4 +209,33 @@ class ProjectsActions
|
|||||||
end
|
end
|
||||||
err
|
err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_related_projects_list(prj_id)
|
||||||
|
links_list = []
|
||||||
|
links = @db.get_projects_links(prj_id)
|
||||||
|
unless links.nil?
|
||||||
|
links_list = links.map do |item|
|
||||||
|
prj_info = @db.proj(item[:proj_id_repository])
|
||||||
|
if prj_info.nil?
|
||||||
|
item[:list_state] = false
|
||||||
|
else
|
||||||
|
item[:list_state] = true
|
||||||
|
item[:prj_info] = prj_info
|
||||||
|
end
|
||||||
|
item
|
||||||
|
end.select { |item| item[:list_state] }
|
||||||
|
end
|
||||||
|
links_list
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_linked_projects(prj_id)
|
||||||
|
@db.delete_linked_projects(prj_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_linked_projects(prj_id, new_ids, delete_ids)
|
||||||
|
delete_ids.each { |item| @db.delete_linked_projects_with_id(prj_id, item) }
|
||||||
|
new_ids.each do |item|
|
||||||
|
@db.save_linked_projects(prj_id, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RepoManager
|
class RepoManager
|
||||||
attr :path, :error
|
attr :path, :error, :last_status, :last_pid
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@error = nil
|
@error = nil
|
||||||
@@ -10,5 +10,10 @@ class RepoManager
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_repo
|
def create_repo
|
||||||
|
%x(/usr/bin/createrepo_c --database --workers 1 "#{@path}")
|
||||||
|
result = $?
|
||||||
|
@last_status = result.exitstatus
|
||||||
|
@last_pid = result.pid
|
||||||
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,22 +4,37 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<h3 class="bg-secondary-subtle text-center border-bottom border-primary-subtle rounded-1 pb-1 mb-2">
|
<h3 class="bg-secondary-subtle text-center border-bottom border-primary-subtle rounded-1 pb-1 mb-2">
|
||||||
project 1
|
<a href="/prjedit/<%= ERB::Util.url_encode(@proj_id) %>"><%= @proj_name %></a>
|
||||||
</h3>
|
</h3>
|
||||||
<div class="pb-2">gfhs ag jahsg jhasgfjhgfjf ha jhf</div>
|
<div class="pb-2"><%= @proj_descr %></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<div class="vstack gap-3">
|
<div class="vstack gap-3">
|
||||||
<form action="/rcpcrt" method="post">
|
<form action="/prjaddrepo/<%= ERB::Util.url_encode(@proj_id) %>" method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="prjlst" class="form-label">Выбирете проекты, от которых зависит данный
|
<label for="prjlst" class="form-label">Выбирете проекты, от которых зависит данный
|
||||||
проект</label>
|
проект</label>
|
||||||
<div class="prjlist">
|
<div class="prjlist">
|
||||||
<select class="form-control" id="prjlst" name="prjlst" multiple>
|
<select class="form-control" id="prjlst" name="prjlst[]" multiple>
|
||||||
<option value="1" selected>test1</option>
|
<% @all_projects.each do |item| %>
|
||||||
<option value="2">tets2</option>
|
<%
|
||||||
<option value="3">test33</option>
|
if item[:id] == @proj_id.to_i
|
||||||
<option value="4">test44</option>
|
next
|
||||||
|
end
|
||||||
|
fnd = false
|
||||||
|
@projects_list.each do |f_i|
|
||||||
|
if f_i[:prj_info][:id] == item[:id]
|
||||||
|
fnd = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<% if fnd %>
|
||||||
|
<option value="<%= item[:id]%>" selected><%= item[:projname] %></option>
|
||||||
|
<% else %>
|
||||||
|
<option value="<%= item[:id]%>"><%= item[:projname] %></option>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user