From 9ac42bb3db1a6c8cb58a6ef34f4a7aba038cd6f5 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 1 Jun 2021 16:14:24 +0200 Subject: [PATCH] Convert all views to svelte --- src/assets/ts/WebsocketClient.ts | 37 +++++++ .../views/auth/account/NamePanel.svelte | 27 +++++ .../views/auth/account/PasswordPanel.svelte | 30 ++++++ src/assets/views/auth/account/account.njk | 98 ----------------- src/assets/views/auth/account/account.svelte | 98 +++++++++++++++++ src/assets/views/auth/account/name_panel.njk | 16 --- .../views/auth/account/password_panel.njk | 45 -------- src/assets/views/auth/auth.svelte | 68 ++++++++++++ .../views/backend/accounts_approval.njk | 63 ----------- .../views/backend/accounts_approval.svelte | 69 ++++++++++++ src/assets/views/backend/index.njk | 28 ----- src/assets/views/backend/index.svelte | 32 ++++++ src/assets/views/components/Breadcrumb.svelte | 13 +++ .../views/components/FlashMessages.svelte | 17 +++ src/assets/views/components/Message.svelte | 17 +++ .../views/components/NavMenuItem.svelte | 23 ++++ src/assets/views/components/Pagination.svelte | 46 ++++++++ src/assets/views/home.svelte | 10 ++ src/assets/views/layouts/BaseLayout.svelte | 78 ++++++++++++++ src/assets/views/layouts/barebone.njk | 37 ------- src/assets/views/magic_link.njk | 18 ---- src/assets/views/magic_link.svelte | 21 ++++ src/assets/views/magic_link_lobby.svelte | 51 +++++++++ src/assets/views/utils/CsrfTokenField.svelte | 7 ++ src/assets/views/utils/Field.svelte | 101 ++++++++++++++++++ src/assets/views/utils/Form.svelte | 39 +++++++ src/assets/views/utils/Icon.svelte | 11 ++ 27 files changed, 795 insertions(+), 305 deletions(-) create mode 100644 src/assets/ts/WebsocketClient.ts create mode 100644 src/assets/views/auth/account/NamePanel.svelte create mode 100644 src/assets/views/auth/account/PasswordPanel.svelte delete mode 100644 src/assets/views/auth/account/account.njk create mode 100644 src/assets/views/auth/account/account.svelte delete mode 100644 src/assets/views/auth/account/name_panel.njk delete mode 100644 src/assets/views/auth/account/password_panel.njk create mode 100644 src/assets/views/auth/auth.svelte delete mode 100644 src/assets/views/backend/accounts_approval.njk create mode 100644 src/assets/views/backend/accounts_approval.svelte delete mode 100644 src/assets/views/backend/index.njk create mode 100644 src/assets/views/backend/index.svelte create mode 100644 src/assets/views/components/Breadcrumb.svelte create mode 100644 src/assets/views/components/FlashMessages.svelte create mode 100644 src/assets/views/components/Message.svelte create mode 100644 src/assets/views/components/NavMenuItem.svelte create mode 100644 src/assets/views/components/Pagination.svelte create mode 100644 src/assets/views/home.svelte create mode 100644 src/assets/views/layouts/BaseLayout.svelte delete mode 100644 src/assets/views/layouts/barebone.njk delete mode 100644 src/assets/views/magic_link.njk create mode 100644 src/assets/views/magic_link.svelte create mode 100644 src/assets/views/magic_link_lobby.svelte create mode 100644 src/assets/views/utils/CsrfTokenField.svelte create mode 100644 src/assets/views/utils/Field.svelte create mode 100644 src/assets/views/utils/Form.svelte create mode 100644 src/assets/views/utils/Icon.svelte diff --git a/src/assets/ts/WebsocketClient.ts b/src/assets/ts/WebsocketClient.ts new file mode 100644 index 0000000..5017d64 --- /dev/null +++ b/src/assets/ts/WebsocketClient.ts @@ -0,0 +1,37 @@ +export default class WebsocketClient { + + /** + * @param websocketUrl + * @param listener + * @param reconnectOnCloseAfter time to reconnect after connection fail in ms. -1 to not reconnect automatically. + * @param checkFunction + */ + public constructor( + private readonly websocketUrl: string, + private readonly listener: (websocket: WebSocket, e: MessageEvent) => void, + private readonly reconnectOnCloseAfter: number = 1000, + ) { + } + + public run(): void { + const websocket = new WebSocket(this.websocketUrl); + websocket.onopen = () => { + console.debug('Websocket connected'); + }; + websocket.onmessage = (e) => { + this.listener(websocket, e); + }; + websocket.onerror = (e) => { + console.error('Websocket error', e); + }; + websocket.onclose = (e) => { + console.debug('Websocket closed', e.code, e.reason); + + if (this.reconnectOnCloseAfter >= 0) { + setTimeout(() => { + this.run(); + }, this.reconnectOnCloseAfter); + } + }; + } +} diff --git a/src/assets/views/auth/account/NamePanel.svelte b/src/assets/views/auth/account/NamePanel.svelte new file mode 100644 index 0000000..466b67b --- /dev/null +++ b/src/assets/views/auth/account/NamePanel.svelte @@ -0,0 +1,27 @@ + + +
+

