Documente Academic
Documente Profesional
Documente Cultură
on
DISCOURSE PLUGIN
BY
AT
1
A REPORT
ON
DISCOURSE PLUGIN
BY
2
ACKNOWLEDGEMENTS
3
BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE
PILANI (RAJASTHAN)
Practice School Division
4
Contents
1. Introduction 6
2. Objectives 9
3. Project Development 11
3.1 Softwares used………………………………………. 11
3.1.1 Docker………………………………………… 11
3.1.2 Ruby on rails…………………………………. 11
3.1.3 Ember.js………………………………………. 12
3.2 Developing the Plugin……………………………….. 12
3.3 Technical Details……………………………………… 14
4. Code 20
5. Summary 21
6. Conclusion 22
7. References 23
5
CHAPTER 1
INTRODUCTION
6
About the platform: Discourse
STEM Games platform has been built upon an existing platform
called Discourse. Discourse is a 100% open source discussion
platform built to be used in a variety of ways.
● Community moderation
● Spam blocking
● Badges
● Two-factor authentication
● Social media integration
● Topic summarization
● Easy collaboration
7
● Comprehensive APIs
● One-click upgrades
● 100% open source
8
CHAPTER 2
Objectives
The objectives of this project touch various aspects of online
learning and discussions. The main goal of this project is to
enable the users of a certain privilege to add suggested
post/prerequisite topics to a certain topic on discourse. This will
help streamline the learning process for the users and provide
them with a structured learning system. The step by step goals
are summarised as follows-
9
topic_id will be a unique ID identifying each topic. next_topics will
be a comma-separated list of topic_ids which will identify topics
added as post requisite topics. prev_topics will be a
comma-separated list of topic_ids which will identify prerequisite
topics. So, for example:
would imply that for the topic referenced by the ID 10109, the
post-requisites are the topics referenced by the IDs 20101 and
20117 and the prerequisites for the same are the topics
referenced by the IDs 10102, 10103 and 10106.
10
CHAPTER 3
Project Development
3.1 Softwares used
Our project majorly used the following softwares:
3.1.1 Docker
Docker is an open-source project that automates the deployment
of applications inside software containers. A docker container
holds a software in a complete file-system that contains every
dependency: code, run-time, system tools, system libraries -
anything that one can install on a server. This guarantees uniform
behavior, independent of the underlying host OS environment.
Docker provides an extra layer of abstraction and automation of
operating system level virtualization on Linux, without actually
using a virtual machine. It uses resource isolation features of
Linux kernel like cgroups and kernel namespaces, and a
union-capable file system such as aufs and others to allow
‘containers’ to run within a single Linux instance, avoiding the
overhead of starting and maintaining virtual machines.
3.1.2 Ruby on Rails
Ruby on Rails is a web application framework that includes
everything needed to create database-backed web applications
according to the Model-View-Controller (MVC) architecture.
Moreover, it is open-source and written in Ruby (which is also
open-source). It is an extremely productive web-application
framework which allows you to develop web application ten times
11
faster than Java frameworks. Rails shun configuration files in
favor of conventions, reflection, and dynamic runtime extensions.
3.1.3 Ember.js
Ember.js is an open-source JavaScript web framework, based on
the Model–view–viewmodel (MVVM) pattern. It allows developers
to create scalable single-page web applications by incorporating
common idioms and best practices into the framework.
Ember is used on many popular websites, including Discourse,
Groupon,LinkedIn, Vine, Twitch.tv, and Chipotle. Although
primarily considered a framework for the web, it is also possible to
build desktop and mobile applications in Ember.
3.2 Developing the Plugin
1. There was a need for Discourse to be used as an LMS.
2. A topic organizer plugin was conceptualized to streamline
the flow of learning
3. Workflow:
a. We coded for an option to be included in the topic
admin menu after every topic. The topic admin menu is
only visible to the admins and staff. Our plugin includes
a custom button in the topic admin menu which will only
be visible to users above a certain trust level. This
minimum trust level can be set by the admins in the
plugin settings page.
b. On clicking the button, a pop-up form shows up with a
search bar to search for topics to be included as
post/prerequisites.
12
c. Both the pop-up form with the search bar and the
button was created using Handlebars as a templating
tool and Ember.js was used to program the functionality
of the button and the search bar in the pop-up form.
d. On entering the search term, a list of topics drops down
as results, each with a checkbox next to it to allow the
user to select/deselect it.
e. Once selected, the topics will be available in a space
below the search bar
f. A radio button is available to switch between selecting
prerequisites and post-requisites.
g. A submit button will be available at the bottom of the
form, clicking this will submit the desired changes which
will then be pushed to the database in the table
mentioned in Chapter 2, Section 3 (page 9)
h. Following this, we will render the changes stored in the
database.
13
3.3 Technical details
Admin menu
User above a given privilege level, are shown an extra button in
the action bar. Clicking this button opens up the admin menu.
This menu allows administrators to perform a number of
functions including deleting topics, change topics etc.
The minimum trust level can be set by admin in the plugin settings
as shown in the figure below:
14
Fig 2: Plugin settings page
export default {
initialize(container) {
withPluginApi('0.8.24', function(api) {
api.decorateWidget('topic-admin-menu:adminMenuButtons',
(decorator) => {
// Adds the button to the admin menu
// and also allows for formatting of the button
return {
icon: 'tasks',
15
fullLabel: 'tl_post_lock.button_label',
action: 'actionTlLock'
}
});
api.attachWidgetAction('topic-admin-menu', 'actionTlLock',
() => {
// api.attachWidgetAction allows us to code the
functionality of the button
}
}
}
16
TOPIC ORGANIZER
Search
The search bar takes the typed input from the user and parses
the available topic names. It then outputs a list of topic names
with the given sequence of characters in their topic name. We
have made sure that the current topic is not displayed in the given
list. Only if a given topic is selected from the list will the plugin
allow the topic to be added to the post/prerequisite list. Hence, the
plugin will not allow a non-existent topic to be added.
17
Fig 4: Search bar
The topics that appear in the search bar are obtained by the fetch
function of javascript. The list of existing topics was fetched using
an API provided by Discourse. The response obtained was
converted to JSON format and then the topics were stored in an
array. Finally the search bar performs a filter on the topics list
according to the input given by the user in the search text field.
Database
The database uses JSON format to store the details of the
prerequisites as well as the post-requisites of a particular topic.
JSON (JavaScript Object Notation) is a lightweight
data-interchange format. It is easy for humans to read and write. It
is easy for machines to parse and generate. It is based on a
subset of the JavaScript Programming Language. We have used
the JSON element to store the topic_id of the post/prerequisite
topics. While displaying the required topic we extract the required
information of the topic from the topic_id of a given topic.
18
Displaying Post/prerequisites
In order to extend the Discourse web interface,discourse has
provided a mechanism called plugin outlets in handlebars
templates.It’s an extension point in the template that plugin
authors can use to add their own handlebars markup.
To display Prerequisites and Post Topics the plugin-outlets used
are topic-title and topic-above-footer-buttons respectively. The
use of these outlets allowed to display prerequisite topics after
topic title and post topics after the main content of current topic.
19
CHAPTER 4
Code
The directory structure of the plugin:
discourse-topic-organizer/
├── app
│ ├── controllers
│ │ ├── custom-public-button_controller.rb
│ │ └── notes_controller.rb
│ └── note_store.rb
├── assets
│ ├── javascripts
│ │ └── discourse
│ │ ├── connectors
│ │ │ └── after-topic-footer-main-buttons
│ │ │ └── custom-public-button.js.es6
│ │ ├── initializers
│ │ │ ├── admin_button.js.es6
│ │ │ └── prereq.js.es6
│ │ ├── models
│ │ │ └── note.js.es6
│ │ └── templates
│ │ └── connectors
│ │ ├── after-topic-footer-main-buttons
│ │ │ └── custom-public-button.hbs
│ │ ├── topic-above-footer-buttons
│ │ │ └── postreq.hbs
│ │ └── topic-title
│ │ └── prereq.hbs
│ └── stylesheets
│ └── custom-public-button.css
├── config
│ ├── locales
│ │ ├── client.en.yml
│ │ └── server.en.yml
│ └── settings.yml
├── plugin.rb
└── README.md
20
CHAPTER 5
A SUMMARY OF THE WORKFLOW
21
CHAPTER 6
CONCLUSION
We succeeded in making the discourse-topic-organizer plugin.
The plugin, as of now, has the following features:
● A button added to the topic admin menu widget which is
the starting point of the use of the plugin
● A search bar to search for the existing topics
● Radio buttons to separate selected topics to be added as
pre or post topics
● A sequencer option which allows at most 1 pre and 1 post
topic to be added to the current topic
● Two widget spaces, 1 each to display pre and post topics
assigned to the current topic
● The plugin has been designed so that it can be used only
by users above a certain trust level. This trust level can be
adjusted by the admins in the plugin settings page
22
CHAPTER 7
REFERENCES
● Ember.js:
https://guides.emberjs.com/release/tutorial/ember-cli/
● Discourse plugin:
https://meta.discourse.org/t/beginners-guide-to-creating-disc
ourse-plugins-part-1/30515
● Github: https://github.com/discourse/discourse
● Stack Overflow: https://stackoverflow.com/
● W3School:
https://www.w3schools.com/howto/howto_js_filter_lists.asp
● HTML: https://html-online.com/articles/simple-popup-box/
23