aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/table_builder_helper
AgeCommit message (Collapse)Author
2018-03-15Merge pull request #372 from af83/6146-line-statesLuc Donnet
6146 Line state update
2018-03-14Refs #6146; Fix display in tablesZog
2018-03-12Refs #6133; First Crud for exportsZog
2018-03-01Merge pull request #302 from af83/5877-handle-nil-objects-in-tablebuilderhelperLuc Donnet
5877 Add a condition on TableBuilderHelper::Column
2018-02-19Refs #5911 @2h; Better stops filters on ReferentialVJs#indexZog
2018-02-12Refs #5877; Add a condition on TableBuilderHelper::Column5877-handle-nil-objects-in-tablebuilderhelperZog
2018-02-07update calendar build_links for table buildercedricnjanga
2018-02-07First draft for including calendars into workgroup for having appropriate ↵cedricnjanga
scoping
2018-02-06update calendar build_links for table buildercedricnjanga
2018-02-06First draft for including calendars into workgroup for having appropriate ↵cedricnjanga
scoping
2018-02-06update calendar build_links for table buildercedricnjanga
2018-02-06First draft for including calendars into workgroup for having appropriate ↵cedricnjanga
scoping
2018-01-31Fix calendar mailer urlcedricnjanga
2018-01-31update calendar build_links for table buildercedricnjanga
2018-01-31First draft for including calendars into workgroup for having appropriate ↵cedricnjanga
scoping
2018-01-24update calendar build_links for table buildercedricnjanga
2018-01-23First draft for including calendars into workgroup for having appropriate ↵cedricnjanga
scoping
2017-12-21BusinessCalendar => PurchaseWindowcedricnjanga
belongs_to referential
2017-09-14create base structure for compliance_control_setsGuillaume
2017-09-01Revert "TableBuilderHelper::Column#link_to: Allow arbitrary number of arguments"Teddy Wing
This reverts commit 28db706443a912e8355e4c48488dc40c403e7f76. Turns out we didn't need to be able to pass an arbitrary number of arguments to the lambda after all. The URL helper objects necessary in addition to the first argument to the lambda can be retrieved from the view context directly instead of passing them into the block as parameters (which would actually make things more difficult, because the block is called in the `TableBuilderHelper`, thus outside the scope of the view).
2017-09-01TableBuilderHelper::Column#link_to: Allow arbitrary number of argumentsTeddy Wing
This enables us to pass multiple objects into the lambda, so that we can for example build a URL using a Rails helper using multiple objects. Example: column.link_to(referential, item) lambda do |referential, item| some_path(referential, item) end
2017-09-01TableBuilderHelper::Column: Add `#linkable?` methodTeddy Wing
This tells the markup assembler whether or not this column should be wrapped in a link (`<a>`). It intends to serve the same purpose as `TableBuilderHelper#column_is_linkable`, but at the column level. The idea is to remove that method when these links only operate by column and not by pre-defined values like before/now.
2017-09-01TableBuilderHelper::Column: Add `link_to` argumentTeddy Wing
This parameter will be used as the `href` to link the column value somewhere. We give it a lambda because this makes it easier to call any method on the row object. This means the accessor needs to take the object as an argument, like in the `#value` method, because we don't have a better way to handle that (it can't be done at initialisation time because at that point we don't have row objects, we have a collection).
2017-08-14Refs #4256: starting with table_builder2 on imports#indexjpl
2017-07-12CustomLinks: Pass referential directly when initialisingTeddy Wing
Instead of getting the referential to use when building the polymorphic URL from the `UserContext`, pass in a referential directly. The old code that used `user_context.context[:referential]` relied on the fact that `ApplicationController#pundit_user` was defined as follows: def pundit_user UserContext.new(current_user, referential: self.try(:current_referential)) end (We pass `pundit_user` into `CustomLinks` from `TableBuilderHelper#build_links`.) However, Robert's change 747d333ffbcc8ee0c9f1daf93ccca32799434e04 removes the `current_referential` call from `#pundit_user`. In `CustomLinks`, we actually always want to be using `current_referential`. For example, on `Companies#index` (/line_referentials/:id/companies), `CustomLinks` fails to build a correct #show link because `user_context.context[:referential]` is `nil`, when it should instead be a `LineReferential` object, that gets returned by the `#current_referential` helper method. Sure, `#current_referential` is hard to understand, so maybe we'll change that around in the future, but this at least allows us to use the current referential in `CustomLinks`. Refs #3479
2017-07-07TableBuilderHelper::URL: Fix polymorphic URL for TimeTableTeddy Wing
Had a problem on the TimeTables#index page where the #show and #edit links in the gear menu would link to `/referentials/:id` instead of `/referentials/:id/time_tables/:id`. This turned out to be caused by a syntax bug in the condition that adds the `Chouette::TimeTable` object to the polymorphic URL array. Now the proper URL is rendered. Refs #3479
2017-07-06Conflict resolvedRobert
2017-07-06TableBuilderHelper::URL: Inject `current_referential` dependencyTeddy Wing
Turns out the only reason why this code worked before was because the only place I was using `table_builder_2` was for a list of `Referential`s, and there's an explicit check for `item.is_a?(Referential)` that avoids calling `current_referential`. Otherwise, when that `unless` condition passes, we get a failure because `current_referential` can't be found. It can't be found because helper methods are not accessible in this scope (duh). In order to make the referential accessible to the method, require one as an argument. Now we explicitly pass the `current_referential` from places where `#polymorphic_url_parts` is called. Refs #3479
2017-07-05Refs: #3478@1h;Robert
- All permissions tied to `!archived?` - Tests adapted - Policies refactored ? Is `create?` permission bound to `organisation_match?`
2017-07-04Refs: #3478@3h; Policy Cleanup and Providing Policy and permissions for all ↵Robert
models and actions - ApplicationPolicy nondestructive permission depend on model existance - ApplicationPolicy destructive permission default to `false` - Tied Policy permissions at ApplicationPolicy Level: edit? → update?, new? → create?, index? → show? - ApplicationPolicy convenience methods `delete?` & `authorizes_action?(action)` - Refactoring of `spec/helpers/table_builder_helper_spec.rb` accordingly - Stubbing scope in specs (cannot switch to referential with a `build_stubbed` instance)
2017-07-04Refs: #3478@0.5h; refactored table_builder_helper/custom_links.rb, according ↵Robert
to moving authoriation BL into policies
2017-07-04Refs: #3478@1h; adapted table builder spexRobert
2017-07-04Refs: #3478@1hRobert
newapplication helper default authorization, (no if) -> * DefaultPolicy (all true) * Add some policies (LinePolicy) * Use `boiv:read` pour show, index * Adapted `table_builder`
2017-06-19TableBuilder: Add documentationTeddy Wing
Add a few doc comments to the table builder to provide a little more detailed explanation of the code. TableBuilderHelper::URL: * Describe dependency on `current_referential` TableBuilderHelper: * Add doc comments to the `collection` and `columns` arguments * Add a description of the module * Detail external global variable dependencies * Provide an example, stolen from one of the tests Refs #3479
2017-06-19TableBuilderHelper::Column: Use `@name` consistentlyTeddy Wing
We were using both the instance variable and the accessor on the same line. Pick one and be consistent. Refs #3479
2017-06-15Link: Change :name & :content into a single property :contentTeddy Wing
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
2017-06-15TableBuilder: Make table-level `sortable` workTeddy Wing
We need the ability to say that an entire table is not sortable. By default, all tables are sortable, and individual columns can have sorting deactivated. This blanket deactivates sorting for all columns. Take our `sortable` argument and pass it to `#thead`. Then `#build_column_header` takes that value into account when creating a header column value. The actual label used in the column header is determined by the old `#column_header_label` method. We've now moved it into the `TableBuilderHelper::Column` class because it makes more sense there. The method will now return the column's `:name` property if it was defined, and otherwise gets the translation for `:key` as before. Add a test on `TableBuilderHelper` that verifies that a table with `sortable: false` returns the correct HTML without sorting links. Refs #3479
2017-06-15TableBuilder;Link: Remove default `:get` for HTTP methodTeddy Wing
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
2017-06-14CustomLinks#actions_after_policy_check: Better document conditionsTeddy Wing
Add comments that describe what each `or` condition is doing. At first I thought maybe I should create separate methods to name these conditions, but settled for comments instead. Moved the final check to a method because that one seemed the most obscure about what it does. Refs #3479
2017-06-14TableBuilderHelper: Move ::Column to its own fileTeddy Wing
Now that we have other classes that belong to `TableBuilderHelper` (`URL` and `CustomLinks`), it makes more sense for this one to live in its own file. Refs #3479
2017-06-14TableBuilderHelper::CustomLinks: Fix policy check for unhandled actionsTeddy Wing
In `#actions_after_policy_check`, we weren't correctly including actions that weren't handled by the prior policy checks. Thus actions that weren't [:delete, :edit, :archive, :unarchive] wouldn't get included in the resulting list of actions. Fix my logic error. Refs #3479
2017-06-14TableBuilder: Extract custom action link methods to a new classTeddy Wing
Move `#action_links`, `#action_link_method`, and `#actions_after_policy_check` to a new class. They all depend on an action and/or a model object, so it made sense to group these together. Also, these should really be tested, and moved out of a private method context. They now live in `TableBuilderHelper::CustomLinks`. The advantage is that we now have these methods grouped together in a separate module that can be tested separately. Needed to change some things around now that they're in a class: * `obj` and `action` are now instance variables * In order to call Pundit's `policy` method, we have to call it directly on `Pundit`, since we're no longer in the context of a helper/controller/view. * Create a `UserContext` that can be passed to Pundit based on the one created in `ApplicationController`. * Rename some methods to make more sense in this new context. * Move `actions_to_http_methods` to a class constant, so we're not redefining it in every call to `method_for_action`. * Use `I18n.t` instead of `t` alone, otherwise getting the translation doesn't work. * Move `TableBuilderHelper#polymorphic_url_parts` to a new class `TableBuilderHelper::URL`. This enables us to use it in both `CustomLinks` and the `TableBuilderHelper`. We can't use it from `CustomLinks` if it's a public method in `TableBuilderHelper`, and we can't use it in `TableBuilderHelper#tbody` if it's a class method in `TableBuilderHelper`. There's a problem with the action symbols that aren't directly handled in `actions_after_policy_check`. The `:show` action was passed by the workbenches/show.html.slim template, but it doesn't appear in the resulting output even though it should. Refs #3479