mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 11:36:45 +00:00
Cleaned up habits view via helpers
This commit is contained in:
parent
c70b082b22
commit
e4afd5c9e5
3 changed files with 39 additions and 23 deletions
|
|
@ -8,11 +8,14 @@
|
|||
.good { background-color:rgb(147, 196, 125); }
|
||||
.done { background-color:rgb(201, 218, 248); }
|
||||
|
||||
#habits, #daily {
|
||||
.habit {
|
||||
list-style:none;
|
||||
border: 1px solid black;
|
||||
margin: 2px;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
#habits li:hover, #daily li:hover {
|
||||
.habit:hover {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,28 @@
|
|||
module HabitsHelper
|
||||
|
||||
def score_color(habit)
|
||||
s = habit.score
|
||||
case
|
||||
when s<-5 then return 'bad'
|
||||
when s>=-5 && s<0 then return 'iffy'
|
||||
when s>=0 && s<5 then return 'ok'
|
||||
when s>=5 && s<15 then return 'good'
|
||||
when s>=15 then return 'done'
|
||||
end
|
||||
end
|
||||
|
||||
def vote_link(habit, state)
|
||||
case state
|
||||
when 'up'
|
||||
return unless habit.up
|
||||
text,dir,style = "+","up","up"
|
||||
when 'down'
|
||||
return unless habit.down
|
||||
text,dir,style = "-","down","down"
|
||||
when 'checked' then text,dir,style = "[ ]","up","check"
|
||||
when 'unchecked' then text,dir,style = "[X]","down","check"
|
||||
end
|
||||
return link_to(text, { :action => "vote", :id => habit.id, :vote => 'dir' }, :class=>style, :remote=>true)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,28 +1,15 @@
|
|||
<li id="habit_<%= habit.id %>" class="ui-state-default">
|
||||
|
||||
<%
|
||||
s = habit.score
|
||||
case
|
||||
when s<-5 then score = 'bad'
|
||||
when s>=-5 && s<0 then score = 'iffy'
|
||||
when s>=0 && s<5 then score = 'ok'
|
||||
when s>=5 && s<15 then score = 'good'
|
||||
when s>=15 then score = 'done'
|
||||
end
|
||||
name = "<span class='#{score}'>#{h(habit.name)}</span>"
|
||||
%>
|
||||
|
||||
<li id="habit_<%= habit.id %>" class="habit <%= score_color(habit) %>">
|
||||
<% if habit.habit_type==Habit::ALWAYS %>
|
||||
<%= link_to("△", { :action => "vote", :id => habit.id, :vote => 'up' }, :class=>'up', :remote=>true) if habit.up %>
|
||||
<%= link_to("▽", { :action => "vote", :id => habit.id, :vote => 'down' }, :class=>'down', :remote=>true) if habit.down %>
|
||||
<%= raw name %> (<%= habit.score.to_i %>)
|
||||
<%= vote_link(habit, 'up') %>
|
||||
<%= vote_link(habit, 'down') %>
|
||||
<%= habit.name %>
|
||||
<% elsif habit.habit_type==Habit::DAILY %>
|
||||
<% if habit.done %>
|
||||
<%= link_to("[X]", { :action => "vote", :id => habit.id, :vote => 'down' }, :class=>'check', :remote=>true) %>
|
||||
<strike><%= raw name %></strike> (<%= habit.score.to_i %>)
|
||||
<%= vote_link(habit, 'checked') %>
|
||||
<strike><%= habit.name %></strike>
|
||||
<% else %>
|
||||
<%= link_to("[ ]", { :action => "vote", :id => habit.id, :vote => 'up' }, :class=>'check', :remote=>true) %>
|
||||
<%= raw name %> (<%= habit.score.to_i %>)
|
||||
<%= vote_link(habit, 'unchecked') %>
|
||||
<%= habit.name %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= link_to 'Edit', edit_habit_path(habit) %>
|
||||
|
|
|
|||
Loading…
Reference in a new issue