Change name

+ + + {#if $locals.can_change_name} +
+ + + + + {:else} + + {/if} +
diff --git a/src/assets/views/auth/account/PasswordPanel.svelte b/src/assets/views/auth/account/PasswordPanel.svelte new file mode 100644 index 0000000..49424ed --- /dev/null +++ b/src/assets/views/auth/account/PasswordPanel.svelte @@ -0,0 +1,30 @@ + + +
+

{$locals.has_password ? 'Change' : 'Set'} password

+ + {#if removePasswordMode} +
+ +
+ {:else} +
+ {#if $locals.has_password} + + + {/if} + + + + + {/if} +
diff --git a/src/assets/views/auth/account/account.njk b/src/assets/views/auth/account/account.njk deleted file mode 100644 index 1ba9e79..0000000 --- a/src/assets/views/auth/account/account.njk +++ /dev/null @@ -1,98 +0,0 @@ -{% extends 'layouts/base.njk' %} -{% import 'macros.njk' as macros %} - -{% set title = 'Account' %} -{% set decription = 'Manage your account settings and data.' %} - -{% block body %} -
-
-

Personal information

- - {% if display_email_warning and emails | length <= 0 %} - {{ macros.message('warning', 'To avoid losing access to your account, please add an email address.') }} - {% endif %} - - {% for field in user.getPersonalInfoFields() %} -

{{ field.name }}: {{ field.value }}

- {% endfor %} - - {% if main_email.email | length > 0 %} -

Contact email: {{ main_email.email }} More...

- {% endif %} -
- - {% if has_name_component %} - {% include 'views/auth/account/name_panel.njk' %} - {% endif %} - - {% if has_password_component %} - {% include 'views/auth/account/password_panel.njk' %} - {% endif %} - -
-

Email addresses

- - - - - - - - - - - - {% for email in emails %} - {% if email.id == user.main_email_id %} - - - - - - {% endif %} - {% endfor %} - {% for email in emails %} - {% if email.id != user.main_email_id %} - - - - - - {% endif %} - {% endfor %} - -
TypeAddressActions
Main{{ email.email }}
Secondary{{ email.email }} -
- - - - {{ macros.csrf(getCsrfToken) }} -
- -
- - - - {{ macros.csrf(getCsrfToken) }} -
-
- -
-

Add an email address:

- - {{ macros.field(_locals, 'email', 'email', null, 'Choose a safe email address', 'An email address we can use to identify you in case you lose access to your account', 'required') }} - - - - {{ macros.csrf(getCsrfToken) }} -
-
-
-{% endblock %} diff --git a/src/assets/views/auth/account/account.svelte b/src/assets/views/auth/account/account.svelte new file mode 100644 index 0000000..e01c34d --- /dev/null +++ b/src/assets/views/auth/account/account.svelte @@ -0,0 +1,98 @@ + + + +
+
+

Personal information

+ + {#if $locals.display_email_warning && $locals.emails.length <= 0} + + {/if} + + {#each personalInfoFields as field} +

{field.name}: {field.value}

+ {/each} + + {#if mainEmail} +

Contact email: {mainEmail} More...

+ {/if} +
+ + {#if $locals.has_name_component} + + {/if} + + {#if $locals.has_password_component} + + {/if} + +
+

Email addresses

+ + + + + + + + + + + + {#each emails as email} + {#if email.id === $locals.user.main_email_id} + + + + + + {/if} + {/each} + + {#each emails as email} + {#if email.id !== $locals.user.main_email_id} + + + + + + {/if} + {/each} + +
TypeAddressActions
Main{email.email}
Secondary{email.email} +
+ + + +
+ + +
+ +
+

Add an email address:

+ + + +
+
+
diff --git a/src/assets/views/auth/account/name_panel.njk b/src/assets/views/auth/account/name_panel.njk deleted file mode 100644 index d2a5cdf..0000000 --- a/src/assets/views/auth/account/name_panel.njk +++ /dev/null @@ -1,16 +0,0 @@ -
-

Change name

- {% if can_change_name %} -
- {{ macros.field(_locals, 'text', 'name', null, 'New name', null, 'required') }} - - {{ macros.field(_locals, 'checkbox', 'terms', null, 'I understand that I can only change my name once every ' + name_change_wait_period, '', 'required') }} - - - - {{ macros.csrf(getCsrfToken) }} -
- {% else %} - {{ macros.message('info', 'You can change your name in ' + can_change_name_in) }} - {% endif %} -
diff --git a/src/assets/views/auth/account/password_panel.njk b/src/assets/views/auth/account/password_panel.njk deleted file mode 100644 index fe5dbd1..0000000 --- a/src/assets/views/auth/account/password_panel.njk +++ /dev/null @@ -1,45 +0,0 @@ -
-

{% if has_password %}Change{% else %}Set{% endif %} password

- -
- {% if has_password %} - {{ macros.field(_locals, 'password', 'current_password', null, 'Current password') }} -

Forgot your password?

- {% endif %} - {{ macros.field(_locals, 'password', 'new_password', null, 'New password') }} - {{ macros.field(_locals, 'password', 'new_password_confirmation', null, 'New password confirmation') }} - - - - {{ macros.csrf(getCsrfToken) }} -
- - {% if has_password %} - - - - {% endif %} -
diff --git a/src/assets/views/auth/auth.svelte b/src/assets/views/auth/auth.svelte new file mode 100644 index 0000000..f13039a --- /dev/null +++ b/src/assets/views/auth/auth.svelte @@ -0,0 +1,68 @@ + + + + +
+
+

Log in

+ +
+ + + {#if !loginUsingMagicLink} + + + {:else} + + {/if} + + +
+ +
+

Register

+ +
+ + + {#if $locals.has_username} + + {/if} + + {#if registerUsingMagicLink} + + + {:else} + + + + {/if} + + + I accept the Terms Of Services. + + +
+
+
diff --git a/src/assets/views/backend/accounts_approval.njk b/src/assets/views/backend/accounts_approval.njk deleted file mode 100644 index 961ce5b..0000000 --- a/src/assets/views/backend/accounts_approval.njk +++ /dev/null @@ -1,63 +0,0 @@ -{% extends 'layouts/base.njk' %} - -{% set title = app.name + ' - Review accounts' %} - -{% block body %} -

Accounts pending review

- -
- - - - - {% if has_user_name_component %} - - {% endif %} - - - - - - - {% for user in accounts %} - - - {% if has_user_name_component %} - - {% endif %} - - - - - {% endfor %} - -
#NameMain emailRegistered atAction
{{ user.id }}{{ user.name }}{{ user.mainEmail.getOrFail().email | default('No email') }}{{ user.created_at.toISOString() }} -
-
- - - {{ macros.csrf(getCsrfToken) }} -
- -
- - - {{ macros.csrf(getCsrfToken) }} -
-
-
-
- - -{% endblock %} \ No newline at end of file diff --git a/src/assets/views/backend/accounts_approval.svelte b/src/assets/views/backend/accounts_approval.svelte new file mode 100644 index 0000000..63d626d --- /dev/null +++ b/src/assets/views/backend/accounts_approval.svelte @@ -0,0 +1,69 @@ + + + + + +

Accounts pending review

+ + + +
+ + + + + {#if $locals.has_user_name_component} + + {/if} + + + + + + + {#each accounts as user} + + + {#if $locals.has_user_name_component} + + {/if} + + + + + {:else} + + + + {/each} + +
#NameMain emailRegistered atAction
{user.id}{user.name}{user.mainEmailStr || 'No email'} +
+
+ + + +
+ + +
+
No account to review.
+
+ + +
diff --git a/src/assets/views/backend/index.njk b/src/assets/views/backend/index.njk deleted file mode 100644 index cd556bf..0000000 --- a/src/assets/views/backend/index.njk +++ /dev/null @@ -1,28 +0,0 @@ -{% extends 'layouts/base.njk' %} - -{% set title = app.name + ' backend' %} - -{% block body %} -
- {{ macros.breadcrumb('Backend') }} - -

App administration

- - -
-{% endblock %} \ No newline at end of file diff --git a/src/assets/views/backend/index.svelte b/src/assets/views/backend/index.svelte new file mode 100644 index 0000000..6c29bbe --- /dev/null +++ b/src/assets/views/backend/index.svelte @@ -0,0 +1,32 @@ + + + +
+ + +

App administration

+ +
+ +
+
+
diff --git a/src/assets/views/components/Breadcrumb.svelte b/src/assets/views/components/Breadcrumb.svelte new file mode 100644 index 0000000..12d4c22 --- /dev/null +++ b/src/assets/views/components/Breadcrumb.svelte @@ -0,0 +1,13 @@ + + + diff --git a/src/assets/views/components/FlashMessages.svelte b/src/assets/views/components/FlashMessages.svelte new file mode 100644 index 0000000..238d5ff --- /dev/null +++ b/src/assets/views/components/FlashMessages.svelte @@ -0,0 +1,17 @@ + + +
+ {#if flashed} + {#each Object.entries(flashed) as [key, bag], i} + {#each bag as content} + + {/each} + {/each} + {/if} +
diff --git a/src/assets/views/components/Message.svelte b/src/assets/views/components/Message.svelte new file mode 100644 index 0000000..4c9d953 --- /dev/null +++ b/src/assets/views/components/Message.svelte @@ -0,0 +1,17 @@ + + +
+ + + {#if raw} + {@html content} + {:else} + {content} + {/if} + +
diff --git a/src/assets/views/components/NavMenuItem.svelte b/src/assets/views/components/NavMenuItem.svelte new file mode 100644 index 0000000..c42d686 --- /dev/null +++ b/src/assets/views/components/NavMenuItem.svelte @@ -0,0 +1,23 @@ + + + +
  • + {#if action} +
    + + + + + {:else} + + {text} + + {/if} +
  • diff --git a/src/assets/views/components/Pagination.svelte b/src/assets/views/components/Pagination.svelte new file mode 100644 index 0000000..0165ef3 --- /dev/null +++ b/src/assets/views/components/Pagination.svelte @@ -0,0 +1,46 @@ + + +{#if paginationObj && (paginationObj.hasPrevious() || paginationObj.hasNext())} + +{/if} diff --git a/src/assets/views/home.svelte b/src/assets/views/home.svelte new file mode 100644 index 0000000..6209982 --- /dev/null +++ b/src/assets/views/home.svelte @@ -0,0 +1,10 @@ + + + + + diff --git a/src/assets/views/layouts/BaseLayout.svelte b/src/assets/views/layouts/BaseLayout.svelte new file mode 100644 index 0000000..522066c --- /dev/null +++ b/src/assets/views/layouts/BaseLayout.svelte @@ -0,0 +1,78 @@ + + + + + + + + + {title || 'Undefined title'} + {#if description} + + {/if} + + + + + + {#if refresh_after} + + {/if} + + + + +
    + + +
    + +
    + +
    + +
    + {#if h1} +

    {h1}

    + {/if} + {#if $$slots.subtitle} +

    + +

    + {/if} + +
    + + diff --git a/src/assets/views/layouts/barebone.njk b/src/assets/views/layouts/barebone.njk deleted file mode 100644 index 3a82d94..0000000 --- a/src/assets/views/layouts/barebone.njk +++ /dev/null @@ -1,37 +0,0 @@ - - - - - {{ title }} - - - - - - - - {% if description %} - - {% endif %} - - {% if refresh_after %} - - {% endif %} - - {% block _stylesheets %}{% endblock %} - {% block _scripts %} - - {% endblock %} - - - -
    - {% block header %}{% endblock %} -
    - -{% block _body %}{% endblock %} - - - - - \ No newline at end of file diff --git a/src/assets/views/magic_link.njk b/src/assets/views/magic_link.njk deleted file mode 100644 index a575e76..0000000 --- a/src/assets/views/magic_link.njk +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'layouts/base.njk' %} - -{% set actionType = magicLink.action_type %} -{% set h1 = 'Magic Link' + (' - ' + actionType if actionType) %} -{% set title = app.name + ' ' + h1 %} - -{% block body %} -
    -
    - {% if err %} - {{ macros.message('error', err) }} - {% else %} - {{ macros.message('success', 'Success!') }} -

    You can now close this page.

    - {% endif %} -
    -
    -{% endblock %} diff --git a/src/assets/views/magic_link.svelte b/src/assets/views/magic_link.svelte new file mode 100644 index 0000000..d764927 --- /dev/null +++ b/src/assets/views/magic_link.svelte @@ -0,0 +1,21 @@ + + + +
    +
    + {#if $locals.err} + + {:else} + +

    You can now close this page.

    + {/if} +
    +
    +
    diff --git a/src/assets/views/magic_link_lobby.svelte b/src/assets/views/magic_link_lobby.svelte new file mode 100644 index 0000000..96f3e1e --- /dev/null +++ b/src/assets/views/magic_link_lobby.svelte @@ -0,0 +1,51 @@ + + + +
    +
    + + + +

    Waiting for you to open the link...

    +
    +
    +
    diff --git a/src/assets/views/utils/CsrfTokenField.svelte b/src/assets/views/utils/CsrfTokenField.svelte new file mode 100644 index 0000000..b757ff1 --- /dev/null +++ b/src/assets/views/utils/CsrfTokenField.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/assets/views/utils/Field.svelte b/src/assets/views/utils/Field.svelte new file mode 100644 index 0000000..98a8c27 --- /dev/null +++ b/src/assets/views/utils/Field.svelte @@ -0,0 +1,101 @@ + + +{#if type === 'hidden'} + {#if validation} + + {/if} + +{:else} +
    +
    + {#if icon} + + {/if} + + {#if type === 'duration'} +
    + {#each extraData as f} +
    + + +
    + {/each} +
    + {:else if type === 'select'} + + + {:else if type === 'textarea'} + + {:else if type === 'checkbox'} + + {:else} + + {/if} + + +
    + + {#if validation} +
    {validation.message}
    + {/if} + {#if hint} +
    {hint}
    + {/if} +
    +{/if} + diff --git a/src/assets/views/utils/Form.svelte b/src/assets/views/utils/Form.svelte new file mode 100644 index 0000000..6102a42 --- /dev/null +++ b/src/assets/views/utils/Form.svelte @@ -0,0 +1,39 @@ + + + +
    + + + + diff --git a/src/assets/views/utils/Icon.svelte b/src/assets/views/utils/Icon.svelte new file mode 100644 index 0000000..a86b726 --- /dev/null +++ b/src/assets/views/utils/Icon.svelte @@ -0,0 +1,11 @@ + + +{#if name} + {#if name.startsWith('fa') } + + {:else} + + {/if} +{/if}