Best way to create an interface for templates?


(Jay Pfaffman) #1

I would like for students in my class to be able to insert a set of checkboxes (I have installed GitHub - cpradio/discourse-plugin-checklist: A simple checklist rendering plugin for discourse) so that they can indicate that they have done whatever it is that they are supposed to have done for a given assignment.

The per-category template is not specific enough. I really need a per-topic template, but that seems unwieldy and of little use for Discourse’s main purpose.

I have hacked the discourse Poll UI (Thanks @cpradio!) plugin to pop up a window and let the user select one of several hard-coded (that is in the code) templates.

My next step is to move those templates from a controller to system settings.

What I think I want is to be able to add template_name:template_text pairs. Another might be to create a special template category and have my code pull out subject:body for its templates.

I have approximately 24 hours of Discourse plugin development experience. I’d appreciate a hint in which direction to head and some code examples.

Thanks.

My plugin, such as it is, is available on github.


Canned responses to help moderators encourage civilized discourse
Discourse for helpdesk use cases?
(Jeff Atwood) #2

Not really clear on this, can you show us a mockup graphic?


(Jay Pfaffman) #3

Button added to composer:

select template by name:

And clicking the insert button pushes a bunch of text into the composer. I’m using it for checkboxes so that students can check off things that they have done to satisfy an assignment. Being able to stick some arbitrary text into the composer might also be useful for a variety of reasons. We already have templates for categories, but users don’t have any choice of what they are or when they get inserted.

One solution would be for this template plugin to pull its text from topics in a category. Knowing almost nothing about developing for Discourse, that seems pretty easy as all those parts are there. If someone could point me toward code that would allow me to pull out subjects from topics in a category and then pull text from a topic, I would appreciate it.


(Jay Pfaffman) #4

Could someone throw me a bone? I think that if I had a clue what I was doing, this would be a 10 minute job. If I had a clue where some similar code was, I think could finish in a day or two, which would be awesome.

export default Ember.Controller.extend(ModalFunctionality, {
  templateName: "",
  templateType: "regular",
  templateTypes: [
-    { 'title': I18n.t("template_manager.template_type.regular"), 'value': "regular" },
-    and the rest of the templates
+   STUFF TO PULL Topic titles & topic_ids from category "templates"

  ],

.....

  actions: {
    apply: function() {
      var name = this.get("templateName"), type = this.get("templateType"), self = this, composerOutput = "";
-      if (type == "regular") {
-	composerOutput += "## I have:\r\n[] Described my learning process  \r\n [] Said how long it took  \r\n[ ] linked to my blog!  \r\n";
-      }
+   switch:
+      ID:
+	composerOutput += CONTENTS OF TOPIC SELECTED;
....

If I can get that done, this plugin will be pretty useable. Next steps would be to put a topic selector in settings so that one could choose the templates topic rather than having it hard-coded.

Thanks for any help.