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 layout #291

Merged
merged 28 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
735069f
Add layout
MarioRodrigues10 Jul 15, 2023
eec29b2
Implement suggestions
MarioRodrigues10 Jul 21, 2023
7ce4cf3
Resolve conflicts
MarioRodrigues10 Jul 21, 2023
b22ab05
Rebase with recent updates
MarioRodrigues10 Aug 1, 2023
ab233a3
Add some updates
MarioRodrigues10 Aug 2, 2023
1d9331d
Add login/register pages
MarioRodrigues10 Aug 4, 2023
40d6902
Add proper documentation
MarioRodrigues10 Aug 5, 2023
c6db5e1
Add organization show page and other stuff
MarioRodrigues10 Aug 5, 2023
d5bfa92
Fix mobile layout
MarioRodrigues10 Aug 5, 2023
5600472
Add department description
MarioRodrigues10 Aug 5, 2023
f944f90
Add session_image and fix associations
MarioRodrigues10 Aug 5, 2023
ef44a9b
Change sidebar based on role
MarioRodrigues10 Aug 5, 2023
6a2136b
Fix scanner and add role verifier
MarioRodrigues10 Aug 5, 2023
2224b08
Add news
MarioRodrigues10 Aug 6, 2023
14ce2fb
Implement suggestions
MarioRodrigues10 Aug 6, 2023
15c282f
Add organization logo
MarioRodrigues10 Aug 6, 2023
68bda5a
Implement suggestions
MarioRodrigues10 Aug 7, 2023
d852cc5
Change organization with live component
MarioRodrigues10 Aug 7, 2023
b4cd1d8
Add partners seeds
MarioRodrigues10 Aug 7, 2023
68a9132
Add collaborators
MarioRodrigues10 Aug 9, 2023
ee6a7ac
Add users settings page
MarioRodrigues10 Aug 9, 2023
f04e40a
Add partners show page
MarioRodrigues10 Aug 9, 2023
4f69414
Add organization index page
MarioRodrigues10 Aug 9, 2023
b804ae5
Add boards
MarioRodrigues10 Aug 9, 2023
9dab7ba
Fix some issues when running without seeds
MarioRodrigues10 Aug 9, 2023
734cf33
Implement suggestions
MarioRodrigues10 Aug 9, 2023
9531d16
Fix some issues
MarioRodrigues10 Aug 10, 2023
6c97f7b
Fix small issue
MarioRodrigues10 Aug 10, 2023
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
4 changes: 3 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import {LiveSocket} from "phoenix_live_view"
import "../vendor/alpine.js";
import topbar from "../vendor/topbar"
import { QrScanner } from "./qr_reading.js";
import { InitSorting } from "./sorting.js";

let Hooks = {
QrScanner: QrScanner
QrScanner: QrScanner,
InitSorting: InitSorting
};

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
Expand Down
17 changes: 17 additions & 0 deletions assets/js/sorting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Sortable from "../vendor/sortable.js"

export const InitSorting = {
mounted() {
new Sortable(this.el, {
animation: 150,
ghostClass: "bg-slate-100",
dragClass: "shadow-2xl",
handle: ".handle",
onEnd: (evt) => {
const elements = Array.from(this.el.children)
const ids = elements.map(elm => elm.id)
this.pushEvent("update-sorting", {ids: ids})
}
})
}
}
9 changes: 8 additions & 1 deletion assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ module.exports = {
'../lib/*_web/**/*.*ex',
],
theme: {
extend: {},
extend: {
border: {
'1': '1px'
},
backgroundImage: {
'hero-pattern': "url('/images/atomic.png')",
},
},
},
plugins: [
require('@tailwindcss/forms'),
Expand Down
2 changes: 2 additions & 0 deletions assets/vendor/sortable.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import Config

config :atomic,
ecto_repos: [Atomic.Repo]
ecto_repos: [Atomic.Repo],
generators: [binary_id: true],
owner: %{
name: "Atomic",
time_zone: "Europe/Lisbon",
day_start: 0,
day_end: 24
}

# Configures the endpoint
config :atomic, AtomicWeb.Endpoint,
Expand Down Expand Up @@ -67,6 +74,9 @@ config :tailwind,
cd: Path.expand("../assets", __DIR__)
]

config :icons,
collection: [Heroicons, Ionicons]

config :atomic, Atomic.Scheduler,
jobs: [
# Runs every midnight:
Expand Down
104 changes: 98 additions & 6 deletions lib/atomic/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,36 @@ defmodule Atomic.Accounts do
|> Repo.insert()
end

@doc """
List all users.

## Examples

iex > list_users()
{:ok, [%User{}]}

iex > list_users()
{:error, %Ecto.Changeset{}}

"""
def list_users do
User
|> Repo.all()
end

@doc """
Gets a course by id.

Raises `Ecto.NoResultsError` if the Course does not exist.

## Examples

iex> get_course(123)
%Course{}

iex> get_course(456)
** (Ecto.NoResultsError)
"""
def get_course(id) do
Repo.get(Course, id)
end
Expand Down Expand Up @@ -115,6 +140,35 @@ defmodule Atomic.Accounts do
end
end

@doc """
Return the first and last name of a name.

## Examples

iex> extract_first_last_name("John Doe")
"John Doe"

iex> extract_first_last_name("John")
"John"

iex> extract_first_last_name(nil)
""

"""
def extract_first_last_name(name) do
names =
name
|> String.split(" ")
|> Enum.filter(&String.match?(String.slice(&1, 0, 1), ~r/^\p{L}$/u))
|> Enum.map(&String.capitalize/1)

case length(names) do
0 -> ""
1 -> hd(names)
_ -> List.first(names) <> " " <> List.last(names)
end
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.

Expand Down Expand Up @@ -388,29 +442,59 @@ defmodule Atomic.Accounts do
end
end

@doc """
Updates the user picture.

## Examples

iex> update_user_picture(user, %{profile_picture: ...})
{:ok, %User{}}

iex> update_user_picture(user, %{profile_picture: ...})
{:error, %Ecto.Changeset{}}

"""
def update_user_picture(%User{} = user, attrs \\ %{}) do
user
|> User.picture_changeset(attrs)
|> Repo.update()
end

@doc """
Updates the user.

## Examples

iex> update_user(user, %{field: value})
{:ok, %User{}}

iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}

"""
def update_user(%User{} = user, attrs \\ %{}) do
user
|> User.changeset(attrs)
|> Repo.update()
end

def change_user(%User{} = user, attrs \\ %{}) do
user
|> User.changeset(attrs)
end
@doc """
Gets a list of courses.

## Examples

iex> list_courses()
{:ok,[%Course{}]}

iex> list_courses()
{:error, %Ecto.Changeset{}}
"""
def list_courses do
Repo.all(Course)
end

@doc """
Creates a course
Creates a course.

## Examples

Expand All @@ -428,7 +512,15 @@ defmodule Atomic.Accounts do
end

@doc """
Gets the user's organizations
Gets an user organizations.

## Examples

iex> get_user_organizations(user)
{:ok,[%Organization{}]}

iex> get_user_organizations(user)
{:error, %Ecto.Changeset{}}
"""
def get_user_organizations(user) do
Repo.all(Ecto.assoc(user, :organizations))
Expand Down
3 changes: 3 additions & 0 deletions lib/atomic/accounts/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ defmodule Atomic.Accounts.Course do
timestamps()
end

@doc """
A changeset for a course.
"""
def changeset(course, attrs) do
course
|> cast(attrs, @required_fields)
Expand Down
9 changes: 6 additions & 3 deletions lib/atomic/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule Atomic.Accounts.User do
alias Atomic.Organizations.{Membership, Organization}
alias Atomic.Uploaders.ProfilePicture

@required_fields ~w(email password role name)a
@optional_fields ~w(course_id default_organization_id)a
@required_fields ~w(email password)a
@optional_fields ~w(name course_id default_organization_id)a

@roles ~w(admin student)a

Expand All @@ -24,7 +24,7 @@ defmodule Atomic.Accounts.User do

belongs_to :course, Course
field :profile_picture, ProfilePicture.Type
field :role, Ecto.Enum, values: @roles
field :role, Ecto.Enum, values: @roles, default: :student

has_many :enrollments, Enrollment

Expand Down Expand Up @@ -63,6 +63,9 @@ defmodule Atomic.Accounts.User do
|> cast_attachments(attrs, [:profile_picture])
end

@doc """
A user changeset for updating the user.
"""
def changeset(user, attrs) do
user
|> cast(attrs, @required_fields ++ @optional_fields)
Expand Down
Loading