maxrossello / redmine_app_timesheets

A true timesheet plugin using orders, not bound to timelogs over issues
GNU General Public License v2.0
32 stars 10 forks source link

Autocomplete for target version #61

Closed sammcj closed 9 years ago

sammcj commented 9 years ago

Hi,

As you add more cost codes / billing centers to the timesheets plugin we've noticed that it's taking everyone a very long time to find and select the correct target version.

I'm wondering if you could change the dropdown box to an input field where you can type and it autocompletes from the available the target versions - for example like: http://designshack.net/articles/javascript/create-a-simple-autocomplete-with-html5-jquery/

timesheets

maxrossello commented 9 years ago

This is a nice suggestion. Having had experience in other context with chosen.js, selectize.js and select2 (and their side problems), I think I would go the selectize way. I need to find the time for this...

maxrossello commented 9 years ago

Sam - out of this scope - once @greyman888 offered to explain the process which you use the plugin into. It would be great to publish the use case into the project wiki. What do you think? Can you share that info?

sammcj commented 9 years ago

Hi Max, We're having an issue internally as since @greyman888 finished his contract with us no one has been given the resources to own the application so it's essentially been left to rot. I don't have the time to look after it but did log this ticket because of how much time of mine it's costing to enter this each day.

@greyman888 - Do you happen to have a presentation or something like that which you could provide to max?

kane-c commented 9 years ago

I'm running a userscript which adds select2 to all the select elements on the timesheet page. It works well.

If anyone is interested:

    if ($(document.body).hasClass('controller-timesheets')) {
        $('head').append('<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" \/>');
        $.getScript('//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js', function () {
            $('#order, .list select').select2();
        });
    }
maxrossello commented 9 years ago

@kane-c thank you for the tip! I didn't even know about userscripts... I learned something https://github.com/OpenUserJs/OpenUserJS.org/wiki/Userscript-Beginners-HOWTO

(an official implementation is due, though)

greyman888 commented 9 years ago

Max, I have a few deadlines to meet in the next few weeks but after that I would be happy to contribute to the project wiki. I will not refer to any organisations by name.

Back on the topic of this thread, there are two forms where people select target version:

  1. In the issues (core Redmine)
  2. In the timesheet (Timesheet Plugin)

To be totally effective the autocomplete function would need to work in both forms.

maxrossello commented 9 years ago

Thank you Adam. Yes, both forms would need to be refactored.

maxrossello commented 9 years ago

I am struggling with adding selectize (or select2), initially on timesheet page. I'm sure I'm doing something silly... @kane-c , maybe you can advice?

What I'm doing: added class "selectize" to the #order select added selectize with bundled sifter and miniplugin into the plugin assets in app/views/timesheets/index.html.erb: on the top <% content_for :header_tags do %> <%= javascript_include_tag '/plugin_assets/redmine_app_timesheets/javascripts/selectize' %> <%= stylesheet_link_tag '/plugin_assets/redmine_app_timesheets/stylesheets/selectize.css' %> <% end %>

then, either in the same :header_tags or at the end of the file:

<script type="text/javascript">
    $(document).ready(function() {
        $('.selectize').selectize({
            create: false,
            sortField: 'text'
        })
    });
</script>

The firefox debugger console says: TypeError: $(...).selectize is not a function

which, afaiu, means there is a duplicate jQuery or no jQuery at all. Adding jQuery in the :header_tags does not help, though.

Anybody can provide some hint, please?

maxrossello commented 9 years ago

Ok, found it. As expected, a silly thing...

maxrossello commented 9 years ago

Done. The approach I chose is to Selectize some core selectors in redmine_app__space, which also configures the css .selectize class as candidates. redmine_app_timesheets then adds the css class to its selectors.

Updated 1.5-dev and master branches.

Please let me know if everything works as expected. Cheers.

sammcj commented 9 years ago

wow that was fast! Thank you so much Max that's really great!

We'll update our plugin and let you know :)

If you're ever in Melbourne we certainly owe you a beer or two.

maxrossello commented 9 years ago

:-) remember to update both plugins, or it won't work

sammcj commented 9 years ago

Almost works @maxrossello , not sure why but when you view the timesheets application you get a 500, note that we have upgraded to Redmine 3.1.1 as well:

: SELECT DISTINCT "ts_permissions"."id" AS t0_r0, "ts_permissions"."order_id" AS t0_r1, "ts_permissions"."access" AS t0_r2, "ts_permissions"."principal_id" AS t0_r3, "ts_permissions"."is_primary" AS t0_r4, "versions"."id" AS t1_r0, "versions"."project_id" AS t1_r1, "versions"."name" AS t1_r2, "versions"."description" AS t1_r3, "versions"."effective_date" AS t1_r4, "versions"."created_on" AS t1_r5, "versions"."updated_on" AS t1_r6, "versions"."wiki_page_title" AS t1_r7, "versions"."status" AS t1_r8, "versions"."sharing" AS t1_r9, "versions"."in_timesheet" AS t1_r10, "versions"."is_order" AS t1_r11 FROM "ts_permissions" INNER JOIN "versions" ON "versions"."id" = "ts_permissions"."order_id" AND "versions"."is_order" = $1 WHERE "ts_permissions"."is_primary" = $2 AND "ts_permissions"."principal_id" IN (303, 290, 414, 422)  ORDER BY access DESC
Completed 500 Internal Server Error in 877ms (ActiveRecord: 47.6ms)

ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...."principal_id" IN (303, 290, 414, 422)  ORDER BY access DES...
                                                             ^
: SELECT DISTINCT "ts_permissions"."id" AS t0_r0, "ts_permissions"."order_id" AS t0_r1, "ts_permissions"."access" AS t0_r2, "ts_permissions"."principal_id" AS t0_r3, "ts_permissions"."is_primary" AS t0_r4, "versions"."id" AS t1_r0, "versions"."project_id" AS t1_r1, "versions"."name" AS t1_r2, "versions"."description" AS t1_r3, "versions"."effective_date" AS t1_r4, "versions"."created_on" AS t1_r5, "versions"."updated_on" AS t1_r6, "versions"."wiki_page_title" AS t1_r7, "versions"."status" AS t1_r8, "versions"."sharing" AS t1_r9, "versions"."in_timesheet" AS t1_r10, "versions"."is_order" AS t1_r11 FROM "ts_permissions" INNER JOIN "versions" ON "versions"."id" = "ts_permissions"."order_id" AND "versions"."is_order" = $1 WHERE "ts_permissions"."is_primary" = $2 AND "ts_permissions"."principal_id" IN (303, 290, 414, 422)  ORDER BY access DESC):
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'
greyman888 commented 9 years ago

This is a duplicate of #56. It occurs with Postgresql but not Mysql. I will spend some time this week to see if I can either fix it or provide more information to help solve it.

maxrossello commented 9 years ago

This is probably due to a change to ActiveRecord in Rails version used by Redmine 3.1. As we identify the culprit queries we can add an explicit select. This is not trivial from just the log because it is not so explicit.

The second log I think it is hardly a responsibility of the timesheet plugin:

Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include?

I can't see how the settings of another plugin (which seem to be nil) can be compromised by this plugin.

sammcj commented 9 years ago

Whoops good spotting Max - I've logged a ticket for that separate plugin ;)