Skip to content

Commit

Permalink
Merge pull request #6 from creativepsyco/app_api
Browse files Browse the repository at this point in the history
Stable Uploads now safe to do a pull request
  • Loading branch information
creativepsyco committed Mar 19, 2013
2 parents 52d5318 + 3b22394 commit 0fd30b1
Show file tree
Hide file tree
Showing 25 changed files with 378 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ capybara-*.html
**.orig
rerun.txt
pickle-email-*.html
public/system
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ gem "cancan"

gem 'jquery-rails'

gem "paperclip", "~> 3.0"

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GEM
bcrypt-ruby (3.0.1)
builder (3.0.4)
cancan (1.6.8)
cocaine (0.4.2)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand Down Expand Up @@ -61,6 +62,12 @@ GEM
mime-types (1.21)
multi_json (1.6.1)
orm_adapter (0.4.0)
paperclip (3.3.1)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.4.0)
mime-types
pg (0.14.1)
polyglot (0.3.3)
rack (1.4.5)
Expand Down Expand Up @@ -119,6 +126,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
devise (>= 2.1.0)
jquery-rails
paperclip (~> 3.0)
pg
rails (= 3.2.11)
sass-rails (~> 3.2.3)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,14 @@ cancel_user_registration GET /users/cancel(.:format) devise/registrati


```

###Requirements
---------------
Symlink your system folder with rails public/system folder
``` perl
bash $ ln -s /panex/system public/system
```


###A Sub-Heading
-------------
3 changes: 3 additions & 0 deletions app/assets/javascripts/apps.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/apps.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the apps controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
96 changes: 96 additions & 0 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
class AppsController < ApplicationController
before_filter :authenticate_user!
# GET /apps
# GET /apps.json
def index
@apps = App.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @apps }
end
end

# GET /apps/1
# GET /apps/1.json
def show
@app = App.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @app }
end
end

# GET /apps/new
# GET /apps/new.json
def new
@app = App.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @app }
end
end

# GET /apps/1/edit
def edit
@app = App.find(params[:id])
end

# POST /apps
# POST /apps.json
def create
puts params
# XXX: make sure authenticated person is same
app_data = {
:name => params[:name],
:description => params[:description],
:thumbnail => params[:thumbnail],
:helpLink => params[:helpLink],
:version => params[:version],
:user_id => params[:user_id],
:appFile => params[:appFile]
}
@app = App.new(app_data)

respond_to do |format|
if @app.save
format.html #{ redirect_to @app, notice: 'App was successfully created.' }
format.json { render json: @app, status: :created }
else
format.html # { render action: "new" }
format.json { render json: @app.errors, status: :unprocessable_entity }
end
end
end

# PUT /apps/1
# PUT /apps/1.json
def update
@app = App.find(params[:id])
@app.user = User.find(params[:user_id])

respond_to do |format|
if @app.update_attributes(params[:app])
format.html # { redirect_to @app, notice: 'App was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @app.errors, status: :unprocessable_entity }
end
end
end

# DELETE /apps/1
# DELETE /apps/1.json
def destroy
@app = App.find(params[:id])
@app.destroy

respond_to do |format|
format.html # { redirect_to apps_url }
format.json { head :no_content }
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def destroy
@user.destroy

respond_to do |format|
format.html { redirect_to users_url }
format.html # { redirect_to users_url }
format.json { head :no_content }
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/apps_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AppsHelper
end
10 changes: 10 additions & 0 deletions app/models/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class App < ActiveRecord::Base
belongs_to :user
attr_accessible :description, :helpLink, :name, :user_id, :version, :thumbnail, :appFile

has_attached_file :thumbnail,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png"

has_attached_file :appFile
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :role, :name
# attr_accessible :title, :body

validates :name, presence: true
VALID_EMAIL_REGEX = /\A[A-Z0-9._%+\-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }

has_many :apps #, :foreign_key => "user_id" #used when wanting to a diff foriegn_key
end
37 changes: 37 additions & 0 deletions app/views/apps/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_for(@app) do |f| %>
<% if @app.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@app.errors.count, "error") %> prohibited this app from being saved:</h2>

<ul>
<% @app.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_field :description %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="field">
<%= f.label :helpLink %><br />
<%= f.text_field :helpLink %>
</div>
<div class="field">
<%= f.label :version %><br />
<%= f.text_field :version %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/apps/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing app</h1>

<%= render 'form' %>
<%= link_to 'Show', @app %> |
<%= link_to 'Back', apps_path %>
31 changes: 31 additions & 0 deletions app/views/apps/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<h1>Listing apps</h1>

<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>User</th>
<th>Helplink</th>
<th>Version</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @apps.each do |app| %>
<tr>
<td><%= app.name %></td>
<td><%= app.description %></td>
<td><%= app.user_id %></td>
<td><%= app.helpLink %></td>
<td><%= app.version %></td>
<td><%= link_to 'Show', app %></td>
<td><%= link_to 'Edit', edit_app_path(app) %></td>
<td><%= link_to 'Destroy', app, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New App', new_app_path %>
5 changes: 5 additions & 0 deletions app/views/apps/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New app</h1>

<%= render 'form' %>
<%= link_to 'Back', apps_path %>
30 changes: 30 additions & 0 deletions app/views/apps/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<p id="notice"><%= notice %></p>

<p>
<b>Name:</b>
<%= @app.name %>
</p>

<p>
<b>Description:</b>
<%= @app.description %>
</p>

<p>
<b>User:</b>
<%= @app.user_id %>
</p>

<p>
<b>Helplink:</b>
<%= @app.helpLink %>
</p>

<p>
<b>Version:</b>
<%= @app.version %>
</p>


<%= link_to 'Edit', edit_app_path(@app) %> |
<%= link_to 'Back', apps_path %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
PanexWebApi::Application.routes.draw do


resources :patients
resources :apps, :only => [:index, :show]


devise_for(:users, :controllers => { :sessions => "sessions" })

resources :users
resources :users do
resources :apps, :only => [:create, :update, :destroy]
end

root :to => "home#index"
# The priority is based upon order of creation:
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20130318173335_create_apps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateApps < ActiveRecord::Migration
def change
create_table :apps do |t|
t.string :name
t.string :description
t.integer :user_id
t.string :helpLink
t.string :version

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130318175019_add_thumbnail_to_apps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddThumbnailToApps < ActiveRecord::Migration
def change
add_attachment :apps, :thumbnail
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130319152734_add_app_file_to_apps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAppFileToApps < ActiveRecord::Migration
def change
add_attachment :apps, :appFile
end
end
Loading

0 comments on commit 0fd30b1

Please sign in to comment.