Skip to content

Commit

Permalink
Release 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Jorge committed Nov 11, 2020
2 parents e908471 + b63a1bc commit 8711930
Show file tree
Hide file tree
Showing 52 changed files with 887 additions and 177 deletions.
2 changes: 2 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@import './navbar.scss';
@import './footer.scss';

@import 'bulma';

/* This file is for your main application css. */
@import "../node_modules/nprogress/nprogress.css";
@import './phoenix.scss';
@import './landing.scss';
14 changes: 8 additions & 6 deletions assets/css/footer.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#page-container {
position: relative;
min-height: 100vh;
min-height: 95vh;
}

#content-wrap {
padding-bottom: 6rem;
padding-bottom: 12rem;
}

#footer {
position: absolute;
bottom: 0;
width: 100%;
height: 6rem;
padding-top: 1rem;
padding-bottom: 1rem;
}
max-height: 12rem;

.aligned-bottom {
align-items: baseline;
}
}
17 changes: 17 additions & 0 deletions assets/css/landing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.has-bg-img {
position: relative;

&:after {
background: url("/images/wallstreet.jpeg")center center;
background-size: cover;
filter: brightness(50%);
opacity: 0.2;
position: absolute;
content:'';
top:0px;
left: 0px;
width:100%;
height:100%;
z-index:-1;
}
}
8 changes: 8 additions & 0 deletions assets/css/navbar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.navbar {
max-height: 5rem;

&.top-of-page {
background-color: transparent;
background-image: none;
}
}
2 changes: 1 addition & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// its own CSS file.
import "../css/app.scss"

import "./nav-burger"
import "./nav"

// webpack automatically bundles all modules in your
// entry points. Those entry points can be configured
Expand Down
18 changes: 0 additions & 18 deletions assets/js/nav-burger.js

This file was deleted.

19 changes: 19 additions & 0 deletions assets/js/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import $ from "jquery";

$(window).on("scroll", () => {
var scrollPos = $(window).scrollTop();
if (scrollPos <= 100) {
$('.landing-nav').addClass('top-of-page');
$('.landing-nav').removeClass('is-light');
} else {
$('.landing-nav').removeClass('top-of-page');
$('.landing-nav').addClass('is-light');
}
});

