diff --git a/.gitignore b/.gitignore index 3877f3c..301563a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ erl_crash.dump /config/*.secret.exs .elixir_ls/ -Notes/ \ No newline at end of file +Notes/ +tmp/ \ No newline at end of file diff --git a/logsrv/.formatter.exs b/logsrv/.formatter.exs new file mode 100644 index 0000000..90a0853 --- /dev/null +++ b/logsrv/.formatter.exs @@ -0,0 +1,5 @@ +# Used by "mix format" +[ + inputs: ["mix.exs", "config/*.exs"], + subdirectories: ["apps/*"] +] diff --git a/logsrv/.gitignore b/logsrv/.gitignore new file mode 100644 index 0000000..2de045d --- /dev/null +++ b/logsrv/.gitignore @@ -0,0 +1,23 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Temporary files, for example, from tests. +/tmp/ diff --git a/logsrv/README.md b/logsrv/README.md new file mode 100644 index 0000000..cfc6445 --- /dev/null +++ b/logsrv/README.md @@ -0,0 +1,4 @@ +# Logsrv + +**TODO: Add description** + diff --git a/logsrv_api/.formatter.exs b/logsrv/apps/logsrv_api/.formatter.exs similarity index 100% rename from logsrv_api/.formatter.exs rename to logsrv/apps/logsrv_api/.formatter.exs diff --git a/logsrv_api/.gitignore b/logsrv/apps/logsrv_api/.gitignore similarity index 93% rename from logsrv_api/.gitignore rename to logsrv/apps/logsrv_api/.gitignore index 41c8958..4328271 100644 --- a/logsrv_api/.gitignore +++ b/logsrv/apps/logsrv_api/.gitignore @@ -1,6 +1,3 @@ -# Notes for dev mode. -/Notes/ - # The directory Mix will write compiled artifacts to. /_build/ @@ -23,7 +20,7 @@ erl_crash.dump *.ez # Ignore package tarball (built via "mix hex.build"). -logsrv-*.tar +logsrv_api-*.tar # Temporary files, for example, from tests. /tmp/ diff --git a/logsrv_api/README.md b/logsrv/apps/logsrv_api/README.md similarity index 68% rename from logsrv_api/README.md rename to logsrv/apps/logsrv_api/README.md index b505b07..660f03c 100644 --- a/logsrv_api/README.md +++ b/logsrv/apps/logsrv_api/README.md @@ -1,21 +1,21 @@ -# Logsrv +# LogsrvApi **TODO: Add description** ## Installation If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `logsrv` to your list of dependencies in `mix.exs`: +by adding `logsrv_api` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:logsrv, "~> 0.1.0"} + {:logsrv_api, "~> 0.1.0"} ] end ``` Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at . +be found at . diff --git a/logsrv/apps/logsrv_api/lib/logsrv_api.ex b/logsrv/apps/logsrv_api/lib/logsrv_api.ex new file mode 100644 index 0000000..df4c822 --- /dev/null +++ b/logsrv/apps/logsrv_api/lib/logsrv_api.ex @@ -0,0 +1,25 @@ +defmodule LogsrvApi do + @moduledoc """ + Documentation for `LogsrvApi`. + """ + alias LogsrvApi.{Filesystem, Journal, Page} + + @repo Filesystem + + def pages do + @repo.all(Page) + end + def page(title) do + @repo.get!(Page, title) + end + + def journals do + @repo.all(Journal) + end + def journal(date) do + @repo.get!(Journal, date) + end + + # Todo - def get_by + +end diff --git a/logsrv/apps/logsrv_api/lib/logsrv_api/application.ex b/logsrv/apps/logsrv_api/lib/logsrv_api/application.ex new file mode 100644 index 0000000..565d76c --- /dev/null +++ b/logsrv/apps/logsrv_api/lib/logsrv_api/application.ex @@ -0,0 +1,20 @@ +defmodule LogsrvApi.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + # Starts a worker by calling: LogsrvApi.Worker.start_link(arg) + # {LogsrvApi.Worker, arg} + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: LogsrvApi.Supervisor] + Supervisor.start_link(children, opts) + end +end diff --git a/logsrv/apps/logsrv_api/lib/logsrv_api/filesystem.ex b/logsrv/apps/logsrv_api/lib/logsrv_api/filesystem.ex new file mode 100644 index 0000000..45db3a1 --- /dev/null +++ b/logsrv/apps/logsrv_api/lib/logsrv_api/filesystem.ex @@ -0,0 +1,46 @@ +defmodule LogsrvApi.Filesystem do + alias LogsrvApi.{Journal, Page} + + def to_date(str) do + str + |> String.replace(~r/\..*/,"") + |> String.replace("_","-") + |> Date.from_iso8601() + end + def dir do + Application.get_env(:logsrv_api, :dir) <> "/" + end + def dir(subdir) do + "#{dir()}/#{subdir}/" + end + def locate(Page, fd) do + dir(:pages) <> fd + end + def locate(Journal, fd) do + dir(:journals) <> fd + end + + def all(Page) do + dir(:pages) + |> File.ls! + |> Enum.map(fn(fd) -> + Page.init(fd) + end) + end + + def all(Journal) do + dir(:journals) + |> File.ls! + |> Enum.map(fn(fd) -> + Journal.init(fd) + end) + end + + def get!(Journal, date) do + Enum.find(all(Journal), fn(entry) -> entry.date === date end) + end + def get!(Page, title) do + Enum.find(all(Page), fn(entry) -> entry.title === title end) + end + +end diff --git a/logsrv/apps/logsrv_api/lib/logsrv_api/journal.ex b/logsrv/apps/logsrv_api/lib/logsrv_api/journal.ex new file mode 100644 index 0000000..4c1dd5c --- /dev/null +++ b/logsrv/apps/logsrv_api/lib/logsrv_api/journal.ex @@ -0,0 +1,14 @@ +defmodule LogsrvApi.Journal do + alias LogsrvApi.{Filesystem,Page,Journal} + + def init(fd) do + {:ok, date} = fd |> String.replace(~r/_/,"-") |> String.replace(~r/\.md$/,"") |> Filesystem.to_date + tags = [:fun] + + %{ + date: date, + filename: fd, + tags: tags + } + end +end diff --git a/logsrv/apps/logsrv_api/lib/logsrv_api/page.ex b/logsrv/apps/logsrv_api/lib/logsrv_api/page.ex new file mode 100644 index 0000000..9caaf71 --- /dev/null +++ b/logsrv/apps/logsrv_api/lib/logsrv_api/page.ex @@ -0,0 +1,17 @@ +defmodule LogsrvApi.Page do + alias LogsrvApi.{Filesystem,Page,Journal} + + def init(fd) do + title = fd |> String.replace(~r/_/," ") |> String.replace(~r/\.md$/,"") + date_modified = Page |> Filesystem.locate(fd) + tags = [:fun] + + %{ + title: title, + filename: fd, + date_modified: date_modified, + tags: tags + } + end + +end diff --git a/logsrv_api/mix.exs b/logsrv/apps/logsrv_api/mix.exs similarity index 57% rename from logsrv_api/mix.exs rename to logsrv/apps/logsrv_api/mix.exs index 97f4cb5..3238379 100644 --- a/logsrv_api/mix.exs +++ b/logsrv/apps/logsrv_api/mix.exs @@ -1,11 +1,15 @@ -defmodule Logsrv.MixProject do +defmodule LogsrvApi.MixProject do use Mix.Project def project do [ - app: :logsrv, + app: :logsrv_api, version: "0.1.0", - elixir: "~> 1.12", + build_path: "../../_build", + config_path: "../../config/config.exs", + deps_path: "../../deps", + lockfile: "../../mix.lock", + elixir: "~> 1.13", start_permanent: Mix.env() == :prod, deps: deps() ] @@ -15,18 +19,16 @@ defmodule Logsrv.MixProject do def application do [ extra_applications: [:logger], - mod: {Logsrv.Application, []} + mod: {LogsrvApi.Application, []} ] end # Run "mix help deps" to learn about dependencies. defp deps do [ - {:plug_cowboy, "~> 2.5"}, - {:jason, "~> 1.3"}, - {:tz, "~> 0.21.1"} # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, + # {:sibling_app_in_umbrella, in_umbrella: true} ] end end diff --git a/logsrv/apps/logsrv_api/test/logsrv_api_test.exs b/logsrv/apps/logsrv_api/test/logsrv_api_test.exs new file mode 100644 index 0000000..a4a6e42 --- /dev/null +++ b/logsrv/apps/logsrv_api/test/logsrv_api_test.exs @@ -0,0 +1,8 @@ +defmodule LogsrvApiTest do + use ExUnit.Case + doctest LogsrvApi + + test "greets the world" do + assert LogsrvApi.hello() == :world + end +end diff --git a/logsrv_api/test/test_helper.exs b/logsrv/apps/logsrv_api/test/test_helper.exs similarity index 100% rename from logsrv_api/test/test_helper.exs rename to logsrv/apps/logsrv_api/test/test_helper.exs diff --git a/logsrv/apps/logsrv_web/.formatter.exs b/logsrv/apps/logsrv_web/.formatter.exs new file mode 100644 index 0000000..4761678 --- /dev/null +++ b/logsrv/apps/logsrv_web/.formatter.exs @@ -0,0 +1,4 @@ +[ + import_deps: [:phoenix], + inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/logsrv/apps/logsrv_web/.gitignore b/logsrv/apps/logsrv_web/.gitignore new file mode 100644 index 0000000..375b94d --- /dev/null +++ b/logsrv/apps/logsrv_web/.gitignore @@ -0,0 +1,34 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +logsrv_web-*.tar + +# Ignore assets that are produced by build tools. +/priv/static/assets/ + +# Ignore digested assets cache. +/priv/static/cache_manifest.json + +# In case you use Node.js/npm, you want to ignore these. +npm-debug.log +/assets/node_modules/ + diff --git a/logsrv/apps/logsrv_web/README.md b/logsrv/apps/logsrv_web/README.md new file mode 100644 index 0000000..da1024d --- /dev/null +++ b/logsrv/apps/logsrv_web/README.md @@ -0,0 +1,18 @@ +# LogsrvWeb + +To start your Phoenix server: + + * Install dependencies with `mix deps.get` + * Start Phoenix endpoint with `mix phx.server` + +Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. + +Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). + +## Learn more + + * Official website: https://www.phoenixframework.org/ + * Guides: https://hexdocs.pm/phoenix/overview.html + * Docs: https://hexdocs.pm/phoenix + * Forum: https://elixirforum.com/c/phoenix-forum + * Source: https://github.com/phoenixframework/phoenix diff --git a/logsrv/apps/logsrv_web/assets/css/app.css b/logsrv/apps/logsrv_web/assets/css/app.css new file mode 100644 index 0000000..19c2e51 --- /dev/null +++ b/logsrv/apps/logsrv_web/assets/css/app.css @@ -0,0 +1,120 @@ +/* This file is for your main application CSS */ +@import "./phoenix.css"; + +/* Alerts and form errors used by phx.new */ +.alert { + padding: 15px; + margin-bottom: 20px; + border: 1px solid transparent; + border-radius: 4px; +} +.alert-info { + color: #31708f; + background-color: #d9edf7; + border-color: #bce8f1; +} +.alert-warning { + color: #8a6d3b; + background-color: #fcf8e3; + border-color: #faebcc; +} +.alert-danger { + color: #a94442; + background-color: #f2dede; + border-color: #ebccd1; +} +.alert p { + margin-bottom: 0; +} +.alert:empty { + display: none; +} +.invalid-feedback { + color: #a94442; + display: block; + margin: -1rem 0 2rem; +} + +/* LiveView specific classes for your customization */ +.phx-no-feedback.invalid-feedback, +.phx-no-feedback .invalid-feedback { + display: none; +} + +.phx-click-loading { + opacity: 0.5; + transition: opacity 1s ease-out; +} + +.phx-loading{ + cursor: wait; +} + +.phx-modal { + opacity: 1!important; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.4); +} + +.phx-modal-content { + background-color: #fefefe; + margin: 15vh auto; + padding: 20px; + border: 1px solid #888; + width: 80%; +} + +.phx-modal-close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.phx-modal-close:hover, +.phx-modal-close:focus { + color: black; + text-decoration: none; + cursor: pointer; +} + +.fade-in-scale { + animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys; +} + +.fade-out-scale { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys; +} + +.fade-in { + animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys; +} +.fade-out { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys; +} + +@keyframes fade-in-scale-keys{ + 0% { scale: 0.95; opacity: 0; } + 100% { scale: 1.0; opacity: 1; } +} + +@keyframes fade-out-scale-keys{ + 0% { scale: 1.0; opacity: 1; } + 100% { scale: 0.95; opacity: 0; } +} + +@keyframes fade-in-keys{ + 0% { opacity: 0; } + 100% { opacity: 1; } +} + +@keyframes fade-out-keys{ + 0% { opacity: 1; } + 100% { opacity: 0; } +} diff --git a/logsrv/apps/logsrv_web/assets/css/phoenix.css b/logsrv/apps/logsrv_web/assets/css/phoenix.css new file mode 100644 index 0000000..0d59050 --- /dev/null +++ b/logsrv/apps/logsrv_web/assets/css/phoenix.css @@ -0,0 +1,101 @@ +/* Includes some default style for the starter application. + * This can be safely deleted to start fresh. + */ + +/* Milligram v1.4.1 https://milligram.github.io + * Copyright (c) 2020 CJ Patoilo Licensed under the MIT license + */ + +*,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;letter-spacing:.01em;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='color'],input[type='date'],input[type='datetime'],input[type='datetime-local'],input[type='email'],input[type='month'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],input[type='week'],input:not([type]),textarea,select{-webkit-appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem .7rem;width:100%}input[type='color']:focus,input[type='date']:focus,input[type='datetime']:focus,input[type='datetime-local']:focus,input[type='email']:focus,input[type='month']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,input[type='week']:focus,input:not([type]):focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}select[multiple]{background:none;height:auto}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.container{margin:0 auto;max-width:112.0rem;padding:0 2.0rem;position:relative;width:100%}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-40{margin-left:40%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-60{margin-left:60%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;display:block;overflow-x:auto;text-align:left;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}@media (min-width: 40rem){table{display:table;overflow-x:initial}}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right} + +/* General style */ +h1{font-size: 3.6rem; line-height: 1.25} +h2{font-size: 2.8rem; line-height: 1.3} +h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35} +h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5} +h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4} +h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2} +pre{padding: 1em;} + +.container{ + margin: 0 auto; + max-width: 80.0rem; + padding: 0 2.0rem; + position: relative; + width: 100% +} +select { + width: auto; +} + +/* Phoenix promo and logo */ +.phx-hero { + text-align: center; + border-bottom: 1px solid #e3e3e3; + background: #eee; + border-radius: 6px; + padding: 3em 3em 1em; + margin-bottom: 3rem; + font-weight: 200; + font-size: 120%; +} +.phx-hero input { + background: #ffffff; +} +.phx-logo { + min-width: 300px; + margin: 1rem; + display: block; +} +.phx-logo img { + width: auto; + display: block; +} + +/* Headers */ +header { + width: 100%; + background: #fdfdfd; + border-bottom: 1px solid #eaeaea; + margin-bottom: 2rem; +} +header section { + align-items: center; + display: flex; + flex-direction: column; + justify-content: space-between; +} +header section :first-child { + order: 2; +} +header section :last-child { + order: 1; +} +header nav ul, +header nav li { + margin: 0; + padding: 0; + display: block; + text-align: right; + white-space: nowrap; +} +header nav ul { + margin: 1rem; + margin-top: 0; +} +header nav a { + display: block; +} + +@media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */ + header section { + flex-direction: row; + } + header nav ul { + margin: 1rem; + } + .phx-logo { + flex-basis: 527px; + margin: 2rem 1rem; + } +} diff --git a/logsrv/apps/logsrv_web/assets/js/app.js b/logsrv/apps/logsrv_web/assets/js/app.js new file mode 100644 index 0000000..2ca06a5 --- /dev/null +++ b/logsrv/apps/logsrv_web/assets/js/app.js @@ -0,0 +1,45 @@ +// We import the CSS which is extracted to its own file by esbuild. +// Remove this line if you add a your own CSS build pipeline (e.g postcss). +import "../css/app.css" + +// If you want to use Phoenix channels, run `mix help phx.gen.channel` +// to get started and then uncomment the line below. +// import "./user_socket.js" + +// You can include dependencies in two ways. +// +// The simplest option is to put them in assets/vendor and +// import them using relative paths: +// +// import "../vendor/some-package.js" +// +// Alternatively, you can `npm install some-package --prefix assets` and import +// them using a path starting with the package name: +// +// import "some-package" +// + +// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. +import "phoenix_html" +// Establish Phoenix Socket and LiveView configuration. +import {Socket} from "phoenix" +import {LiveSocket} from "phoenix_live_view" +import topbar from "../vendor/topbar" + +let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) + +// Show progress bar on live navigation and form submits +topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) +window.addEventListener("phx:page-loading-start", info => topbar.show()) +window.addEventListener("phx:page-loading-stop", info => topbar.hide()) + +// connect if there are any LiveViews on the page +liveSocket.connect() + +// expose liveSocket on window for web console debug logs and latency simulation: +// >> liveSocket.enableDebug() +// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session +// >> liveSocket.disableLatencySim() +window.liveSocket = liveSocket + diff --git a/logsrv/apps/logsrv_web/assets/vendor/topbar.js b/logsrv/apps/logsrv_web/assets/vendor/topbar.js new file mode 100644 index 0000000..1f62209 --- /dev/null +++ b/logsrv/apps/logsrv_web/assets/vendor/topbar.js @@ -0,0 +1,157 @@ +/** + * @license MIT + * topbar 1.0.0, 2021-01-06 + * https://buunguyen.github.io/topbar + * Copyright (c) 2021 Buu Nguyen + */ +(function (window, document) { + "use strict"; + + // https://gist.github.com/paulirish/1579671 + (function () { + var lastTime = 0; + var vendors = ["ms", "moz", "webkit", "o"]; + for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = + window[vendors[x] + "RequestAnimationFrame"]; + window.cancelAnimationFrame = + window[vendors[x] + "CancelAnimationFrame"] || + window[vendors[x] + "CancelRequestAnimationFrame"]; + } + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function (callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function () { + callback(currTime + timeToCall); + }, timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function (id) { + clearTimeout(id); + }; + })(); + + var canvas, + progressTimerId, + fadeTimerId, + currentProgress, + showing, + addEvent = function (elem, type, handler) { + if (elem.addEventListener) elem.addEventListener(type, handler, false); + else if (elem.attachEvent) elem.attachEvent("on" + type, handler); + else elem["on" + type] = handler; + }, + options = { + autoRun: true, + barThickness: 3, + barColors: { + 0: "rgba(26, 188, 156, .9)", + ".25": "rgba(52, 152, 219, .9)", + ".50": "rgba(241, 196, 15, .9)", + ".75": "rgba(230, 126, 34, .9)", + "1.0": "rgba(211, 84, 0, .9)", + }, + shadowBlur: 10, + shadowColor: "rgba(0, 0, 0, .6)", + className: null, + }, + repaint = function () { + canvas.width = window.innerWidth; + canvas.height = options.barThickness * 5; // need space for shadow + + var ctx = canvas.getContext("2d"); + ctx.shadowBlur = options.shadowBlur; + ctx.shadowColor = options.shadowColor; + + var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0); + for (var stop in options.barColors) + lineGradient.addColorStop(stop, options.barColors[stop]); + ctx.lineWidth = options.barThickness; + ctx.beginPath(); + ctx.moveTo(0, options.barThickness / 2); + ctx.lineTo( + Math.ceil(currentProgress * canvas.width), + options.barThickness / 2 + ); + ctx.strokeStyle = lineGradient; + ctx.stroke(); + }, + createCanvas = function () { + canvas = document.createElement("canvas"); + var style = canvas.style; + style.position = "fixed"; + style.top = style.left = style.right = style.margin = style.padding = 0; + style.zIndex = 100001; + style.display = "none"; + if (options.className) canvas.classList.add(options.className); + document.body.appendChild(canvas); + addEvent(window, "resize", repaint); + }, + topbar = { + config: function (opts) { + for (var key in opts) + if (options.hasOwnProperty(key)) options[key] = opts[key]; + }, + show: function () { + if (showing) return; + showing = true; + if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId); + if (!canvas) createCanvas(); + canvas.style.opacity = 1; + canvas.style.display = "block"; + topbar.progress(0); + if (options.autoRun) { + (function loop() { + progressTimerId = window.requestAnimationFrame(loop); + topbar.progress( + "+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2) + ); + })(); + } + }, + progress: function (to) { + if (typeof to === "undefined") return currentProgress; + if (typeof to === "string") { + to = + (to.indexOf("+") >= 0 || to.indexOf("-") >= 0 + ? currentProgress + : 0) + parseFloat(to); + } + currentProgress = to > 1 ? 1 : to; + repaint(); + return currentProgress; + }, + hide: function () { + if (!showing) return; + showing = false; + if (progressTimerId != null) { + window.cancelAnimationFrame(progressTimerId); + progressTimerId = null; + } + (function loop() { + if (topbar.progress("+.1") >= 1) { + canvas.style.opacity -= 0.05; + if (canvas.style.opacity <= 0.05) { + canvas.style.display = "none"; + fadeTimerId = null; + return; + } + } + fadeTimerId = window.requestAnimationFrame(loop); + })(); + }, + }; + + if (typeof module === "object" && typeof module.exports === "object") { + module.exports = topbar; + } else if (typeof define === "function" && define.amd) { + define(function () { + return topbar; + }); + } else { + this.topbar = topbar; + } +}.call(this, window, document)); diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web.ex b/logsrv/apps/logsrv_web/lib/logsrv_web.ex new file mode 100644 index 0000000..5af3c2a --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web.ex @@ -0,0 +1,110 @@ +defmodule LogsrvWeb do + @moduledoc """ + The entrypoint for defining your web interface, such + as controllers, views, channels and so on. + + This can be used in your application as: + + use LogsrvWeb, :controller + use LogsrvWeb, :view + + The definitions below will be executed for every view, + controller, 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. + """ + + def controller do + quote do + use Phoenix.Controller, namespace: LogsrvWeb + + import Plug.Conn + import LogsrvWeb.Gettext + alias LogsrvWeb.Router.Helpers, as: Routes + end + end + + def view do + quote do + use Phoenix.View, + root: "lib/logsrv_web/templates", + namespace: LogsrvWeb + + # Import convenience functions from controllers + import Phoenix.Controller, + only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1] + + # Include shared imports and aliases for views + unquote(view_helpers()) + end + end + + def live_view do + quote do + use Phoenix.LiveView, + layout: {LogsrvWeb.LayoutView, "live.html"} + + unquote(view_helpers()) + end + end + + def live_component do + quote do + use Phoenix.LiveComponent + + unquote(view_helpers()) + end + end + + def component do + quote do + use Phoenix.Component + + unquote(view_helpers()) + end + end + + def router do + quote do + use Phoenix.Router + + import Plug.Conn + import Phoenix.Controller + import Phoenix.LiveView.Router + end + end + + def channel do + quote do + use Phoenix.Channel + import LogsrvWeb.Gettext + end + end + + defp view_helpers do + quote do + # Use all HTML functionality (forms, tags, etc) + use Phoenix.HTML + + # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) + import Phoenix.LiveView.Helpers + + # Import basic rendering functionality (render, render_layout, etc) + import Phoenix.View + + import LogsrvWeb.ErrorHelpers + import LogsrvWeb.Gettext + alias LogsrvWeb.Router.Helpers, as: Routes + end + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/application.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/application.ex new file mode 100644 index 0000000..e2976c0 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/application.ex @@ -0,0 +1,33 @@ +defmodule LogsrvWeb.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + # Start the Telemetry supervisor + LogsrvWeb.Telemetry, + # Start the Endpoint (http/https), + {Phoenix.PubSub, [name: LogsrvWeb.PubSub, adapter: Phoenix.PubSub.PG2]}, + LogsrvWeb.Endpoint + # Start a worker by calling: LogsrvWeb.Worker.start_link(arg) + # {LogsrvWeb.Worker, arg} + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: LogsrvWeb.Supervisor] + Supervisor.start_link(children, opts) + end + + # Tell Phoenix to update the endpoint configuration + # whenever the application is updated. + @impl true + def config_change(changed, _new, removed) do + LogsrvWeb.Endpoint.config_change(changed, removed) + :ok + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/controllers/post_controller.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/controllers/post_controller.ex new file mode 100644 index 0000000..ef61fcf --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/controllers/post_controller.ex @@ -0,0 +1,9 @@ +defmodule LogsrvWeb.PostController do + use LogsrvWeb, :controller + + def index(conn, _params) do + pages = LogsrvApi.pages() + journals = LogsrvApi.journals() + render(conn, "index.html", pages: pages, journals: journals) + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/endpoint.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/endpoint.ex new file mode 100644 index 0000000..73027a4 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/endpoint.ex @@ -0,0 +1,49 @@ +defmodule LogsrvWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :logsrv_web + + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_logsrv_web_key", + signing_salt: "7jqLz63m" + ] + + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] + + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :logsrv_web, + gzip: false, + only: ~w(assets fonts images favicon.ico robots.txt) + + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + end + + plug Phoenix.LiveDashboard.RequestLogger, + param_key: "request_logger", + cookie_key: "request_logger" + + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug LogsrvWeb.Router +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/gettext.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/gettext.ex new file mode 100644 index 0000000..75a3527 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/gettext.ex @@ -0,0 +1,24 @@ +defmodule LogsrvWeb.Gettext do + @moduledoc """ + A module providing Internationalization with a gettext-based API. + + By using [Gettext](https://hexdocs.pm/gettext), + your module gains a set of macros for translations, for example: + + import LogsrvWeb.Gettext + + # Simple translation + gettext("Here is the string to translate") + + # Plural translation + ngettext("Here is the string to translate", + "Here are the strings to translate", + 3) + + # Domain-based translation + dgettext("errors", "Here is the error message to translate") + + See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. + """ + use Gettext, otp_app: :logsrv_web +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/router.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/router.ex new file mode 100644 index 0000000..2d914a0 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/router.ex @@ -0,0 +1,56 @@ +defmodule LogsrvWeb.Router do + use LogsrvWeb, :router + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_live_flash + plug :put_root_layout, {LogsrvWeb.LayoutView, :root} + plug :protect_from_forgery + plug :put_secure_browser_headers + end + + pipeline :api do + plug :accepts, ["json"] + end + + scope "/", LogsrvWeb do + pipe_through :browser + + get "/", PostController, :index + end + + # Other scopes may use custom stacks. + scope "/api", LogsrvWeb do + pipe_through :api + end + + # Enables LiveDashboard only for development + # + # If you want to use the LiveDashboard in production, you should put + # it behind authentication and allow only admins to access it. + # If your application does not have an admins-only section yet, + # you can use Plug.BasicAuth to set up some basic authentication + # as long as you are also using SSL (which you should anyway). + if Mix.env() in [:dev, :test] do + import Phoenix.LiveDashboard.Router + + scope "/" do + pipe_through :browser + + live_dashboard "/dashboard", metrics: LogsrvWeb.Telemetry + end + end + + # Enables the Swoosh mailbox preview in development. + # + # Note that preview only shows emails that were sent by the same + # node running the Phoenix server. + if Mix.env() == :dev do + scope "/dev" do + pipe_through :browser + + forward "/mailbox", Plug.Swoosh.MailboxPreview + end + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/telemetry.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/telemetry.ex new file mode 100644 index 0000000..06c19cb --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/telemetry.ex @@ -0,0 +1,48 @@ +defmodule LogsrvWeb.Telemetry do + use Supervisor + import Telemetry.Metrics + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + @impl true + def init(_arg) do + children = [ + # Telemetry poller will execute the given period measurements + # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics + {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} + # Add reporters as children of your supervision tree. + # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} + ] + + Supervisor.init(children, strategy: :one_for_one) + end + + def metrics do + [ + # Phoenix Metrics + summary("phoenix.endpoint.stop.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.stop.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + + # VM Metrics + summary("vm.memory.total", unit: {:byte, :kilobyte}), + summary("vm.total_run_queue_lengths.total"), + summary("vm.total_run_queue_lengths.cpu"), + summary("vm.total_run_queue_lengths.io") + ] + end + + defp periodic_measurements do + [ + # A module, function and arguments to be invoked periodically. + # This function must call :telemetry.execute/3 and a metric must be added above. + # {LogsrvWeb, :count_users, []} + ] + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/app.html.heex b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/app.html.heex new file mode 100644 index 0000000..169aed9 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/app.html.heex @@ -0,0 +1,5 @@ +
+ + + <%= @inner_content %> +
diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/live.html.heex b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/live.html.heex new file mode 100644 index 0000000..a29d604 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/live.html.heex @@ -0,0 +1,11 @@ +
+ + + + + <%= @inner_content %> +
diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/root.html.heex b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/root.html.heex new file mode 100644 index 0000000..53b1d8f --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/layout/root.html.heex @@ -0,0 +1,20 @@ + + + + + + + + <%= live_title_tag assigns[:page_title] || "LogsrvWeb", suffix: " · Phoenix Framework" %> + + + + +
+
+ Logo +
+
+ <%= @inner_content %> + + diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/templates/post/index.html.heex b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/post/index.html.heex new file mode 100644 index 0000000..3670572 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/templates/post/index.html.heex @@ -0,0 +1,18 @@ +
+
+

