Skip to content

Commit

Permalink
Merge branch 'master' of github.com:EyraCo/eylixir
Browse files Browse the repository at this point in the history
  • Loading branch information
vloothuis committed Aug 27, 2021
2 parents b2566b6 + 26934e2 commit 43b585a
Show file tree
Hide file tree
Showing 55 changed files with 966 additions and 181 deletions.
13 changes: 11 additions & 2 deletions core/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { decode } from "blurhash";
import { urlBase64ToUint8Array } from "./tools";
import { registerAPNSDeviceToken } from "./apns";
import "./100vh-fix";
import { ViewportResize } from "./viewport_resize"

window.registerAPNSDeviceToken = registerAPNSDeviceToken;

Expand Down Expand Up @@ -65,10 +66,12 @@ window.blurHash = () => {
let csrfToken = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");
let Hooks = {};

let Hooks = { ViewportResize };

Hooks.NativeWrapper = {
mounted() {
console.log("NativeWrapper mounted")
window.nativeWrapperHook = this
},
toggleSidePanel() {
Expand All @@ -83,6 +86,8 @@ Hooks.PythonUploader = {
this.worker && this.worker.terminate();
},
mounted(){
console.log("PythonUploader mounted")

this.worker = new Worker("/js/pyworker.js");
this.worker.onerror = console.log;
this.worker.onmessage = (event) => {
Expand Down Expand Up @@ -149,7 +154,11 @@ let liveSocket = new LiveSocket('/live', Socket, {
}
},
params: {
_csrf_token: csrfToken
_csrf_token: csrfToken,
viewport: {
width: window.innerWidth,
height: window.innerHeight
}
},
hooks: Hooks
})
Expand Down
28 changes: 28 additions & 0 deletions core/assets/js/viewport_resize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import _ from 'lodash'

let resizeHandler

export const ViewportResize = {

mounted () {
// Direct push of current window size to properly update view
this.pushResizeEvent()

resizeHandler = _.debounce(() => {
this.pushResizeEvent()
}, 100)
window.addEventListener('resize', resizeHandler)
},

pushResizeEvent () {
console.log("pushResizeEvent")
this.pushEvent('viewport_resize', {
width: window.innerWidth,
height: window.innerHeight
})
},

turbolinksDisconnected () {
window.removeEventListener('resize', resizeHandler)
}
}
20 changes: 13 additions & 7 deletions core/assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ module.exports = {
"sheet": "760px",
"form" : "400px",
"card": "376px",
"image-preview": "200px",
"image-preview-circle": "150px",
"popup-md": "730px",
"popup-lg": "1228px",
"image-preview": "120px",
"image-preview-sm": "200px",
"image-preview-circle": "120px",
"image-preview-circle-sm": "150px",
"button-sm": "14px",
},
height: {
Expand All @@ -103,8 +103,10 @@ module.exports = {
"image-header": "375px",
"image-header-sm": "500px",
"image-card": "200px",
"image-preview": "150px",
"image-preview-circle": "150px",
"image-preview": "90px",
"image-preview-sm": "150px",
"image-preview-circle": "120px",
"image-preview-circle-sm": "150px",
"campaign-banner": "224px",
"button-sm": "14px",
},
Expand Down Expand Up @@ -153,7 +155,11 @@ module.exports = {
maxWidth: {
"card": "376px",
"form": "400px",
"sheet": "760px"
"sheet": "760px",
"popup": "480px",
"popup-sm": "520px",
"popup-md": "730px",
"popup-lg": "1228px"
},
maxHeight: {
"header1": "376px",
Expand Down
6 changes: 5 additions & 1 deletion core/bundles/link/lib/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ defmodule Link.Index do
<Intro>
{{ dgettext("eyra-link", "link.message") }}
</Intro>
<Intro>
{{ dgettext("eyra-link", "link.message.interested") }}
<a href="mailto:[email protected]" class="text-primary" >[email protected]</a>.
</Intro>
</div>
<div>
<div :if={{ @current_user != nil }}>
<PrimaryCTA
title={{ cta_title(@current_user) }}
button_label={{ dgettext("eyra-link", "dashboard-button") }}
button_label={{ if @current_user.researcher do dgettext("eyra-link", "dashboard-button") else dgettext("eyra-link", "marketplace-button") end }}
to={{ Routes.live_path(@socket, CoreWeb.Dashboard)}} />
</div>
<div :if={{ @current_user == nil }}>
Expand Down
8 changes: 6 additions & 2 deletions core/bundles/link/lib/layouts/workspace/menu_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ defmodule Link.Layouts.Workspace.MenuBuilder do

[]
|> append(live_item(socket, :dashboard, active_item), can_access?(user_state, Link.Dashboard))
|> append(live_item(socket, :surveys, active_item), can_access?(user_state, CoreWeb.Study.New))
|> append(
live_item(socket, :surveys, active_item),
can_access?(user_state, CoreWeb.Study.New)
)
|> append(live_item(socket, :studentpool, active_item), user_state.coordinator)
|> append(live_item(socket, :marketplace, active_item))
|> append(live_item(socket, :todo, active_item, true, next_action_count))
Expand All @@ -48,9 +51,10 @@ defmodule Link.Layouts.Workspace.MenuBuilder do
defp build_menu_second_part(socket, active_item, page_id) do
[
language_switch_item(socket, page_id),
live_item(socket, :support, active_item),
live_item(socket, :settings, active_item),
live_item(socket, :profile, active_item),
user_session_item(socket, :signout, active_item),
user_session_item(socket, :signout, active_item)
]
|> append(live_item(socket, :debug, active_item), feature_enabled?(:debug))
end
Expand Down
21 changes: 17 additions & 4 deletions core/bundles/link/lib/survey/web/content.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Link.Survey.Content do
use CoreWeb, :live_view
use CoreWeb.MultiFormAutoSave
use CoreWeb.Layouts.Workspace.Component, :survey
use Coreweb.UI.ViewportHelpers

import CoreWeb.Gettext

Expand All @@ -30,7 +31,6 @@ defmodule Link.Survey.Content do
data(initial_image_query, :any)
data(uri_origin, :any)


@impl true
def get_authorization_context(%{"id" => id}, _session, _socket) do
Tools.get_survey_tool!(id)
Expand All @@ -55,6 +55,8 @@ defmodule Link.Survey.Content do
hide_flash_timer: nil
)
|> update_menus()
|> assign_viewport()
|> assign_breakpoint()
}
end

Expand Down Expand Up @@ -171,18 +173,29 @@ defmodule Link.Survey.Content do
{:noreply, socket}
end

defp marginX(:mobile), do: "mx-6"
defp marginX(_), do: "mx-10"

def render(assigns) do
~H"""
<Workspace
title={{ dgettext("link-survey", "content.title") }}
menus={{ @menus }}
>
<div phx-click="reset_focus">
<div id={{ :survey_content }} phx-hook="ViewportResize" phx-click="reset_focus">
<div x-data="{ open: false }">
<div class="fixed z-20 left-0 top-0 w-full h-full" x-show="open">
<div class="flex flex-row items-center justify-center w-full h-full">
<div class="w-5/6 md:w-popup-md lg:w-popup-lg" @click.away="open = false, $parent.$parent.overlay = false">
<ImageCatalogPicker conn={{@socket}} static_path={{&Routes.static_path/2}} initial_query={{initial_image_query(assigns)}} id={{:image_picker}} image_catalog={{Core.ImageCatalog.Unsplash}} />
<div class="{{marginX(@breakpoint)}} w-full max-w-popup sm:max-w-popup-sm md:max-w-popup-md lg:max-w-popup-lg" @click.away="open = false, $parent.$parent.overlay = false">
<ImageCatalogPicker
id={{:image_picker}}
conn={{@socket}}
viewport={{@viewport}}
breakpoint={{@breakpoint}}
static_path={{&Routes.static_path/2}}
initial_query={{initial_image_query(assigns)}}
image_catalog={{Core.ImageCatalog.Unsplash}}
/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion core/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ config :core, SignInWithApple,
config :core, GoogleSignIn,
client_id: "1027619588178-ckkft8qhcj2jev6bsonbuqghe6pn6isf.apps.googleusercontent.com",
client_secret: "C-x02CCKC29o4OttKzhi0hE8",
redirect_uri: "http://74aa-2a02-a443-cab9-1-589c-bd8a-c01b-f0e1.ngrok.io/google-sign-in/auth"
redirect_uri: "http://localhost:4000/google-sign-in/auth"

config :core, Core.ImageCatalog.Unsplash,
access_key: "",
Expand Down
4 changes: 3 additions & 1 deletion core/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ config :core,
try do
import_config "dev.secret.exs"
rescue
_ -> IO.puts("Continueing without `dev.secret.exs` file..")
File.Error ->
# Continuing without `dev.secret.exs` file...
nil
end
2 changes: 2 additions & 0 deletions core/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ if config_env() == :prod do
https: [port: String.to_integer(System.get_env("HTTPS_PORT", "443"))]

if https_keyfile = System.get_env("HTTPS_KEYFILE") do
config :core, :ssl, mode: :manual

config :core, CoreWeb.Endpoint,
https: [
cipher_suite: :strong,
Expand Down
6 changes: 5 additions & 1 deletion core/lib/core/admin.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
defmodule Core.Admin do
def emails do
Application.get_env(:core, :admins, MapSet.new())
end

def admin?(email) when is_nil(email), do: false

def admin?(email) when is_binary(email) do
Application.get_env(:core, :admins, MapSet.new()) |> MapSet.member?(email)
MapSet.member?(emails(), email)
end

def admin?(%{email: email}) do
Expand Down
2 changes: 2 additions & 0 deletions core/lib/core/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ defmodule Core.Authorization do

grant_access(CoreWeb.Admin.Login, [:visitor, :member])
grant_access(CoreWeb.Admin.CoordinatorManagement, [:admin])
grant_access(CoreWeb.Admin.SupportTickets, [:admin])
grant_access(CoreWeb.Index, [:visitor, :member])
grant_access(CoreWeb.Support, [:member])
grant_access(CoreWeb.Dashboard, [:researcher])
grant_access(CoreWeb.Marketplace, [:member])
grant_access(CoreWeb.Todo, [:member])
Expand Down
16 changes: 15 additions & 1 deletion core/lib/core/factories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Core.Factories do
Authorization,
DataDonation,
NotificationCenter,
WebPush
WebPush,
Helpdesk
}

alias Core.Repo
Expand All @@ -40,6 +41,11 @@ defmodule Core.Factories do
})
end

def build(:admin) do
:member
|> build(%{email: Core.Admin.emails() |> Enum.random()})
end

def build(:student) do
:member
|> build(%{student: true})
Expand Down Expand Up @@ -72,6 +78,14 @@ defmodule Core.Factories do
}
end

def build(:helpdesk_ticket) do
%Helpdesk.Ticket{
title: Faker.Lorem.sentence(),
description: Faker.Lorem.paragraph(),
user: build(:member)
}
end

def build(:author) do
%Studies.Author{
fullname: Faker.Person.name(),
Expand Down
35 changes: 35 additions & 0 deletions core/lib/core/helpdesk.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Core.Helpdesk do
@moduledoc """
The Helpdesk context.
"""

import Ecto.Query, warn: false
alias Core.Repo

alias Core.Helpdesk.Ticket

def list_open_tickets do
from(t in Ticket,
where: is_nil(t.completed_at),
order_by: {:asc, :inserted_at},
preload: :user
)
|> Repo.all()
end

def close_ticket_by_id(id) do
from(t in Ticket, where: t.id == ^id)
|> Repo.update_all(set: [completed_at: DateTime.utc_now()])
end

def create_ticket(user, attrs \\ %{}) do
%Ticket{}
|> Ticket.changeset(attrs)
|> Ecto.Changeset.put_assoc(:user, user)
|> Repo.insert()
end

def new_ticket_changeset(attrs \\ %{}) do
Ticket.changeset(%Ticket{}, attrs)
end
end
21 changes: 21 additions & 0 deletions core/lib/core/helpdesk/ticket.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Core.Helpdesk.Ticket do
use Ecto.Schema
import Ecto.Changeset
alias Core.Accounts.User

schema "helpdesk_tickets" do
belongs_to(:user, User)
field(:description, :string)
field(:title, :string)
field(:completed_at, :utc_datetime)

timestamps()
end

@doc false
def changeset(ticket, attrs) do
ticket
|> cast(attrs, [:title, :description, :completed_at])
|> validate_required([:title, :description])
end
end
7 changes: 3 additions & 4 deletions core/lib/core_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ defmodule CoreWeb.Endpoint do

@impl Phoenix.Endpoint
def init(_key, config) do
if Application.get_env(:core, __MODULE__) |> Keyword.get(:certfile) do
# Disable let's encrypt
{:ok, put_in(config, [:https, :mode], :manual)}
if Application.get_env(:core, __MODULE__) |> get_in([:https, :certfile]) do
{:ok, config}
else
{:ok, SiteEncrypt.Phoenix.configure_https(config, mode: :manual) |> IO.inspect()}
{:ok, SiteEncrypt.Phoenix.configure_https(config)}
end
end

Expand Down
Loading

0 comments on commit 43b585a

Please sign in to comment.