Compare commits

...

64 Commits
0.1.10 ... dev

Author SHA1 Message Date
shibao 48f7c8d18e fix empty invite index page
continuous-integration/drone/push Build is passing Details
2024-02-24 13:14:38 -05:00
shibao 571e0b65b6 fix faq page copy 2024-02-23 23:36:00 -05:00
shibao 7dc2047e97 fix missing ssl and crypto packages
continuous-integration/drone/tag Build is passing Details
continuous-integration/drone/push Build is passing Details
2024-02-23 22:44:36 -05:00
shibao f769e710d8 sanitize tags while they are being typed
continuous-integration/drone/push Build is passing Details
2024-02-23 22:39:01 -05:00
shibao d09f698b71 remove requirement for note and content to have content 2024-02-23 22:34:08 -05:00
shibao 8666f663ba Prevent possible additional submissions 2024-02-23 22:31:51 -05:00
shibao 22ccea893c sanitize titles while they are being typed 2024-02-23 22:31:15 -05:00
shibao 362c406471 fix credo warning for is_owner? 2024-02-23 22:18:25 -05:00
shibao 2a87037f06 fix credo warning for is_owner_or_admin? 2024-02-23 22:17:56 -05:00
shibao 53d0dcfb15 fix credo warning for is_admin? 2024-02-23 22:17:19 -05:00
shibao c892b5449b fix credo warning for is_already_admin? 2024-02-23 22:16:08 -05:00
shibao 7cd9dca958 update elixir deps 2024-02-23 22:14:28 -05:00
shibao 0e8ddc22c5 update npm deps 2024-02-23 22:14:28 -05:00
shibao 3671ad6199 update tool versions 2024-02-23 22:14:20 -05:00
shibao 7189c955c3 bump version 2023-11-26 17:30:20 -05:00
shibao f56ecc0ba3 fix content being displayed when blank 2023-11-26 17:30:14 -05:00
shibao fdfca3f7a5 bump version
continuous-integration/drone/push Build is passing Details
2023-11-26 11:25:29 -05:00
shibao c61b2c67b7 fix issue with displaying content 2023-11-26 11:25:26 -05:00
shibao d0d958a638 update npm deps
continuous-integration/drone/push Build is passing Details
2023-11-04 23:46:21 -04:00
shibao a437b5966f update elixir deps 2023-11-04 23:40:15 -04:00
shibao e2378279d7 change how backlinks work
continuous-integration/drone/push Build is passing Details
2023-11-04 23:34:11 -04:00
shibao 1b49b668b3 add ctrl-enter submit 2023-11-04 22:40:56 -04:00
shibao 03021614b5 fix live flashes not dismissable by click 2023-11-04 22:22:46 -04:00
shibao 50af86798a fix warning in tests 2023-11-04 22:20:06 -04:00
shibao be01723be2 make content previews resizable 2023-11-04 22:19:35 -04:00
shibao 0a27a4ee29 make step content not a required field 2023-11-04 22:10:16 -04:00
shibao e2f8ac6b78 add bottom padding 2023-11-04 22:09:05 -04:00
shibao d5e334dc09 tolerate spaces in tags 2023-11-04 22:07:25 -04:00
shibao 1d6ba5960c fix debounces 2023-11-04 22:05:20 -04:00
shibao bc29ca6c20 update elixir/erlang version
continuous-integration/drone/push Build is passing Details
2023-10-20 18:25:36 -04:00
shibao bf9fd4880f run mix format
continuous-integration/drone/push Build is passing Details
2023-09-07 18:43:25 -04:00
shibao 957e433847 update dependencies 2023-09-07 18:43:25 -04:00
shibao edd631f520 run npm audit fix 2023-09-07 18:08:02 -04:00
shibao 2e1545a9f5 update npm 2023-09-07 18:07:21 -04:00
shibao 3e296080f5 fix user registration controller 2023-06-04 00:11:09 -04:00
shibao d2ae6024ce fix error/404 pages not rendering properly 2023-05-12 22:59:04 -04:00
shibao 4615a29c11 disable arm builds
continuous-integration/drone/push Build is passing Details
2023-04-16 21:36:33 -04:00
shibao eb48ff7dc0 build in arm64 and amd64
continuous-integration/drone/push Build was killed Details
2023-04-16 17:05:13 -04:00
shibao fcfd9857d5 remove maintain attrs
continuous-integration/drone/push Build is passing Details
2023-04-16 01:12:07 -04:00
shibao c5f96a9d9d change invite path slightly
continuous-integration/drone/push Build is passing Details
2023-04-16 00:48:04 -04:00
shibao c1a0b4017f improve tests
continuous-integration/drone/push Build is failing Details
2023-04-15 21:40:57 -04:00
shibao 04ebe59afe ee cummings even more 2023-04-15 21:40:17 -04:00
shibao 50be85a1c3 make test async
continuous-integration/drone/push Build is running Details
2023-04-14 23:50:16 -04:00
shibao 994aa96a20 simply assigns
continuous-integration/drone/push Build is passing Details
2023-04-14 20:32:47 -04:00
shibao 026bf22f60 improve formatting 2023-04-14 20:08:03 -04:00
shibao 56e6eb3609 use more verified routes
continuous-integration/drone/push Build is passing Details
2023-04-14 19:51:14 -04:00
shibao c49140e7f5 ee cummings even more
continuous-integration/drone/push Build is failing Details
2023-04-14 19:19:58 -04:00
shibao 1276635a3e make emails more efficient
continuous-integration/drone/push Build is passing Details
2023-04-14 19:02:06 -04:00
shibao f00dc50215 clean up router 2023-04-14 19:01:56 -04:00
shibao 35de8a6395 use embed templates suffix
continuous-integration/drone/push Build is passing Details
2023-04-14 18:45:12 -04:00
shibao 96e155a49a ee cummings more emails 2023-04-14 18:29:34 -04:00
shibao c02fb06eb2 update erlang version
continuous-integration/drone/push Build is passing Details
2023-04-14 18:10:28 -04:00
shibao a9d5649bef fix live reload glob
continuous-integration/drone/push Build is passing Details
2023-04-14 00:15:55 -04:00
shibao 650d61e95f fix email comment
continuous-integration/drone/push Build is passing Details
2023-04-13 23:48:17 -04:00
shibao 63d854ffbe upgrade to phoenix 1.7
continuous-integration/drone/push Build is passing Details
2023-04-13 23:29:29 -04:00
shibao a1c846be33 update npm version 2023-04-13 18:45:32 -04:00
shibao 1b9f212e66 update to elixir 1.14.4 2023-04-13 18:44:12 -04:00
shibao 7805ddc270 update npm dependencies 2023-04-13 18:37:43 -04:00
shibao c1455bccad update elixir deps 2023-04-13 18:35:25 -04:00
shibao dd956be93f generate fonts with correct filename
continuous-integration/drone/push Build is passing Details
2023-03-28 22:03:11 -04:00
shibao 04361a5838 improve invite tests 2023-03-28 22:03:00 -04:00
shibao cb049cb178 improve components
continuous-integration/drone/push Build is passing Details
2023-03-23 00:22:04 -04:00
shibao 5a41d8b3e7 improve tests
continuous-integration/drone/push Build is passing Details
2023-03-22 22:08:37 -04:00
shibao 64320dbdae add extra feature to changelog
continuous-integration/drone/push Build is passing Details
2023-03-19 16:01:35 -04:00
160 changed files with 12352 additions and 8181 deletions

View File

@ -17,7 +17,7 @@ steps:
- .mix
- name: test
image: elixir:1.14.1-alpine
image: elixir:1.16.1-alpine
environment:
TEST_DATABASE_URL: ecto://postgres:postgres@database/memex_test
HOST: testing.example.tld
@ -42,7 +42,8 @@ steps:
repo: shibaobun/memex
purge: true
compress: true
platforms: linux/amd64,linux/arm/v7
platforms:
- linux/amd64
username:
from_secret: docker_username
password:
@ -59,7 +60,8 @@ steps:
repo: shibaobun/memex
purge: true
compress: true
platforms: linux/amd64,linux/arm/v7
platforms:
- linux/amd64
username:
from_secret: docker_username
password:

View File

@ -1,6 +1,6 @@
[
import_deps: [:ecto, :phoenix],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
import_deps: [:ecto, :ecto_sql, :phoenix],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter]
]

View File

@ -1,3 +1,3 @@
elixir 1.14.1-otp-25
erlang 25.1.2
nodejs 18.9.1
elixir 1.16.1-otp-26
erlang 26.2.2
nodejs 21.6.2

View File

@ -1,4 +1,4 @@
FROM elixir:1.14.1-alpine AS build
FROM elixir:1.16.1-alpine AS build
# install build dependencies
RUN apk add --no-cache build-base npm git python3
@ -37,7 +37,7 @@ RUN mix do compile, release
FROM alpine:latest AS app
RUN apk upgrade --no-cache && \
apk add --no-cache bash openssl libssl1.1 libcrypto1.1 libgcc libstdc++ ncurses-libs
apk add --no-cache bash openssl libssl3 libcrypto3 libgcc libstdc++ ncurses-libs
WORKDIR /app

View File

@ -26,16 +26,19 @@ import 'phoenix_html'
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'
import topbar from 'topbar'
import CtrlEnter from './ctrlenter'
import Date from './date'
import DateTime from './datetime'
import MaintainAttrs from './maintain_attrs'
import SanitizeTags from './sanitizetags'
import SanitizeTitles from './sanitizetitles'
const csrfTokenElement = document.querySelector("meta[name='csrf-token']")
let csrfToken
if (csrfTokenElement) { csrfToken = csrfTokenElement.getAttribute('content') }
const liveSocket = new LiveSocket('/live', Socket, {
params: { _csrf_token: csrfToken },
hooks: { Date, DateTime, MaintainAttrs }
hooks: { CtrlEnter, Date, DateTime, SanitizeTags, SanitizeTitles }
})
// Show progress bar on live navigation and form submits

11
assets/js/ctrlenter.js Normal file
View File

@ -0,0 +1,11 @@
export default {
addFormSubmit (context) {
context.el.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 'Enter') {
context.el.dispatchEvent(
new Event('submit', { bubbles: true, cancelable: true }))
}
})
},
mounted () { this.addFormSubmit(this) }
}

View File

@ -1,22 +0,0 @@
// maintain user adjusted attributes, like textbox length on phoenix liveview
// update. https://github.com/phoenixframework/phoenix_live_view/issues/1011
export default {
attrs () {
if (this.el && this.el.getAttribute('data-attrs')) {
return this.el.getAttribute('data-attrs').split(', ')
} else {
return []
}
},
beforeUpdate () {
if (this.el) {
this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)])
}
},
updated () {
if (this.el) {
this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val))
}
}
}

11
assets/js/sanitizetags.js Normal file
View File

@ -0,0 +1,11 @@
export default {
SanitizeTags (context) {
context.el.addEventListener('keyup', (e) => {
e.target.value = e.target.value
.replace(' ', ',')
.replace(',,', ',')
.replace(/[^a-zA-Z0-9,]/, '')
})
},
mounted () { this.SanitizeTags(this) }
}

View File

@ -0,0 +1,10 @@
export default {
SanitizeTitles (context) {
context.el.addEventListener('keyup', (e) => {
e.target.value = e.target.value
.replace(' ', '-')
.replace(/[^a-zA-Z0-9-]/, '')
})
},
mounted () { this.SanitizeTitles(this) }
}

15549
assets/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,8 @@
"description": " ",
"license": "MIT",
"engines": {
"node": "v18.9.1",
"npm": "8.19.1"
"node": "v21.6.2",
"npm": "10.2.4"
},
"scripts": {
"deploy": "NODE_ENV=production webpack --mode production",
@ -13,35 +13,35 @@
"test": "standard"
},
"dependencies": {
"@fontsource/nunito-sans": "^4.5.10",
"@fortawesome/fontawesome-free": "^6.3.0",
"@fontsource/nunito-sans": "^5.0.8",
"@fortawesome/fontawesome-free": "^6.5.1",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view",
"topbar": "^2.0.1"
"topbar": "^2.0.2"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/preset-env": "^7.20.2",
"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.2",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"css-minimizer-webpack-plugin": "^4.2.2",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"autoprefixer": "^10.4.17",
"babel-loader": "^9.1.3",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.10.0",
"css-minimizer-webpack-plugin": "^6.0.0",
"file-loader": "^6.2.0",
"mini-css-extract-plugin": "^2.7.5",
"npm-check-updates": "^16.7.12",
"postcss": "^8.4.21",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.1.0",
"postcss-preset-env": "^8.0.1",
"sass": "^1.59.3",
"sass-loader": "^13.2.1",
"standard": "^17.0.0",
"tailwindcss": "^3.2.7",
"terser-webpack-plugin": "^5.3.7",
"webpack": "^5.76.2",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.1"
"mini-css-extract-plugin": "^2.8.0",
"npm-check-updates": "^16.14.15",
"postcss": "^8.4.35",
"postcss-import": "^16.0.1",
"postcss-loader": "^8.1.0",
"postcss-preset-env": "^9.4.0",
"sass": "^1.71.1",
"sass-loader": "^14.1.1",
"standard": "^17.1.0",
"tailwindcss": "^3.4.1",
"terser-webpack-plugin": "^5.3.10",
"webpack": "^5.90.3",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.2"
}
}

View File

@ -45,7 +45,7 @@ module.exports = (env, options) => {
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
type: 'asset/resource',
generator: { filename: 'fonts/[name][ext]' }
generator: { filename: 'fonts/[name].[ext]' }
}
]
},

View File

