From 2022831d4960054aef904e27fd2934beb4e3c65e Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 14 Nov 2024 17:16:43 +0000 Subject: Adds category model but not wired up to resource yet --- app/views/categories/_category.html.erb | 17 +++++++++++++++ app/views/categories/_category.json.jbuilder | 2 ++ app/views/categories/_form.html.erb | 32 ++++++++++++++++++++++++++++ app/views/categories/edit.html.erb | 8 +++++++ app/views/categories/index.html.erb | 21 ++++++++++++++++++ app/views/categories/index.json.jbuilder | 1 + app/views/categories/new.html.erb | 7 ++++++ app/views/categories/show.html.erb | 15 +++++++++++++ app/views/categories/show.json.jbuilder | 1 + 9 files changed, 104 insertions(+) create mode 100644 app/views/categories/_category.html.erb create mode 100644 app/views/categories/_category.json.jbuilder create mode 100644 app/views/categories/_form.html.erb create mode 100644 app/views/categories/edit.html.erb create mode 100644 app/views/categories/index.html.erb create mode 100644 app/views/categories/index.json.jbuilder create mode 100644 app/views/categories/new.html.erb create mode 100644 app/views/categories/show.html.erb create mode 100644 app/views/categories/show.json.jbuilder (limited to 'app/views') diff --git a/app/views/categories/_category.html.erb b/app/views/categories/_category.html.erb new file mode 100644 index 0000000..3c51d8f --- /dev/null +++ b/app/views/categories/_category.html.erb @@ -0,0 +1,17 @@ +
+

+ Name: + <%= category.name %> +

+ +

+ Colour: + <%= category.colour %> +

+ +

+ Badge foreground colour: + <%= category.badge_foreground_colour %> +

+ +
diff --git a/app/views/categories/_category.json.jbuilder b/app/views/categories/_category.json.jbuilder new file mode 100644 index 0000000..c0950c8 --- /dev/null +++ b/app/views/categories/_category.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! category, :id, :name, :colour, :badge_foreground_colour, :created_at, :updated_at +json.url category_url(category, format: :json) diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb new file mode 100644 index 0000000..fec6c3b --- /dev/null +++ b/app/views/categories/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_with(model: category, class: "contents") do |form| %> + <% if category.errors.any? %> +
+

<%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:

+ + +
+ <% end %> + +
+ <%= required_label_tag(form, :name) %> + <%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :colour, class: "font-bold" %> + <%= form.text_field :colour, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.label :badge_foreground_colour, class: "font-bold" %> + <%= form.text_field :badge_foreground_colour, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ +
+ <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+<% end %> diff --git a/app/views/categories/edit.html.erb b/app/views/categories/edit.html.erb new file mode 100644 index 0000000..57da660 --- /dev/null +++ b/app/views/categories/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing category

+ + <%= render "form", category: @category %> + + <%= link_to "Show this category", @category, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to categories", categories_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000..68911e6 --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,21 @@ +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <% content_for :title, "Categories" %> + +
+

Categories

+ <%= link_to "New category", new_category_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+ +
+ <% @categories.each do |category| %> + <%= render category %> +

+ <%= link_to "Show this category", category, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +

+ <% end %> +
+
diff --git a/app/views/categories/index.json.jbuilder b/app/views/categories/index.json.jbuilder new file mode 100644 index 0000000..aa5baad --- /dev/null +++ b/app/views/categories/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @categories, partial: "categories/category", as: :category diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000..fae8770 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,7 @@ +
+

New category

+ + <%= render "form", category: @category %> + + <%= link_to "Back to categories", categories_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000..e38975f --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,15 @@ +
+
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <%= render @category %> + + <%= link_to "Edit this category", edit_category_path(@category), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to categories", categories_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+ <%= button_to "Destroy this category", @category, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> +
+
+
diff --git a/app/views/categories/show.json.jbuilder b/app/views/categories/show.json.jbuilder new file mode 100644 index 0000000..30e6b47 --- /dev/null +++ b/app/views/categories/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "categories/category", category: @category -- cgit v1.2.3