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

plugins
(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

(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.

(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?:

(Robin Ward) #33

It should! Is it not working for you?

(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:

(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!

(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
(Robin Ward) #41

Just so I can update the original post, what steps were required to fix this tutorial?

(David Taylor) #42

If it was what I said, then no changes, other than maybe a message to say how important it is that file names are exactly correct

(Mittineague) #43

I don’t know how far things should go for teaching prerequisite “basic knowledge”. But I think a lot of the troubles are when it is not only the first Discourse plugin but also an early venture into Ruby / Ember

That is, an unfamiliarity with the conventions that do “magic”. When structure and naming look like arbitrary is OK but it isn’t it can be a pain to figure out what’s wrong.

The “this can be whatever, this must be” stuff.

7 Likes
(Cheng Zheng) #44

Work for me!
2018-4-29

1. Code




2. Result

3 Likes
(Jay Pfaffman) #45

Glad it worked, but It is always better to post code than pictures of code.

3 Likes
(Cheng Zheng) #46

Thanks for reply
original post have all these code,
it’s not necessary for me to post code again.

The purpose of these picture is to show it work, give viewer a big picture view
(not for viewer to copy&paste)
(code in code editor have nicer code highlight)

(Josh) #47

If anyone runs into a testing error, I had to add id="show-tentacle" to the button component to get the tests to pass in part 6 of the tutorial:

<div class="buttons">
  {{d-button label="purple_tentacle.show" action="showTentacle" icon="eye" id="show-tentacle"}}
</div>
(Marcus Baw) #48

I found the Ember routing didn’t work until I commented out path: '/plugins' in the route-map file:

export default {
  resource: 'admin.adminPlugins',
  // path: '/plugins',
  map () {
    this.route('watch-mute')
  }
}

For some reason Ember was expecting a route at adminPlugins/watch-mute not at adminPlugins/plugins/watch-mute. Is this something I did wrong upstream in the routing call chain, or has something changed in the way Discourse/Ember handles these?