@ -1,9 +1,49 @@
# v0.1.16
- Fix empty invite index page
- Fix faq copy
# v0.1.15
- Sanitize titles while they are being typed
- Sanitize tags while they are being typed
- Remove requirement for note and content to have content
- Prevent possible additional submissions
- Fix content being displayed when blank
# v0.1.14
- Fix issue with item content not able to be displayed sometimes
# v0.1.13
- Update dependencies
- Fix debounces
- Allow space as delimiter for tags
- Add bottom padding to page
- Make pipeline step not require content
- Make content previews resizable
- Fix live flashes not dismissable by click
- Fix disconnection modal not displaying
- Submit items with ctrl-enter
- Display backlinks in pipeline description
- Modify backlink format
# v0.1.12
- Code quality fixes
- Fix error/404 pages not rendering properly
- Update dependencies
# v0.1.11
- Update dependencies
- ee cummings even more
- Improve tests
- Change invite path slightly
- Disable arm builds since ci fails to build
# v0.1.10
- Improve accessibility
- Code quality improvements
- Fix dates displaying incorrectly
- Add links to readme for github mirror
- Add license (whoops)
- Display links in note/context/step contents
# v0.1.9
- Improve server log

View File

@ -18,7 +18,10 @@ config :memex, MemexWeb.Endpoint,
url: [scheme: "https", host: System.get_env("HOST") || "localhost", port: "443"],
http: [port: String.to_integer(System.get_env("PORT") || "4000")],
secret_key_base: "KH59P0iZixX5gP/u+zkxxG8vAAj6vgt0YqnwEB5JP5K+E567SsqkCz69uWShjE7I",
render_errors: [view: MemexWeb.ErrorView, accepts: ~w(html json), layout: false],
render_errors: [
formats: [html: MemexWeb.ErrorHTML, json: MemexWeb.ErrorJSON],
layout: false
],
pubsub_server: Memex.PubSub,
live_view: [signing_salt: "zOLgd3lr"]

View File

@ -59,8 +59,7 @@ config :memex, MemexWeb.Endpoint,
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"lib/memex_web/(live|views)/.*(ex)$",
~r"lib/memex_web/templates/.*(eex)$"
~r"lib/memex_web/*/.*(ex)$"
]
]

View File

@ -26,7 +26,7 @@ config :memex, Memex.Mailer, adapter: Swoosh.Adapters.Test
config :memex, Memex.Accounts, registration: "public"
# Print only warnings and errors during test
config :logger, level: :warn
config :logger, level: :warning
# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime

View File

@ -374,8 +374,8 @@ defmodule Memex.Accounts do
@doc """
Deletes the signed token with the given context.
"""
@spec delete_session_token(token :: String.t()) :: :ok
def delete_session_token(token) do
@spec delete_user_session_token(token :: String.t()) :: :ok
def delete_user_session_token(token) do
UserToken.token_and_context_query(token, "session") |> Repo.delete_all()
:ok
end
@ -405,15 +405,15 @@ defmodule Memex.Accounts do
## Examples
iex> is_admin?(%User{role: :admin})
iex> admin?(%User{role: :admin})
true
iex> is_admin?(%User{})
iex> admin?(%User{})
false
"""
@spec is_admin?(User.t()) :: boolean()
def is_admin?(%User{id: user_id}) do
@spec admin?(User.t()) :: boolean()
def admin?(%User{id: user_id}) do
Repo.exists?(from u in User, where: u.id == ^user_id, where: u.role == :admin)
end
@ -422,16 +422,16 @@ defmodule Memex.Accounts do
## Examples
iex> is_already_admin?(%User{role: :admin})
iex> already_admin?(%User{role: :admin})
true
iex> is_already_admin?(%User{})
iex> already_admin?(%User{})
false
"""
@spec is_already_admin?(User.t() | nil) :: boolean()
def is_already_admin?(%User{role: :admin}), do: true
def is_already_admin?(_invalid_user), do: false
@spec already_admin?(User.t() | nil) :: boolean()
def already_admin?(%User{role: :admin}), do: true
def already_admin?(_invalid_user), do: false
## Confirmation

View File

@ -3,14 +3,15 @@ defmodule Memex.Email do
Emails that can be sent using Swoosh.
You can find the base email templates at
`lib/memex_web/templates/layout/email.html.heex` for html emails and
`lib/memex_web/templates/layout/email.txt.heex` for text emails.
`lib/memex_web/components/layouts/email_html.html.heex` for html emails and
`lib/memex_web/components/layouts/email_text.txt.eex` for text emails.
"""
use Phoenix.Swoosh, view: MemexWeb.EmailView, layout: {MemexWeb.LayoutView, :email}
import Swoosh.Email
import MemexWeb.Gettext
import Phoenix.Template
alias Memex.Accounts.User
alias MemexWeb.EmailView
alias MemexWeb.{EmailHTML, Layouts}
@typedoc """
Represents an HTML and text body email that can be sent
@ -27,22 +28,29 @@ defmodule Memex.Email do
@spec generate_email(key :: String.t(), User.t(), attrs :: map()) :: t()
def generate_email("welcome", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "Confirm your Memex account"))
|> render_body("confirm_email.html", %{user: user, url: url})
|> text_body(EmailView.render("confirm_email.txt", %{user: user, url: url}))
|> base_email(dgettext("emails", "confirm your memEx account"))
|> render_body(:confirm_email, %{user: user, url: url})
end
def generate_email("reset_password", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "Reset your Memex password"))
|> render_body("reset_password.html", %{user: user, url: url})
|> text_body(EmailView.render("reset_password.txt", %{user: user, url: url}))
|> base_email(dgettext("emails", "reset your memEx password"))
|> render_body(:reset_password, %{user: user, url: url})
end
def generate_email("update_email", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "Update your Memex email"))
|> render_body("update_email.html", %{user: user, url: url})
|> text_body(EmailView.render("update_email.txt", %{user: user, url: url}))
|> base_email(dgettext("emails", "update your memEx email"))
|> render_body(:update_email, %{user: user, url: url})
end
defp render_body(email, template, assigns) do
html_heex = apply(EmailHTML, String.to_existing_atom("#{template}_html"), [assigns])
html = render_to_string(Layouts, "email_html", "html", email: email, inner_content: html_heex)
text_heex = apply(EmailHTML, String.to_existing_atom("#{template}_text"), [assigns])
text = render_to_string(Layouts, "email_text", "text", email: email, inner_content: text_heex)
email |> html_body(html) |> text_body(text)
end
end

View File

@ -229,12 +229,12 @@ defmodule Memex.Contexts do
context |> Context.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Context.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Context.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Context.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner?(_context, _other_user), do: false
@spec owner?(Context.t(), User.t()) :: boolean()
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
def owner?(_context, _other_user), do: false
end

View File

@ -9,6 +9,7 @@ defmodule Memex.Contexts.Context do
alias Ecto.{Changeset, UUID}
alias Memex.{Accounts.User, Repo}
@derive {Phoenix.Param, key: :slug}
@derive {Jason.Encoder,
only: [
:slug,
@ -56,7 +57,7 @@ defmodule Memex.Contexts.Context do
|> validate_format(:slug, ~r/^[\p{L}\p{N}\-]+$/,
message: dgettext("errors", "invalid format: only numbers, letters and hyphen are accepted")
)
|> validate_required([:slug, :content, :user_id, :visibility])
|> validate_required([:slug, :user_id, :visibility])
|> unique_constraint(:slug)
|> unsafe_validate_unique(:slug, Repo)
end
@ -69,7 +70,7 @@ defmodule Memex.Contexts.Context do
|> validate_format(:slug, ~r/^[\p{L}\p{N}\-]+$/,
message: dgettext("errors", "invalid format: only numbers, letters and hyphen are accepted")
)
|> validate_required([:slug, :content, :visibility])
|> validate_required([:slug, :visibility])
|> unique_constraint(:slug)
|> unsafe_validate_unique(:slug, Repo)
end
@ -78,11 +79,11 @@ defmodule Memex.Contexts.Context do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -97,9 +98,9 @@ defmodule Memex.Contexts.Context do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -14,17 +14,17 @@ defmodule Memex.Logger do
|> Map.put(:stacktrace, Exception.format_stacktrace(stacktrace))
|> pretty_encode()
Logger.error(meta.reason, data: data)
Logger.error("#{meta.reason} #{data}")
end
def handle_event([:oban, :job, :start], measure, meta, _config) do
data = get_oban_job_data(meta, measure) |> pretty_encode()
Logger.info("Started oban job", data: data)
Logger.info("Started oban job: #{data}")
end
def handle_event([:oban, :job, :stop], measure, meta, _config) do
data = get_oban_job_data(meta, measure) |> pretty_encode()
Logger.info("Finished oban job", data: data)
Logger.info("Finished oban job: #{data}")
end
def handle_event([:oban, :job, unhandled_event], measure, meta, _config) do
@ -33,7 +33,7 @@ defmodule Memex.Logger do
|> Map.put(:event, unhandled_event)
|> pretty_encode()
Logger.warning("Unhandled oban job event", data: data)
Logger.warning("Unhandled oban job event: #{data}")
end
def handle_event(unhandled_event, measure, meta, config) do
@ -45,7 +45,7 @@ defmodule Memex.Logger do
config: config
})
Logger.warning("Unhandled telemetry event", data: data)
Logger.warning("Unhandled telemetry event: #{data}")
end
defp get_oban_job_data(%{job: job}, measure) do

View File

@ -229,12 +229,12 @@ defmodule Memex.Notes do
note |> Note.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Note.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Note.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Note.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner?(_context, _other_user), do: false
@spec owner?(Note.t(), User.t()) :: boolean()
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
def owner?(_context, _other_user), do: false
end

View File

