From 361b15e3986151b7bc220a4147e8b3d016683d52 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sat, 1 Jul 2017 04:44:00 +0200 Subject: Added more json support --- app/controllers/forumgroups_controller.rb | 9 +++++++-- app/controllers/forums_controller.rb | 7 ++++++- app/controllers/forumthreads_controller.rb | 9 +++++++-- app/controllers/users_controller.rb | 22 +++++++++++++++++++++- 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) -- cgit v1.2.3