module Adminix module Web class Router < Server include ViewHelper def process_request if @http_request_uri == '/ping' render text: 'pong' elsif @http_request_uri == '/' dashboard_route elsif @http_request_uri == '/link' link_route elsif @http_request_uri =="/log" log_route elsif @http_request_uri =="/job" job_route elsif @http_request_uri =="/loadstamp" loadstamp_route elsif @http_request_uri =="/start" start_route elsif @http_request_uri == "/stop" stop_route else asset = Helpers::Files.read_asset(@http_request_uri) if asset render text: asset else not_found_route end end end # initialize def params params = {} ls = @http_query_string.to_s.split('&') return params if ls == '' ls.each do |p| parts = p.split('=') params[parts[0]] = parts[1] end return params end # Routes def dashboard_route content = view('dashboard.html') render html: content, content_type: 'text/html' end def link_route @page = !params['page'].nil? ? params['page'].to_i : 1 @per_page = 2 content = view('link.html') render html: content, content_type: 'text/html' end def log_route @page = !params['page'].nil? ? params['page'].to_i : 1 @per_page = 2 content = view('log.html') render html: content, content_type: 'text/html' end def job_route @page = !params['page'].nil? ? params['page'].to_i : 1 @per_page = 2 content = view('job.html') render html: content, content_type: 'text/html' end def loadstamp_route # Adminix.logger.debug params @page = !params['page'].nil? ? params['page'].to_i : 1 @per_page = 2 content = view('loadstamp.html') render html: content, content_type: 'text/html' end def start_route Adminix.watcher.app_service.start_process content = {"status": "process started"}.to_json render json: content end def stop_route Adminix.watcher.app_service.stop_process content = {"status": "process stopped"}.to_json render json: content end end end end