From d2cdf0a2cb3e1520598bb7c92da33d834699cde6 Mon Sep 17 00:00:00 2001 From: gpopides <46693847+gpopides@users.noreply.github.com> Date: Sun, 10 Oct 2021 12:29:45 +0200 Subject: [PATCH] Display creation date of a session in home (#593) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add created_at to Session struct * test + doc enhcncement * change format creation date function name * use helper function to format created_at * use mix format * apply review suggested changes and 2 more tests * Store creation time in session state and sort by date by default Co-authored-by: Jonatan Kłosko --- lib/livebook/session.ex | 10 +++++++--- lib/livebook_web/live/home_live.ex | 10 +++++++++- lib/livebook_web/live/session_live.ex | 3 ++- test/livebook/session_test.exs | 12 ++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/livebook/session.ex b/lib/livebook/session.ex index 264a53bfa..0e5e67835 100644 --- a/lib/livebook/session.ex +++ b/lib/livebook/session.ex @@ -46,7 +46,7 @@ defmodule Livebook.Session do # The struct holds the basic session information that we track # and pass around. The notebook and evaluation state is kept # within the process state. - defstruct [:id, :pid, :origin, :notebook_name, :file, :images_dir] + defstruct [:id, :pid, :origin, :notebook_name, :file, :images_dir, :created_at] use GenServer, restart: :temporary @@ -61,12 +61,14 @@ defmodule Livebook.Session do origin: {:file, FileSystem.File.t()} | {:url, String.t()} | nil, notebook_name: String.t(), file: FileSystem.File.t() | nil, - images_dir: FileSystem.File.t() + images_dir: FileSystem.File.t(), + created_at: DateTime.t() } @type state :: %{ session_id: id(), data: Data.t(), + created_at: DateTime.t(), runtime_monitor_ref: reference() | nil, autosave_timer_ref: reference() | nil, save_task_pid: pid() | nil @@ -378,6 +380,7 @@ defmodule Livebook.Session do state = %{ session_id: id, data: data, + created_at: DateTime.utc_now(), runtime_monitor_ref: nil, autosave_timer_ref: nil, save_task_pid: nil @@ -691,7 +694,8 @@ defmodule Livebook.Session do origin: state.data.origin, notebook_name: state.data.notebook.name, file: state.data.file, - images_dir: images_dir_from_state(state) + images_dir: images_dir_from_state(state), + created_at: state.created_at } end diff --git a/lib/livebook_web/live/home_live.ex b/lib/livebook_web/live/home_live.ex index da6057ae0..8da48ab7b 100644 --- a/lib/livebook_web/live/home_live.ex +++ b/lib/livebook_web/live/home_live.ex @@ -180,6 +180,9 @@ defmodule LivebookWeb.HomeLive do
<%= if session.file, do: session.file.path, else: "No file" %>
+
+ Created <%= format_creation_date(session.created_at) %> +