@raketa-cloud/admin 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "npx tailwindcss -i ./src/styles/application.css -o ../../apps/admin/static/application.css --watch",
@@ -102,6 +102,7 @@ export default class HonoAdapter extends Adapter {
102
102
  ctx.remoteConfig = { ...this.globalConfig.remoteConfig };
103
103
 
104
104
  const _context = {
105
+ timezones: this.globalConfig.i18n.timezones,
105
106
  locales: ctx.locales,
106
107
  locale: ctx.locale,
107
108
  defaultLocale: ctx.defaultLocale,
@@ -15,9 +15,9 @@ export default class Events extends RaketaClient {
15
15
  return {
16
16
  visibility: "private",
17
17
  layout: "default",
18
- publish_at: toDateTimeInput(new Date()),
19
- starts_at: toDateTimeInput(new Date()),
20
- ends_at: toDateTimeInput(new Date()),
18
+ publish_at: toDateTimeInput(),
19
+ starts_at: toDateTimeInput(),
20
+ ends_at: toDateTimeInput(),
21
21
  tags: [],
22
22
  categories: [],
23
23
  };
@@ -166,6 +166,10 @@ body {
166
166
  .checkbox-wrapper input[type="checkbox"] {
167
167
  @apply size-4 px-0;
168
168
  }
169
+
170
+ .hint {
171
+ @apply text-sm opacity-50;
172
+ }
169
173
  }
170
174
 
171
175
  .inline-form {
@@ -38,7 +38,7 @@ describe("Article revision genereal settings", () => {
38
38
  title: revision.title,
39
39
  slug: revision.slug,
40
40
  visibility: revision.visibility,
41
- publish_at: "2024-08-30T19:05",
41
+ publish_at: "2024-08-30T16:05:00",
42
42
  username: revision.settings?.credentials?.user || "",
43
43
  password: revision.settings?.credentials?.password || "",
44
44
  },
@@ -54,7 +54,7 @@ describe("Article revision general settings", () => {
54
54
  slug: updateSettings.slug,
55
55
  title: updateSettings.title,
56
56
  visibility: updateSettings.visibility,
57
- publishAt: "2024-08-30T16:05:00Z",
57
+ publishAt: "2024-08-30T19:05:00Z",
58
58
  widgets: JSON.stringify(revision.widgets),
59
59
  tags: revision.tags.map((t) => t.id),
60
60
  categories: revision.categories.map((c) => c.id),
@@ -107,7 +107,7 @@ describe("Article revision general settings", () => {
107
107
  slug: updateSettings.slug,
108
108
  title: updateSettings.title,
109
109
  visibility: updateSettings.visibility,
110
- publishAt: "2024-08-30T16:05:00Z",
110
+ publishAt: "2024-08-30T19:05:00Z",
111
111
  widgets: JSON.stringify(revision.widgets),
112
112
  tags: revision.tags.map((t) => t.id),
113
113
  categories: revision.categories.map((c) => c.id),
@@ -50,7 +50,7 @@ describe("Articles Handler", () => {
50
50
  title: params.title,
51
51
  slug: params.slug,
52
52
  visibility: params.visibility,
53
- publishAt: "2024-10-10T03:58:00Z",
53
+ publishAt: "2024-10-10T06:58:00Z",
54
54
  settings: {
55
55
  layout: params.layout,
56
56
  meta: {
@@ -116,7 +116,7 @@ describe("Articles Handler", () => {
116
116
  title: params.title,
117
117
  slug: "",
118
118
  visibility: params.visibility,
119
- publishAt: "2024-10-10T03:58:00Z",
119
+ publishAt: "2024-10-10T06:58:00Z",
120
120
  settings: {
121
121
  layout: params.layout,
122
122
  meta: {
@@ -40,9 +40,9 @@ describe("Event revision genereal settings", () => {
40
40
  title: revision.title,
41
41
  slug: revision.slug,
42
42
  visibility: revision.visibility,
43
- publish_at: "2024-08-30T22:05",
44
- starts_at: "2024-08-30T22:10",
45
- ends_at: "2024-08-30T22:15",
43
+ publish_at: "2024-08-30T19:05:00",
44
+ starts_at: "2024-08-30T19:10:00",
45
+ ends_at: "2024-08-30T19:15:00",
46
46
  username: revision.settings?.credentials?.user || "",
47
47
  password: revision.settings?.credentials?.password || "",
48
48
  },
@@ -56,9 +56,9 @@ describe("Event revision general settings", () => {
56
56
  slug: updateSettings.slug,
57
57
  title: updateSettings.title,
58
58
  visibility: updateSettings.visibility,
59
- publishAt: "2024-08-30T16:05:00Z",
60
- startsAt: "2024-08-30T16:10:00Z",
61
- endsAt: "2024-08-30T16:15:00Z",
59
+ publishAt: "2024-08-30T19:05:00Z",
60
+ startsAt: "2024-08-30T19:10:00Z",
61
+ endsAt: "2024-08-30T19:15:00Z",
62
62
  widgets: JSON.stringify(revision.widgets),
63
63
  tags: revision.tags.map((t) => t.id),
64
64
  categories: revision.categories.map((c) => c.id),
@@ -113,9 +113,9 @@ describe("Event revision general settings", () => {
113
113
  slug: updateSettings.slug,
114
114
  title: updateSettings.title,
115
115
  visibility: updateSettings.visibility,
116
- publishAt: "2024-08-30T16:05:00Z",
117
- startsAt: "2024-08-30T16:10:00Z",
118
- endsAt: "2024-08-30T16:15:00Z",
116
+ publishAt: "2024-08-30T19:05:00Z",
117
+ startsAt: "2024-08-30T19:10:00Z",
118
+ endsAt: "2024-08-30T19:15:00Z",
119
119
  widgets: JSON.stringify(revision.widgets),
120
120
  tags: revision.tags.map((t) => t.id),
121
121
  categories: revision.categories.map((c) => c.id),
@@ -52,9 +52,9 @@ describe("Events Handler", () => {
52
52
  title: params.title,
53
53
  slug: params.slug,
54
54
  visibility: params.visibility,
55
- publishAt: "2024-10-10T03:40:00Z",
56
- startsAt: "2024-10-10T03:50:00Z",
57
- endsAt: "2024-10-10T03:59:00Z",
55
+ publishAt: "2024-10-10T06:40:00Z",
56
+ startsAt: "2024-10-10T06:50:00Z",
57
+ endsAt: "2024-10-10T06:59:00Z",
58
58
  settings: {
59
59
  layout: params.layout,
60
60
  meta: {
@@ -122,9 +122,9 @@ describe("Events Handler", () => {
122
122
  title: params.title,
123
123
  slug: "",
124
124
  visibility: params.visibility,
125
- publishAt: "2024-10-10T03:40:00Z",
126
- startsAt: "2024-10-10T03:50:00Z",
127
- endsAt: "2024-10-10T03:59:00Z",
125
+ publishAt: "2024-10-10T06:40:00Z",
126
+ startsAt: "2024-10-10T06:50:00Z",
127
+ endsAt: "2024-10-10T06:59:00Z",
128
128
  settings: {
129
129
  layout: params.layout,
130
130
  meta: {
package/src/utils.js CHANGED
@@ -1,46 +1,30 @@
1
- export function toUTCISO8601String(initialDate) {
2
- let date = null;
3
-
4
- if (typeof initialDate === "string") {
5
- date = new Date(initialDate);
6
- } else {
7
- date = initialDate;
8
- }
9
-
10
- return [
11
- date.getUTCFullYear(),
12
- "-",
13
- (date.getUTCMonth() + 1).toString().padStart(2, "0"),
14
- "-",
15
- date.getUTCDate().toString().padStart(2, "0"),
16
- "T",
17
- date.getUTCHours().toString().padStart(2, "0"),
18
- ":",
19
- date.getUTCMinutes().toString().padStart(2, "0"),
20
- ":",
21
- date.getUTCSeconds().toString().padStart(2, "0"),
22
- "Z",
23
- ].join("");
1
+ export function toUTCISO8601String(inputDate) {
2
+ // The format coming from the datetie-local input is YYYY-mm-ddTHH:MM
3
+ // e.g. 2024-10-10T14:25
4
+ // Currently we will just use that as a UTC value and show some explanation in the UI!
5
+ return `${inputDate}:00Z`;
24
6
  }
25
7
 
26
- export function toDateTimeInput(initialDate) {
27
- let date = null;
28
-
8
+ export function toDateTimeInput(initialDate = null) {
29
9
  if (typeof initialDate === "string") {
30
- date = new Date(initialDate);
31
- } else {
32
- date = initialDate;
10
+ // The case where it comes from the DB it is in UTC. We are going to directly feed it to the
11
+ // datetime-local input and add explanations in the UI!
12
+ return initialDate.replace("Z", "");
33
13
  }
34
14
 
15
+ // Directly use the current time for to feed the datetime-local input.
16
+ // show UI hints that this is going to be used as UTC time.
17
+ const now = new Date();
18
+
35
19
  return [
36
- date.getFullYear(),
20
+ now.getFullYear(),
37
21
  "-",
38
- (date.getMonth() + 1).toString().padStart(2, "0"),
22
+ (now.getMonth() + 1).toString().padStart(2, "0"),
39
23
  "-",
40
- date.getDate().toString().padStart(2, "0"),
24
+ now.getDate().toString().padStart(2, "0"),
41
25
  "T",
42
- date.getHours().toString().padStart(2, "0"),
26
+ now.getHours().toString().padStart(2, "0"),
43
27
  ":",
44
- date.getMinutes().toString().padStart(2, "0"),
28
+ now.getMinutes().toString().padStart(2, "0"),
45
29
  ].join("");
46
30
  }
@@ -11,7 +11,7 @@
11
11
  <form action="<%= `/${_context.locale}/article_revisions/${general_settings.id}/general` %>" method="POST" class="form">
12
12
  <%- f.field('general_settings.title', { required: true }) %>
13
13
  <%- f.field('general_settings.slug', { label: "URL", required: true }) %>
14
- <%- f.field('general_settings.publish_at', { required: true, type: 'datetime-local' }) %>
14
+ <%- f.field('general_settings.publish_at', { required: true, type: 'datetime-local', label: 'Publish at (UTC)' }) %>
15
15
  <%- f.field('general_settings.visibility', { as: 'select', required: true, options: visibilityOptions }) %>
16
16
 
17
17
  <%- f.field('general_settings.username', { required: true }) %>
@@ -11,9 +11,9 @@
11
11
  <form action="<%= `/${_context.locale}/event_revisions/${general_settings.id}/general` %>" method="POST" class="form">
12
12
  <%- f.field('general_settings.title', { required: true }) %>
13
13
  <%- f.field('general_settings.slug', { label: "URL", required: true }) %>
14
- <%- f.field('general_settings.publish_at', { required: true, type: 'datetime-local' }) %>
15
- <%- f.field('general_settings.starts_at', { required: true, type: 'datetime-local' }) %>
16
- <%- f.field('general_settings.ends_at', { required: true, type: 'datetime-local' }) %>
14
+ <%- f.field('general_settings.publish_at', { required: true, type: 'datetime-local', label: 'Publish at (UTC)' }) %>
15
+ <%- f.field('general_settings.starts_at', { required: true, type: 'datetime-local', label: 'Starts at (UTC)' }) %>
16
+ <%- f.field('general_settings.ends_at', { required: true, type: 'datetime-local', label: 'Ends at (UTC)' }) %>
17
17
  <%- f.field('general_settings.visibility', { as: 'select', required: true, options: visibilityOptions }) %>
18
18
 
19
19
  <%- f.field('general_settings.username', { required: true }) %>
@@ -104,6 +104,38 @@
104
104
  initToggle();
105
105
  toggleEl.addEventListener('click', handleToggle);
106
106
  </script>
107
+
108
+ <script>
109
+ // Don't ask
110
+ const TIMEZONES = JSON.parse("<%= JSON.stringify(_context.timezones) %>".replaceAll("&#34;", '"'))
111
+
112
+ function enhanceDateTimeInputs(input) {
113
+ // skew the date so it is like in UTC for the user...
114
+ // The datetime-local input gives the result witout a timezone so we can just attach the UTC one...
115
+ const fakeUTCDate = new Date(`${input.value}:00Z`)
116
+
117
+ const parent = input.parentNode;
118
+
119
+ parent.querySelectorAll('[data-auto="1"]').forEach(node => node.remove())
120
+
121
+ TIMEZONES.forEach(timeZone => {
122
+ const strTime = fakeUTCDate.toLocaleString("en-EU",{timeZone: `${timeZone.value}`});
123
+ const hint = document.createElement("div");
124
+
125
+ hint.classList.add('hint')
126
+ hint.innerText = `${timeZone.label}: ${strTime}`;
127
+ hint.dataset.auto = "1";
128
+
129
+ parent.appendChild(hint)
130
+ })
131
+ }
132
+
133
+ document.querySelectorAll('input[type="datetime-local"]').forEach(input => {
134
+ enhanceDateTimeInputs(input);
135
+
136
+ input.addEventListener("change", (event) => enhanceDateTimeInputs(event.target))
137
+ } )
138
+ </script>
107
139
  </body>
108
140
 
109
141
  </html>