Beginner's Guide to Creating Discourse Plugins Part 5: Admin Interfaces

plugins
#21

That’s the file structure I have.

I don’t see a point in getting stuck on this, already hacked together a couple of rails sites and trying to absorb as much as possible.

Just going to leave this as some simple error on my part that I’ll come look back at later on and probably realize right away what it was.

Thanks, thou

0 Likes

(Robin Ward) #22

Another mistake of mine! I’ve updated the OP, thanks.

2 Likes

(Einsteino) #23

Is there any way I can change a global plugin setting, say, a siteSetting, from here?
I need admins to be able to use this interface to add data into a global array.

0 Likes

(Einsteino) #24

Discourse. does this, but is not persistent.

0 Likes

(Robin Ward) #25

You can update site settings via a custom interface but not automatically. You’ll have to define rails controllers and have them respond to REST calls which update the stuff. The Embedding interface does this if you want an example in the Discourse code base.

0 Likes

(Thanh Pham) #26

[quote=“eviltrout, post:25, topic:31761”]
assets/javascripts/discourse/templates/admin/plugins-purple-tentacle.hbs

{{#if tentacleVisible}}
  <div class='tentacle'>
    <img src="http://eviltrout.com/images/tentacle.gif">
  </div>
{{/if}}

<div class='buttons'>
  {{d-button label="purple_tentacle.show" action="showTentacle" icon="eye"}}
</div>
```[/quote]

{{d-button label=“purple_tentacle.show” action=“showTentacle” icon=“eye”}}


This line should have `id="show-tentacle"` for test in Part 6 :smile:
4 Likes

(Aman Jagga) #27
export default {
  resource: 'admin.adminPlugins',
  path: '/plugins',
  map() {
    this.route('purple-tentacle');
  }
};

What do we exactly specify in the resource field here?

0 Likes

(Robin Ward) #28

If you’re following this tutorial, you’d leave it as is, because the route is embedded in admin/plugins

0 Likes

(Aman Jagga) #29

I am not embedding it in admin plugins, I want to embed it in a new independent static page
@eviltrout …please help, I couldnt find any tutorial for this

0 Likes

(Robin Ward) #30

I suggest making a new topic in the #dev category asking for advice, and giving as much information as possible. It’s hard to help someone without knowing what they want.

0 Likes

(James Kiesel) #31

I’ve recently done this in the Lattice plugin, where I was able to get this to go without specifying a resource field.

# lattice-route-map.js.es6
export default function() {
  this.resource('lattice', { path: '/lattices/:id' })
}

Fun fact: Discourse does pattern matching on filenames to determine what to cook into the routes. Anything matching /route-map$/ will attempt to get baked into the router.

3 Likes

(André Karge) #32

Does this still work with Ember v2.10?:

0 Likes

(Robin Ward) #33

It should! Is it not working for you?

0 Likes

(André Karge) #34

Hi Robin,
It does work but I was suspicious that this might not work since you switched to Ember v2.10 all resources in the app-route-map were changed to routes.

2 Likes

#35

@gdpelican, thanks a million for advertising this! Your plugin is the only example I found about how to create a public route (non-admin) from a plugin.

3 Likes

(James Kiesel) #36

Seems like a common enough plugin use case that it would be really nice to put it into a plugin helper, something like

define_route :get, '/lattices', 'lattices#index'
define_route :post, '/lattices', 'lattices#create'

Rather than having plugin authors care about rails engines and mounting and whatnot.

If I get back to having some time to work on Discourse, I may do that :slight_smile:

5 Likes

(Jen) #37

same issue with the title, renaming to client.en.yml has worked for me :slight_smile:

0 Likes

(Jen) #38

Hi,
My “show purple tentacle” (I’ve used other namings) button is not displaying.

discourse/plugins/dis-plug/assets/javascripts/discourse/templates/admin/dis-plug.hbs

{{#if imgVisible}}
  <div class='tentacle'>
    <img src="https://media.giphy.com/media/oiGCnybFPh6Q8/giphy.gif">
  </div>
{{/if}}

<div class='buttons'>
  {{d-button label="dis-plug.show" action="showImg" icon="eye"}}
</div>

I rm -rf tmp; bundle exec rails s when I start the server. I’ve compared the code with eviltrout’s repo and all seems alright. What could be the issue? Thanks!

0 Likes

(David Taylor) #39

The auto-loading of handlebars templates (and other ember related things) is quite sensitive to file names - it might be as simple as adding plugins- to the beginning of the file name so it matches the instructions closer.

If that doesn’t work, I’d suggest trying the tutorial again, but using exactly the plugin & file names specified in the instructions. Then if that works adapt it from there

4 Likes

(Jen) #40

it has worked like magic!

1 Like