Archived
add color to roles, improvement in label color detection
This commit is contained in:
@@ -408,7 +408,6 @@ blockquote p {
|
|||||||
|
|
||||||
a.role {
|
a.role {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
color: #fff !important;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding: 4px 0.5em;
|
padding: 4px 0.5em;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@@ -419,20 +418,7 @@ blockquote p {
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
max-width: 27em; // works with the 30 character limit
|
max-width: 27em; // works with the 30 character limit
|
||||||
|
|
||||||
&.superadmin, &.admin {
|
|
||||||
background: #d22 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.mod {
|
|
||||||
background: #6af !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.normal {
|
|
||||||
background: #282 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.banned, &.disabled {
|
&.banned, &.disabled {
|
||||||
background: #ccc !important;
|
|
||||||
text-decoration: line-through !important;
|
text-decoration: line-through !important;
|
||||||
color: #888 !important;
|
color: #888 !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,19 @@ module ApplicationHelper
|
|||||||
render_youtube(md.render(content))
|
render_youtube(md.render(content))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# calculate the foreground color
|
||||||
|
# either +dark+ or +light+, based on the +bgcolor+
|
||||||
|
def fcolor(bgcolor = "#000", light = "#fff", dark = "#000")
|
||||||
|
bg = bgcolor.gsub(/[^0-9a-f]/i, "")
|
||||||
|
# convert 3 char to 6 char hex
|
||||||
|
bg.gsub!(/./, '\&\&') if bg.length == 3
|
||||||
|
sum = 0
|
||||||
|
[0, 2, 4].each do |i|
|
||||||
|
sum += bg[i..i+1].to_i(16)
|
||||||
|
end
|
||||||
|
return (sum/3 < 128) ? light : dark
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_youtube(content)
|
def render_youtube(content)
|
||||||
|
|||||||
@@ -8,20 +8,6 @@ class Label < ActiveRecord::Base
|
|||||||
name.upcase
|
name.upcase
|
||||||
end
|
end
|
||||||
|
|
||||||
# calculate the foreground color
|
|
||||||
# either black or white, based on the bg color
|
|
||||||
def fcolor
|
|
||||||
bg = color.dup
|
|
||||||
# convert 3 char to 6 char hex
|
|
||||||
bg.gsub!(/./, '\&\&') if bg.length == 3
|
|
||||||
[0, 2, 4].each do |i|
|
|
||||||
if bg[i..i+1] >= "7f"
|
|
||||||
return "000"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "fff"
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def color_valid
|
def color_valid
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ class Role < ActiveRecord::Base
|
|||||||
include Comparable
|
include Comparable
|
||||||
has_many :users
|
has_many :users
|
||||||
|
|
||||||
|
validates :color, format: {with: /#[0-9a-f]{3,6}/i}
|
||||||
|
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
self.name
|
self.name
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<% if label %>
|
<% if label %>
|
||||||
<span class="label label-<%= label.name.downcase %>" style="color: #<%= label.fcolor %>;background-color: #<%= label.color %>"><%= label %></span>
|
<span class="label label-<%= label.name.downcase %>" style="color: <%= fcolor(label.color) %>;background-color: #<%= label.color %>"><%= label %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<div class="user">
|
<div class="user">
|
||||||
<%= link_to user.name, user, class: "role #{user.role.name} #{"banned" if user.banned?} #{"disabled" if user.disabled?} #{"unconfirmed" unless user.confirmed?}", title: user.ign %>
|
<%= link_to user.name, user, class: "role #{user.role.name} #{"banned" if user.banned?} #{"disabled" if user.disabled?} #{"unconfirmed" unless user.confirmed?}", title: user.ign, style: "color: #{fcolor(user.role.color)}; background-color: #{user.role.color}" %>
|
||||||
<%= link_to "$", donate_statics_path, class: "role donor", title: "Donator" if user.donor? %>
|
<%= link_to "$", donate_statics_path, class: "role donor", title: "Donator" if user.donor? %>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddColorToRoles < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :roles, :color, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
+2
-1
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150117154652) do
|
ActiveRecord::Schema.define(version: 20150309221221) do
|
||||||
|
|
||||||
create_table "blogposts", force: true do |t|
|
create_table "blogposts", force: true do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
@@ -83,6 +83,7 @@ ActiveRecord::Schema.define(version: 20150117154652) do
|
|||||||
create_table "roles", force: true do |t|
|
create_table "roles", force: true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "value"
|
t.integer "value"
|
||||||
|
t.string "color"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "sessions", force: true do |t|
|
create_table "sessions", force: true do |t|
|
||||||
|
|||||||
+6
-6
@@ -2,12 +2,12 @@
|
|||||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||||
|
|
||||||
Role.create!([
|
Role.create!([
|
||||||
{name: "disabled", value: 1},
|
{name: "disabled", value: 1, color: "#ccc"},
|
||||||
{name: "banned", value: 2},
|
{name: "banned", value: 2, color: "#ccc"},
|
||||||
{name: "normal", value: 10},
|
{name: "normal", value: 10, color: "#282"},
|
||||||
{name: "mod", value: 100},
|
{name: "mod", value: 100, color: "#6af"},
|
||||||
{name: "admin", value: 200},
|
{name: "admin", value: 200, color: "#d22"},
|
||||||
{name: "superadmin", value: 500}
|
{name: "superadmin", value: 500, color: "#d22"}
|
||||||
])
|
])
|
||||||
|
|
||||||
userpw = SecureRandom.hex(64)
|
userpw = SecureRandom.hex(64)
|
||||||
|
|||||||
Reference in New Issue
Block a user