$(document).on("ready", () => {
$(".navbar-burger").on("click", () => {
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
});
5 changes: 5 additions & 0 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"bulma": "^0.9.1",
"jquery": "^3.5.1",
"nprogress": "^0.2.0",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
Expand Down
Binary file added assets/static/images/franciscomaia.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/josegomes.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/lauraesteves.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/static/images/wallstreet.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions lib/infin/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ defmodule Infin.Accounts do
end

@doc """
Returns an `%Ecto.Changeset{}` for changing the user company.
Updates the user company.
"""
def change_user_company(user, attrs) do
User.company_changeset(user, attrs)
def change_user_company(user, company) do
user
|> Repo.preload(:company)
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_assoc(:company, company)
|> Repo.update!()
end

Expand Down Expand Up @@ -236,6 +239,7 @@ defmodule Infin.Accounts do
"""
def get_user_by_session_token(token) do
{:ok, query} = UserToken.verify_session_token_query(token)

query
|> Repo.one()
|> Repo.preload(:company)
Expand Down
39 changes: 2 additions & 37 deletions lib/infin/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Infin.Accounts.User do
field :password, :string, virtual: true
field :hashed_password, :string
field :confirmed_at, :naive_datetime
belongs_to :company, Infin.Companies.Company
belongs_to :company, Infin.Companies.Company, on_replace: :nilify

timestamps()
end
Expand All @@ -23,39 +23,13 @@ defmodule Infin.Accounts.User do
"""
def registration_changeset(user, attrs) do
user
|> cast(to_company_form(attrs), [:email, :password])
|> cast(attrs, [:email, :password])
|> validate_confirmation(:password, message: "does not match password")
|> cast_assoc(:company, required: true)
|> validate_email()
|> validate_password()
end

defp to_company_form(%{"nif" => nif, "name" => name} = attrs),
do: Map.put(attrs, "company", %{"nif" => nif, "name" => name})

defp to_company_form(%{nif: nif, name: name} = attrs),
do: Map.put(attrs, :company, %{nif: nif, name: name})

defp to_company_form(%{} = attrs), do: attrs

def copy_company_errors(%Ecto.Changeset{} = changeset) do
cond do
Map.has_key?(changeset.changes, :company) ->
company = changeset.changes.company

Enum.reduce(company.errors, changeset, fn err, acc ->
key = Kernel.elem(err, 0)
pre_message = Kernel.elem(err, 1)
message = Kernel.elem(pre_message, 0)

Ecto.Changeset.add_error(acc, key, message)
end)

true ->
changeset
end
end

defp validate_email(changeset) do
changeset
|> validate_required([:email])
Expand Down Expand Up @@ -108,15 +82,6 @@ defmodule Infin.Accounts.User do
|> validate_password()
end

@doc """
A user changeset for changing the company.
"""
def company_changeset(user, attrs) do
user
|> cast(attrs, [:company_id])
|> validate_required([:company_id])
end

@doc """
Confirms the account by setting `confirmed_at`.
"""
Expand Down
124 changes: 123 additions & 1 deletion lib/infin/companies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Infin.Companies do
"""
def create_company(attrs \\ %{}) do
%Company{}
|> Company.changeset(attrs)
|> Company.registration_changeset(attrs)
|> Repo.insert()
end

Expand Down Expand Up @@ -117,4 +117,126 @@ defmodule Infin.Companies do
def change_company(%Company{} = company, attrs \\ %{}) do
Company.changeset(company, attrs)
end

def preload_company_categories(%Company{} = company) do
Repo.preload(company, :categories)
end

alias Infin.Companies.Category

@doc """
Returns the list of categories.
## Examples
iex> list_categories()
[%Category{}, ...]
"""
def list_categories() do
Repo.all(Category)
end

def list_company_categories(company_id) do
Repo.all(from c in Category, where: c.company_id == ^company_id)
end

@doc """
Gets a single category.
Raises `Ecto.NoResultsError` if the Category does not exist.
## Examples
iex> get_category!(123)
%Category{}
iex> get_category!(456)
** (Ecto.NoResultsError)
"""
def get_category!(id), do: Repo.get!(Category, id)

def get_category(id), do: Repo.get(Category, id)

@doc """
Creates a category.
## Examples
iex> create_category(%{field: value})
{:ok, %Category{}}
iex> create_category(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_category(attrs) do
%Category{}
|> Category.changeset(attrs)
|> Repo.insert()
end

def create_category(attrs, company_id) do
category = %{:name => attrs["name"], :company_id => company_id}

%Category{}
|> Category.changeset(category)
|> Repo.insert()
end

@doc """
Updates a category.
## Examples
iex> update_category(category, %{field: new_value})
{:ok, %Category{}}
iex> update_category(category, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_category(%Category{} = category, attrs) do
category
|> Category.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a category.
## Examples
iex> delete_category(category)
{:ok, %Category{}}
iex> delete_category(category)
{:error, %Ecto.Changeset{}}
"""
def delete_category(%Category{} = category) do
Repo.delete(category)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking category changes.
## Examples
iex> change_category(category)
%Ecto.Changeset{data: %Category{}}
"""
def change_category(%Category{} = category, attrs \\ %{}) do
Category.changeset(category, attrs)
end

def change_category_company(category, company) do
category
|> Repo.preload(:company)
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_assoc(:company, company)
|> Repo.update!()
end
end
19 changes: 19 additions & 0 deletions lib/infin/companies/category.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Infin.Companies.Category do
use Ecto.Schema
import Ecto.Changeset

schema "categories" do
field :name, :string
belongs_to :company, Infin.Companies.Company, on_replace: :nilify

timestamps()
end

@doc false
def changeset(category, attrs) do
category
|> cast(attrs, [:name, :company_id])
|> validate_required([:name, :company_id])
|> unique_constraint([:name, :company_id])
end
end

0 comments on commit 8711930

Please sign in to comment.