Pages

+
    + <%= for page <- @pages do %> +
  • <%= page.title %> (<%= page.filename %>)
  • + <% end %> +
+
+
+

Journals

+
    + <%= for journal <- @journals do %> +
  • <%= journal.date %> (<%= journal.filename %>)
  • + <% end %> +
+
+
diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_helpers.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_helpers.ex new file mode 100644 index 0000000..77c051a --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_helpers.ex @@ -0,0 +1,47 @@ +defmodule LogsrvWeb.ErrorHelpers do + @moduledoc """ + Conveniences for translating and building error messages. + """ + + use Phoenix.HTML + + @doc """ + Generates tag for inlined form input errors. + """ + def error_tag(form, field) do + Enum.map(Keyword.get_values(form.errors, field), fn error -> + content_tag(:span, translate_error(error), + class: "invalid-feedback", + phx_feedback_for: input_name(form, field) + ) + end) + end + + @doc """ + Translates an error message using gettext. + """ + def translate_error({msg, opts}) do + # When using gettext, we typically pass the strings we want + # to translate as a static argument: + # + # # Translate "is invalid" in the "errors" domain + # dgettext("errors", "is invalid") + # + # # Translate the number of files with plural rules + # dngettext("errors", "1 file", "%{count} files", count) + # + # Because the error messages we show in our forms and APIs + # are defined inside Ecto, we need to translate them dynamically. + # This requires us to call the Gettext module passing our gettext + # backend as first argument. + # + # Note we use the "errors" domain, which means translations + # should be written to the errors.po file. The :count option is + # set by Ecto and indicates we should also apply plural rules. + if count = opts[:count] do + Gettext.dngettext(LogsrvWeb.Gettext, "errors", msg, msg, count, opts) + else + Gettext.dgettext(LogsrvWeb.Gettext, "errors", msg, opts) + end + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_view.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_view.ex new file mode 100644 index 0000000..587b194 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/views/error_view.ex @@ -0,0 +1,16 @@ +defmodule LogsrvWeb.ErrorView do + use LogsrvWeb, :view + + # If you want to customize a particular status code + # for a certain format, you may uncomment below. + # def render("500.html", _assigns) do + # "Internal Server Error" + # end + + # By default, Phoenix returns the status message from + # the template name. For example, "404.html" becomes + # "Not Found". + def template_not_found(template, _assigns) do + Phoenix.Controller.status_message_from_template(template) + end +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/views/layout_view.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/views/layout_view.ex new file mode 100644 index 0000000..7ffeb10 --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/views/layout_view.ex @@ -0,0 +1,7 @@ +defmodule LogsrvWeb.LayoutView do + use LogsrvWeb, :view + + # Phoenix LiveDashboard is available only in development by default, + # so we instruct Elixir to not warn if the dashboard route is missing. + @compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}} +end diff --git a/logsrv/apps/logsrv_web/lib/logsrv_web/views/post_view.ex b/logsrv/apps/logsrv_web/lib/logsrv_web/views/post_view.ex new file mode 100644 index 0000000..831c2af --- /dev/null +++ b/logsrv/apps/logsrv_web/lib/logsrv_web/views/post_view.ex @@ -0,0 +1,3 @@ +defmodule LogsrvWeb.PostView do + use LogsrvWeb, :view +end diff --git a/logsrv/apps/logsrv_web/mix.exs b/logsrv/apps/logsrv_web/mix.exs new file mode 100644 index 0000000..0217587 --- /dev/null +++ b/logsrv/apps/logsrv_web/mix.exs @@ -0,0 +1,65 @@ +defmodule LogsrvWeb.MixProject do + use Mix.Project + + def project do + [ + app: :logsrv_web, + version: "0.1.0", + build_path: "../../_build", + config_path: "../../config/config.exs", + deps_path: "../../deps", + lockfile: "../../mix.lock", + elixir: "~> 1.12", + elixirc_paths: elixirc_paths(Mix.env()), + compilers: Mix.compilers(), + start_permanent: Mix.env() == :prod, + aliases: aliases(), + deps: deps() + ] + end + + # Configuration for the OTP application. + # + # Type `mix help compile.app` for more information. + def application do + [ + mod: {LogsrvWeb.Application, []}, + extra_applications: [:logger, :runtime_tools] + ] + end + + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + + # Specifies your project dependencies. + # + # Type `mix help deps` for examples and options. + defp deps do + [ + {:phoenix, "~> 1.6.11"}, + {:phoenix_html, "~> 3.0"}, + {:phoenix_live_reload, "~> 1.2", only: :dev}, + {:phoenix_live_view, "~> 0.17.5"}, + {:floki, ">= 0.30.0", only: :test}, + {:phoenix_live_dashboard, "~> 0.6"}, + {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, + {:telemetry_metrics, "~> 0.6"}, + {:telemetry_poller, "~> 1.0"}, + {:gettext, "~> 0.18"}, + {:jason, "~> 1.2"}, + {:plug_cowboy, "~> 2.5"}, + {:logsrv_api, in_umbrella: true} + ] + end + + # Aliases are shortcuts or tasks specific to the current project. + # + # See the documentation for `Mix` for more info on aliases. + defp aliases do + [ + setup: ["deps.get"], + "assets.deploy": ["esbuild default --minify", "phx.digest"] + ] + end +end diff --git a/logsrv/apps/logsrv_web/priv/gettext/en/LC_MESSAGES/errors.po b/logsrv/apps/logsrv_web/priv/gettext/en/LC_MESSAGES/errors.po new file mode 100644 index 0000000..cdec3a1 --- /dev/null +++ b/logsrv/apps/logsrv_web/priv/gettext/en/LC_MESSAGES/errors.po @@ -0,0 +1,11 @@ +## `msgid`s in this file come from POT (.pot) files. +## +## Do not add, change, or remove `msgid`s manually here as +## they're tied to the ones in the corresponding POT file +## (with the same domain). +## +## Use `mix gettext.extract --merge` or `mix gettext.merge` +## to merge POT files into PO files. +msgid "" +msgstr "" +"Language: en\n" diff --git a/logsrv/apps/logsrv_web/priv/gettext/errors.pot b/logsrv/apps/logsrv_web/priv/gettext/errors.pot new file mode 100644 index 0000000..d6f47fa --- /dev/null +++ b/logsrv/apps/logsrv_web/priv/gettext/errors.pot @@ -0,0 +1,10 @@ +## This is a PO Template file. +## +## `msgid`s here are often extracted from source code. +## Add new translations manually only if they're dynamic +## translations that can't be statically extracted. +## +## Run `mix gettext.extract` to bring this file up to +## date. Leave `msgstr`s empty as changing them here has no +## effect: edit them in PO (`.po`) files instead. + diff --git a/logsrv/apps/logsrv_web/priv/static/favicon.ico b/logsrv/apps/logsrv_web/priv/static/favicon.ico new file mode 100644 index 0000000..0629e8d --- /dev/null +++ b/logsrv/apps/logsrv_web/priv/static/favicon.ico @@ -0,0 +1,107 @@ + +Logseq: A privacy-first, open-source knowledge base
Beta testingWhy logseq?

