Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
/log/*.log
/tmp

# Ignore .env (ENV variables), coverage (SimpleCov), .DS_Store
# Ignore .env (ENV variables), coverage (SimpleCov), .DS_Store, heroku
.env
coverage/
.DS_Store
.DS_Store
heroku.txt
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

[![Circle CI](https://circleci.com/gh/mtvillwock/jho.svg?style=svg&circle-token=:61c1a903f8b4b59801920e70480195dbc7295f69)](https://circleci.com/gh/mtvillwock/jho)

![JHO screenshot](./dbc-mixer-jho.png)

## Test Drive

1. `git clone https://github.com/mtvillwock/JHO.git` - clone down local copy of API
1. `cd JHO` - change directory
2. `bundle install` - install gems / dependencies
3. `rake db:create` - create database
4. `rake db:migrate` - migrate database tables
3. `rails s` - start server
4. Use the [client repo](https://github.com/mtvillwock/JHO_Angular_Experimentation) to interact with the API.

## Implemented:

- Rails API [deployed](https://jho.herokuapp.com) on Heroku
Expand Down
28 changes: 19 additions & 9 deletions app/controllers/boards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@ def index
end

def dashboard

board = @current_user.boards.first
lists = board.lists
cards = lists.map { |list| list.cards }
board = @current_user.boards.first # Board object
lists = board.lists # ActiveRecord collection of List objects
cards = lists.map { |list| list.cards } # AR collection of AR collections of cards
flat_cards = cards.flatten!
tasks = flat_cards.map { |card| card.tasks } # AR collection of AR collection of tasks

# create a hash of the board's attributes
board_hash = board.attributes
# initialize lists key in board hash
board_hash["lists"] = []

# build out nested board hash by adding lists and cards
# build out nested board hash by adding lists, cards and tasks
lists.each_with_index do |list, index|
# add hash of the list's attributes to lists array
board_hash["lists"] << list.attributes
board_hash["lists"][index]['cards'] = list.cards
# initialize cards key in list hash
board_hash["lists"][index]["cards"] = []
cards.each_with_index do |card, i|
# add hash of the cards's attributes to cards array
board_hash["lists"][index]["cards"] << card.attributes
# set card["tasks"] to an AR collection of the card's tasks
board_hash["lists"][index]["cards"][i]["tasks"] = card.tasks
end
end

# refactoring for efficiency
# refactor with include/joins for efficiency
# board.lists.include(:cards).to_json

# definitely should refactor this to use ActiveModel::Serializer
render json: { board: board_hash, lists: lists, cards: cards.flatten! }
# refactor this to use ActiveModel::Serializer or jBuilder for easier JSON manipulation
render json: { board: board_hash, lists: lists, cards: cards.flatten!, tasks: tasks.flatten! }
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ def destroy

private
def task_params
params.require(:task).permit(:card_id, :title, :completed)
params.require(:task).permit(:card_id, :title, :completed, :notes)
end
end
5 changes: 5 additions & 0 deletions db/migrate/20150927032613_add_notes_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotesToTasks < ActiveRecord::Migration
def change
add_column :tasks, :notes, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150915011113) do
ActiveRecord::Schema.define(version: 20150927032613) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -78,6 +78,7 @@
t.boolean "completed", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "notes"
end

create_table "users", force: :cascade do |t|
Expand Down
Binary file added dbc-mixer-jho.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions jho-schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, https://github.com/ondras/wwwsqldesigner/ -->
<!-- Active URL: http://ondras.zarovi.cz/sql/demo/ -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" quote=""/>
<type label="TINYINT" length="0" sql="TINYINT" quote=""/>
<type label="SMALLINT" length="0" sql="SMALLINT" quote=""/>
<type label="MEDIUMINT" length="0" sql="MEDIUMINT" quote=""/>
<type label="INT" length="0" sql="INT" quote=""/>
<type label="BIGINT" length="0" sql="BIGINT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>
</group>

<group label="Character" color="rgb(255,200,200)">
<type label="Char" length="1" sql="CHAR" quote="'"/>
<type label="Varchar" length="1" sql="VARCHAR" quote="'"/>
<type label="Text" length="0" sql="MEDIUMTEXT" re="TEXT" quote="'"/>
<type label="Binary" length="1" sql="BINARY" quote="'"/>
<type label="Varbinary" length="1" sql="VARBINARY" quote="'"/>
<type label="BLOB" length="0" sql="BLOB" re="BLOB" quote="'"/>
</group>

<group label="Date &amp; Time" color="rgb(200,255,200)">
<type label="Date" length="0" sql="DATE" quote="'"/>
<type label="Time" length="0" sql="TIME" quote="'"/>
<type label="Datetime" length="0" sql="DATETIME" quote="'"/>
<type label="Year" length="0" sql="YEAR" quote=""/>
<type label="Timestamp" length="0" sql="TIMESTAMP" quote="'"/>
</group>

<group label="Miscellaneous" color="rgb(200,200,255)">
<type label="ENUM" length="1" sql="ENUM" quote=""/>
<type label="SET" length="1" sql="SET" quote=""/>
<type label="Bit" length="0" sql="bit" quote=""/>
</group>
</datatypes><table x="299" y="50" name="boards">
<row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<row name="name" null="1" autoincrement="0">
<datatype>VARCHAR</datatype>
<default>NULL</default></row>
<row name="user_id" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="users" row="id" />
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="169" y="22" name="users">
<row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="452" y="101" name="lists">
<row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<row name="name" null="1" autoincrement="0">
<datatype>VARCHAR</datatype>
<default>NULL</default></row>
<row name="board_id" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="boards" row="id" />
</row>
<row name="position_id" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="601" y="202" name="cards">
<row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<row name="list_id" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="lists" row="id" />
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
<table x="801" y="301" name="tasks">
<row name="id" null="1" autoincrement="1">
<datatype>INTEGER</datatype>
<default>NULL</default></row>
<row name="card_id" null="1" autoincrement="0">
<datatype>INTEGER</datatype>
<default>NULL</default><relation table="cards" row="id" />
</row>
<row name="title" null="1" autoincrement="0">
<datatype>VARCHAR</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
</sql>