Added choice of project, r/w perms, and fixed up some css
This commit is contained in:
Binary file not shown.
@@ -1,10 +1,17 @@
|
||||
$(function() {
|
||||
$('td').focus(function() {
|
||||
if (this.id.split("-")[0] == "memory") {
|
||||
$(this).css("background-color", "lightblue")
|
||||
}
|
||||
});
|
||||
var data = [];
|
||||
$('td').keydown(function() {
|
||||
data.push(this.id, $(this).html().substr(0, 2)); //position, value
|
||||
})
|
||||
$('td').blur(function() {
|
||||
$(this).css("background", "none");
|
||||
if ((id_i = data.indexOf(this.id) != -1) && data[id_i+1] != $(this).html().substr(0, 2)) {
|
||||
$(this).css("color", "darkgreen");
|
||||
var int_id = this.id.split("-")[1]
|
||||
$.post("/memory/update_memory?project="+$(this).closest("table").data("project")+"&file="+Math.floor((int_id/2048)+1)+"&mem_id="+int_id%2048+"&value="+$(this).html().substr(0, 2));
|
||||
data.splice(id_i, 2);
|
||||
|
||||
@@ -1028,9 +1028,11 @@ nav.pagination {
|
||||
text-shadow: none;
|
||||
}
|
||||
.memory-table {
|
||||
width: 870px;
|
||||
width: 980px;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
th, td {
|
||||
height: 20px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,30 +16,31 @@ class MemoryController < ApplicationController
|
||||
end
|
||||
|
||||
def table
|
||||
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project]}")
|
||||
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
|
||||
@data = []
|
||||
Dir.glob('*').reverse.each do |f|
|
||||
File.open(Dir.pwd+"/#{f}") do |file|
|
||||
@data.concat(file.read.unpack("C*").map{|h| h.to_s(16)})
|
||||
if JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read)["read"].include? current_user.uuid.gsub("-","")
|
||||
@can_edit = false
|
||||
else
|
||||
unless (parse = JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read))["read"].include? current_user.uuid.gsub("-","")
|
||||
@can_edit = true
|
||||
end
|
||||
@name = parse["name"]
|
||||
jf.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_memory
|
||||
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project]}")
|
||||
new_text = ""
|
||||
File.open("#{params[:file]}.hex"){|f| new_text = f.read.unpack("C*").collect{|h| h.to_s(16)}}
|
||||
new_text[params[:mem_id].to_i] = params[:value]
|
||||
File.open("#{params[:file]}.hex", "w") do |f|
|
||||
f.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
|
||||
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
|
||||
unless params[:mem_id].to_i > JSON.parse(File.read("project.json"))["size"] || (/[^A-Fa-f0-9]/.match params[:value])
|
||||
new_text = ""
|
||||
File.open("#{params[:file]}.hex"){|f| new_text = f.read.unpack("C*").collect{|h| h.to_s(16)}}
|
||||
new_text[params[:mem_id].to_i] = params[:value]
|
||||
File.open("#{params[:file]}.hex", "w") do |f|
|
||||
f.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
|
||||
end
|
||||
render nothing: true
|
||||
end
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<%= form_tag "memory/table", method: :get do %>
|
||||
<%= form_tag url_for(controller: "memory", action: "table"), method: :get do %>
|
||||
<%= select_tag "project", options_for_select(@projects.collect.with_index{|p, i| [@project_names[i], p]}) %>
|
||||
<%= submit_tag "View Table", name: nil %>
|
||||
<br><br>
|
||||
<%= submit_tag "Load table", name: nil, class: "btn blue" %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<h1 style="text-align:center"><%= title @name + (" (read-only)" if !@can_edit).to_s %></h1>
|
||||
<table class="memory-table", data-project="<%=params[:project]%>">
|
||||
<tr>
|
||||
<% ["Address","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"].each do |i| %>
|
||||
@@ -8,7 +9,7 @@
|
||||
<tr>
|
||||
<td><b><%=(rindex*16).to_s(16).upcase.rjust(6, "0")%></b></td>
|
||||
<% row.each_with_index do |hex, hindex| %>
|
||||
<td contenteditable="<%=@can_edit%>" id="memory-<%=(16*rindex)+hindex%>"><%=hex.to_s.upcase.rjust(2, "0")%></td>
|
||||
<td contenteditable="<%=!!@can_edit%>" id="memory-<%=(16*rindex)+hindex%>"><%=hex.to_s.upcase.rjust(2, "0")%></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -10,7 +10,7 @@ default: &default
|
||||
development:
|
||||
<<: *default
|
||||
database: redstoner-web
|
||||
username: root
|
||||
username: web
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
@@ -24,4 +24,4 @@ test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
timeout: 5000
|
||||
|
||||
@@ -43,4 +43,4 @@ Redstoner::Application.configure do
|
||||
password: ENV["GMAIL_PASSWORD"],
|
||||
}
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,4 +38,4 @@ User.create!(
|
||||
password: "123456789", # high seructity!
|
||||
password_confirmation: "123456789",
|
||||
role: Role.get(:superadmin)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user