summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrYummy <elemental428@gmail.com>2017-07-01 04:44:00 +0200
committerMrYummy <elemental428@gmail.com>2017-07-01 04:44:40 +0200
commit361b15e3986151b7bc220a4147e8b3d016683d52 (patch)
tree33a038e6cbcc28ae17d61b64c2b9e3e0d4fdeaaf
parent0972181e75fec23c0dc5bde26be71cf26bea715f (diff)
Added more json supportapi
-rw-r--r--app/controllers/forumgroups_controller.rb9
-rw-r--r--app/controllers/forums_controller.rb7
-rw-r--r--app/controllers/forumthreads_controller.rb9
-rw-r--r--app/controllers/users_controller.rb22
4 files changed, 41 insertions, 6 deletions
diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb
index a7b31ab..2344602 100644
--- a/app/controllers/forumgroups_controller.rb
+++ b/app/controllers/forumgroups_controller.rb
@@ -5,7 +5,12 @@ class ForumgroupsController < ApplicationController
end
def show
- redirect_to forums_path + "#group-#{params[:id].to_i}"
+ if request.format.html?
+ redirect_to forums_path + "#group-#{params[:id].to_i}"
+ else
+ fg = Forumgroup.find_by(id: params[:id])
+ respond_to {|format| format.json {render json: (fg.attributes.to_json if fg.try(:can_read?, :current_user))}}
+ end
end
def edit
@@ -77,4 +82,4 @@ class ForumgroupsController < ApplicationController
params.require(:forumgroup).permit(a)
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb
index ecf570e..cebdf65 100644
--- a/app/controllers/forums_controller.rb
+++ b/app/controllers/forums_controller.rb
@@ -13,6 +13,11 @@ class ForumsController < ApplicationController
[t.sticky ? 0 : 1, -(t.replies.last.try(:created_at) || t.created_at).to_i]
end
@threads = Kaminari.paginate_array(@threads).page(params[:page])
+ respond_to do |format|
+ format.html
+ f = Forum.find_by(id: params[:id])
+ format.json {render json: f.attributes.to_json}
+ end
end
def edit
@@ -92,4 +97,4 @@ class ForumsController < ApplicationController
a = [:name, :position, :role_read_id, :role_write_id] + add
params.require(:forum).permit(a)
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb
index b9b5714..a2485ef 100644
--- a/app/controllers/forumthreads_controller.rb
+++ b/app/controllers/forumthreads_controller.rb
@@ -7,7 +7,12 @@ class ForumthreadsController < ApplicationController
end
def show
- @replies = @thread.replies.page(params[:page])
+ if @thread
+ @replies = @thread.replies.page(params[:page])
+ else
+ respond_to {|format| format.json {render json: Comment.find_by(id: params[:id][1..-1]).try(:attributes).to_json}}
+ end
+
end
def edit
@@ -92,4 +97,4 @@ class ForumthreadsController < ApplicationController
a += add
params.require(:forumthread).permit(a)
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 64aa2b7..2501e15 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -4,7 +4,7 @@ class UsersController < ApplicationController
include MailerHelper
include ERB::Util
- before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions]
+ before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions, :update_memory]
def index
if params[:role]
@@ -327,6 +327,26 @@ class UsersController < ApplicationController
end
end
+ def memory
+ params[:page] ||= (page ||= 1)
+ file = File.open("/etc/minecraft/redstoner/plugins/JavaUtils/memory/hexfile.hex")
+ @hex_a = file.read.unpack("C*").map {|h| h.to_s(16)}
+ @hex_a = Kaminari.paginate_array(@hex_a).page(params[:page]).per(2048)
+ file.close
+ end
+
+ def update_memory
+ file = File.open("/etc/minecraft/redstoner/plugins/JavaUtils/memory/hexfile.hex")
+ new_text = file.read
+ file.close
+ new_text = new_text.unpack("C*").collect{|h| h.to_s(16)}
+ new_text[params[:mem_id].split("-")[1].to_i] = params[:value]
+ file = File.open("/etc/minecraft/redstoner/plugins/JavaUtils/memory/hexfile.hex", "w")
+ file.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
+ file.close
+ render nothing: true
+ end
+
private
def validate_token(uuid, email, token)