mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 03:52:14 +00:00
Cleaning up rewards & showing on main page
This commit is contained in:
parent
dd96bfee83
commit
4004c4fbcc
8 changed files with 21 additions and 91 deletions
BIN
app/assets/images/dollar.png
Normal file
BIN
app/assets/images/dollar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 657 B |
|
|
@ -21,7 +21,7 @@
|
|||
margin-left:0px;
|
||||
}
|
||||
|
||||
.habit {
|
||||
.habit, .reward {
|
||||
list-style:none;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
text-shadow:none;
|
||||
}
|
||||
|
||||
.habit:hover {
|
||||
.habit:hover, .reward:hover {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class HabitsController < ApplicationController
|
|||
@habits = current_user.habits.where(:habit_type => Habit::ALWAYS)
|
||||
@daily = current_user.habits.where(:habit_type => Habit::DAILY)
|
||||
@one_time = current_user.habits.where(:habit_type => Habit::ONE_TIME).where(:done=>false)
|
||||
@rewards = current_user.rewards
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
|
|
|||
|
|
@ -1,30 +1,10 @@
|
|||
class RewardsController < ApplicationController
|
||||
# GET /rewards
|
||||
# GET /rewards.json
|
||||
def index
|
||||
@rewards = Reward.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @rewards }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /rewards/1
|
||||
# GET /rewards/1.json
|
||||
def show
|
||||
@reward = Reward.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @reward }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /rewards/new
|
||||
# GET /rewards/new.json
|
||||
def new
|
||||
@reward = Reward.new
|
||||
@reward.user_id = current_user.id
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
|
|
@ -34,17 +14,18 @@ class RewardsController < ApplicationController
|
|||
|
||||
# GET /rewards/1/edit
|
||||
def edit
|
||||
@reward = Reward.find(params[:id])
|
||||
@reward.user_id = current_user.id
|
||||
end
|
||||
|
||||
# POST /rewards
|
||||
# POST /rewards.json
|
||||
def create
|
||||
@reward = Reward.new(params[:reward])
|
||||
@reward.user_id = current_user.id
|
||||
|
||||
respond_to do |format|
|
||||
if @reward.save
|
||||
format.html { redirect_to @reward, notice: 'Reward was successfully created.' }
|
||||
format.html { redirect_to habits_url, notice: 'Reward was successfully created.' }
|
||||
format.json { render json: @reward, status: :created, location: @reward }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
|
|
@ -56,11 +37,11 @@ class RewardsController < ApplicationController
|
|||
# PUT /rewards/1
|
||||
# PUT /rewards/1.json
|
||||
def update
|
||||
@reward = Reward.find(params[:id])
|
||||
@reward = curren_user.rewards.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @reward.update_attributes(params[:reward])
|
||||
format.html { redirect_to @reward, notice: 'Reward was successfully updated.' }
|
||||
format.html { redirect_to habits_url, notice: 'Reward was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
|
|
@ -72,11 +53,11 @@ class RewardsController < ApplicationController
|
|||
# DELETE /rewards/1
|
||||
# DELETE /rewards/1.json
|
||||
def destroy
|
||||
@reward = Reward.find(params[:id])
|
||||
@reward = current_user.reward.find(params[:id])
|
||||
@reward.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to rewards_url }
|
||||
format.html { redirect_to habits_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,9 +55,19 @@
|
|||
<%= render 'money'%>
|
||||
</h2>
|
||||
<div class='inner'>
|
||||
<% @rewards.each do |reward| %>
|
||||
<li id="reward_<%= reward.id %>" class="reward">
|
||||
<%= link_to(image_tag('dollar.png'), { :controller=>"reward", :action => "buy", :id => reward.id }, :remote=>true) %>
|
||||
<%= reward.name %>
|
||||
<div class='edit'>
|
||||
<%= link_to 'Edit', edit_reward_path(reward) %>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%= link_to 'New Reward', new_reward_path %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -19,14 +19,6 @@
|
|||
<%= f.label :value %><br />
|
||||
<%= f.number_field :value %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :position %><br />
|
||||
<%= f.number_field :position %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :user_id %><br />
|
||||
<%= f.number_field :user_id %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
<h1>Listing rewards</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Value</th>
|
||||
<th>Position</th>
|
||||
<th>User</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @rewards.each do |reward| %>
|
||||
<tr>
|
||||
<td><%= reward.name %></td>
|
||||
<td><%= reward.value %></td>
|
||||
<td><%= reward.position %></td>
|
||||
<td><%= reward.user_id %></td>
|
||||
<td><%= link_to 'Show', reward %></td>
|
||||
<td><%= link_to 'Edit', edit_reward_path(reward) %></td>
|
||||
<td><%= link_to 'Destroy', reward, confirm: 'Are you sure?', method: :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Reward', new_reward_path %>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Name:</b>
|
||||
<%= @reward.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Value:</b>
|
||||
<%= @reward.value %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Position:</b>
|
||||
<%= @reward.position %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>User:</b>
|
||||
<%= @reward.user_id %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_reward_path(@reward) %> |
|
||||
<%= link_to 'Back', rewards_path %>
|
||||
Loading…
Reference in a new issue