Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Session Copy in User List to Enhance Usability #5478

Open
wants to merge 2 commits into
base: 1.11.x
Choose a base branch
from

Conversation

bezael
Copy link

@bezael bezael commented May 4, 2024

The project aims to enhance functionality and usability in user management within an application by allowing administrators to easily copy the list of sessions a user is registered in. Currently, when accessing the user list and clicking on the session icon, a modal appears showing the active sessions of the selected user.

However, this modal automatically closes when it loses focus, which can be inconvenient for administrators who need to manipulate or reference this information more extensively.

To address this, a new option will be introduced in the general configuration file (configuration.php). This option, named "admin_user_list_allow_copy_to_clipboard_sessions_list," will enable administrators to activate or deactivate the functionality of copying the session list to the clipboard.

The option will accept boolean values, true or false, with the default being false.

In the user_list, we check the value of $allowSessionCopyToClipboard to allow copying.

@ywarnier
Copy link
Member

Altough I applaud the effort, thank you for the contribution, and apologize for the delay reviewing this, your PR just breaks the JS on that page. Maybe this is due to the Chamilo code evolving since you submitted the PR.

From your explanation, it would seem that the main JS block should have been located inside the function load_session_list() but it is now weirdly located inside the function load_course_list()...

@ywarnier
Copy link
Member

I've modified the JS section to this:

$htmlHeadXtra[] = '<script>
function load_course_list (div_course,my_user_id) {
    $.ajax({
        contentType: "application/x-www-form-urlencoded",
        beforeSend: function(myObject) {
            $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />");
        },
        type: "POST",
        url: "'.$url.'",
        data: "user_id="+my_user_id,
        success: function(datos) {
            $("div#"+div_course).html(datos);
            $("div#div_"+my_user_id).attr("class","blackboard_show");
            $("div#div_"+my_user_id).attr("style","");
        }
    });
}

function load_session_list(div_session, my_user_id) {
    $.ajax({
        contentType: "application/x-www-form-urlencoded",
        beforeSend: function (myObject) {
            $("div#" + div_session).html("<img src=\'.../inc/lib/javascript/indicator.gif\' />");
        },
        type: "POST",
        url: "'.$urlSession.'",
        data: "user_id=" + my_user_id,
        success: function (datos) {
            $("div#" + div_session).html(datos);
            $("divdiv_s_" + my_user_id).attr("class", "blackboard_show");
            $("divdiv_s_" + my_user_id).attr("style", "");'.
    ($allowSessionCopyToClipboard ?
        'var textToCopy = datos.replace(/<br\s*\/?>/gi, "\n");
            navigator.clipboard.writeText(textToCopy)
                .then(() => {
                    console.info("Text copied to clipboard");
                })
                .catch(err => {
                    console.error("Error copying to clipboard: ", err);
                });'
        : '')
    .'  }
    })
}

Which is in a nicer shape, but then if the setting is not set it, clicking the session icon doesn't do anything anymore (it does not list sessions as it should).
Enabling the configuration setting doesn't seem to do anything either, so there's definitely something still missing.

I'm happy to review this for an upcoming version, but please make sure it works before submitting (some of the apostrophes' escaping in your PR suggest it wouldn't have worked anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants