Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternate color palettes #67

Merged
merged 6 commits into from Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
141 changes: 57 additions & 84 deletions priv/repo/seeds.exs
Expand Up @@ -10,13 +10,7 @@
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.

alias Streamr.{Repo, Topic, Stream, Color, StreamData}

defmodule SeedHelpers do
def aws_url(path) do
"https://s3-us-west-2.amazonaws.com/streamr-staging/Seeds/" <> path
end
end
alias Streamr.{Repo, Topic, Color}

Repo.delete_all Topic
Repo.insert! %Topic{name: "Art History"}
Expand All @@ -36,88 +30,67 @@ Repo.insert! %Topic{name: "Physics"}
Repo.insert! %Topic{name: "US History"}
Repo.insert! %Topic{name: "World History"}

Repo.delete_all StreamData
Repo.delete_all Stream
Repo.insert! %Stream{
title: "Electic Charge, Fields, and Potential pt. 1",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.25.36+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Electic Charge, Fields, and Potential pt. 2",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.26.01+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Half Life Into",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.27.00+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Linear Equations",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.29.31+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Riemann Sum Proof",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.30.04+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Squeeze Theorem Explained",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.34.46+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "Intro to Differential Equations",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.36.42+PM.png"),
user_id: 1
}

Repo.insert! %Stream{
title: "R-squared Coefficient",
image: SeedHelpers.aws_url("Screen+Shot+2017-01-29+at+6.38.11+PM.png"),
user_id: 1
}

# Blue
Repo.insert! %Color{
normal: "#61afef",
order: 5
}

# Red
Repo.insert! %Color{
normal: "#e06c75",
order: 2
normal_colors = %{
white: "#abb2bf",
red: "#e06c75",
orange: "#d19a66",
green: "#98c379",
blue: "#61afef",
purple: "#c678dd",
}

# Green
Repo.insert! %Color{
normal: "#98c379",
order: 4
deuteranopia_colors = %{
white: "#ffffff",
red: "#adedbd",
orange: "#d19a66",
green: "#9b9fa2",
blue: "#61afef",
purple: "#b940dd",
}

# Purps
Repo.insert! %Color{
normal: "#c678dd",
order: 6
protanopia_colors = %{
white: "#ffffff",
red: "#adedbd",
orange: "#d19a66",
green: "#9b9fa2",
blue: "#61afef",
purple: "#b940dd",
}

# Orange
Repo.insert! %Color{
normal: "#d19a66",
order: 3
tritanopia_colors = %{
white: "#ffffff",
red: "#adedbd",
orange: "#d19a66",
green: "#9b9fa2",
blue: "#61afef",
purple: "#c500ff",
}

# White
Repo.insert! %Color{
normal: "#abb2bf",
order: 1
}
color_orders = [
{:white, 1},
{:red, 2},
{:orange, 3},
{:green, 4},
{:blue, 5},
{:purple, 6}
]

Enum.each color_orders, fn {color_atom, order} ->
changes = %{
normal: normal_colors[color_atom],
protanopia: protanopia_colors[color_atom],
deuteranopia: deuteranopia_colors[color_atom],
tritanopia: tritanopia_colors[color_atom],
order: order
}

if color = Repo.get_by(Color, order: order) do
color
|> Color.changeset(changes)
|> Repo.update!()
else
%Color{}
|> Color.changeset(changes)
|> Repo.insert!()
end
end
4 changes: 4 additions & 0 deletions web/models/color.ex
Expand Up @@ -15,4 +15,8 @@ defmodule Streamr.Color do
from color in query,
order_by: [asc: color.order]
end

def changeset(color, params \\ []) do
cast(color, params, [:normal, :deuteranopia, :protanopia, :tritanopia, :order])
end
end