Skip to content

Commit

Permalink
everything basic except project edit for queen jodreen
Browse files Browse the repository at this point in the history
everything basic except edit project view

years visible and white space

add TODOs, remove button

create all data values when years are created

demo and manually entered

refactoring for ma boi sameroni

turn autocomplete off

added loader but didn't need it

refactor destroys, add confirm for deleting data types, edit seeds one last time

delete all unneeded parts of static mockups and any uninformative comments

remove useless static controllers spec
  • Loading branch information
kevintxwu committed Oct 27, 2015
1 parent ee056ba commit 888afd9
Show file tree
Hide file tree
Showing 47 changed files with 701 additions and 496 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ gem "recipient_interceptor"
gem "simple_form"
gem "turbolinks"

# Formula parser
gem 'dentaku'

# Frontend
gem "autoprefixer-rails"
gem "coffee-rails"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ GEM
daemons (1.2.3)
database_cleaner (1.5.1)
debug_inspector (0.0.2)
dentaku (2.0.5)
devise (3.5.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -338,6 +339,7 @@ DEPENDENCIES
codeclimate-test-reporter
coffee-rails
database_cleaner
dentaku
devise
factory_girl_rails
ffaker
Expand Down
35 changes: 28 additions & 7 deletions app/assets/stylesheets/ayylmao.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ a {
transition: $transition;
}

.active {
#active {
opacity: 1;
}

Expand Down Expand Up @@ -140,15 +140,20 @@ a.card h1:hover {
max-width: 300px;
}

.h1-alt {
.h1-alt, .btn, input[type="submit"] {
padding: 15px 20px !important;
font-size: 14px !important;
background: $gray !important;
color: $white;
border: none;
border-radius: 4px;
font-weight: 500;
opacity: 0.8;
}

.h1-alt:hover {
.h1-alt:hover, .btn:hover, input[type="submit"]:hover {
opacity: 1;
cursor: pointer;
}

.gray {
Expand All @@ -164,6 +169,15 @@ a.card h1:hover {
padding: 30px;
}

.card-content-form {
padding-top: 15px;
padding-bottom: 15px;
}

.card-content-alt {
padding-bottom: 15px;
}

h2, h3, p {
padding: 0;
margin: 0;
Expand All @@ -185,7 +199,7 @@ h2, h3, p {
.heavy {
display: inline-block;
font-weight: 400;
min-width: 100px;
min-width: 150px;
}

.light {
Expand Down Expand Up @@ -282,10 +296,17 @@ h2, h3, p {
background-color: $teal;
}

input[type="text"], input[type="password"] {
label {
display: inline-block;
font-weight: 500;
min-width: 150px;
}

input[type="text"], input[type="password"], input[type="number"] {
border: 1px solid $white !important;
}

input[type="text"]:hover, input[type="password"]:hover, input[type="text"]:focus, input[type="password"]:focus {
input[type="text"]:hover, input[type="password"]:hover, input[type="number"]:hover,
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus {
border: 1px solid $teal !important;
}
}
6 changes: 2 additions & 4 deletions app/assets/stylesheets/index.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@
border: 1px solid $teal !important;
}

.search-wrapper select {
select {
height: 50px;
background: $white;
background: $lighter-gray;
border: none;
float: left;
color: $black;
margin-left: 20px;
border: 1px solid $white;
padding-left: 20px !important;
padding-right: 50px !important;
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/login.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#login-bg {
position: absolute;
z-index: 98;
z-index: 100;
top: 0;
left: 0;
bottom: 0;
Expand Down Expand Up @@ -206,7 +206,7 @@
left: 0;
right: 0;
bottom: 0;
z-index: 99;
z-index: -2;
background: $content-gray;
}

Expand Down
4 changes: 1 addition & 3 deletions app/assets/stylesheets/project.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ table {
box-shadow: -1px -1px 0px 0px $teal;
border-right: 1px solid $teal !important;
border-bottom: 1px solid $teal !important;
// background: $green;
// color: $white;
}

.formula {
Expand All @@ -165,7 +163,7 @@ table {
}

.card-content input {
width: 150px;
width: 290px;
padding: 15px 20px;
background: $lighter-gray;
border: none;
Expand Down
14 changes: 11 additions & 3 deletions app/controllers/data_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ def index
end

def new
@data_types = DataType.all
@data_type = DataType.new
end

def edit
@data_types = DataType.all
@data_type = DataType.find(params[:id])
end

def create
@data_type = DataType.new(data_type_params)

@years = Year.all
@data_type.save

@years.each do |year|
@data_value = DataValue.new(value: 0.0, year: year, data_type: @data_type)
@data_value.save
end

redirect_to action: "index"
end

Expand All @@ -29,8 +37,8 @@ def update
end

def destroy
@data_type = DataType.find(params[:id])
@data_type.destroy
DataType.destroy params[:id]

redirect_to action: "index"
end

Expand Down
12 changes: 0 additions & 12 deletions app/controllers/data_values_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
class DataValuesController < ApplicationController
def create
@data_value = DataValue.new(data_value_params)
@data_types = DataType.all

if @data_value.save
@data_types.find(@data_value.data_type_id) << @data_value
redirect_to @data_value.year.project
else
render 'new'
end
end

private
def data_value_params
params.require(:data_value).permit(:value)
Expand Down
62 changes: 60 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,69 @@
require 'tsort'

# Topological sorting hash
class TsortableHash < Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end

class ProjectsController < ApplicationController
def index
@projects = Project.all
end

# TODO (kevin): Transfer to service object
def show
@project = Project.find(params[:id])
@data_types = DataType.all
@data_values = DataValue.all

# Find dependencies of each data value
data_values = TsortableHash[]
@data_values.each do |data_value|
# Only calculate data values in this project
if @project.years.find_by_id(data_value.year_id)
formula = @data_types.find(data_value.data_type_id).formula
if formula
year = data_value.year_id
dependencies = []
@data_types.each do |data_type|
if formula.include? derscore(data_type.name)
dependencies.push(@data_values.find_by(year: year, data_type: data_type))
end
end
data_values[data_value] = dependencies
else
data_values[data_value] = []
end
end
end

# Calculate data values in topological order
data_values.tsort.each do |data_value|
formula = @data_types.find(data_value.data_type_id).formula
if formula
# Initialize calculator and year
calculator = Dentaku::Calculator.new
year = data_value.year_id
@data_types.each do |data_type|
if formula.include? derscore(data_type.name)
name = derscore(data_type.name)
value = @data_values.find_by(year: year, data_type: data_type).value
calculator.store(name => value)
end
end
# Evaluate formula and save
data_value.value = calculator.evaluate(formula)
data_value.save
end
end
end

def derscore(string)
return string.split(' ').join('_')
end

def new
Expand Down Expand Up @@ -36,8 +95,7 @@ def update
end

def destroy
@project = Project.find(params[:id])
@project.destroy
Project.destroy params[:id]

redirect_to projects_path
end
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
class StaticPagesController < ApplicationController
def home
end

def help
end
end
8 changes: 6 additions & 2 deletions app/controllers/years_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def edit

def create
@projects = Project.all
@data_types = DataType.all

@projects.each do |project|
@year = Year.new(year_params)
Expand All @@ -25,6 +26,10 @@ def create
else
render 'new'
end
@data_types.each do |data_type|
@data_value = DataValue.new(value: 0.0, year: @year, data_type: data_type)
@data_value.save
end
end
redirect_to years_path
end
Expand All @@ -40,8 +45,7 @@ def update
end

def destroy
@year = Year.find(params[:id])
@year.destroy
Year.destroy params[:id]

redirect_to years_path
end
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module ApplicationHelper
def is_active?(page_name)
"active" if params[:controller] == page_name
end
end
2 changes: 1 addition & 1 deletion app/models/data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# updated_at :datetime not null

class DataType < ActiveRecord::Base
has_many :data_values
has_many :data_values, :dependent => :destroy
end
3 changes: 2 additions & 1 deletion app/models/data_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
# data_type_id :integer not null

class DataValue < ActiveRecord::Base
belongs_to :year, :data_type
belongs_to :year
belongs_to :data_type
end
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
#

class Project < ActiveRecord::Base
has_many :years
has_many :years, :dependent => :destroy
end
2 changes: 1 addition & 1 deletion app/models/year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

class Year < ActiveRecord::Base
belongs_to :project
has_many :data_values
has_many :data_values, :dependent => :destroy
end
5 changes: 0 additions & 5 deletions app/views/data_types/_form.html.erb

This file was deleted.

Loading

0 comments on commit 888afd9

Please sign in to comment.