From 07ed048cd2f2231fa26345a94c725363344ee77b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 12 Jun 2017 18:59:23 +0200 Subject: referentials/show.html.slim: Extract header buttons to a decorator Add a new `ReferentialDecorator` that we can use to define the links that appear as buttons in the header of the `/referentials/:id` page. The idea is that these links will take the place of the existing view code and in the view, we'll instead loop over the links provided by the decorator and render them as buttons. I decided to do it this way because there's a requirement that the links in the gear menu in tables show the same links that appear in the header of the page. So the Workbenches#show page would show a table of referentials, and their gear menu links should ostensibly be the same as the header links in the Referentials#show page. My goal was to abstract links, and try to separate them from the presentation layer. Still having trouble with this though. I created a new `Link` class to represent a link. We can then use this in the template to create a `link_to`. It becomes messy, though, when we want to put other elements inside a certain link, as evidenced by the `:delete` link. Don't like how that's done, but still working out the best approach to make it cleaner. Refs #3479 --- lib/link.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/link.rb (limited to 'lib') diff --git a/lib/link.rb b/lib/link.rb new file mode 100644 index 000000000..911f189c9 --- /dev/null +++ b/lib/link.rb @@ -0,0 +1,10 @@ +class Link + attr_reader :name, :href, :method, :data + + def initialize(name: nil, href:, method: :get, data: nil) + @name = name + @href = href + @method = method + @data = data + end +end -- cgit v1.2.3 From 133bb6b8471df2ec1057d061dc170712a94a9425 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Jun 2017 11:32:18 +0200 Subject: TableBuilder;Link: Remove default `:get` for HTTP method Don't set links as `method: :get` by default. This shows up as: link_to _, _, method: :get If we set the method to `nil` instead, we don't get a `data-method="get"` attribute in our HTML output. Instead, we get no `data-method` attribute, which is a lot better and cleaner. I had originally used `:get` as a default because I wanted to generalise links and certain ones we create need `:delete` or `:put` methods. I figured, since we're always going to be passing `method:` to `link_to`, we should have a sane default for that option. However, using `nil` is even better as a default because then we don't get an extra attribute in our HTML at all. Refs #3479 --- lib/link.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/link.rb b/lib/link.rb index 911f189c9..c875b85ac 100644 --- a/lib/link.rb +++ b/lib/link.rb @@ -1,7 +1,7 @@ class Link attr_reader :name, :href, :method, :data - def initialize(name: nil, href:, method: :get, data: nil) + def initialize(name: nil, href:, method: nil, data: nil) @name = name @href = href @method = method -- cgit v1.2.3 From 3b621ee93c5097c55bd4ce4c7bdecdaa18c6f9ab Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Jun 2017 14:37:14 +0200 Subject: TableBuilder: Make destroy link in gear menu render correctly Previously we weren't correctly outputting the proper HTML to get the :delete link rendering correctly with the icon and text. It should show: [TRASH CAN ICON] Supprimer but instead was showing the href. To get this working, I added a `@content` attribute to `Link`. This allows us to optionally specify non-text content to display in the link. We then have delete-link-specific handling when rendering the gear menu's HTML. In that particular case, the `
  • ` needs to have a 'delete-action' class in order for the styling to work properly. Created a new `destroy_link` helper method to allow us to reuse the destroy link content in the header bar. TODO: Collect Link#content and Link#name into the same property. TODO: Rename `#destroy_link` to `#destroy_link_content` Refs #3479 --- lib/link.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/link.rb b/lib/link.rb index c875b85ac..3ce12ae24 100644 --- a/lib/link.rb +++ b/lib/link.rb @@ -1,10 +1,11 @@ class Link - attr_reader :name, :href, :method, :data + attr_reader :name, :href, :method, :data, :content - def initialize(name: nil, href:, method: nil, data: nil) + def initialize(name: nil, href:, method: nil, data: nil, content: nil) @name = name @href = href @method = method @data = data + @content = content end end -- cgit v1.2.3 From 40b02ab0bdbf51ea4c9d3ebef26d880c789edf44 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Jun 2017 14:49:34 +0200 Subject: Link: Change :name & :content into a single property :content The only difference between :name and :content was that :name contained a string and :content contained HTML. But they're really the same thing. Thus it makes much more sense to combine those into a single property that means both, and handles content regardless of type. Refs #3479 --- lib/link.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/link.rb b/lib/link.rb index 3ce12ae24..7683a808f 100644 --- a/lib/link.rb +++ b/lib/link.rb @@ -1,11 +1,10 @@ class Link - attr_reader :name, :href, :method, :data, :content + attr_reader :content, :href, :method, :data - def initialize(name: nil, href:, method: nil, data: nil, content: nil) - @name = name + def initialize(content: nil, href:, method: nil, data: nil) + @content = content @href = href @method = method @data = data - @content = content end end -- cgit v1.2.3 From 1d489cef3b9aeb474071b89be6d256e554182863 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Jun 2017 17:44:55 +0200 Subject: ReferentialDecorator: Handle non-`Link` buttons Referentials#show has a button "Purger" that isn't a link. Instead, it's a `