Added projects. Part 5
This commit is contained in:
44
app.rb
44
app.rb
@@ -347,6 +347,12 @@ post "/prjcreate" do
|
||||
end
|
||||
|
||||
get "/prjedit/:id" do
|
||||
unless session[:prj_modal_text].nil?
|
||||
@modal_info = session[:prj_modal_info]
|
||||
@modal_text = session[:prj_modal_text]
|
||||
session[:prj_modal_info] = nil
|
||||
session[:prj_modal_text] = nil
|
||||
end
|
||||
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||
if prj.path.nil?
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
@@ -382,6 +388,44 @@ get "/prjedit/:id" do
|
||||
end
|
||||
end
|
||||
|
||||
post "/prjagit/:id" do
|
||||
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||
if prj.path.nil?
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
else
|
||||
repo = GitRepo.new(cfg.get_repo, db)
|
||||
if repo.path.nil?
|
||||
print_error_page(503, "Путь к репозиториям не существует")
|
||||
else
|
||||
prj_info = prj.get_project(params["id"])
|
||||
if prj_info.nil?
|
||||
print_error_page(503, "Путь к проектам не существует")
|
||||
else
|
||||
proj_repo_list = prj.get_project_gits(prj_info[:id])
|
||||
git_info = repo.get_repo_short_info_by_id(params["gitlist"].to_i)
|
||||
if git_info.nil?
|
||||
print_error_page(503, "Репозиторий исчез")
|
||||
else
|
||||
fnd = false
|
||||
proj_repo_list.each do |item|
|
||||
if item[:id] == git_info[:id]
|
||||
fnd = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if fnd
|
||||
session[:prj_modal_info] = "Ошибка"
|
||||
session[:prj_modal_text] = "Данный git-репозиторий уже добавлен к проекту"
|
||||
redirect back
|
||||
else
|
||||
prj.add_git_to_project(prj_info[:id], git_info[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
not_found do
|
||||
status 404
|
||||
@page_name = "Кто-то потерялся"
|
||||
|
||||
@@ -37,6 +37,10 @@ class DBase
|
||||
Repos.where(reponame: repo_name)
|
||||
end
|
||||
|
||||
def get_repo_info_by_id(id)
|
||||
Repos[id]
|
||||
end
|
||||
|
||||
def get_recips()
|
||||
result = []
|
||||
Recips.order(:id).map do |item|
|
||||
@@ -49,7 +53,7 @@ class DBase
|
||||
unless rep_id[:id].nil?
|
||||
id = rep_id[:id]
|
||||
RepocRecips.where(repo_id: id).delete
|
||||
Repos.where(id: id).delete
|
||||
ReposProjects.where(repo_id: id).delete
|
||||
end
|
||||
end
|
||||
|
||||
@@ -147,4 +151,12 @@ class DBase
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def save_git_project(prj_id, git_id)
|
||||
result = ReposProjects.where(proj_id: prj_id, repo_id: git_id).first
|
||||
if result.nil?
|
||||
id = ReposProjects.insert(proj_id: prj_id, repo_id: git_id)
|
||||
@last_id = id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,4 +148,32 @@ class GitRepo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_repo_short_info_by_id(id)
|
||||
@db.get_repo_info_by_id(id)
|
||||
end
|
||||
|
||||
def clone_repo_master(id, path)
|
||||
@error = nil
|
||||
repo_info = @db.get_repo_info_by_id(id)
|
||||
unless repo_info.nil?
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
git_path = File.join(@path, repo_info[:reponame] + ".git")
|
||||
if File.exist?(git_path)
|
||||
repo = Rugged::Repository.new(git_path)
|
||||
if repo.empty?
|
||||
@error = "Репозиторий пустой, нельзя добавить в проект пустой репозиторий"
|
||||
else
|
||||
#TODO clone repo
|
||||
end
|
||||
else
|
||||
@error = "Файла репозитория не существует"
|
||||
end
|
||||
end
|
||||
else
|
||||
@error = "Нет информации о репозитории"
|
||||
end
|
||||
@error
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,4 +90,8 @@ class ProjectsActions
|
||||
def get_project_gits(id)
|
||||
@db.get_gits_for_projects(id)
|
||||
end
|
||||
|
||||
def add_git_to_project(prj_id, git_id)
|
||||
@db.save_git_project(prj_id, git_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
<h3 class="pb-2 text-danger">Избранные</h3>
|
||||
<div class="row gap-3">
|
||||
<% @list_selected.each do |item| %>
|
||||
<div class="col-3 bg-info rounded-4">
|
||||
<a href="/bldcfginfo?info=<%= ERB::Util.url_encode(item[2]) %>" class="link-light"><%= item[1] %></a>
|
||||
<div class="col-3 bg-info rounded-4 p-2">
|
||||
<a href="/bldcfginfo?info=<%= ERB::Util.url_encode(item[2]) %>" class="link-dark"><%= item[1] %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<h3 class="p-3 text-danger">Локальные</h3>
|
||||
<div class="row gap-3">
|
||||
<% @list_local.each do |item| %>
|
||||
<div class="col-3 bg-primary rounded-4">
|
||||
<div class="col-3 bg-primary rounded-4 p-2">
|
||||
<a href="/bldcfginfo?info=<%= ERB::Util.url_encode(item[2]) %>" class="link-light"><%= item[1] %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -20,7 +20,7 @@
|
||||
<h3 class="p-3 text-danger">Глобальные</h3>
|
||||
<div class="row gap-3">
|
||||
<% @list_global.each do |item| %>
|
||||
<div class="col-3 bg-success rounded-4">
|
||||
<div class="col-3 bg-success rounded-4 p-2">
|
||||
<a href="/bldcfginfo?info=<%= ERB::Util.url_encode(item[2]) %>" class="link-light"><%= item[1] %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="tab-pane active" role="tabpanel" id="tab-1">
|
||||
<div class="container">
|
||||
<div class="row align-items-start">
|
||||
<div class="col-10">
|
||||
<div class="col-10 p-5">
|
||||
<p style="font-weight: bold;"><%= @repo_data[:info][:reponame] %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
<%= erb :header %>
|
||||
<script src="/js/jquery.dropdown.min.js"></script>
|
||||
<div class="container">
|
||||
<% unless @modal_text.nil? %>
|
||||
<div class="modal fade" id="modalData" aria-hidden="true" aria-labelledby="modalDataLabel"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="modalDataLabel"><%= @modal_info %></h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<%= @modal_text %>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" data-bs-dismiss="modal">Закрыть</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<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">
|
||||
@@ -32,7 +51,7 @@
|
||||
<div class="gitlist">
|
||||
<select class="form-control" id="gitlist" name="gitlist">
|
||||
<% @repo_list.each do |item| %>
|
||||
<option value="<% item[:id] %>"><% item[:reponame] %></option>
|
||||
<option value="<%= item[:id] %>"><%= item[:reponame] %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
@@ -64,4 +83,11 @@
|
||||
searchNoData: '<li style="color:#ddd">Нет данных</li>',
|
||||
});
|
||||
</script>
|
||||
<% unless @modal_text.nil? %>
|
||||
<script type="text/javascript">
|
||||
$(window).on('load', function () {
|
||||
$('#modalData').modal('show');
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
<%= erb :footer %>
|
||||
Reference in New Issue
Block a user