From 8cafeae03092a643c1167aa5ade4d42ac470735f Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sun, 27 Apr 2014 03:11:47 +0100 Subject: [PATCH] Merged in changes from https://github.com/taekwonjoe01/ensl.org --- app/controllers/posts_controller.rb | 1 + app/controllers/servers_controller.rb | 7 +++++-- app/controllers/teams_controller.rb | 2 +- app/models/team.rb | 4 ++++ app/models/user.rb | 2 +- app/views/servers/show.html.erb | 1 + app/views/teams/index.html.erb | 12 ++++++++++++ app/views/users/index.html.erb | 1 + config/locales/en.yml | 3 ++- 9 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 6e1da8f..c2830d5 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -27,6 +27,7 @@ class PostsController < ApplicationController if @post.save flash[:notice] = t(:posts_create) format.js { render } + format.html { return_to } else format.html { render :new } end diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 1197d7c..72825c2 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -66,8 +66,11 @@ class ServersController < ApplicationController def destroy raise AccessError unless @server.can_destroy? cuser - @server.destroy - redirect_to(servers_url) + + if @server.destroy + flash[:notice] = t(:server_destroy) + redirect_to servers_url + end end private diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index a610a21..4151ab5 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -2,7 +2,7 @@ class TeamsController < ApplicationController before_filter :get_team, only: [:show, :edit, :update, :destroy, :recover] def index - @teams = Team.with_teamers_num(0).ordered + @teams = Team.search(params[:search]).paginate(per_page: 40, page: params[:page]).with_teamers_num(0).ordered end def show diff --git a/app/models/team.rb b/app/models/team.rb index 44eca06..a427900 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -88,6 +88,10 @@ class Team < ActiveRecord::Base founder.update_attribute :team_id, self.id end + def self.search(search) + search ? where("LOWER(name) LIKE LOWER(?)", "%#{search}%") : scoped + end + def destroy if matches.count > 0 update_attribute :active, false diff --git a/app/models/user.rb b/app/models/user.rb index 543ee4b..f56319e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -280,6 +280,6 @@ class User < ActiveRecord::Base end def self.search(search) - search ? where('username LIKE ?', "%#{search}%") : scoped + search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : scoped end end diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 31b3ada..73502a9 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -17,6 +17,7 @@ <% if @server.can_update? cuser %> <%= link_to 'Edit Server', edit_server_path(@server), class: 'button' %> + <%= link_to 'Delete Server', @server, confirm: 'Are you sure?', method: :delete, class: 'button' %> <% if @server.domain == Server::DOMAIN_HLTV %> <%= link_to 'Default Record', action: "default", id: @server, class: 'button' %> <% end %> diff --git a/app/views/teams/index.html.erb b/app/views/teams/index.html.erb index 29ad380..05966f3 100644 --- a/app/views/teams/index.html.erb +++ b/app/views/teams/index.html.erb @@ -1,5 +1,17 @@

Listing teams

Teams with no current members are not displayed.

+

Search for teams by name:

+ +<%= form_tag(teams_path, method: 'get', class: 'square search') do %> + <%= hidden_field_tag :direction, params[:direction] %> + <%= hidden_field_tag :sort, params[:sort] %> +
+ <%= text_field_tag :search, params[:search] %> +
+
+ <%= submit_tag "Search", name: nil %> +
+<% end %>
<%= render partial: 'list', locals: { teams: @teams } %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 97d9b6c..2f68d6e 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,5 @@

Listing Users

+

Search for users by name or Steam ID:

<%= form_tag(users_path, method: 'get', class: 'square search') do %> <%= hidden_field_tag :direction, params[:direction] %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 7b019e4..bfe3d27 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -64,7 +64,8 @@ en: predictions_create: "Prediction was successfully created." servers_updated: "Servers updated." servers_create: "Server was successfully created." - servers_update: "Server was successfully update." + servers_update: "Server was successfully updated." + server_destroy: "Server was removed successfully." invalid_message: "Invalid message." sites_create: "Site was successfully created." sites_update: "Site was successfully updated."