@ -8,6 +8,7 @@ defmodule Memex.Notes.Note do
alias Ecto.{Changeset, UUID}
alias Memex.{Accounts.User, Repo}
@derive {Phoenix.Param, key: :slug}
@derive {Jason.Encoder,
only: [
:slug,
@ -55,7 +56,7 @@ defmodule Memex.Notes.Note do
|> validate_format(:slug, ~r/^[\p{L}\p{N}\-]+$/,
message: dgettext("errors", "invalid format: only numbers, letters and hyphen are accepted")
)
|> validate_required([:slug, :content, :user_id, :visibility])
|> validate_required([:slug, :user_id, :visibility])
|> unique_constraint(:slug)
|> unsafe_validate_unique(:slug, Repo)
end
@ -68,7 +69,7 @@ defmodule Memex.Notes.Note do
|> validate_format(:slug, ~r/^[\p{L}\p{N}\-]+$/,
message: dgettext("errors", "invalid format: only numbers, letters and hyphen are accepted")
)
|> validate_required([:slug, :content, :visibility])
|> validate_required([:slug, :visibility])
|> unique_constraint(:slug)
|> unsafe_validate_unique(:slug, Repo)
end
@ -77,11 +78,11 @@ defmodule Memex.Notes.Note do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -96,9 +97,9 @@ defmodule Memex.Notes.Note do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -231,12 +231,12 @@ defmodule Memex.Pipelines do
pipeline |> Pipeline.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Pipeline.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner?(_context, _other_user), do: false
@spec owner?(Pipeline.t(), User.t()) :: boolean()
def owner?(%{user_id: user_id}, %{id: user_id}), do: true
def owner?(_context, _other_user), do: false
end

View File

@ -8,6 +8,7 @@ defmodule Memex.Pipelines.Pipeline do
alias Ecto.{Changeset, UUID}
alias Memex.{Accounts.User, Pipelines.Steps.Step, Repo}
@derive {Phoenix.Param, key: :slug}
@derive {Jason.Encoder,
only: [
:slug,
@ -80,11 +81,11 @@ defmodule Memex.Pipelines.Pipeline do
changeset
|> put_change(:tags_string, changeset |> get_field(:tags) |> get_tags_string())
|> cast(attrs, [:tags_string])
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\,]+$/,
|> validate_format(:tags_string, ~r/^[\p{L}\p{N}\-\, ]+$/,
message:
dgettext(
"errors",
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma-delimited"
"invalid format: only numbers, letters and hyphen are accepted. tags must be comma or space delimited"
)
)
|> cast_tags()
@ -99,9 +100,9 @@ defmodule Memex.Pipelines.Pipeline do
defp process_tags(tags_string) when tags_string |> is_binary() do
tags_string
|> String.split(",", trim: true)
|> String.split([",", " "], trim: true)
|> Enum.map(fn str -> str |> String.trim() end)
|> Enum.reject(fn str -> str |> is_nil() end)
|> Enum.reject(fn str -> str in [nil, ""] end)
|> Enum.sort()
end

View File

@ -50,7 +50,7 @@ defmodule Memex.Pipelines.Steps.Step do
%__MODULE__{}
|> cast(attrs, [:title, :content])
|> change(pipeline_id: pipeline_id, user_id: user_id, position: position)
|> validate_required([:title, :content, :user_id, :position])
|> validate_required([:title, :user_id, :position])
end
@spec update_changeset(t(), attrs :: map(), User.t()) ::
@ -62,7 +62,7 @@ defmodule Memex.Pipelines.Steps.Step do
) do
step
|> cast(attrs, [:title, :content])
|> validate_required([:title, :content, :user_id, :position])
|> validate_required([:title, :user_id, :position])
end
@spec position_changeset(t(), position :: non_neg_integer(), User.t()) :: changeset()
@ -73,6 +73,6 @@ defmodule Memex.Pipelines.Steps.Step do
) do
step
|> change(position: position)
|> validate_required([:title, :content, :user_id, :position])
|> validate_required([:title, :user_id, :position])
end
end

View File

@ -1,54 +1,61 @@
defmodule MemexWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
as controllers, components, channels, and so on.
This can be used in your application as:
use MemexWeb, :controller
use MemexWeb, :view
use MemexWeb, :html
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
The definitions below will be executed for every controller,
component, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below. Instead, define any helper function in modules
and import those modules here.
below. Instead, define additional modules and import
those modules here.
"""
def controller do
quote do
use Phoenix.Controller, namespace: MemexWeb
def static_paths, do: ~w(css js fonts images favicon.ico robots.txt)
def router do
quote do
use Phoenix.Router, helpers: false
# Import common connection and controller functions to use in pipelines
import Plug.Conn
import MemexWeb.Gettext
alias MemexWeb.Endpoint
alias MemexWeb.Router.Helpers, as: Routes
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end
def view do
def channel do
quote do
use Phoenix.View,
root: "lib/memex_web/templates",
namespace: MemexWeb
use Phoenix.Channel
end
end
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
def controller do
quote do
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: MemexWeb.Layouts]
# Include shared imports and aliases for views
unquote(view_helpers())
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Plug.Conn
import MemexWeb.Gettext
unquote(verified_routes())
end
end
def live_view do
quote do
use Phoenix.LiveView, layout: {MemexWeb.LayoutView, :live}
use Phoenix.LiveView,
layout: {MemexWeb.Layouts, :app}
on_mount MemexWeb.InitAssigns
unquote(view_helpers())
unquote(html_helpers())
end
end
@ -56,50 +63,44 @@ defmodule MemexWeb do
quote do
use Phoenix.LiveComponent
unquote(view_helpers())
unquote(html_helpers())
end
end
def component do
def html do
quote do
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
use Phoenix.Component
unquote(view_helpers())
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
def router do
defp html_helpers do
quote do
use Phoenix.Router
use PhoenixHTMLHelpers
import Phoenix.{Component, HTML, HTML.Form}
import MemexWeb.{ErrorHelpers, Gettext, CoreComponents, HTMLHelpers}
import Phoenix.{Controller, LiveView.Router}
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Plug.Conn
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
# Routes generation with the ~p sigil
unquote(verified_routes())
end
end
def channel do
def verified_routes do
quote do
use Phoenix.Channel
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import MemexWeb.Gettext
end
end
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
use Phoenix.HTML
# Import LiveView and .heex helpers (live_render, link, <.form>, etc)
# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.{Component, View}
import MemexWeb.{ErrorHelpers, Gettext, CoreComponents, ViewHelpers}
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
alias MemexWeb.Endpoint
alias MemexWeb.Router.Helpers, as: Routes
use Phoenix.VerifiedRoutes,
endpoint: MemexWeb.Endpoint,
router: MemexWeb.Router,
statics: MemexWeb.static_paths()
end
end

View File

@ -88,11 +88,9 @@ defmodule MemexWeb.Components.ContextsTableComponent do
@spec get_value_for_key(atom(), Context.t(), additional_data :: map()) ::
any() | {any(), Rendered.t()}
defp get_value_for_key(:slug, %{slug: slug}, _additional_data) do
assigns = %{slug: slug}
defp get_value_for_key(:slug, %{slug: slug} = assigns, _additional_data) do
slug_block = ~H"""
<.link navigate={Routes.context_show_path(Endpoint, :show, @slug)} class="link">
<.link navigate={~p"/context/#{@slug}"} class="link">
<%= @slug %>
</.link>
"""
@ -100,16 +98,10 @@ defmodule MemexWeb.Components.ContextsTableComponent do
{slug, slug_block}
end
defp get_value_for_key(:tags, %{tags: tags}, _additional_data) do
assigns = %{tags: tags}
defp get_value_for_key(:tags, assigns, _additional_data) do
~H"""
<div class="flex flex-wrap justify-center space-x-1">
<.link
:for={tag <- @tags}
patch={Routes.context_index_path(Endpoint, :search, tag)}
class="link"
>
<.link :for={tag <- @tags} patch={~p"/contexts/#{tag}"} class="link">
<%= tag %>
</.link>
</div>

View File

@ -2,14 +2,14 @@ defmodule MemexWeb.CoreComponents do
@moduledoc """
Provides core UI components.
"""
use PhoenixHTMLHelpers
use Phoenix.Component
import MemexWeb.{Gettext, ViewHelpers}
use MemexWeb, :verified_routes
import MemexWeb.{Gettext, HTMLHelpers}
alias Memex.{Accounts, Accounts.Invite, Accounts.User}
alias Memex.Contexts.Context
alias Memex.Notes.Note
alias Memex.Pipelines.Steps.Step
alias MemexWeb.{Endpoint, HomeLive}
alias MemexWeb.Router.Helpers, as: Routes
alias Memex.Pipelines.{Pipeline, Steps.Step}
alias Phoenix.HTML
alias Phoenix.LiveView.JS
@ -31,13 +31,13 @@ defmodule MemexWeb.CoreComponents do
## Examples
<.modal return_to={Routes.<%= schema.singular %>_index_path(Endpoint, :index)}>
<.modal return_to={~p"/\#{<%= schema.plural %>}"}>
<.live_component
module={<%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent}
id={@<%= schema.singular %>.id || :new}
title={@page_title}
action={@live_action}
return_to={Routes.<%= schema.singular %>_index_path(Endpoint, :index)}
return_to={~p"/\#{<%= schema.singular %>}"}
<%= schema.singular %>: @<%= schema.singular %>
/>
</.modal>
@ -131,53 +131,126 @@ defmodule MemexWeb.CoreComponents do
def step_content(assigns)
defp add_links_to_content(content, data_qa_prefix) do
# replace links
attr :pipeline, Pipeline, required: true
# link regex from
# https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
# and modified with additional schemes from
# https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
def pipeline_content(assigns)
content =
Regex.replace(
~r<((file|git|https?|ipfs|ipns|irc|jabber|magnet|mailto|mumble|tel|udp|xmpp):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))>,
content,
fn _whole_match, link ->
link =
HTML.Link.link(
link,
to: link,
class: "link inline",
target: "_blank",
rel: "noopener noreferrer"
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
defp display_links(record) do
record
|> get_content()
|> replace_hyperlinks(record)
|> replace_triple_links(record)
|> replace_double_links(record)
|> replace_single_links(record)
|> HTML.raw()
end
"</p>#{link}<p class=\"inline\">"
end
)
defp get_content(%{content: content}), do: content |> get_text()
defp get_content(%{description: description}), do: description |> get_text()
defp get_content(_fallthrough), do: nil |> get_text()
content =
Regex.replace(
~r/\[\[([\p{L}\p{N}\-]+)\]\]/,
content,
fn _whole_match, slug ->
link =
HTML.Link.link(
"[[#{slug}]]",
to: Routes.note_show_path(Endpoint, :show, slug),
class: "link inline",
data: [qa: "#{data_qa_prefix}-#{slug}"]
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
defp get_text(string) when is_binary(string), do: string
defp get_text(_fallthrough), do: ""
"</p>#{link}<p class=\"inline\">"
end
)
# replaces hyperlinks like https://bubbletea.dev
#
# link regex from
# https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
# and modified with additional schemes from
# https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
defp replace_hyperlinks(content, _record) do
Regex.replace(
~r<((file|git|https?|ipfs|ipns|irc|jabber|magnet|mailto|mumble|tel|udp|xmpp):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))>,
content,
fn _whole_match, link ->
link =
link(
link,
to: link,
class: "link inline",
target: "_blank",
rel: "noopener noreferrer"
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
content |> HTML.raw()
"</p>#{link}<p class=\"inline\">"
end
)
end
# replaces triple links like [[[slug-title]]]
defp replace_triple_links(content, _record) do
Regex.replace(
~r/(^|[^\[])\[\[\[([\p{L}\p{N}\-]+)\]\]\]($|[^\]])/,
content,
fn _whole_match, prefix, slug, suffix ->
link =
link(
"[[[#{slug}]]]",
to: ~p"/note/#{slug}",
class: "link inline"
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
"#{prefix}</p>#{link}<p class=\"inline\">#{suffix}"
end
)
end
# replaces double links like [[slug-title]]
defp replace_double_links(content, record) do
Regex.replace(
~r/(^|[^\[])\[\[([\p{L}\p{N}\-]+)\]\]($|[^\]])/,
content,
fn _whole_match, prefix, slug, suffix ->
target =
case record do
%Pipeline{} -> ~p"/context/#{slug}"
%Step{} -> ~p"/context/#{slug}"
_context -> ~p"/note/#{slug}"
end
link =
link(
"[[#{slug}]]",
to: target,
class: "link inline"
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
"#{prefix}</p>#{link}<p class=\"inline\">#{suffix}"
end
)
end
# replaces single links like [slug-title]
defp replace_single_links(content, record) do
Regex.replace(
~r/(^|[^\[])\[([\p{L}\p{N}\-]+)\]($|[^\]])/,
content,
fn _whole_match, prefix, slug, suffix ->
target =
case record do
%Pipeline{} -> ~p"/pipeline/#{slug}"
%Step{} -> ~p"/pipeline/#{slug}"
%Context{} -> ~p"/context/#{slug}"
_note -> ~p"/note/#{slug}"
end
link =
link(
"[#{slug}]",
to: target,
class: "link inline"
)
|> HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
"#{prefix}</p>#{link}<p class=\"inline\">#{suffix}"
end
)
end
end

View File

@ -1,8 +1,8 @@
<div
:if={@context.content}
id={"show-context-content-#{@context.id}"}
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
phx-hook="MaintainAttrs"
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto resize-y"
phx-update="ignore"
readonly
phx-no-format
><p class="inline"><%= add_links_to_content(@context.content, "context-note") %></p></div>
><p class="inline"><%= display_links(@context) %></p></div>

View File

@ -24,7 +24,7 @@
<% end %>
<.qr_code
content={Routes.user_registration_url(Endpoint, :new, invite: @invite.token)}
content={url(MemexWeb.Endpoint, ~p"/users/register?invite=#{@invite.token}")}
filename={@invite.name}
/>
@ -38,7 +38,7 @@
class="mx-2 my-1 text-xs px-4 py-2 rounded-lg text-center break-all
text-primary-400 bg-primary-800"
phx-no-format
><%= Routes.user_registration_url(Endpoint, :new, invite: @invite.token) %></code>
><%= url(MemexWeb.Endpoint, ~p"/users/register?invite=#{@invite.token}") %></code>
<%= if @code_actions, do: render_slot(@code_actions) %>
</div>

View File

@ -1,8 +1,8 @@
<div
:if={@note.content}
id={"show-note-content-#{@note.id}"}
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
phx-hook="MaintainAttrs"
class="input input-primary h-128 min-h-128 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto resize-y"
phx-update="ignore"
readonly
phx-no-format
><p class="inline"><%= add_links_to_content(@note.content, "note-link") %></p></div>
><p class="inline"><%= display_links(@note) %></p></div>

View File

@ -0,0 +1,8 @@
<div
:if={@pipeline.description}
id={"show-pipeline-description-#{@pipeline.id}"}
class="input input-primary h-32 min-h-32 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto resize-y"
phx-update="ignore"
readonly
phx-no-format
><p class="inline"><%= display_links(@pipeline) %></p></div>

View File

@ -1,8 +1,8 @@
<div
:if={@step.content}
id={"show-step-content-#{@step.id}"}
class="input input-primary h-32 min-h-32 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto"
phx-hook="MaintainAttrs"
class="input input-primary h-32 min-h-32 inline-block whitespace-pre-wrap overflow-x-hidden overflow-y-auto resize-y"
phx-update="ignore"
readonly
phx-no-format
><p class="inline"><%= add_links_to_content(@step.content, "step-context") %></p></div>
><p class="inline"><%= display_links(@step) %></p></div>

View File

@ -1,4 +1,4 @@
<label for={@id || @action} class="inline-flex relative items-center cursor-pointer">
<label for={@id || @action} class="relative inline-flex items-center cursor-pointer">
<input
id={@id || @action}
type="checkbox"
@ -23,7 +23,7 @@
</div>
<span
id={"#{@id || @action}-label"}
class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300"
class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300 whitespace-nowrap"
>
<%= render_slot(@inner_block) %>
</span>

View File

@ -1,10 +1,7 @@
<nav role="navigation" class="mb-8 px-8 py-4 w-full bg-primary-900 text-primary-400">
<div class="flex flex-col sm:flex-row justify-between items-center">
<div class="mb-4 sm:mb-0 sm:mr-8 flex flex-row justify-start items-center space-x-2">
<.link
navigate={Routes.live_path(Endpoint, HomeLive)}
class="mx-2 my-1 leading-5 text-xl text-primary-400 hover:underline"
>
<.link navigate={~p"/"} class="mx-2 my-1 leading-5 text-xl text-primary-400 hover:underline">
<%= gettext("memEx") %>
</.link>
@ -21,28 +18,19 @@
<ul class="flex flex-row flex-wrap justify-center items-center
text-lg text-primary-400 text-ellipsis">
<li class="mx-2 my-1">
<.link
navigate={Routes.note_index_path(Endpoint, :index)}
class="text-primary-400 hover:underline truncate"
>
<.link navigate={~p"/notes"} class="text-primary-400 hover:underline truncate">
<%= gettext("notes") %>
</.link>
</li>
<li class="mx-2 my-1">
<.link
navigate={Routes.context_index_path(Endpoint, :index)}
class="text-primary-400 hover:underline truncate"
>
<.link navigate={~p"/contexts"} class="text-primary-400 hover:underline truncate">
<%= gettext("contexts") %>
</.link>
</li>
<li class="mx-2 my-1">
<.link
navigate={Routes.pipeline_index_path(Endpoint, :index)}
class="text-primary-400 hover:underline truncate"
>
<.link navigate={~p"/pipelines"} class="text-primary-400 hover:underline truncate">
<%= gettext("pipelines") %>
</.link>
</li>
@ -50,26 +38,20 @@
<li class="mx-2 my-1 border-left border border-primary-700"></li>
<%= if @current_user do %>
<li :if={@current_user |> Accounts.is_already_admin?()} class="mx-2 my-1">
<.link
navigate={Routes.invite_index_path(Endpoint, :index)}
class="text-primary-400 hover:underline"
>
<li :if={@current_user |> Accounts.already_admin?()} class="mx-2 my-1">
<.link navigate={~p"/invites"} class="text-primary-400 hover:underline">
<%= gettext("invites") %>
</.link>
</li>
<li class="mx-2 my-1">
<.link
navigate={Routes.user_settings_path(Endpoint, :edit)}
class="text-primary-400 hover:underline truncate"
>
<.link navigate={~p"/users/settings"} class="text-primary-400 hover:underline truncate">
<%= @current_user.email %>
</.link>
</li>
<li class="mx-2 my-1">
<.link
href={Routes.user_session_path(Endpoint, :delete)}
href={~p"/users/log_out"}
method="delete"
data-confirm={dgettext("prompts", "are you sure you want to log out?")}
aria-label={gettext("log out")}
@ -84,7 +66,7 @@
class="mx-2 my-1"
>
<.link
navigate={Routes.live_dashboard_path(Endpoint, :home)}
navigate={~p"/dashboard"}
class="text-primary-400 hover:underline"
aria-label={gettext("live dashboard")}
>
@ -93,19 +75,13 @@
</li>
<% else %>
<li :if={Accounts.allow_registration?()} class="mx-2 my-1">
<.link
href={Routes.user_registration_path(Endpoint, :new)}
class="text-primary-400 hover:underline truncate"
>
<.link href={~p"/users/register"} class="text-primary-400 hover:underline truncate">
<%= dgettext("actions", "register") %>
</.link>
</li>
<li class="mx-2 my-1">
<.link
href={Routes.user_session_path(Endpoint, :new)}
class="text-primary-400 hover:underline truncate"
>
<.link href={~p"/users/log_in"} class="text-primary-400 hover:underline truncate">
<%= dgettext("actions", "log in") %>
</.link>
</li>

View File

@ -0,0 +1,17 @@
defmodule MemexWeb.Layouts do
@moduledoc """
The root layouts for the entire application
"""
use MemexWeb, :html
embed_templates "layouts/*"
def get_title(%{assigns: %{title: title}}) when title not in [nil, ""] do
gettext("memEx | %{title}", title: title)
end
def get_title(_conn) do
gettext("memEx")
end
end

View File

@ -1,26 +1,26 @@
<main class="pb-8 min-w-full">
<main role="main" class="pb-8 min-w-full">
<header>
<.topbar current_user={assigns[:current_user]} />
<div class="mx-8 my-2 flex flex-col space-y-4 text-center">
<p
:if={@flash && @flash |> Map.has_key?("info")}
class="alert alert-info"
class="alert alert-info cursor-pointer"
role="alert"
phx-click="lv:clear-flash"
phx-value-key="info"
>
<%= live_flash(@flash, "info") %>
<%= live_flash(@flash, :info) %>
</p>
<p
:if={@flash && @flash |> Map.has_key?("error")}
class="alert alert-danger"
class="alert alert-danger cursor-pointer"
role="alert"
phx-click="lv:clear-flash"
phx-value-key="error"
>
<%= live_flash(@flash, "error") %>
<%= live_flash(@flash, :error) %>
</p>
</div>
</header>
@ -32,7 +32,7 @@
<div
id="disconnect"
class="z-50 fixed opacity-0 bottom-12 right-12 px-8 py-4 w-max h-max
class="z-50 fixed opacity-0 bottom-8 right-12 px-8 py-4 w-max h-max
border border-primary-400 shadow-lg rounded-lg bg-primary-900 text-primary-400
flex justify-center items-center space-x-4
transition-opacity ease-in-out duration-500 delay-[2000ms]"

View File

@ -9,11 +9,8 @@
<hr style="margin: 2em auto; border-width: 1px; border-color: rgb(161, 161, 170); width: 100%; max-width: 42rem;" />
<a style="color: rgb(161, 161, 170);" href={Routes.live_url(Endpoint, HomeLive)}>
<%= dgettext(
"emails",
"This email was sent from memEx"
) %>
<a style="color: rgb(161, 161, 170);" href={~p"/"}>
<%= dgettext("emails", "this email was sent from memEx") %>
</a>
</body>
</html>

View File

@ -0,0 +1,9 @@
<%= @email.subject %>
====================
<%= @inner_content %>
=====================
<%= dgettext("emails", "this email was sent from memEx at %{url}", url: ~p"/") %>

View File

@ -8,13 +8,8 @@
<.live_title suffix={" | #{gettext("memEx")}"}>
<%= assigns[:page_title] || gettext("memEx") %>
</.live_title>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
<script
defer
phx-track-static
type="text/javascript"
src={Routes.static_path(@conn, "/js/app.js")}
>
<link phx-track-static rel="stylesheet" href={~p"/css/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/js/app.js"}>
</script>
</head>

View File

@ -88,11 +88,9 @@ defmodule MemexWeb.Components.NotesTableComponent do
@spec get_value_for_key(atom(), Note.t(), additional_data :: map()) ::
any() | {any(), Rendered.t()}
defp get_value_for_key(:slug, %{slug: slug}, _additional_data) do
assigns = %{slug: slug}
defp get_value_for_key(:slug, %{slug: slug} = assigns, _additional_data) do
slug_block = ~H"""
<.link navigate={Routes.note_show_path(Endpoint, :show, @slug)} class="link">
<.link navigate={~p"/note/#{@slug}"} class="link">
<%= @slug %>
</.link>
"""
@ -100,12 +98,10 @@ defmodule MemexWeb.Components.NotesTableComponent do
{slug, slug_block}
end
defp get_value_for_key(:tags, %{tags: tags}, _additional_data) do
assigns = %{tags: tags}
defp get_value_for_key(:tags, assigns, _additional_data) do
~H"""
<div class="flex flex-wrap justify-center space-x-1">
<.link :for={tag <- @tags} patch={Routes.note_index_path(Endpoint, :search, tag)} class="link">
<.link :for={tag <- @tags} patch={~p"/notes/#{tag}"} class="link">
<%= tag %>
</.link>
</div>

View File

@ -89,11 +89,9 @@ defmodule MemexWeb.Components.PipelinesTableComponent do
@spec get_value_for_key(atom(), Pipeline.t(), additional_data :: map()) ::
any() | {any(), Rendered.t()}
defp get_value_for_key(:slug, %{slug: slug}, _additional_data) do
assigns = %{slug: slug}
defp get_value_for_key(:slug, %{slug: slug} = assigns, _additional_data) do
slug_block = ~H"""
<.link navigate={Routes.pipeline_show_path(Endpoint, :show, @slug)} class="link">
<.link navigate={~p"/pipeline/#{@slug}"} class="link">
<%= @slug %>
</.link>
"""
@ -101,9 +99,7 @@ defmodule MemexWeb.Components.PipelinesTableComponent do
{slug, slug_block}
end
defp get_value_for_key(:description, %{description: description}, _additional_data) do
assigns = %{description: description}
defp get_value_for_key(:description, %{description: description} = assigns, _additional_data) do
description_block = ~H"""
<div class="truncate max-w-sm">
<%= @description %>
@ -113,16 +109,10 @@ defmodule MemexWeb.Components.PipelinesTableComponent do
{description, description_block}
end
defp get_value_for_key(:tags, %{tags: tags}, _additional_data) do
assigns = %{tags: tags}
defp get_value_for_key(:tags, assigns, _additional_data) do
~H"""
<div class="flex flex-wrap justify-center space-x-1">
<.link
:for={tag <- @tags}
patch={Routes.pipeline_index_path(Endpoint, :search, tag)}
class="link"
>
<.link :for={tag <- @tags} patch={~p"/pipelines/#{tag}"} class="link">
<%= tag %>
</.link>
</div>

View File

@ -135,4 +135,25 @@ defmodule MemexWeb.Components.TableComponent do
sort_mode
)
end
@doc """
Conditionally composes elements into the columns list, supports maps and
lists. Works tail to front in order for efficiency
iex> []
...> |> maybe_compose_columns(%{label: "Column 3"}, true)
...> |> maybe_compose_columns(%{label: "Column 2"}, false)
...> |> maybe_compose_columns(%{label: "Column 1"})
[%{label: "Column 1"}, %{label: "Column 3"}]
"""
@spec maybe_compose_columns(list(), element_to_add :: list() | map()) :: list()
@spec maybe_compose_columns(list(), element_to_add :: list() | map(), boolean()) :: list()
def maybe_compose_columns(columns, element_or_elements, add? \\ true)
def maybe_compose_columns(columns, elements, true) when is_list(elements),
do: Enum.concat(elements, columns)
def maybe_compose_columns(columns, element, true) when is_map(element), do: [element | columns]
def maybe_compose_columns(columns, _element_or_elements, false), do: columns
end

View File

@ -6,7 +6,8 @@ defmodule MemexWeb.EmailController do
use MemexWeb, :controller
alias Memex.Accounts.User
plug :put_layout, {MemexWeb.LayoutView, :email}
plug :put_root_layout, html: {MemexWeb.Layouts, :email_html}
plug :put_layout, false
@sample_assigns %{
email: %{subject: "Example subject"},
@ -18,6 +19,6 @@ defmodule MemexWeb.EmailController do
Debug route used to preview emails
"""
def preview(conn, %{"id" => template}) do
render(conn, "#{template |> to_string()}.html", @sample_assigns)
render(conn, String.to_existing_atom(template), @sample_assigns)
end
end

View File

@ -0,0 +1,10 @@
defmodule MemexWeb.EmailHTML do
@moduledoc """
Renders email templates
"""
use MemexWeb, :html
embed_templates "email_html/*.html", suffix: "_html"
embed_templates "email_html/*.txt", suffix: "_text"
end

View File

@ -15,7 +15,7 @@
<br />
<a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
<a style="margin: 1em; color: rgb(161, 161, 170);" href={@url}><%= @url %></a>
<br />

View File

@ -9,4 +9,4 @@
<%= dgettext("emails",
"If you didn't create an account at %{url}, please ignore this.",
url: Routes.live_url(Endpoint, HomeLive)) %>
url: ~p"/") %>

View File

@ -9,7 +9,7 @@
<br />
<a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
<a style="margin: 1em; color: rgb(161, 161, 170);" href={@url}><%= @url %></a>
<br />

View File

@ -7,4 +7,4 @@
<%= dgettext("emails",
"If you didn't request this change from %{url}, please ignore this.",
url: Routes.live_url(Endpoint, HomeLive)) %>
url: ~p"/") %>

View File

@ -9,7 +9,7 @@
<br />
<a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
<a style="margin: 1em; color: rgb(161, 161, 170);" href={@url}><%= @url %></a>
<br />

View File

@ -7,4 +7,4 @@
<%= dgettext("emails",
"If you didn't request this change from %{url}, please ignore this.",
url: Routes.live_url(Endpoint, HomeLive)) %>
url: ~p"/") %>

View File

@ -1,15 +1,16 @@
defmodule MemexWeb.ErrorView do
use MemexWeb, :view
alias MemexWeb.HomeLive
defmodule MemexWeb.ErrorHTML do
use MemexWeb, :html
def template_not_found(error_path, _assigns) do
embed_templates "error_html/*"
def render(template, _assigns) do
error_string =
case error_path do
case template do
"404.html" -> dgettext("errors", "not found")
"401.html" -> dgettext("errors", "unauthorized")
_other_path -> dgettext("errors", "internal server error")
end
render("error.html", %{error_string: error_string})
error(%{error_string: error_string})
end
end

View File

@ -24,10 +24,7 @@
<hr class="w-full hr" />
<.link
href={Routes.live_path(Endpoint, HomeLive)}
class="link title text-primary-400 text-lg"
>
<.link href={~p"/"} class="link title text-primary-400 text-lg">
<%= dgettext("errors", "go back home") %>
</.link>
</div>

View File

@ -0,0 +1,14 @@
defmodule MemexWeb.ErrorJSON do
import MemexWeb.Gettext
def render(template, _assigns) do
error_string =
case template do
"404.json" -> dgettext("errors", "not found")
"401.json" -> dgettext("errors", "unauthorized")
_other_path -> dgettext("errors", "internal server error")
end
%{errors: %{detail: error_string}}
end
end

View File

@ -1,11 +0,0 @@
defmodule MemexWeb.HomeController do
@moduledoc """
Controller for home page
"""
use MemexWeb, :controller
def index(conn, _params) do
render(conn, "index.html")
end
end

View File

@ -0,0 +1,5 @@
defmodule MemexWeb.HomeHTML do
use MemexWeb, :html
embed_templates "home_html/*"
end

View File

@ -3,12 +3,11 @@ defmodule MemexWeb.UserAuth do
Functions for user session and authentication
"""
use MemexWeb, :verified_routes
import Plug.Conn
import Phoenix.Controller
import MemexWeb.Gettext
alias Memex.{Accounts, Accounts.User}
alias MemexWeb.HomeLive
alias MemexWeb.Router.Helpers, as: Routes
# Make the remember me cookie valid for 60 days.
# If you want bump or reduce this value, also change
@ -39,7 +38,7 @@ defmodule MemexWeb.UserAuth do
dgettext("errors", "You must confirm your account and log in to access this page.")
)
|> maybe_store_return_to()
|> redirect(to: Routes.user_session_path(conn, :new))
|> redirect(to: ~p"/users/log_in")
|> halt()
end
@ -49,8 +48,7 @@ defmodule MemexWeb.UserAuth do
conn
|> renew_session()
|> put_session(:user_token, token)
|> put_session(:live_socket_id, "users_sessions:#{Base.url_encode64(token)}")
|> put_token_in_session(token)
|> maybe_write_remember_me_cookie(token, params)
|> redirect(to: user_return_to || signed_in_path(conn))
end
@ -96,7 +94,7 @@ defmodule MemexWeb.UserAuth do
"""
def log_out_user(conn) do
user_token = get_session(conn, :user_token)
user_token && Accounts.delete_session_token(user_token)
user_token && Accounts.delete_user_session_token(user_token)
if live_socket_id = get_session(conn, :live_socket_id) do
MemexWeb.Endpoint.broadcast(live_socket_id, "disconnect", %{})
@ -105,7 +103,7 @@ defmodule MemexWeb.UserAuth do
conn
|> renew_session()
|> delete_resp_cookie(@remember_me_cookie)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
@doc """
@ -119,19 +117,110 @@ defmodule MemexWeb.UserAuth do
end
defp ensure_user_token(conn) do
if user_token = get_session(conn, :user_token) do
{user_token, conn}
if token = get_session(conn, :user_token) do
{token, conn}
else
conn = fetch_cookies(conn, signed: [@remember_me_cookie])
if user_token = conn.cookies[@remember_me_cookie] do
{user_token, put_session(conn, :user_token, user_token)}
if token = conn.cookies[@remember_me_cookie] do
{token, put_token_in_session(conn, token)}
else
{nil, conn}
end
end
end
@doc """
Handles mounting and authenticating the current_user in LiveViews.
## `on_mount` arguments
* `:mount_current_user` - Assigns current_user
to socket assigns based on user_token, or nil if
there's no user_token or no matching user.
* `:ensure_authenticated` - Authenticates the user from the session,
and assigns the current_user to socket assigns based
on user_token.
Redirects to login page if there's no logged user.
* `:redirect_if_user_is_authenticated` - Authenticates the user from the session.
Redirects to signed_in_path if there's a logged user.
## Examples
Use the `on_mount` lifecycle macro in LiveViews to mount or authenticate
the current_user:
defmodule MemexWeb.PageLive do
use MemexWeb, :live_view
on_mount {MemexWeb.UserAuth, :mount_current_user}
...
end
Or use the `live_session` of your router to invoke the on_mount callback:
live_session :authenticated, on_mount: [{MemexWeb.UserAuth, :ensure_authenticated}] do
live "/profile", ProfileLive, :index
end
"""
def on_mount(:mount_current_user, _params, session, socket) do
{:cont, mount_current_user(session, socket)}
end
def on_mount(:ensure_authenticated, _params, session, socket) do
socket = mount_current_user(session, socket)
if socket.assigns.current_user do
{:cont, socket}
else
error_flash = dgettext("errors", "You must log in to access this page.")
socket =
socket
|> Phoenix.LiveView.put_flash(:error, error_flash)
|> Phoenix.LiveView.redirect(to: ~p"/users/log_in")
{:halt, socket}
end
end
def on_mount(:ensure_admin, _params, session, socket) do
socket = mount_current_user(session, socket)
if socket.assigns.current_user && socket.assigns.current_user.role == :admin do
{:cont, socket}
else
error_flash = dgettext("errors", "You must log in as an administrator to access this page.")
socket =
socket
|> Phoenix.LiveView.put_flash(:error, error_flash)
|> Phoenix.LiveView.redirect(to: ~p"/users/log_in")
{:halt, socket}
end
end
def on_mount(:redirect_if_user_is_authenticated, _params, session, socket) do
socket = mount_current_user(session, socket)
if socket.assigns.current_user do
{:halt, Phoenix.LiveView.redirect(socket, to: signed_in_path(socket))}
else
{:cont, socket}
end
end
defp mount_current_user(session, socket) do
Phoenix.Component.assign_new(socket, :current_user, fn ->
if user_token = session["user_token"] do
Accounts.get_user_by_session_token(user_token)
end
end)
end
@doc """
Used for routes that require the user to not be authenticated.
"""
@ -161,7 +250,7 @@ defmodule MemexWeb.UserAuth do
dgettext("errors", "You must confirm your account and log in to access this page.")
)
|> maybe_store_return_to()
|> redirect(to: Routes.user_session_path(conn, :new))
|> redirect(to: ~p"/users/log_in")
|> halt()
end
end
@ -176,16 +265,34 @@ defmodule MemexWeb.UserAuth do
conn
|> put_flash(:error, dgettext("errors", "You are not authorized to view this page."))
|> maybe_store_return_to()
|> redirect(to: Routes.live_path(conn, HomeLive))
|> redirect(to: ~p"/")
|> halt()
end
end
def put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, _opts) do
default = Application.fetch_env!(:gettext, :default_locale)
Gettext.put_locale(locale || default)
conn |> put_session(:locale, locale || default)
end
def put_user_locale(conn, _opts) do
default = Application.fetch_env!(:gettext, :default_locale)
Gettext.put_locale(default)
conn |> put_session(:locale, default)
end
defp put_token_in_session(conn, token) do
conn
|> put_session(:user_token, token)
|> put_session(:live_socket_id, "users_sessions:#{Base.url_encode64(token)}")
end
defp maybe_store_return_to(%{method: "GET"} = conn) do
put_session(conn, :user_return_to, current_path(conn))
end
defp maybe_store_return_to(conn), do: conn
defp signed_in_path(_conn), do: "/"
defp signed_in_path(_conn), do: ~p"/"
end

View File

@ -5,14 +5,14 @@ defmodule MemexWeb.UserConfirmationController do
alias Memex.Accounts
def new(conn, _params) do
render(conn, "new.html", page_title: gettext("Confirm your account"))
render(conn, :new, page_title: gettext("confirm your account"))
end
def create(conn, %{"user" => %{"email" => email}}) do
if user = Accounts.get_user_by_email(email) do
Accounts.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
fn token -> url(MemexWeb.Endpoint, ~p"/users/confirm/#{token}") end
)
end
@ -22,11 +22,10 @@ defmodule MemexWeb.UserConfirmationController do
:info,
dgettext(
"prompts",
"If your email is in our system and it has not been confirmed yet, " <>
"you will receive an email with instructions shortly."
"if your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
)
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
# Do not log in the user after confirmation to avoid a
@ -36,7 +35,7 @@ defmodule MemexWeb.UserConfirmationController do
{:ok, %{email: email}} ->
conn
|> put_flash(:info, dgettext("prompts", "%{email} confirmed successfully.", email: email))
|> redirect(to: "/")
|> redirect(to: ~p"/")
:error ->
# If there is a current user and the account was already confirmed,
@ -45,15 +44,15 @@ defmodule MemexWeb.UserConfirmationController do
# a warning message.
case conn.assigns do
%{current_user: %{confirmed_at: confirmed_at}} when not is_nil(confirmed_at) ->
redirect(conn, to: "/")
redirect(conn, to: ~p"/")
%{} ->
conn
|> put_flash(
:error,
dgettext("errors", "User confirmation link is invalid or it has expired.")
dgettext("errors", "user confirmation link is invalid or it has expired.")
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
end
end

View File

@ -0,0 +1,6 @@
defmodule MemexWeb.UserConfirmationHTML do
use MemexWeb, :html
alias Memex.Accounts
embed_templates "user_confirmation_html/*"
end

View File

@ -7,7 +7,7 @@
:let={f}
for={%{}}
as={:user}
action={Routes.user_confirmation_path(@conn, :create)}
action={~p"/users/confirm"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<%= label(f, :email, gettext("Email"), class: "title text-lg text-primary-400") %>
@ -21,14 +21,10 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<.link
:if={Accounts.allow_registration?()}
href={Routes.user_registration_path(@conn, :new)}
class="btn btn-primary"
>
<.link :if={Accounts.allow_registration?()} href={~p"/users/register"} class="btn btn-primary">
<%= dgettext("actions", "register") %>
</.link>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/log_in"} class="btn btn-primary">
<%= dgettext("actions", "log in") %>
</.link>
</div>

View File

@ -1,16 +1,16 @@
defmodule MemexWeb.UserRegistrationController do
use MemexWeb, :controller
import MemexWeb.Gettext
alias Ecto.Changeset
alias Memex.{Accounts, Accounts.Invites}
alias MemexWeb.HomeLive
def new(conn, %{"invite" => invite_token}) do
if Invites.valid_invite_token?(invite_token) do
conn |> render_new(invite_token)
else
conn
|> put_flash(:error, dgettext("errors", "Sorry, this invite was not found or expired"))
|> redirect(to: Routes.live_path(Endpoint, HomeLive))
|> put_flash(:error, dgettext("errors", "sorry, this invite was not found or expired"))
|> redirect(to: ~p"/")
end
end
@ -19,14 +19,14 @@ defmodule MemexWeb.UserRegistrationController do
conn |> render_new()
else
conn
|> put_flash(:error, dgettext("errors", "Sorry, public registration is disabled"))
|> redirect(to: Routes.live_path(Endpoint, HomeLive))
|> put_flash(:error, dgettext("errors", "sorry, public registration is disabled"))
|> redirect(to: ~p"/")
end
end
# renders new user registration page
defp render_new(conn, invite_token \\ nil) do
render(conn, "new.html",
render(conn, :new,
changeset: Accounts.change_user_registration(),
invite_token: invite_token,
page_title: gettext("register")
@ -38,8 +38,8 @@ defmodule MemexWeb.UserRegistrationController do
conn |> create_user(attrs, invite_token)
else
conn
|> put_flash(:error, dgettext("errors", "Sorry, this invite was not found or expired"))
|> redirect(to: Routes.live_path(Endpoint, HomeLive))
|> put_flash(:error, dgettext("errors", "sorry, this invite was not found or expired"))
|> redirect(to: ~p"/")
end
end
@ -48,8 +48,8 @@ defmodule MemexWeb.UserRegistrationController do
conn |> create_user(attrs)
else
conn
|> put_flash(:error, dgettext("errors", "Sorry, public registration is disabled"))
|> redirect(to: Routes.live_path(Endpoint, HomeLive))
|> put_flash(:error, dgettext("errors", "sorry, public registration is disabled"))
|> redirect(to: ~p"/")
end
end
@ -58,20 +58,20 @@ defmodule MemexWeb.UserRegistrationController do
{:ok, user} ->
Accounts.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
fn token -> url(MemexWeb.Endpoint, ~p"/users/confirm/#{token}") end
)
conn
|> put_flash(:info, dgettext("prompts", "please check your email to verify your account"))
|> redirect(to: Routes.user_session_path(Endpoint, :new))
|> redirect(to: ~p"/users/log_in")
{:error, :invalid_token} ->
conn
|> put_flash(:error, dgettext("errors", "sorry, this invite was not found or expired"))
|> redirect(to: Routes.live_path(Endpoint, HomeLive))
|> redirect(to: ~p"/")
{:error, %Ecto.Changeset{} = changeset} ->
conn |> render("new.html", changeset: changeset, invite_token: invite_token)
{:error, %Changeset{} = changeset} ->
conn |> render(:new, changeset: changeset, invite_token: invite_token)
end
end
end

View File

@ -0,0 +1,5 @@
defmodule MemexWeb.UserRegistrationHTML do
use MemexWeb, :html
embed_templates "user_registration_html/*"
end

View File

@ -6,7 +6,7 @@
<.form
:let={f}
for={@changeset}
action={Routes.user_registration_path(@conn, :create)}
action={~p"/users/register"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<p :if={@changeset.action && not @changeset.valid?()} class="alert alert-danger col-span-3">
@ -40,10 +40,10 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/log_in"} class="btn btn-primary">
<%= dgettext("actions", "log in") %>
</.link>
<.link href={Routes.user_reset_password_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/reset_password"} class="btn btn-primary">
<%= dgettext("actions", "forgot your password?") %>
</.link>
</div>

View File

@ -6,14 +6,14 @@ defmodule MemexWeb.UserResetPasswordController do
plug :get_user_by_reset_password_token when action in [:edit, :update]
def new(conn, _params) do
render(conn, "new.html", page_title: gettext("forgot your password?"))
render(conn, :new, page_title: gettext("forgot your password?"))
end
def create(conn, %{"user" => %{"email" => email}}) do
if user = Accounts.get_user_by_email(email) do
Accounts.deliver_user_reset_password_instructions(
user,
&Routes.user_reset_password_url(conn, :edit, &1)
fn token -> url(MemexWeb.Endpoint, ~p"/users/reset_password/#{token}") end
)
end
@ -23,17 +23,16 @@ defmodule MemexWeb.UserResetPasswordController do
:info,
dgettext(
"prompts",
"If your email is in our system, you will receive instructions to " <>
"reset your password shortly."
"if your email is in our system, you will receive instructions to reset your password shortly."
)
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
end
def edit(conn, _params) do
render(conn, "edit.html",
render(conn, :edit,
changeset: Accounts.change_user_password(conn.assigns.user),
page_title: gettext("Reset your password")
page_title: gettext("reset your password")
)
end
@ -43,11 +42,11 @@ defmodule MemexWeb.UserResetPasswordController do
case Accounts.reset_user_password(conn.assigns.user, user_params) do
{:ok, _} ->
conn
|> put_flash(:info, dgettext("prompts", "Password reset successfully."))
|> redirect(to: Routes.user_session_path(conn, :new))
|> put_flash(:info, dgettext("prompts", "password reset successfully."))
|> redirect(to: ~p"/users/log_in")
{:error, changeset} ->
render(conn, "edit.html", changeset: changeset)
render(conn, :edit, changeset: changeset)
end
end
@ -60,9 +59,9 @@ defmodule MemexWeb.UserResetPasswordController do
conn
|> put_flash(
:error,
dgettext("errors", "Reset password link is invalid or it has expired.")
dgettext("errors", "reset password link is invalid or it has expired.")
)
|> redirect(to: "/")
|> redirect(to: ~p"/")
|> halt()
end
end

View File

@ -0,0 +1,6 @@
defmodule MemexWeb.UserResetPasswordHTML do
use MemexWeb, :html
alias Memex.Accounts
embed_templates "user_reset_password_html/*"
end

View File

@ -1,12 +1,12 @@
<div class="mx-auto pb-8 max-w-2xl flex flex-col justify-center items-center space-y-4">
<h1 class="title text-primary-400 text-xl">
<%= dgettext("actions", "Reset password") %>
<%= dgettext("actions", "reset password") %>
</h1>
<.form
:let={f}
for={@changeset}
action={Routes.user_reset_password_path(@conn, :update, @token)}
action={~p"/users/reset_password/#{@token}"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<p :if={@changeset.action && not @changeset.valid?()} class="alert alert-danger col-span-3">
@ -26,7 +26,7 @@
) %>
<%= error_tag(f, :password_confirmation, "col-span-3") %>
<%= submit(dgettext("actions", "Reset password"),
<%= submit(dgettext("actions", "reset password"),
class: "mx-auto btn btn-primary col-span-3"
) %>
</.form>
@ -34,14 +34,10 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<.link
:if={Accounts.allow_registration?()}
href={Routes.user_registration_path(@conn, :new)}
class="btn btn-primary"
>
<.link :if={Accounts.allow_registration?()} href={~p"/users/register"} class="btn btn-primary">
<%= dgettext("actions", "register") %>
</.link>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/log_in"} class="btn btn-primary">
<%= dgettext("actions", "log in") %>
</.link>
</div>

View File

@ -7,7 +7,7 @@
:let={f}
for={%{}}
as={:user}
action={Routes.user_reset_password_path(@conn, :create)}
action={~p"/users/reset_password"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<%= label(f, :email, gettext("email"), class: "title text-lg text-primary-400") %>
@ -21,14 +21,10 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<.link
:if={Accounts.allow_registration?()}
href={Routes.user_registration_path(@conn, :new)}
class="btn btn-primary"
>
<.link :if={Accounts.allow_registration?()} href={~p"/users/register"} class="btn btn-primary">
<%= dgettext("actions", "register") %>
</.link>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/log_in"} class="btn btn-primary">
<%= dgettext("actions", "log in") %>
</.link>
</div>

View File

@ -5,7 +5,7 @@ defmodule MemexWeb.UserSessionController do
alias MemexWeb.UserAuth
def new(conn, _params) do
render(conn, "new.html", error_message: nil, page_title: gettext("log in"))
render(conn, :new, error_message: nil, page_title: gettext("log in"))
end
def create(conn, %{"user" => user_params}) do
@ -14,7 +14,7 @@ defmodule MemexWeb.UserSessionController do
if user = Accounts.get_user_by_email_and_password(email, password) do
UserAuth.log_in_user(conn, user, user_params)
else
render(conn, "new.html", error_message: dgettext("errors", "Invalid email or password"))
render(conn, :new, error_message: dgettext("errors", "invalid email or password"))
end
end

View File

@ -0,0 +1,6 @@
defmodule MemexWeb.UserSessionHTML do
use MemexWeb, :html
alias Memex.Accounts
embed_templates "user_session_html/*"
end

View File

@ -6,8 +6,8 @@
<.form
:let={f}
for={@conn}
action={Routes.user_session_path(@conn, :create)}
as="user"
action={~p"/users/log_in"}
as={:user}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<p :if={@error_message} class="alert alert-danger col-span-3">
@ -31,14 +31,10 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<.link
:if={Accounts.allow_registration?()}
href={Routes.user_registration_path(@conn, :new)}
class="btn btn-primary"
>
<.link :if={Accounts.allow_registration?()} href={~p"/users/register"} class="btn btn-primary">
<%= dgettext("actions", "register") %>
</.link>
<.link href={Routes.user_reset_password_path(@conn, :new)} class="btn btn-primary">
<.link href={~p"/users/reset_password"} class="btn btn-primary">
<%= dgettext("actions", "forgot your password?") %>
</.link>
</div>

View File

@ -2,12 +2,12 @@ defmodule MemexWeb.UserSettingsController do
use MemexWeb, :controller
import MemexWeb.Gettext
alias Memex.Accounts
alias MemexWeb.{HomeLive, UserAuth}
alias MemexWeb.UserAuth
plug :assign_email_and_password_changesets
def edit(conn, _params) do
render(conn, "edit.html", page_title: gettext("settings"))
render(conn, :edit, page_title: gettext("settings"))
end
def update(%{assigns: %{current_user: user}} = conn, %{
@ -20,7 +20,7 @@ defmodule MemexWeb.UserSettingsController do
Accounts.deliver_update_email_instructions(
applied_user,
user.email,
&Routes.user_settings_url(conn, :confirm_email, &1)
fn token -> url(MemexWeb.Endpoint, ~p"/users/settings/confirm_email/#{token}") end
)
conn
@ -31,10 +31,10 @@ defmodule MemexWeb.UserSettingsController do
"a link to confirm your email change has been sent to the new address."
)
)
|> redirect(to: Routes.user_settings_path(conn, :edit))
|> redirect(to: ~p"/users/settings")
{:error, changeset} ->
conn |> render("edit.html", email_changeset: changeset)
conn |> render(:edit, email_changeset: changeset)
end
end
@ -47,11 +47,11 @@ defmodule MemexWeb.UserSettingsController do
{:ok, user} ->
conn
|> put_flash(:info, dgettext("prompts", "password updated successfully."))
|> put_session(:user_return_to, Routes.user_settings_path(conn, :edit))
|> put_session(:user_return_to, ~p"/users/settings")
|> UserAuth.log_in_user(user)
{:error, changeset} ->
conn |> render("edit.html", password_changeset: changeset)
conn |> render(:edit, password_changeset: changeset)
end
end
@ -63,10 +63,10 @@ defmodule MemexWeb.UserSettingsController do
{:ok, _user} ->
conn
|> put_flash(:info, dgettext("prompts", "language updated successfully."))
|> redirect(to: Routes.user_settings_path(conn, :edit))
|> redirect(to: ~p"/users/settings")
{:error, changeset} ->
conn |> render("edit.html", locale_changeset: changeset)
conn |> render(:edit, locale_changeset: changeset)
end
end
@ -75,7 +75,7 @@ defmodule MemexWeb.UserSettingsController do
:ok ->
conn
|> put_flash(:info, dgettext("prompts", "email changed successfully."))
|> redirect(to: Routes.user_settings_path(conn, :edit))
|> redirect(to: ~p"/users/settings")
:error ->
conn
@ -83,7 +83,7 @@ defmodule MemexWeb.UserSettingsController do
:error,
dgettext("errors", "email change link is invalid or it has expired.")
)
|> redirect(to: Routes.user_settings_path(conn, :edit))
|> redirect(to: ~p"/users/settings")
end
end
@ -93,11 +93,11 @@ defmodule MemexWeb.UserSettingsController do
conn
|> put_flash(:error, dgettext("prompts", "your account has been deleted"))
|> redirect(to: Routes.live_path(conn, HomeLive))
|> redirect(to: ~p"/")
else
conn
|> put_flash(:error, dgettext("errors", "unable to delete user"))
|> redirect(to: Routes.user_settings_path(conn, :edit))
|> redirect(to: ~p"/users/settings")
end
end

View File

@ -0,0 +1,5 @@
defmodule MemexWeb.UserSettingsHTML do
use MemexWeb, :html
embed_templates "user_settings_html/*"
end

View File

@ -8,7 +8,7 @@
<.form
:let={f}
for={@email_changeset}
action={Routes.user_settings_path(@conn, :update)}
action={~p"/users/settings"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<h3 class="title text-primary-400 text-lg text-center col-span-3">
@ -50,7 +50,7 @@
<.form
:let={f}
for={@password_changeset}
action={Routes.user_settings_path(@conn, :update)}
action={~p"/users/settings"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<h3 class="title text-primary-400 text-lg text-center col-span-3">
@ -104,7 +104,7 @@
<.form
:let={f}
for={@locale_changeset}
action={Routes.user_settings_path(@conn, :update)}
action={~p"/users/settings"}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<%= label(f, :locale, dgettext("actions", "change language"),
@ -134,17 +134,13 @@
<hr class="hr" />
<div class="flex justify-end items-center">
<.link
href={Routes.export_path(@conn, :export, :json)}
class="mx-4 my-2 btn btn-primary"
target="_blank"
>
<.link href={~p"/export/json"} class="mx-4 my-2 btn btn-primary" target="_blank">
<%= dgettext("actions", "export data as json") %>
</.link>
<.link
href={Routes.user_settings_path(@conn, :delete, @current_user)}
method={:delete}
href={~p"/users/settings/#{@current_user}"}
method="delete"
class="mx-4 my-2 btn btn-alert"
data-confirm={dgettext("prompts", "are you sure you want to delete your account?")}
>

View File

@ -20,7 +20,7 @@ defmodule MemexWeb.Endpoint do
at: "/",
from: :memex,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
only: MemexWeb.static_paths()
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.

View File

@ -3,8 +3,8 @@ defmodule MemexWeb.ErrorHelpers do
Conveniences for translating and building error messages.
"""
use Phoenix.HTML
import Phoenix.Component
use PhoenixHTMLHelpers
import Phoenix.{Component, HTML.Form}
alias Ecto.Changeset
alias Phoenix.{HTML.Form, LiveView.Rendered}

View File

@ -1,8 +1,6 @@
defmodule MemexWeb.ViewHelpers do
defmodule MemexWeb.HTMLHelpers do
@moduledoc """
Contains common helpers that can be used in liveviews and regular views. These
are automatically imported into any Phoenix View using `use MemexWeb,
:view`
Contains common helpers that are used for rendering
"""
use Phoenix.Component

View File

@ -6,31 +6,37 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
phx-debounce="300"
phx-hook="CtrlEnter"
class="flex flex-col justify-start items-stretch space-y-4"
>
<%= text_input(f, :slug,
aria_label: gettext("slug"),
class: "input input-primary",
placeholder: gettext("slug"),
aria_label: gettext("slug")
phx_debounce: 300,
phx_hook: "SanitizeTitles",
placeholder: gettext("slug")
) %>
<%= error_tag(f, :slug) %>
<%= textarea(f, :content,
id: "context-form-content",
class: "input input-primary h-64 min-h-64",
phx_hook: "MaintainAttrs",
phx_update: "ignore",
placeholder: gettext("use [[note-slug]] to link to a note"),
aria_label: gettext("use [[note-slug]] to link to a note")
placeholder:
gettext("use [[note-slug]] to link to a note or [context-slug] to link to a context"),
aria_label:
gettext("use [[note-slug]] to link to a note or [context-slug] to link to a context"),
phx_debounce: 300
) %>
<%= error_tag(f, :content) %>
<%= text_input(f, :tags_string,
id: "tags-input",
aria_label: gettext("tag1,tag2"),
class: "input input-primary",
placeholder: gettext("tag1,tag2"),
aria_label: gettext("tag1,tag2")
id: "tags-input",
phx_debounce: 300,
phx_hook: "SanitizeTags",
placeholder: gettext("tag1,tag2")
) %>
<%= error_tag(f, :tags_string) %>
@ -38,7 +44,8 @@
<%= select(f, :visibility, Ecto.Enum.values(Memex.Contexts.Context, :visibility),
class: "grow input input-primary",
prompt: gettext("select privacy"),
aria_label: gettext("select privacy")
aria_label: gettext("select privacy"),
phx_debounce: 300
) %>
<%= submit(dgettext("actions", "save"),

View File

@ -60,11 +60,11 @@ defmodule MemexWeb.ContextLive.Index do
end
def handle_event("search", %{"search" => %{"search_term" => ""}}, socket) do
{:noreply, socket |> push_patch(to: Routes.context_index_path(Endpoint, :index))}
{:noreply, socket |> push_patch(to: ~p"/contexts")}
end
def handle_event("search", %{"search" => %{"search_term" => search_term}}, socket) do
redirect_to = Routes.context_index_path(Endpoint, :search, search_term)
redirect_to = ~p"/contexts/#{search_term}"
{:noreply, socket |> push_patch(to: redirect_to)}
end

View File

@ -33,14 +33,14 @@
>
<:actions :let={context}>
<.link
:if={Contexts.is_owner?(context, @current_user)}
patch={Routes.context_index_path(@socket, :edit, context.slug)}
:if={Contexts.owner?(context, @current_user)}
patch={~p"/contexts/#{context}/edit"}
aria-label={dgettext("actions", "edit %{context_slug}", context_slug: context.slug)}
>
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Contexts.is_owner_or_admin?(context, @current_user)}
:if={Contexts.owner_or_admin?(context, @current_user)}
href="#"
phx-click="delete"
phx-value-id={context.id}
@ -53,16 +53,12 @@
</.live_component>
<% end %>
<.link
:if={@current_user}
patch={Routes.context_index_path(@socket, :new)}
class="self-end btn btn-primary"
>
<.link :if={@current_user} patch={~p"/contexts/new"} class="self-end btn btn-primary">
<%= dgettext("actions", "new context") %>
</.link>
</div>
<.modal :if={@live_action in [:new, :edit]} return_to={Routes.context_index_path(@socket, :index)}>
<.modal :if={@live_action in [:new, :edit]} return_to={~p"/contexts"}>
<.live_component
module={MemexWeb.ContextLive.FormComponent}
id={@context.id || :new}
@ -70,6 +66,6 @@
title={@page_title}
action={@live_action}
context={@context}
return_to={Routes.context_index_path(@socket, :index)}
return_to={~p"/contexts"}
/>
</.modal>

View File

@ -38,7 +38,7 @@ defmodule MemexWeb.ContextLive.Show do
socket =
socket
|> put_flash(:info, gettext("%{slug} deleted", slug: slug))
|> push_navigate(to: Routes.context_index_path(Endpoint, :index))
|> push_navigate(to: ~p"/contexts")
{:noreply, socket}
end

View File

@ -4,11 +4,7 @@
</h1>
<div class="flex flex-wrap space-x-1">
<.link
:for={tag <- @context.tags}
navigate={Routes.context_index_path(Endpoint, :search, tag)}
class="link"
>
<.link :for={tag <- @context.tags} navigate={~p"/contexts/#{tag}"} class="link">
<%= tag %>
</.link>
</div>
@ -21,14 +17,14 @@
<div class="self-end flex space-x-4">
<.link
:if={Contexts.is_owner?(@context, @current_user)}
:if={Contexts.owner?(@context, @current_user)}
class="btn btn-primary"
patch={Routes.context_show_path(@socket, :edit, @context.slug)}
patch={~p"/context/#{@context}/edit"}
>
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Contexts.is_owner_or_admin?(@context, @current_user)}
:if={Contexts.owner_or_admin?(@context, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"
@ -40,10 +36,7 @@
</div>
</div>
<.modal
:if={@live_action == :edit}
return_to={Routes.context_show_path(@socket, :show, @context.slug)}
>
<.modal :if={@live_action == :edit} return_to={~p"/context/#{@context}"}>
<.live_component
module={MemexWeb.ContextLive.FormComponent}
id={@context.id}
@ -51,6 +44,6 @@
title={@page_title}
action={@live_action}
context={@context}
return_to={Routes.context_show_path(@socket, :show, @context.slug)}
return_to={~p"/context/#{@context}"}
/>
</.modal>

View File

@ -89,7 +89,7 @@
<p>
<%= gettext("in my opinion, contexts should be like single-topic blog posts.") %>
<%= gettext(
"for instance, a good context could be what makes some physical designs spark joy for you, and in that context you could backlink to the spoon note as an example of how it fits nicely into your hand."
"for instance, a good context could be what makes some physical designs spark joy for you, and in that context you could link to the spoon note as an example of how it fits nicely into your hand."
) %>
</p>
</li>
@ -100,10 +100,10 @@
</b>
<p>
<%= gettext(
"in my opinion, pipelines should be pretty lightweight, and just backlink to contexts to provide most of the heavy lifting."
"in my opinion, pipelines should be pretty lightweight, and just link to contexts to provide most of the heavy lifting."
) %>
<%= gettext(
"for instance, a pipeline for buying an object could have a step where you consider how much it sparks joy, and it could backlink to the physical designs context, maybe with some notes about how it applies in this case."
"for instance, a pipeline for buying an object could have a step where you consider how much it sparks joy, and it could link to the physical designs context, maybe with some notes about how it applies in this case."
) %>
</p>
</li>
@ -117,7 +117,7 @@
"while memEx fully supports multiple users, each memEx instance should be treated as a single cohesive and collaborative document."
) %>
<%= gettext(
"note, context and pipeline slugs must be unique, and you are free to backlink to notes not written by you."
"note, context and pipeline slugs must be unique, and you are free to link to notes not written by you."
) %>
<%= gettext(
"so, i'd recommend inviting anyone you'd like to work on your collective memEx. however, when in doubt, hopefully setting up a new instance is easy enough. if it isn't, then feel free to let me know :)"

View File

@ -5,7 +5,6 @@ defmodule MemexWeb.HomeLive do
use MemexWeb, :live_view
alias Memex.Accounts
alias MemexWeb.FaqLive
@version Mix.Project.config()[:version]

View File

@ -32,7 +32,7 @@
</li>
<li class="flex flex-col justify-center items-center text-right space-y-2">
<.link navigate={Routes.live_path(Endpoint, FaqLive)} class="btn btn-primary">
<.link navigate={~p"/faq"} class="btn btn-primary">
<%= gettext("read more on how to use memEx") %>
</.link>
</li>
@ -86,7 +86,7 @@
</b>
<p class="flex flex-col justify-center items-center space-y-2">
<%= if @admins |> Enum.empty?() do %>
<.link href={Routes.user_registration_path(Endpoint, :new)} class="link">
<.link href={~p"/users/register"} class="link">
<%= dgettext("prompts", "register to setup memEx") %>
</.link>
<% else %>

View File

@ -10,6 +10,7 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
phx-hook="CtrlEnter"
>
<div
:if={@changeset.action && not @changeset.valid?()}
@ -18,13 +19,27 @@
<%= changeset_errors(@changeset) %>
</div>
<%= label(f, :name, gettext("name"), class: "title text-lg text-primary-400") %>
<%= text_input(f, :name, class: "input input-primary col-span-2") %>
<%= label(f, :name, gettext("name"),
class: "title text-lg text-primary-400",
phx_debounce: 300
) %>
<%= text_input(f, :name,
class: "input input-primary col-span-2",
phx_debounce: 300
) %>
<%= error_tag(f, :name, "col-span-3") %>
<%= label(f, :uses_left, gettext("uses left"), class: "title text-lg text-primary-400") %>
<%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
<%= label(f, :uses_left, gettext("uses left"),
class: "title text-lg text-primary-400",
phx_debounce: 300
) %>
<%= number_input(f, :uses_left,
min: 0,
class: "input input-primary col-span-2",
phx_debounce: 300
) %>
<%= error_tag(f, :uses_left, "col-span-3") %>
<span class="col-span-3 text-primary-500 italic text-center">
<%= gettext(~s/leave "uses left" blank to make invite unlimited/) %>
</span>

View File

@ -4,12 +4,12 @@
</h1>
<%= if @invites |> Enum.empty?() do %>
<h1 class="title text-xl text-primary-400">
<h1 class="title text-xl text-primary-400 text-center">
<%= gettext("no invites 😔") %>
</h1>
<.link patch={Routes.invite_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "invite someone new!") %>
<.link patch={~p"/invites"} class="ml-auto btn btn-primary">
<%= dgettext("actions", "new invite") %>
</.link>
<% end %>
@ -35,7 +35,7 @@
</form>
</:code_actions>
<.link
patch={Routes.invite_index_path(Endpoint, :edit, invite)}
patch={~p"/invites/edit/#{invite}"}
class="text-primary-400 link"
aria-label={
dgettext("actions", "edit invite for %{invite_name}", invite_name: invite.name)
@ -86,11 +86,7 @@
</.link>
</.invite_card>
<.link
:if={@invites != []}
patch={Routes.invite_index_path(Endpoint, :new)}
class="btn btn-primary ml-auto"
>
<.link :if={@invites != []} patch={~p"/invites/new"} class="btn btn-primary ml-auto">
<%= dgettext("actions", "create invite") %>
</.link>
</div>
@ -152,14 +148,14 @@
<% end %>
</div>
<.modal :if={@live_action in [:new, :edit]} return_to={Routes.invite_index_path(Endpoint, :index)}>
<.modal :if={@live_action in [:new, :edit]} return_to={~p"/invites"}>
<.live_component
module={MemexWeb.InviteLive.FormComponent}
id={@invite.id || :new}
title={@page_title}
action={@live_action}
invite={@invite}
return_to={Routes.invite_index_path(Endpoint, :index)}
return_to={~p"/invites"}
current_user={@current_user}
/>
</.modal>

View File

@ -6,31 +6,35 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
phx-debounce="300"
phx-hook="CtrlEnter"
class="flex flex-col justify-start items-stretch space-y-4"
>
<%= text_input(f, :slug,
aria_label: gettext("slug"),
class: "input input-primary",
placeholder: gettext("slug"),
aria_label: gettext("slug")
phx_debounce: 300,
phx_hook: "SanitizeTitles",
placeholder: gettext("slug")
) %>
<%= error_tag(f, :slug) %>
<%= textarea(f, :content,
id: "note-form-content",
class: "input input-primary h-64 min-h-64",
phx_hook: "MaintainAttrs",
phx_update: "ignore",
placeholder: gettext("content"),
aria_label: gettext("content")
placeholder: gettext("use [note-slug] to link to a note"),
aria_label: gettext("use [note-slug] to link to a note"),
phx_debounce: 300
) %>
<%= error_tag(f, :content) %>
<%= text_input(f, :tags_string,
id: "tags-input",
aria_label: gettext("tag1,tag2"),
class: "input input-primary",
placeholder: gettext("tag1,tag2"),
aria_label: gettext("tag1,tag2")
id: "tags-input",
phx_debounce: 300,
phx_hook: "SanitizeTags",
placeholder: gettext("tag1,tag2")
) %>
<%= error_tag(f, :tags_string) %>
@ -38,7 +42,8 @@
<%= select(f, :visibility, Ecto.Enum.values(Memex.Notes.Note, :visibility),
class: "grow input input-primary",
prompt: gettext("select privacy"),
aria_label: gettext("select privacy")
aria_label: gettext("select privacy"),
phx_debounce: 300
) %>
<%= submit(dgettext("actions", "save"),

View File

@ -60,11 +60,11 @@ defmodule MemexWeb.NoteLive.Index do
end
def handle_event("search", %{"search" => %{"search_term" => ""}}, socket) do
{:noreply, socket |> push_patch(to: Routes.note_index_path(Endpoint, :index))}
{:noreply, socket |> push_patch(to: ~p"/notes")}
end
def handle_event("search", %{"search" => %{"search_term" => search_term}}, socket) do
{:noreply, socket |> push_patch(to: Routes.note_index_path(Endpoint, :search, search_term))}
{:noreply, socket |> push_patch(to: ~p"/notes/#{search_term}")}
end
defp display_notes(%{assigns: %{current_user: current_user, search: search}} = socket)

View File

@ -33,14 +33,14 @@
>
<:actions :let={note}>
<.link
:if={Notes.is_owner?(note, @current_user)}
patch={Routes.note_index_path(@socket, :edit, note.slug)}
:if={Notes.owner?(note, @current_user)}
patch={~p"/notes/#{note}/edit"}
aria-label={dgettext("actions", "edit %{note_slug}", note_slug: note.slug)}
>
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Notes.is_owner_or_admin?(note, @current_user)}
:if={Notes.owner_or_admin?(note, @current_user)}
href="#"
phx-click="delete"
phx-value-id={note.id}
@ -53,16 +53,12 @@
</.live_component>
<% end %>
<.link
:if={@current_user}
patch={Routes.note_index_path(@socket, :new)}
class="self-end btn btn-primary"
>
<.link :if={@current_user} patch={~p"/notes/new"} class="self-end btn btn-primary">
<%= dgettext("actions", "new note") %>
</.link>
</div>
<.modal :if={@live_action in [:new, :edit]} return_to={Routes.note_index_path(@socket, :index)}>
<.modal :if={@live_action in [:new, :edit]} return_to={~p"/notes"}>
<.live_component
module={MemexWeb.NoteLive.FormComponent}
id={@note.id || :new}
@ -70,6 +66,6 @@
title={@page_title}
action={@live_action}
note={@note}
return_to={Routes.note_index_path(@socket, :index)}
return_to={~p"/notes"}
/>
</.modal>

View File

@ -38,7 +38,7 @@ defmodule MemexWeb.NoteLive.Show do
socket =
socket
|> put_flash(:info, gettext("%{slug} deleted", slug: slug))
|> push_navigate(to: Routes.note_index_path(Endpoint, :index))
|> push_navigate(to: ~p"/notes")
{:noreply, socket}
end

View File

@ -4,11 +4,7 @@
</h1>
<div class="flex flex-wrap space-x-1">
<.link
:for={tag <- @note.tags}
navigate={Routes.note_index_path(Endpoint, :search, tag)}
class="link"
>
<.link :for={tag <- @note.tags} navigate={~p"/notes/#{tag}"} class="link">
<%= tag %>
</.link>
</div>
@ -21,14 +17,14 @@
<div class="self-end flex space-x-4">
<.link
:if={Notes.is_owner?(@note, @current_user)}
:if={Notes.owner?(@note, @current_user)}
class="btn btn-primary"
patch={Routes.note_show_path(@socket, :edit, @note.slug)}
patch={~p"/note/#{@note}/edit"}
>
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Notes.is_owner_or_admin?(@note, @current_user)}
:if={Notes.owner_or_admin?(@note, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"
@ -40,7 +36,7 @@
</div>
</div>
<.modal :if={@live_action == :edit} return_to={Routes.note_show_path(@socket, :show, @note.slug)}>
<.modal :if={@live_action == :edit} return_to={~p"/note/#{@note}"}>
<.live_component
module={MemexWeb.NoteLive.FormComponent}
id={@note.id}
@ -48,6 +44,6 @@
title={@page_title}
action={@live_action}
note={@note}
return_to={Routes.note_show_path(@socket, :show, @note.slug)}
return_to={~p"/note/#{@note}"}
/>
</.modal>

View File

@ -6,31 +6,41 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
phx-debounce="300"
phx-hook="CtrlEnter"
class="flex flex-col justify-start items-stretch space-y-4"
>
<%= text_input(f, :slug,
aria_label: gettext("slug"),
class: "input input-primary",
placeholder: gettext("slug"),
aria_label: gettext("slug")
phx_debounce: 300,
phx_hook: "SanitizeTitles",
placeholder: gettext("slug")
) %>
<%= error_tag(f, :slug) %>
<%= textarea(f, :description,
id: "pipeline-form-description",
class: "input input-primary h-64 min-h-64",
phx_hook: "MaintainAttrs",
phx_update: "ignore",
placeholder: gettext("description"),
aria_label: gettext("description")
placeholder:
gettext(
"use [[[note-slug]]] to link to a note or use [[context-slug]] to link to a context or [pipeline-slug] to link to a pipeline"
),
aria_label:
gettext(
"use [[[note-slug]]] to link to a note or use [[context-slug]] to link to a context or [pipeline-slug] to link to a pipeline"
),
phx_debounce: 300
) %>
<%= error_tag(f, :description) %>
<%= text_input(f, :tags_string,
id: "tags-input",
aria_label: gettext("tag1,tag2"),
class: "input input-primary",
placeholder: gettext("tag1,tag2"),
aria_label: gettext("tag1,tag2")
id: "tags-input",
phx_debounce: 300,
phx_hook: "SanitizeTags",
placeholder: gettext("tag1,tag2")
) %>
<%= error_tag(f, :tags_string) %>
@ -38,7 +48,8 @@
<%= select(f, :visibility, Ecto.Enum.values(Memex.Pipelines.Pipeline, :visibility),
class: "grow input input-primary",
prompt: gettext("select privacy"),
aria_label: gettext("select privacy")
aria_label: gettext("select privacy"),
phx_debounce: 300
) %>
<%= submit(dgettext("actions", "save"),

View File

@ -60,12 +60,11 @@ defmodule MemexWeb.PipelineLive.Index do
end
def handle_event("search", %{"search" => %{"search_term" => ""}}, socket) do
{:noreply, socket |> push_patch(to: Routes.pipeline_index_path(Endpoint, :index))}
{:noreply, socket |> push_patch(to: ~p"/pipelines")}
end
def handle_event("search", %{"search" => %{"search_term" => search_term}}, socket) do
redirect_to = Routes.pipeline_index_path(Endpoint, :search, search_term)
{:noreply, socket |> push_patch(to: redirect_to)}
{:noreply, socket |> push_patch(to: ~p"/pipelines/#{search_term}")}
end
defp display_pipelines(%{assigns: %{current_user: current_user, search: search}} = socket)

View File

@ -33,14 +33,14 @@
>
<:actions :let={pipeline}>
<.link
:if={Pipelines.is_owner?(pipeline, @current_user)}
patch={Routes.pipeline_index_path(@socket, :edit, pipeline.slug)}
:if={Pipelines.owner?(pipeline, @current_user)}
patch={~p"/pipelines/#{pipeline}/edit"}
aria-label={dgettext("actions", "edit %{pipeline_slug}", pipeline_slug: pipeline.slug)}
>
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Pipelines.is_owner_or_admin?(pipeline, @current_user)}
:if={Pipelines.owner_or_admin?(pipeline, @current_user)}
href="#"
phx-click="delete"
phx-value-id={pipeline.id}
@ -55,19 +55,12 @@
</.live_component>
<% end %>
<.link
:if={@current_user}
patch={Routes.pipeline_index_path(@socket, :new)}
class="self-end btn btn-primary"
>
<.link :if={@current_user} patch={~p"/pipelines/new"} class="self-end btn btn-primary">
<%= dgettext("actions", "new pipeline") %>
</.link>
</div>
<.modal
:if={@live_action in [:new, :edit]}
return_to={Routes.pipeline_index_path(@socket, :index)}
>
<.modal :if={@live_action in [:new, :edit]} return_to={~p"/pipelines"}>
<.live_component
module={MemexWeb.PipelineLive.FormComponent}
id={@pipeline.id || :new}
@ -75,6 +68,6 @@
title={@page_title}
action={@live_action}
pipeline={@pipeline}
return_to={Routes.pipeline_index_path(@socket, :index)}
return_to={~p"/pipelines"}
/>
</.modal>

View File

@ -73,7 +73,7 @@ defmodule MemexWeb.PipelineLive.Show do
socket =
socket
|> put_flash(:info, gettext("%{slug} deleted", slug: slug))
|> push_navigate(to: Routes.pipeline_index_path(Endpoint, :index))
|> push_navigate(to: ~p"/pipelines")
{:noreply, socket}
end
@ -91,7 +91,7 @@ defmodule MemexWeb.PipelineLive.Show do
socket =
socket
|> put_flash(:info, gettext("%{title} deleted", title: title))
|> push_patch(to: Routes.pipeline_show_path(Endpoint, :show, pipeline_slug))
|> push_patch(to: ~p"/pipeline/#{pipeline_slug}")
{:noreply, socket}
end
@ -110,7 +110,7 @@ defmodule MemexWeb.PipelineLive.Show do
socket =
socket
|> push_patch(to: Routes.pipeline_show_path(Endpoint, :show, pipeline_slug))
|> push_patch(to: ~p"/pipeline/#{pipeline_slug}")
{:noreply, socket}
end

View File

@ -4,24 +4,12 @@
</h1>
<div class="flex flex-wrap space-x-1">
<.link
:for={tag <- @pipeline.tags}
navigate={Routes.pipeline_index_path(Endpoint, :search, tag)}
class="link"
>
<.link :for={tag <- @pipeline.tags} navigate={~p"/pipelines/#{tag}"} class="link">
<%= tag %>
</.link>
</div>
<textarea
:if={@pipeline.description}
id="show-pipeline-description"
class="input input-primary h-32 min-h-32"
phx-hook="MaintainAttrs"
phx-update="ignore"
readonly
phx-no-format
><%= @pipeline.description %></textarea>
<.pipeline_content pipeline={@pipeline} />
<p class="self-end">
<%= gettext("Visibility: %{visibility}", visibility: @pipeline.visibility) %>
@ -29,14 +17,14 @@
<div class="pb-4 self-end flex space-x-4">
<.link
:if={Pipelines.is_owner?(@pipeline, @current_user)}
:if={Pipelines.owner?(@pipeline, @current_user)}
class="btn btn-primary"
patch={Routes.pipeline_show_path(@socket, :edit, @pipeline.slug)}
patch={~p"/pipeline/#{@pipeline}/edit"}
>
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Pipelines.is_owner_or_admin?(@pipeline, @current_user)}
:if={Pipelines.owner_or_admin?(@pipeline, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"
@ -64,7 +52,7 @@
<%= gettext("%{position}. %{title}", position: position + 1, title: title) %>
</h3>
<%= if Pipelines.is_owner?(@pipeline, @current_user) do %>
<%= if Pipelines.owner?(@pipeline, @current_user) do %>
<div class="flex justify-between items-center space-x-4">
<%= if position <= 0 do %>
<i class="fas text-xl fa-chevron-up cursor-not-allowed opacity-25"></i>
@ -100,7 +88,7 @@
<.link
class="self-end btn btn-primary"
patch={Routes.pipeline_show_path(@socket, :edit_step, @pipeline.slug, step_id)}
patch={~p"/pipeline/#{@pipeline}/#{step_id}"}
aria-label={dgettext("actions", "edit %{step_title}", step_title: step.title)}
>
<%= dgettext("actions", "edit") %>
@ -125,9 +113,9 @@
<% end %>
<.link
:if={Pipelines.is_owner?(@pipeline, @current_user)}
:if={Pipelines.owner?(@pipeline, @current_user)}
class="self-end btn btn-primary"
patch={Routes.pipeline_show_path(@socket, :add_step, @pipeline.slug)}
patch={~p"/pipeline/#{@pipeline}/add_step"}
>
<%= dgettext("actions", "add step") %>
</.link>
@ -135,7 +123,7 @@
<%= case @live_action do %>
<% :edit -> %>
<.modal return_to={Routes.pipeline_show_path(@socket, :show, @pipeline.slug)}>
<.modal return_to={~p"/pipeline/#{@pipeline}"}>
<.live_component
module={MemexWeb.PipelineLive.FormComponent}
id={@pipeline.id}
@ -143,11 +131,11 @@
title={@page_title}
action={@live_action}
pipeline={@pipeline}
return_to={Routes.pipeline_show_path(@socket, :show, @pipeline.slug)}
return_to={~p"/pipeline/#{@pipeline}"}
/>
</.modal>
<% action when action in [:add_step, :edit_step] -> %>
<.modal return_to={Routes.pipeline_show_path(@socket, :show, @pipeline.slug)}>
<.modal return_to={~p"/pipeline/#{@pipeline}"}>
<.live_component
module={MemexWeb.StepLive.FormComponent}
id={@pipeline.id || :new}
@ -156,7 +144,7 @@
action={@live_action}
pipeline={@pipeline}
step={@step}
return_to={Routes.pipeline_show_path(@socket, :show, @pipeline.slug)}
return_to={~p"/pipeline/#{@pipeline}"}
/>
</.modal>
<% _ -> %>

View File

@ -6,23 +6,31 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
phx-debounce="300"
phx-hook="CtrlEnter"
class="flex flex-col justify-start items-stretch space-y-4"
>
<%= text_input(f, :title,
aria_label: gettext("title"),
class: "input input-primary",
placeholder: gettext("title"),
aria_label: gettext("title")
phx_debounce: 300,
phx_hook: "SanitizeTitles",
placeholder: gettext("title")
) %>
<%= error_tag(f, :title) %>
<%= textarea(f, :content,
id: "step-form-content",
class: "input input-primary h-64 min-h-64",
phx_hook: "MaintainAttrs",
phx_update: "ignore",
placeholder: gettext("use [[context-slug]] to link to a context"),
aria_label: gettext("use [[context-slug]] to link to a context")
placeholder:
gettext(
"use [[[note-slug]]] to link to a note or use [[context-slug]] to link to a context or [pipeline-slug] to link to a pipeline"
),
aria_label:
gettext(
"use [[[note-slug]]] to link to a note or use [[context-slug]] to link to a context or [pipeline-slug] to link to a pipeline"
),
phx_debounce: 300
) %>
<%= error_tag(f, :content) %>

View File

@ -7,25 +7,13 @@ defmodule MemexWeb.Router do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {MemexWeb.LayoutView, :root}
plug :put_root_layout, {MemexWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
plug :put_user_locale
end
defp put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, _opts) do
default = Application.fetch_env!(:gettext, :default_locale)
Gettext.put_locale(locale || default)
conn |> put_session(:locale, locale || default)
end
defp put_user_locale(conn, _opts) do
default = Application.fetch_env!(:gettext, :default_locale)
Gettext.put_locale(default)
conn |> put_session(:locale, default)
end
pipeline :require_admin do
plug :require_role, role: :admin
end
@ -34,15 +22,6 @@ defmodule MemexWeb.Router do
plug :accepts, ["json"]
end
scope "/", MemexWeb do
pipe_through :browser
live "/", HomeLive
live "/faq", FaqLive
end
## Authentication routes
scope "/", MemexWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
@ -56,10 +35,16 @@ defmodule MemexWeb.Router do
put "/users/reset_password/:token", UserResetPasswordController, :update
end
live_session :default do
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user]
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user]
get "/users/settings", UserSettingsController, :edit
put "/users/settings", UserSettingsController, :update
delete "/users/settings/:id", UserSettingsController, :delete
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
get "/export/:mode", ExportController, :export
live_session :default, on_mount: [{MemexWeb.UserAuth, :ensure_authenticated}] do
live "/notes/new", NoteLive.Index, :new
live "/notes/:slug/edit", NoteLive.Index, :edit
live "/note/:slug/edit", NoteLive.Show, :edit
@ -73,16 +58,20 @@ defmodule MemexWeb.Router do
live "/pipeline/:slug/edit", PipelineLive.Show, :edit
live "/pipeline/:slug/add_step", PipelineLive.Show, :add_step
live "/pipeline/:slug/:step_id", PipelineLive.Show, :edit_step
get "/users/settings", UserSettingsController, :edit
put "/users/settings", UserSettingsController, :update
delete "/users/settings/:id", UserSettingsController, :delete
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
get "/export/:mode", ExportController, :export
end
end
scope "/", MemexWeb do
pipe_through [:browser]
scope "/", MemexWeb do
pipe_through [:browser]
delete "/users/log_out", UserSessionController, :delete
get "/users/confirm", UserConfirmationController, :new
post "/users/confirm", UserConfirmationController, :create
get "/users/confirm/:token", UserConfirmationController, :confirm
live_session :public, on_mount: [{MemexWeb.UserAuth, :mount_current_user}] do
live "/", HomeLive
live "/faq", FaqLive
live "/notes", NoteLive.Index, :index
live "/notes/:search", NoteLive.Index, :search
@ -98,29 +87,16 @@ defmodule MemexWeb.Router do
end
end
live_session :admin do
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin]
live "/invites", InviteLive.Index, :index
live "/invites/new", InviteLive.Index, :new
live "/invites/:id/edit", InviteLive.Index, :edit
end
end
scope "/", MemexWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin]
live_dashboard "/dashboard", metrics: MemexWeb.Telemetry, ecto_repos: [Memex.Repo]
end
scope "/", MemexWeb do
pipe_through [:browser]
delete "/users/log_out", UserSessionController, :delete
get "/users/confirm", UserConfirmationController, :new
post "/users/confirm", UserConfirmationController, :create
get "/users/confirm/:token", UserConfirmationController, :confirm
live_session :admin, on_mount: [{MemexWeb.UserAuth, :ensure_admin}] do
live "/invites", InviteLive.Index, :index
live "/invites/new", InviteLive.Index, :new
live "/invites/edit/:id", InviteLive.Index, :edit
end
end
# Enables the Swoosh mailbox preview in development.
@ -132,9 +108,6 @@ defmodule MemexWeb.Router do
pipe_through :browser
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
scope "/dev" do
get "/preview/:id", MemexWeb.EmailController, :preview
end
end

Some files were not shown because too many files have changed in this diff Show More