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
|
||||
|
||||
get "/gitbld/:id/:git_id" do
|
||||
end
|
||||
|
||||
get "/prjcfg/:id" do
|
||||
unless session[:prjcfg_modal_text].nil?
|
||||
@modal_info = session[:prjcfg_modal_info]
|
||||
@@ -684,6 +681,60 @@ post "/gitspec/:id/:git_id" do
|
||||
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
|
||||
status 404
|
||||
@page_name = "Кто-то потерялся"
|
||||
|
||||
@@ -188,4 +188,20 @@ class DBase
|
||||
def get_projects_links(prj_id)
|
||||
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
||||
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
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def generate_linked_repos(id, proj_path, proj_name)
|
||||
def generate_linked_repos(id, proj_path, proj_name, linked_repo_tpl)
|
||||
linked_prj = []
|
||||
proj_repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||
proj_repo = <<~PRJ_CFG
|
||||
@@ -99,7 +99,17 @@ class ProjectsActions
|
||||
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
|
||||
|
||||
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])
|
||||
prj_incl_path = File.join(conf_path, "repos_include.tpl")
|
||||
proj_config = <<~PRJ_CFG
|
||||
include("#{configuration}")
|
||||
include("#{configuration_path}")
|
||||
include("#{prj_incl_path}")
|
||||
config_opts['plugin_conf']['ccache_enable'] = True
|
||||
config_opts['plugin_conf']['ccache_opts']['max_cache_size'] = '4G'
|
||||
@@ -121,7 +131,7 @@ class ProjectsActions
|
||||
config_opts['plugin_conf']['yum_cache_enable'] = True
|
||||
PRJ_CFG
|
||||
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
|
||||
|
||||
def create_project(name, description, configuration)
|
||||
@@ -134,7 +144,7 @@ class ProjectsActions
|
||||
ret_val = 1
|
||||
else
|
||||
created = false
|
||||
begin
|
||||
#begin
|
||||
Dir.mkdir(fname)
|
||||
PROJECTS_STRUCTURE.each_pair do |key, value|
|
||||
new_path = File.join(fname, value)
|
||||
@@ -153,10 +163,10 @@ class ProjectsActions
|
||||
ret_val = 1
|
||||
@error = "Конфигурация #{configuration} не существует"
|
||||
end
|
||||
rescue => e
|
||||
ret_val = 1
|
||||
@error = e.message
|
||||
end
|
||||
#rescue => e
|
||||
# ret_val = 1
|
||||
# @error = e.message
|
||||
#end
|
||||
unless created
|
||||
FileUtils.rm_rf(fname, secure: true)
|
||||
end
|
||||
@@ -199,4 +209,33 @@ class ProjectsActions
|
||||
end
|
||||
err
|
||||
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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class RepoManager
|
||||
attr :path, :error
|
||||
attr :path, :error, :last_status, :last_pid
|
||||
|
||||
def initialize(path)
|
||||
@error = nil
|
||||
@@ -10,5 +10,10 @@ class RepoManager
|
||||
end
|
||||
|
||||
def create_repo
|
||||
%x(/usr/bin/createrepo_c --database --workers 1 "#{@path}")
|
||||
result = $?
|
||||
@last_status = result.exitstatus
|
||||
@last_pid = result.pid
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,22 +4,37 @@
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<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>
|
||||
<div class="pb-2">gfhs ag jahsg jhasgfjhgfjf ha jhf</div>
|
||||
<div class="pb-2"><%= @proj_descr %></div>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<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">
|
||||
<label for="prjlst" class="form-label">Выбирете проекты, от которых зависит данный
|
||||
проект</label>
|
||||
<div class="prjlist">
|
||||
<select class="form-control" id="prjlst" name="prjlst" multiple>
|
||||
<option value="1" selected>test1</option>
|
||||
<option value="2">tets2</option>
|
||||
<option value="3">test33</option>
|
||||
<option value="4">test44</option>
|
||||
<select class="form-control" id="prjlst" name="prjlst[]" multiple>
|
||||
<% @all_projects.each do |item| %>
|
||||
<%
|
||||
if item[:id] == @proj_id.to_i
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user