<commit_before>defmodule Lyn.AdminController do
  use Lyn.Web, :controller

  import Lyn.ParamsToAtoms

  alias Lyn.Domain
  alias Lyn.Language
  alias Lyn.ObjectType
  alias Lyn.Site

  def models, do: %{
    "domains" => Domain,
    "languages" => Language,
    "object_types" => ObjectType,
    "sites" => Site
  }

  plug :put_layout, "admin.html"

  def index(conn, params) do
    model = models[params["resource"]]

    contents = case model do
      nil ->
        render(conn, "dashboard.html")
      model ->
        entries = case conn.assigns[:entries] do
          nil ->
            Repo.all(model)
          entries ->
            entries
        end

        columns = Enum.drop(Map.keys(model.__struct__), 2)

        render(conn, "index.html", entries: entries, columns: model.admin_fields)
    end
  end

  def new(conn, params) do
    model = models[params["resource"]]

    changeset = model.changeset(struct(model))

    render(conn, "new.html", changeset: changeset)
  end
end<commit_msg>feat(admin): add columns to render(conn) in #new<commit_after>defmodule Lyn.AdminController do
  use Lyn.Web, :controller

  import Lyn.ParamsToAtoms

  alias Lyn.Domain
  alias Lyn.Language
  alias Lyn.ObjectType
  alias Lyn.Site

  def models, do: %{
    "domains" => Domain,
    "languages" => Language,
    "object_types" => ObjectType,
    "sites" => Site
  }

  plug :put_layout, "admin.html"

  def index(conn, params) do
    model = models[params["resource"]]

    contents = case model do
      nil ->
        render(conn, "dashboard.html")
      model ->
        entries = case conn.assigns[:entries] do
          nil ->
            Repo.all(model)
          entries ->
            entries
        end

        columns = Enum.drop(Map.keys(model.__struct__), 2)

        render(conn, "index.html", entries: entries, columns: model.admin_fields)
    end
  end

  def new(conn, params) do
    model = models[params["resource"]]

    changeset = model.changeset(struct(model))

    render(conn, "new.html", changeset: changeset, columns: model.admin_fields)
  end
end
{'fraction_non_alphanumeric': 0.11756238003838772, 'fraction_numerical': 0.0009596928982725527, 'mean_word_length': 2.5580204778157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1669935', 'n_tokens_mistral': 664, 'n_tokens_neox': 633, 'n_words': 163}