Aggiungi pulsante di disconnessione al menu superiore

Ho un cliente con una community i cui membri utilizzano spesso computer ad accesso pubblico; durante i test hanno riscontrato che molti utenti faticano a trovare il link di disconnessione nel menu hamburger. Purtroppo, non credo esista un modo efficace per insegnare a tutti a premere ZZ.

Pertanto: sto cercando di aggiungere un pulsante logout al menu in alto.

Sembra che dovrei poter utilizzare (Superseded) Add a "+ New Topic" button on every page per creare non un nuovo argomento, ma per effettuare il logout, e che dovrebbe essere “facile” modificare questo createTopic in logout, dopodiché sarebbe tutto risolto.

https://github.com/discourse/discourse-new-topic-button-theme-component/blob/master/common/header.html#L39

Ho dato un’occhiata per un’ora o più, ma non riesco proprio a capire come fare.

4 Mi Piace

I’ll happily use what you come up with,

could you mimic the home button api function?

image

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href' , 'xxx')
</script>
1 Mi Piace

I’ve got the button OK, it’s the logout API that I can’t find.

3 Mi Piace

sorry, I do like the plan and hoped I could help, what does the $0 refer to and is it part of document.querySelector that may help?

image

1 Mi Piace

I got it! I won’t promise that it’ll work for you, but this might do it for you.

This is common/header.html

<script type="text/discourse-plugin" version="0.8">    
    const { iconNode } = require("discourse-common/lib/icon-library");
    const { logout } = require("discourse/lib/logout");

    api.decorateWidget("header-buttons:before", helper => {
        if (!Discourse.User.current()) return;
        currentUser = Discourse.User.current();


        let container = api.container,
        logout_text = 'Log Out', // button text!
        logout_title = 'Log Out',
        logout_icon = 'sign-out-alt',
        logout_button_class = "btn btn-default btn btn-icon-text",
        logout_button_helper = "button#logout",
        logout_label_helper = "span.d-button-label",
        composerModal = require("discourse/models/composer").default,
        composerController = container.lookup("controller:composer");

        const myLogout = function () {
            if (currentUser) {
                currentUser.destroySession();
            }
        };
 

        let currentUser = Discourse.User.current();
        let currentUsername = Discourse.User.current().username;
        return helper.h("span.header-links", [

        helper.h(
            logout_button_helper,
            {
              className: logout_button_class,
              title: logout_title,
              onclick: myLogout
            },
            [iconNode(logout_icon), helper.h(logout_label_helper, logout_text)]
          )        
      ])
    });
    </script>
14 Mi Piace

WTH Jay,

I put that script in and got a

Summary

a working button!
image

I’ll need to tune the look a bit but it works, great job!

Thanks for sharing :sunglasses:

4 Mi Piace

Hello Jay,
your code works like a charm!
I have a custom menu below the standard header. How can I relocate this button there? Screenshot by Lightshot
in order to create my custom navigation, I added HTML to section common -> header

thanks in advance

1 Mi Piace

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.