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

1 download text note #3

Merged
merged 9 commits into from
Jul 24, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ However, this application should be useful as a web application while outside th
- [ ] Download as text, html single note (In Progress)
- [ ] Export all notes as json
- [ ] Share notes as text (Social Media)
- [ ] Create User profile page CRUD operations (add fields like timezone, name, email, phone, profile_picture, language)
- [ ] Add multi language support (Google translate or pot?)
- [ ] Create institution role and dashboard
- [ ] Institution should be able to add, delete, enable, disable, update students
- [ ] Institution should be able to create pinned/read only notes for all students
Expand Down
14 changes: 13 additions & 1 deletion assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
html {
font-family: "Lucida Sans", sans-serif;
height: 100%;
width: 100%;
margin: 0;
}

Expand All @@ -23,14 +24,20 @@ html {
padding: 2px;
}

.fill-note-vw {
height: 75vh;
}

h1 {
font-family: 'Quicksand';
}

.root {
background-color: rgb(255, 255, 255);
height: 100vh;
}


.container {
margin: 0;
padding: 0;
Expand All @@ -40,6 +47,11 @@ h1 {
margin: 0;
}

.vh-fill {
height: 100%;
overflow-y: auto;
}

.ms-8 {
margin-left: ($spacer * 8) !important;
}
Expand All @@ -50,7 +62,7 @@ h1 {

.page_content {
background-color: rgb(245, 242, 240);
height: 80vh;
height: 94vh;
}

.footer {
Expand Down
2 changes: 2 additions & 0 deletions lib/buddi_manager/view_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ defmodule BuddiManager.ViewHelpers do
end)
end
end

def gen_dom_id, do: for(_ <- 1..8, into: "", do: <<Enum.random('abcdefghijklmnopqrstuvxyz')>>)
end
5 changes: 4 additions & 1 deletion lib/buddi_manager_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ defmodule BuddiManagerWeb do
quote do
use Phoenix.View,
root: "lib/buddi_manager_web/templates",
namespace: BuddiManagerWeb
namespace: BuddiManagerWeb,
pattern: "**/*"

# Import convenience functions from controllers
import Phoenix.Controller,
Expand Down Expand Up @@ -98,6 +99,8 @@ defmodule BuddiManagerWeb do

import BuddiManagerWeb.ErrorHelpers
import BuddiManagerWeb.Gettext
import HeexIgnore
import BuddiManagerWeb.DashboardComponents
alias BuddiManagerWeb.Router.Helpers, as: Routes
end
end
Expand Down
99 changes: 99 additions & 0 deletions lib/buddi_manager_web/components/dashboard_components.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
defmodule BuddiManagerWeb.DashboardComponents do
use Phoenix.Component
import BuddiManagerWeb.Gettext
import BuddiManager.ViewHelpers

@doc """
This module will hold phoenix static components for dashboard
"""
attr(:note, :any)
attr(:note_delete_path, :string)
attr(:note_show_path, :string)

def note_card(assigns) do
~H"""
<div class="card me-2 p-0" style="width: 16vw; height: 28vh;">
<h6 class="card_title bg-primary text-white text-center">
<%= if @note.label, do: @note.label, else: gettext("No title") %>
</h6>

<div class="card_body mx-2" style="height: 23vh; max-height: 23vh; overflow-y: auto">
<p class="card-text">
<%= note_visualize(@note) %>
</p>
</div>

<p class="mx-2 my-1 md-12 text-secondary"><%= "Created by: " <> @note.created_by %></p>

<div class="card-footer container align-items-center d-flex" style="height: 2rem">
<div class="col-6 d-flex flex-row justify-content-start">
<a
class="btn me-1 p-0 d-flex flex-row justify-content-start"
data-csrf={Plug.CSRFProtection.get_csrf_token()}
data-method="delete"
data-to={@note_delete_path}
data-confirm="Are you sure?"
title={gettext("Delete Note")}
>
<span class="material-icons md-18">
highlight_off
</span>
</a>

<button
class="btn me-1 p-0 d-flex flex-row justify-content-start"
data-method="get"
data-to={@note_show_path}
title={gettext("Full Screen")}
>
<span class="material-icons md-18">
aspect_ratio
</span>
</button>
</div>

<% container_id = gen_dom_id() %>

<div class="col-6 d-flex flex-row justify-content-end" id={container_id} phx-update="ignore">
<% toggle_id = gen_dom_id() %>
<% data_bs_parent = gen_dom_id() %>

<button
class="btn me-1 p-0 d-flex flex-row justify-content-start"
title={gettext("Download note")}
data-bs-toggle="collapse"
data-bs-target={"#" <> toggle_id}
aria-expanded="false"
aria-controls="optionsCollapse"
data-bs-parent={"#" <> data_bs_parent}
>
<span class="material-icons md-18">
download_for_offline
</span>
</button>

<button
class="btn me-1 p-0 d-flex flex-row justify-content-start"
title={gettext("Share note")}
>
<span class="material-icons md-18">
share
</span>
</button>
</div>

<div
class="collapse"
id={toggle_id}
data-bs-parent={"#" <> data_bs_parent}
style="z-index: 100;"
>
<button type="button" class="btn btn-secondary">Option 1</button>
<button type="button" class="btn btn-secondary">Option 2</button>
<button type="button" class="btn btn-secondary">Option 3</button>
</div>
</div>
</div>
"""
end
end
2 changes: 0 additions & 2 deletions lib/buddi_manager_web/controllers/dashboard_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ defmodule BuddiManagerWeb.DashboardController do
|> assign(:notes, notes)
|> assign(:per_page, per_page)
|> assign(:per_row, per_row)
|> put_layout("dashboard.html")
|> render("index.html")
end

end
43 changes: 6 additions & 37 deletions lib/buddi_manager_web/controllers/note_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,21 @@ defmodule BuddiManagerWeb.NoteController do
alias BuddiManager.Notes
alias BuddiManager.Notes.Note

action_fallback BuddiManagerWeb.FallbackController

def index(conn, _params) do
notes = Notes.list_notes()
render(conn, "index.json", notes: notes)
end

def create(conn, %{"note" => note_params}) do
with {:ok, %Note{} = note} <- Notes.create_note(note_params) do
conn
|> put_status(:created)
|> put_resp_header("location", Routes.note_path(conn, :show, note))
|> render("show.json", note: note)
end
def edit(conn, %{"id" => id}) do
conn
|> redirect(
to: Routes.live_path(BuddiManagerWeb.Endpoint, BuddiManagerWeb.NoteWebLive, note_id: id)
)
end

def show(conn, %{"id" => id}) do
note = Notes.get_note!(id)
render(conn, "show.json", note: note)
end

def update(conn, %{"id" => id, "note" => note_params}) do
note = Notes.get_note!(id)

with {:ok, %Note{} = note} <- Notes.update_note(note, note_params) do
render(conn, "show.json", note: note)
end
end

def delete(conn, %{"id" => id}) do
note = Notes.get_note!(id)

with {:ok, %Note{}} <- Notes.delete_note(note) do
send_resp(conn, :no_content, "")
end
end

def show_web(conn, %{"id" => id}) do
note = Notes.get_note!(id)

conn
|> put_layout("general.html")
|> render("show.html", note: note)
end

def delete_web(conn, %{"id" => id}) do
def delete(conn, %{"id" => id}) do
note = Notes.get_note!(id)

with {:ok, %Note{}} <- Notes.delete_note(note) do
Expand Down
1 change: 0 additions & 1 deletion lib/buddi_manager_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule BuddiManagerWeb.PageController do
|> assign(:notes, notes)
|> assign(:per_page, per_page)
|> assign(:per_row, per_row)
|> put_layout("dashboard.html")
|> render("index.html")
end
end
5 changes: 5 additions & 0 deletions lib/buddi_manager_web/heex_ignore.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule HeexIgnore do
use Phoenix.Component

def ignore(assigns), do: ~H""
end
34 changes: 19 additions & 15 deletions lib/buddi_manager_web/live_controllers/note_web_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ defmodule BuddiManagerWeb.NoteWebLive do
This module is reponsible for creating and updating notes
FIXME: Need to modify the liveview logic, by initializing with initial struct and later on update and validate based on that
"""
def mount(params, %{"user_token" => user_token} = _session, socket) do
def mount(%{"note_id" => note_id} = params, %{"user_token" => user_token} = _session, socket) do
user = BuddiManager.Accounts.get_user_by_session_token(user_token)
changeset = init_changeset(params, user)

action = if note_id, do: :edit, else: :create

socket =
socket
|> assign(current_user: user)
|> assign(action: action)
|> assign(changeset: changeset)
|> assign(preview_content: "")
|> assign(preview_label: "")

{:ok, socket}
end

def mount(params, %{"user_token" => _user_token} = session, socket) do
mount(Map.put(params, "note_id", nil), session, socket)
end

def render(assigns, _params \\ %{}) do
Phoenix.View.render(BuddiManagerWeb.NoteWebLiveView, "index.html", assigns)
end
Expand Down Expand Up @@ -82,19 +89,16 @@ defmodule BuddiManagerWeb.NoteWebLive do
end
end

defp init_changeset(params, user) do
params["id"]
|> case do
nil ->
%Note{
user: user,
content: ""
}
|> Note.changeset(%{})

note_id ->
Repo.get!(Note, note_id)
|> Note.changeset()
end
defp init_changeset(%{"note_id" => note_id} = _params, user) when not is_nil(note_id) do
Repo.get!(Note, note_id)
|> Note.changeset()
end

defp init_changeset(_params, user) do
%Note{
user: user,
content: ""
}
|> Note.changeset(%{})
end
end
Loading