Connected thoughts to increase understanding

Logseq is a privacy-first, open-source knowledge base that works on top of local plain-text Markdown and Org-mode files. Use it to write, organize and share your thoughts, keep your to-do list, and build your own digital garden.

For Macs with Apple Silicon chips, click here to download

Apple App Store badge
Android App and real-time collaboration coming soon

Your data is yours, forever!

No data lock-in, no proprietary formats, you can edit the same Markdown/Org-mode file with any tools at the same time.

Connect your ideas like you do

Connect your [[ideas]] and [[thoughts]] with Logseq. Your knowledge graph grows just as your brain generates and connects neurons from new knowledge and ideas.

Task management made easy

Organize your tasks and projects with built-in workflow commands like NOW/LATER/DONE, A/B/C priorities and repeated Scheduled/Deadlines. Moreover, Logseq comes with powerful query system to help you get insights and build your own workflow.

Joyful learning experience!

PDF highlights, flashcards, and more...

PDF Highlights

Ready to dive in?

Join the discord group to chat with the makers and our helpful community members.

What People Are Saying

Awesome plugins from the community

100+ plugins, 30+ themes on Logseq marketplace

\ No newline at end of file diff --git a/logsrv/apps/logsrv_web/priv/static/images/logseq-logo.png b/logsrv/apps/logsrv_web/priv/static/images/logseq-logo.png new file mode 100644 index 0000000..a62dd26 Binary files /dev/null and b/logsrv/apps/logsrv_web/priv/static/images/logseq-logo.png differ diff --git a/logsrv/apps/logsrv_web/priv/static/images/phoenix.png b/logsrv/apps/logsrv_web/priv/static/images/phoenix.png new file mode 100644 index 0000000..9c81075 Binary files /dev/null and b/logsrv/apps/logsrv_web/priv/static/images/phoenix.png differ diff --git a/logsrv/apps/logsrv_web/priv/static/robots.txt b/logsrv/apps/logsrv_web/priv/static/robots.txt new file mode 100644 index 0000000..26e06b5 --- /dev/null +++ b/logsrv/apps/logsrv_web/priv/static/robots.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/logsrv/apps/logsrv_web/test/logsrv_web/controllers/page_controller_test.exs b/logsrv/apps/logsrv_web/test/logsrv_web/controllers/page_controller_test.exs new file mode 100644 index 0000000..dbf9be2 --- /dev/null +++ b/logsrv/apps/logsrv_web/test/logsrv_web/controllers/page_controller_test.exs @@ -0,0 +1,8 @@ +defmodule LogsrvWeb.PageControllerTest do + use LogsrvWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, "/") + assert html_response(conn, 200) =~ "Welcome to Phoenix!" + end +end diff --git a/logsrv/apps/logsrv_web/test/logsrv_web/views/error_view_test.exs b/logsrv/apps/logsrv_web/test/logsrv_web/views/error_view_test.exs new file mode 100644 index 0000000..eb7af11 --- /dev/null +++ b/logsrv/apps/logsrv_web/test/logsrv_web/views/error_view_test.exs @@ -0,0 +1,14 @@ +defmodule LogsrvWeb.ErrorViewTest do + use LogsrvWeb.ConnCase, async: true + + # Bring render/3 and render_to_string/3 for testing custom views + import Phoenix.View + + test "renders 404.html" do + assert render_to_string(LogsrvWeb.ErrorView, "404.html", []) == "Not Found" + end + + test "renders 500.html" do + assert render_to_string(LogsrvWeb.ErrorView, "500.html", []) == "Internal Server Error" + end +end diff --git a/logsrv/apps/logsrv_web/test/logsrv_web/views/layout_view_test.exs b/logsrv/apps/logsrv_web/test/logsrv_web/views/layout_view_test.exs new file mode 100644 index 0000000..a325762 --- /dev/null +++ b/logsrv/apps/logsrv_web/test/logsrv_web/views/layout_view_test.exs @@ -0,0 +1,8 @@ +defmodule LogsrvWeb.LayoutViewTest do + use LogsrvWeb.ConnCase, async: true + + # When testing helpers, you may want to import Phoenix.HTML and + # use functions such as safe_to_string() to convert the helper + # result into an HTML string. + # import Phoenix.HTML +end diff --git a/logsrv/apps/logsrv_web/test/logsrv_web/views/page_view_test.exs b/logsrv/apps/logsrv_web/test/logsrv_web/views/page_view_test.exs new file mode 100644 index 0000000..dcf5b7d --- /dev/null +++ b/logsrv/apps/logsrv_web/test/logsrv_web/views/page_view_test.exs @@ -0,0 +1,3 @@ +defmodule LogsrvWeb.PageViewTest do + use LogsrvWeb.ConnCase, async: true +end diff --git a/logsrv/apps/logsrv_web/test/support/conn_case.ex b/logsrv/apps/logsrv_web/test/support/conn_case.ex new file mode 100644 index 0000000..ac257b6 --- /dev/null +++ b/logsrv/apps/logsrv_web/test/support/conn_case.ex @@ -0,0 +1,37 @@ +defmodule LogsrvWeb.ConnCase do + @moduledoc """ + This module defines the test case to be used by + tests that require setting up a connection. + + Such tests rely on `Phoenix.ConnTest` and also + import other functionality to make it easier + to build common data structures and query the data layer. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use LogsrvWeb.ConnCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with connections + import Plug.Conn + import Phoenix.ConnTest + import LogsrvWeb.ConnCase + + alias LogsrvWeb.Router.Helpers, as: Routes + + # The default endpoint for testing + @endpoint LogsrvWeb.Endpoint + end + end + + setup _tags do + {:ok, conn: Phoenix.ConnTest.build_conn()} + end +end diff --git a/logsrv/apps/logsrv_web/test/test_helper.exs b/logsrv/apps/logsrv_web/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/logsrv/apps/logsrv_web/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/logsrv/config/config.exs b/logsrv/config/config.exs new file mode 100644 index 0000000..b0a3a71 --- /dev/null +++ b/logsrv/config/config.exs @@ -0,0 +1,33 @@ +import Config + +config :logsrv_web, + generators: [context_app: false] + +# Configures the endpoint +config :logsrv_web, LogsrvWeb.Endpoint, + url: [host: "localhost"], + render_errors: [view: LogsrvWeb.ErrorView, accepts: ~w(html json), layout: false], + pubsub_server: LogsrvWeb.PubSub, + live_view: [signing_salt: "7AiruzXN"] + +# Configure esbuild (the version is required) +config :esbuild, + version: "0.14.29", + default: [ + args: + ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + cd: Path.expand("../apps/logsrv_web/assets", __DIR__), + env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} + ] + +# Configures Elixir's Logger +config :logger, :console, + format: "$time $metadata[$level] $message\n", + metadata: [:request_id] + +# Use Jason for JSON parsing in Phoenix +config :phoenix, :json_library, Jason + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{config_env()}.exs" diff --git a/logsrv/config/dev.exs b/logsrv/config/dev.exs new file mode 100644 index 0000000..d3700e1 --- /dev/null +++ b/logsrv/config/dev.exs @@ -0,0 +1,57 @@ +import Config + +# For development, we disable any cache and enable +# debugging and code reloading. +# +# The watchers configuration can be used to run external +# watchers to your application. For example, we use it +# with esbuild to bundle .js and .css sources. +config :logsrv_web, LogsrvWeb.Endpoint, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {127, 0, 0, 1}, port: 4000], + check_origin: false, + code_reloader: true, + debug_errors: true, + secret_key_base: "bxXhC5hsomnTf4awI22UAMBAzMD1QNVTgEWvhmhqSDYjgB5eM21+M2ZB+CJJdp/D", + watchers: [ + # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) + esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]} + ] + +# ## SSL Support +# +# In order to use HTTPS in development, a self-signed +# certificate can be generated by running the following +# Mix task: +# +# mix phx.gen.cert +# +# Note that this task requires Erlang/OTP 20 or later. +# Run `mix help phx.gen.cert` for more information. +# +# The `http:` config above can be replaced with: +# +# https: [ +# port: 4001, +# cipher_suite: :strong, +# keyfile: "priv/cert/selfsigned_key.pem", +# certfile: "priv/cert/selfsigned.pem" +# ], +# +# If desired, both `http:` and `https:` keys can be +# configured to run both http and https servers on +# different ports. + +# Watch static and templates for browser reloading. +config :logsrv_web, LogsrvWeb.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/logsrv_web/(live|views)/.*(ex)$", + ~r"lib/logsrv_web/templates/.*(eex)$" + ] + ] + +config :logsrv_api, dir: "../../../Notes" diff --git a/logsrv/config/prod.exs b/logsrv/config/prod.exs new file mode 100644 index 0000000..5a40bff --- /dev/null +++ b/logsrv/config/prod.exs @@ -0,0 +1,48 @@ +import Config + +# For production, don't forget to configure the url host +# to something meaningful, Phoenix uses this information +# when generating URLs. +# +# Note we also include the path to a cache manifest +# containing the digested version of static files. This +# manifest is generated by the `mix phx.digest` task, +# which you should run after static files are built and +# before starting your production server. +config :logsrv_web, LogsrvWeb.Endpoint, + url: [host: "example.com", port: 80], + cache_static_manifest: "priv/static/cache_manifest.json" + +# ## SSL Support +# +# To get SSL working, you will need to add the `https` key +# to the previous section and set your `:url` port to 443: +# +# config :logsrv_web, LogsrvWeb.Endpoint, +# ..., +# url: [host: "example.com", port: 443], +# https: [ +# ..., +# port: 443, +# cipher_suite: :strong, +# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), +# certfile: System.get_env("SOME_APP_SSL_CERT_PATH") +# ] +# +# The `cipher_suite` is set to `:strong` to support only the +# latest and more secure SSL ciphers. This means old browsers +# and clients may not be supported. You can set it to +# `:compatible` for wider support. +# +# `:keyfile` and `:certfile` expect an absolute path to the key +# and cert in disk or a relative path inside priv, for example +# "priv/ssl/server.key". For all supported SSL configuration +# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 +# +# We also recommend setting `force_ssl` in your endpoint, ensuring +# no data is ever sent via http, always redirecting to https: +# +# config :logsrv_web, LogsrvWeb.Endpoint, +# force_ssl: [hsts: true] +# +# Check `Plug.SSL` for all available options in `force_ssl`. diff --git a/logsrv/config/runtime.exs b/logsrv/config/runtime.exs new file mode 100644 index 0000000..7c4e711 --- /dev/null +++ b/logsrv/config/runtime.exs @@ -0,0 +1,52 @@ +import Config + +if config_env() == :prod do + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ + + config :logsrv_web, LogsrvWeb.Endpoint, + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: String.to_integer(System.get_env("PORT") || "4000") + ], + secret_key_base: secret_key_base + + # ## Using releases + # + # If you are doing OTP releases, you need to instruct Phoenix + # to start each relevant endpoint: + # + # config :logsrv_web, LogsrvWeb.Endpoint, server: true + # + # Then you can assemble a release by calling `mix release`. + # See `mix help release` for more information. + + # ## Configuring the mailer + # + # In production you need to configure the mailer to use a different adapter. + # Also, you may need to configure the Swoosh API client of your choice if you + # are not using SMTP. Here is an example of the configuration: + # + # config :logsrv_web, LogsrvWeb.Mailer, + # adapter: Swoosh.Adapters.Mailgun, + # api_key: System.get_env("MAILGUN_API_KEY"), + # domain: System.get_env("MAILGUN_DOMAIN") + # + # For this example you need include a HTTP client required by Swoosh API client. + # Swoosh supports Hackney and Finch out of the box: + # + # config :swoosh, :api_client, Swoosh.ApiClient.Hackney + # + # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. +end diff --git a/logsrv/config/test.exs b/logsrv/config/test.exs new file mode 100644 index 0000000..8181bb3 --- /dev/null +++ b/logsrv/config/test.exs @@ -0,0 +1,8 @@ +import Config + +# We don't run a server during test. If one is required, +# you can enable the server option below. +config :logsrv_web, LogsrvWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], + secret_key_base: "/UzE9V6eMLrRbpiELmK3L99kEPgZBAQms9nzG8+Pyc/uiCzzrFMDcCtr/wNRh4XO", + server: false diff --git a/logsrv/mix.exs b/logsrv/mix.exs new file mode 100644 index 0000000..839f40b --- /dev/null +++ b/logsrv/mix.exs @@ -0,0 +1,21 @@ +defmodule Logsrv.MixProject do + use Mix.Project + + def project do + [ + apps_path: "apps", + version: "0.1.0", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Dependencies listed here are available only for this + # project and cannot be accessed from applications inside + # the apps folder. + # + # Run "mix help deps" for examples and options. + defp deps do + [] + end +end diff --git a/logsrv/mix.lock b/logsrv/mix.lock new file mode 100644 index 0000000..3e27a8d --- /dev/null +++ b/logsrv/mix.lock @@ -0,0 +1,27 @@ +%{ + "castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"}, + "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, + "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, + "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "floki": {:hex, :floki, "0.33.1", "f20f1eb471e726342b45ccb68edb9486729e7df94da403936ea94a794f072781", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "461035fd125f13fdf30f243c85a0b1e50afbec876cbf1ceefe6fddd2e6d712c6"}, + "gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"}, + "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, + "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, + "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, + "phoenix": {:hex, :phoenix, "1.6.11", "29f3c0fd12fa1fc4d4b05e341578e55bc78d96ea83a022587a7e276884d397e4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1664e34f80c25ea4918fbadd957f491225ef601c0e00b4e644b1a772864bfbc2"}, + "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, + "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.11", "205f6aa5405648c76f2abcd57716f42fc07d8f21dd8ea7b262dd12b324b50c95", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7177791944b7f90ed18f5935a6a5f07f760b36f7b3bdfb9d28c57440a3c43f99"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, + "phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"}, + "plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"}, + "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"}, + "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, + "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, +} diff --git a/logsrv_api/config/config.exs b/logsrv_api/config/config.exs deleted file mode 100644 index 93dd3a0..0000000 --- a/logsrv_api/config/config.exs +++ /dev/null @@ -1,7 +0,0 @@ -import Config - -config :elixir, :time_zone_database, Tz.TimeZoneDatabase - -# Import environment specific config. This must remain at the bottom -# of this file so it overrides the configuration defined above. -import_config "#{config_env()}.env.exs" diff --git a/logsrv_api/config/dev.env.exs b/logsrv_api/config/dev.env.exs deleted file mode 100644 index 26314aa..0000000 --- a/logsrv_api/config/dev.env.exs +++ /dev/null @@ -1,4 +0,0 @@ -import Config - -config :logsrv, port: 8080 -config :logsrv, dir: "../Notes" diff --git a/logsrv_api/config/prod.env.exs b/logsrv_api/config/prod.env.exs deleted file mode 100644 index 6252867..0000000 --- a/logsrv_api/config/prod.env.exs +++ /dev/null @@ -1,3 +0,0 @@ -import Config - -config :logsrv, port: 12545 diff --git a/logsrv_api/config/test.env.exs b/logsrv_api/config/test.env.exs deleted file mode 100644 index eae5753..0000000 --- a/logsrv_api/config/test.env.exs +++ /dev/null @@ -1,3 +0,0 @@ -import Config - -config :logsrv, port: 8081 diff --git a/logsrv_api/lib/logsrv.ex b/logsrv_api/lib/logsrv.ex deleted file mode 100644 index 4b00157..0000000 --- a/logsrv_api/lib/logsrv.ex +++ /dev/null @@ -1,115 +0,0 @@ -defmodule Logsrv do - @moduledoc """ - Documentation for `Logsrv`. - """ - def hello do - :world - end - - def dir do - Application.get_env(:logsrv, :dir) <> "/" - end - - def dir(subdir) do - "#{dir()}/#{subdir}/" - end - - def journals do - dir(:journals) - |> File.ls! - end - - def get(fd) do - if fd |> File.exists? do - {:ok, fd} - else - {:error, :enoent} - end - end - - def page(title) do - fd = dir(:pages) <> title <> ".md" - get fd - end - - def journal(date) do - fd = dir(:journals) <> date <> ".md" - get fd - end - - def pages do - dir(:pages) - |> File.ls! - end - - def compare(fd) do - sync_conflict_fd = fd - orig_fd = fd - |> String.replace(~r/\.sync.*/,"\.md") - - sync_conflict = sync_conflict_fd |> File.read! - orig = orig_fd |> File.read! - - # FOR NOW, just return the diff - diff = orig - |> String.myers_difference(sync_conflict) - - diff - |> Kernel.inspect() - |> Jason.encode! - - end - - def conflicts do - {conflicts(journals()), conflicts(pages())} - end - - def conflicts! do - [conflicts(journals()), conflicts(pages())] - |> List.flatten() - end - - - def conflicts(list) do - list - |> Enum.filter( fn (fd) -> - fd |> String.match?(~r/.*sync.*/) - end) - end - - def resolve_conflicts do - {journal_conflicts, pages_conflicts} = conflicts() - - [ - journal_conflicts - |> Enum.map( fn(fd) -> - %{ - :type => :journal, - :date => fd |> Logsrv.Helpers.to_date!, - :file => fd, - :diff => compare(dir(:journals) <> fd), - } - end), - - pages_conflicts - |> Enum.map( fn(fd) -> - %{ - :type => :page, - :file => fd, - :diff => compare(dir(:pages) <> fd), - } end) - ] - |> List.flatten() - - end - - def add_thought(:journals, data) do - journal_date = data.date - date_formatted = journal_date - |> Calendar.strftime("%Y_%m_%d") - content = data.content - - {:ok, date_formatted} - end - -end diff --git a/logsrv_api/lib/logsrv/application.ex b/logsrv_api/lib/logsrv/application.ex deleted file mode 100644 index 8a9a428..0000000 --- a/logsrv_api/lib/logsrv/application.ex +++ /dev/null @@ -1,29 +0,0 @@ -defmodule Logsrv.Application do - # See https://hexdocs.pm/elixir/Application.html - # for more information on OTP Applications - @moduledoc false - - use Application - - @impl true - def start(_type, _args) do - children = [ - # Starts a worker by calling: Logsrv.Worker.start_link(arg) - # {Logsrv.Worker, arg} - { - Plug.Cowboy, - scheme: :http, - plug: Logsrv.Router, - options: - [ - port: Application.get_env(:logsrv, :port) - ] - } - ] - - # See https://hexdocs.pm/elixir/Supervisor.html - # for other strategies and supported options - opts = [strategy: :one_for_one, name: Logsrv.Supervisor] - Supervisor.start_link(children, opts) - end -end diff --git a/logsrv_api/lib/logsrv/helpers.ex b/logsrv_api/lib/logsrv/helpers.ex deleted file mode 100644 index c8adf66..0000000 --- a/logsrv_api/lib/logsrv/helpers.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule Logsrv.Helpers do - - def moot do - "moo" - end - - def to_date(str) do - str - |> String.replace(~r/\..*/,"") - |> String.replace("_","-") - |> Date.from_iso8601() - end - def to_date!(str) do - str - |> String.replace(~r/\..*/,"") - |> String.replace("_","-") - |> Date.from_iso8601!() - end - -end diff --git a/logsrv_api/lib/logsrv/router.ex b/logsrv_api/lib/logsrv/router.ex deleted file mode 100644 index ad67c33..0000000 --- a/logsrv_api/lib/logsrv/router.ex +++ /dev/null @@ -1,105 +0,0 @@ -defmodule Logsrv.Router do - # Bring Plug.Router module into scope - use Plug.Router - - # Attach the Logger to log incoming requests - plug(Plug.Logger) - - # Tell Plug to match the incoming request with the defined endpoints - plug(:match) - - # Once there is a match, parse the response body if the content-type - # is application/json. The order is important here, as we only want to - # parse the body if there is a matching route.(Using the Jayson parser) - plug(Plug.Parsers, - parsers: [:json], - pass: ["application/json"], - json_decoder: Jason - ) - - # Dispatch the connection to the matched handler - plug(:dispatch) - - # Handler for GET request with "/" path - get "/" do - - send_resp(conn, 200, "OK") - - end - - # Handler for GET request to "/status" - get "/status" do - - most_recent = Logsrv.journals - |> Enum.sort - |> List.last - |> Logsrv.Helpers.to_date! - - conflicts = Logsrv.conflicts! |> length - - status = case conflicts do - 0 -> - :ok - _ -> - :conflict - end - - summary = %{ - :status => status, - :journals => Logsrv.journals |> length, - :pages => Logsrv.pages|> length, - :most_recent => most_recent, - :conflicts => conflicts - } - |> Jason.encode! - - conn - |> put_resp_content_type("application/json") - |> send_resp(200, summary) - end - - get "/journals.json" do - journals = - Logsrv.journals - |> Enum.sort - |> Jason.encode!() # Encode the list to a JSON string - - conn - |> put_resp_content_type("application/json") - |> send_resp(200, journals) # Send a 200 OK response with the posts in the body - end - - get "/journals/:date" do - date = conn.params["date"] - - journal = Logsrv.journal(date) |> File.read - - conn - |> put_resp_content_type("application/json") - |> send_resp(200, journal) # Send a 200 OK response with the posts in the body - end - - get "/pages" do - pages = - Logsrv.pages - |> Jason.encode!() # Encode the list to a JSON string - - conn - |> put_resp_content_type("application/json") - |> send_resp(200, pages) # Send a 200 OK response with the posts in the body - end - - get "/conflicts" do - conflicts = Logsrv.resolve_conflicts - |> Jason.encode! - - conn - |> put_resp_content_type("application/json") - |> send_resp(200, conflicts) # Send a 200 OK response with the conflicts - end - - # Fallback handler when there was no match - match _ do - send_resp(conn, 404, "Not Found") - end -end diff --git a/logsrv_api/mix.lock b/logsrv_api/mix.lock deleted file mode 100644 index 9d8fb94..0000000 --- a/logsrv_api/mix.lock +++ /dev/null @@ -1,13 +0,0 @@ -%{ - "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, - "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, - "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, - "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, - "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, - "plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"}, - "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, - "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"}, - "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, - "telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"}, - "tz": {:hex, :tz, "0.21.1", "9aad76e2ae54aead5c6b3fbd3cc7c062c2cccfff63fd4945dd81768b55d22889", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:mint, "~> 1.4", [hex: :mint, repo: "hexpm", optional: true]}], "hexpm", "42caf2056655577d5247d46d4572f193707bd08200d50eac0de5d686b3232b5f"}, -} diff --git a/logsrv_api/test/logsrv_test.exs b/logsrv_api/test/logsrv_test.exs deleted file mode 100644 index 58126a9..0000000 --- a/logsrv_api/test/logsrv_test.exs +++ /dev/null @@ -1,45 +0,0 @@ -defmodule LogsrvTest do - use ExUnit.Case - doctest Logsrv - - test "greets the world" do - assert Logsrv.hello() == :world - end -end - -defmodule LogsrvTest.Router do - # Bringing ExUnit's case module to scope and configure it to run - # tests in this module concurrently with tests in other modules - # https://hexdocs.pm/ex_unit/ExUnit.Case.html - use ExUnit.Case, async: true - - # This makes the conn object avaiable in the scope of the tests, - # which can be used to make the HTTP request - # https://hexdocs.pm/plug/Plug.Test.html - use Plug.Test - - # We call the Plug init/1 function with the options then store - # returned options in a Module attribute opts. - # Note: @ is module attribute unary operator - # https://hexdocs.pm/elixir/main/Kernel.html#@/1 - # https://hexdocs.pm/plug/Plug.html#c:init/1 - @opts Logsrv.Router.init([]) - - - # Create a test with the name "return ok" - test "return ok" do - # Build a connection which is GET request on / url - conn = conn(:get, "/") - - # Then call Plug.call/2 with the connection and options - # https://hexdocs.pm/plug/Plug.html#c:call/2 - conn = Logsrv.Router.call(conn, @opts) - - # Finally we are using the assert/2 function to check for the - # correctness of the response - # https://hexdocs.pm/ex_unit/ExUnit.Assertions.html#assert/2 - assert conn.state == :sent - assert conn.status == 200 - assert conn.resp_body == "OK" - end -end