Receipt create. Part 2
This commit is contained in:
@@ -17,8 +17,8 @@ class DBase
|
||||
|
||||
def creategit(project_name, description)
|
||||
@error = nil
|
||||
data = Repos.where(reponame: project_name)
|
||||
unless data.nil?
|
||||
data = Repos.where(reponame: project_name).first
|
||||
if data.nil?
|
||||
id = Repos.insert(reponame: project_name, descr: description, public: 1)
|
||||
@last_id = id
|
||||
else
|
||||
@@ -46,4 +46,66 @@ class DBase
|
||||
Repos.where(id: id).delete
|
||||
end
|
||||
end
|
||||
|
||||
def createrecip(filepath, description, codedata, gitlist)
|
||||
error_data = nil
|
||||
filepath_san = sanitize_rcptname(filepath)
|
||||
is_data = Recips.where(filepath: filepath_san).first
|
||||
if codedata.nil? || codedata.strip == ""
|
||||
error_data
|
||||
else
|
||||
if is_data.nil?
|
||||
id = Recips.insert(filepath: filepath_san, descr: description, content: codedata)
|
||||
@last_id = id
|
||||
if !gitlist.nil? && gitlist.length > 0
|
||||
gitlist.each do |item|
|
||||
data = Repos.where(id: item.to_i).first
|
||||
unless data.nil?
|
||||
RepocRecips.insert(repo_id: data[:id], recip_id: id)
|
||||
end
|
||||
end
|
||||
end
|
||||
error_data
|
||||
else
|
||||
"Рецепт с таким именем #{filepath_san} уже существует"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def updaterecip(id, filepath, description, codedata, gitlist)
|
||||
error_data = nil
|
||||
filepath_san = sanitize_rcptname(filepath)
|
||||
is_data = Recips.where(filepath: filepath_san).first
|
||||
if codedata.nil? || codedata.strip == ""
|
||||
error_data
|
||||
else
|
||||
unless is_data.nil?
|
||||
Recips.where(id: id.to_i).update(filepath: filepath_san, descr: description, content: codedata)
|
||||
RepocRecips.where(recip_id: id.to_i).delete
|
||||
if !gitlist.nil? && gitlist.length > 0
|
||||
gitlist.each do |item|
|
||||
data = Repos.where(id: item.to_i).first
|
||||
unless data.nil?
|
||||
RepocRecips.insert(repo_id: data[:id], recip_id: id)
|
||||
end
|
||||
end
|
||||
end
|
||||
error_data
|
||||
else
|
||||
"Рецепт с таким именем #{filepath_san} не существует"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_rcp_info_by_id(rcpi_id)
|
||||
info = Recips[rcpi_id.to_i]
|
||||
gits = RepocRecips.where(recip_id: info[:id])
|
||||
info[:repos_list] = gits.map { |item| item[:repo_id].to_s }
|
||||
info
|
||||
end
|
||||
|
||||
def delete_rcp(id)
|
||||
RepocRecips.where(recip_id: id.to_i).delete
|
||||
Recips.where(id: id.to_i).delete
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,13 +67,13 @@ class GitRepo
|
||||
db_info = @db.get_repo_info_by_name(repo_name)
|
||||
unless db_info.nil?
|
||||
db_info = db_info.first
|
||||
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public }
|
||||
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :id => db_info.id }
|
||||
else
|
||||
result = create_git_db_only(repo_name)
|
||||
if result.nil?
|
||||
db_info = @db.get_repo_info_by_name(repo_name)
|
||||
db_info = db_info.first
|
||||
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public }
|
||||
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :id => db_info.id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
15
classes/utilities.rb
Normal file
15
classes/utilities.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
def sanitize_filename(filename)
|
||||
filename = filename.strip
|
||||
sanitized = filename.gsub(/[^a-zA-Z0-9_]/, "_")
|
||||
sanitized.gsub!(/_+/, "_")
|
||||
sanitized.gsub!(/^_+|_+$/, "")
|
||||
sanitized
|
||||
end
|
||||
|
||||
def sanitize_rcptname(filename)
|
||||
filename = filename.strip
|
||||
sanitized = filename.gsub(/[^a-zA-Z0-9_\.]/, "_")
|
||||
sanitized.gsub!(/_+/, "_")
|
||||
sanitized.gsub!(/^_+|_+$/, "")
|
||||
sanitized
|
||||
end
|
||||
Reference in New Issue
Block a user