[Userscript] Self-Study Quiz

I know how it works, I’m just making a suggestion

Why? Could just be an array of items as returned by WKOF. I think it makes a lot of sense to be able to provide an array of items in addition to the filters

1 Like

You are right. I didn’t think about that. Or better, it could be passed as a parameter in place of the presets. No need to modify WKOF this way. This would require to change Self Study Code to accommodate this.

From an Item Inspector perspective there is a little bit of work to make sure the right items are ready but this is simple to do. It is simpler than the filter.

I think we are comparing a good solution with a better one. The strong point of the filter is it works with Self-Study Quiz as it is. @rfindley is overloaded with work and I don’t think the array of items provides enough advantages over the filter to be worth the effort.

1 Like

Rather than permanently add the filter to the registry, you could add it immediately before opening the quiz, and remove it immediately after the quiz is closed.

…though I don’t know if there is a callback for when the quiz closes.

Either way, I’m happy to add someone’s enhancements to the quiz API or Wkof… whichever makes more sense. I always had bigger plans for the quiz interface, but there wasn’t anyone using it back then, so I just slapped together a simple interface.

2 Likes

I don’t find one. Here is the function closing the quiz.

    //========================================================================
    // close_quiz()
    //------------------------------------------------------------------------
    function close_quiz(e) {
        unfreeze_body();
        $('body').off('.ss_quiz_key');
        quiz.dialog.remove();
        wkof.Settings.background.close();
    }

The only possibility for a callback is in the quiz.dialog.remove() call. Here is how quiz.dialog is initialized.

var dialog = (quiz.dialog = $(quiz_html));

This is a JQuery object. There is no callback.

The advantage of the no_ui flag is its simplicity. It is a flag to add when registering the filter and a single line of code in the UI construction loop for filters.

Do you have any reasons to prefer the callback approach?

The simple interface fulfills my needs perfectly. I can send any quiz I want no matter how constructed to Self Study Quiz. There is no need for more functionality. The code is written and it works well. There is no urge to change. I can and will roll out my code even if you don’t implement the no_ui flag. People will just see an inert filter in their Self Study Quiz settings. There is no damage. I can put a hover_tip explaining what this filter is about and only the fools and the curious will turn it on. They will see it does nothing good and they will turn it off. The flag just makes for a cleaner UI in Self Study Quiz.

I am thinking about the callback approach. It is not bulletproof. When i start the quiz I put the filter on. If people go to the settings before they take their quiz they will see the filter. With the no_ui flag approach the filter will be hidden in any scenario.

Yes, it represents the filter you passed to ss_quiz.

Question: When the user wants to do a quiz that is not filtered by Item Inspector, how would they deselect it as a filter without an entry in the UI? Or are you saying that no_ui would have a checkbox but no field to edit?

[edit: Or would it simply default to deselected in all presets except the custom one passed by Item Inspector when opening Self-Study via its API?]

This is how it should be. The point of hiding it is to make sure the user never manually selects it. It could only cause them trouble.

I have run some test to verify the no_ui flag behave as it should. I had set a console.log command in my filter to trace when it is called. Here is what I found.

  • When I invoke Self Study from Item Inspector it is always called. This is because I explicitly request for it in the invocation parameters.
  • If I add the test for ‘no_ui’ flag in Self Study the filter does not show in the settings UI and the filter is not called. This is the wanted behavior.
  • The filter is called from Self Study when we let it show in the settings UI and its enabling checkbox is checked. This is problematic.

I conclude that the no_ui flag does exactly what we want to do.

I looked at the fetch_items function which is responsible for calling wkof.ItemData.get_items. It builds the config parameter by going through the filters in the settings. If the Item Inspector filter is not in the settings it cannot finds its way in the ItemData.get_items call. This is exactly what we want.

Thanks for the up-front work! I’ll add the no_ui to Self Study. Probably sometime tonight.

2 Likes

:point_right: [v3.0.30] - Added support for ‘.no_ui’ and ‘.validate’ on filter configurations.

I’ve confirmed that .no_ui works in the update, but didn’t have a quick way to test the .validate function.
So, if you use it, please let me know if there are any problems.

1 Like

I use it. It works fine. You can merge it.

I mean, I already posted it on Greasyfork. But in case I have any typos or whatever that cause it to not work, let me know.

1 Like

Yeah I just noticed. I tested the new 3.0.30 version. The validation works my my test filter.

1 Like

Also, just added an ‘.on_close’ option on the custom quiz config. v3.0.31

[edit: I need to find a good place to document the self-study options :thinking: ]
[edit2: And time to do so… ]

2 Likes

You mean I can supply a callback through the on_close property of the custom config object? Cool I can perform clean up tasks after running the quiz. Thanks a lot. :+1:

What is the signature of the call back? I guess it is just a call with no parameters.

I tested the on_close callback. It works.

Correct. I thought about passing back the config that was passed in, but the caller could just as easily bind some custom parameters to their callback.

edit: I suppose I could return some quiz results, though I’m not sure if that would be useful since the user may have re-quized.

1 Like

I know what is the config since I initiated the call. Self Study locks the screen by setting up the background. We can’t run many quizzes in parallel. There is no need to identify which quiz was called because there can be just one…

You may return an array of [preset_names, results] pairs for the session. I don’t have uses for this but someone else may.

Edit: I wonder how the quiz items are chosen when the Maximum Quiz Size parameter is non zero? Are they picked randomly? I have noticed that if you reshuffled the same items come back, but if you close and restart Self Study afresh new items show up.

The For scripter section in the top post was sufficient for me. You just need to add a note on the on_close callback there, unless there are more options I am unaware of.