FEATURE: Rename from Knowledge Explorer to Docs (#27)

After internal discussion, the team decided to rename this plugin to `discourse-docs`. No substantial changes made here aside from a settings migration.
This commit is contained in:
Justin DiRose 2021-01-18 10:38:09 -06:00 committed by GitHub
parent cb7c12defe
commit f32aebdba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 221 additions and 215 deletions

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
module KnowledgeExplorer
class KnowledgeExplorerController < ApplicationController
requires_plugin 'knowledge-explorer'
module Docs
class DocsController < ApplicationController
requires_plugin 'docs'
skip_before_action :check_xhr, only: [:index]
@ -18,7 +18,7 @@ module KnowledgeExplorer
page: params[:page]
}
query = KnowledgeExplorer::Query.new(current_user, filters).list
query = Docs::Query.new(current_user, filters).list
if filters[:topic].present?
begin
@ -45,7 +45,7 @@ module KnowledgeExplorer
end
def get_topic(topic, current_user)
return nil unless topic_in_explorer(topic.category_id, topic.tags)
return nil unless topic_in_docs(topic.category_id, topic.tags)
topic_view = TopicView.new(topic.id, current_user)
guardian = Guardian.new(current_user)
@ -53,13 +53,12 @@ module KnowledgeExplorer
TopicViewSerializer.new(topic_view, scope: guardian, root: false)
end
def topic_in_explorer(category, tags)
category_match = KnowledgeExplorer::Query.categories.include?(category.to_s)
def topic_in_docs(category, tags)
category_match = Docs::Query.categories.include?(category.to_s)
tags = tags.pluck(:name)
tag_match = KnowledgeExplorer::Query.tags.any? { |tag| tags.include?(tag) }
tag_match = Docs::Query.tags.any? { |tag| tags.include?(tag) }
category_match || tag_match
end
end
end

View File

@ -0,0 +1,4 @@
<%- if SiteSetting.docs_enabled%>
User-agent: *
Disallow: /docs/
<% end %>

View File

@ -1,4 +0,0 @@
<%- if SiteSetting.knowledge_explorer_enabled %>
User-agent: *
Disallow: /knowledge-explorer/
<% end %>

View File

@ -3,7 +3,7 @@ import { debounce } from "@ember/runloop";
import discourseDebounce from "discourse-common/lib/debounce";
export default Component.extend({
classNames: "knowledge-explorer-search",
classNames: "docs-search",
debouncedSearch(term) {
// TODO: Use discouseDebounce when discourse 2.7 gets released.

View File

@ -2,7 +2,7 @@ import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
classNames: "knowledge-explorer-topic-list",
classNames: "docs-topic-list",
@discourseComputed("order")
sortTitle(order) {
return order === "title";
@ -15,7 +15,7 @@ export default Component.extend({
// need to handle clicks here since links are in a raw view
click(e) {
if (e.target.classList.contains("knowledge-explorer-topic-link")) {
if (e.target.classList.contains("docs-topic-link")) {
const topicId = e.target.dataset.topicId;
this.selectTopic(topicId);
return false;

View File

@ -3,7 +3,7 @@ import { reads } from "@ember/object/computed";
import { computed } from "@ember/object";
export default Component.extend({
classNames: "knowledge-explorer-topic",
classNames: "docs-topic",
originalPostContent: reads("post.cooked"),
@ -27,16 +27,12 @@ export default Component.extend({
didInsertElement() {
this._super(...arguments);
document
.querySelector("body")
.classList.add("archetype-knowledge-explorer-topic");
document.querySelector("body").classList.add("archetype-docs-topic");
},
willDestroyElement() {
this._super(...arguments);
document
.querySelector("body")
.classList.remove("archetype-knowledge-explorer-topic");
document.querySelector("body").classList.remove("archetype-docs-topic");
},
});

View File

@ -3,7 +3,7 @@ import { inject } from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import { alias, readOnly, equal } from "@ember/object/computed";
import { on } from "discourse-common/utils/decorators";
import KnowledgeExplorer from "discourse/plugins/discourse-knowledge-explorer/discourse/models/knowledge-explorer";
import Docs from "discourse/plugins/discourse-docs/discourse/models/docs";
import { getOwner } from "@ember/application";
export default Controller.extend({
@ -69,7 +69,7 @@ export default Controller.extend({
canFilterSolved() {
return (
this.siteSettings.solved_enabled &&
this.siteSettings.knowledge_explorer_add_solved_filter
this.siteSettings.docs_add_solved_filter
);
},
@ -157,7 +157,7 @@ export default Controller.extend({
if (this.canLoadMore && !this.isLoadingMore) {
this.set("isLoadingMore", true);
KnowledgeExplorer.loadMore(this.loadMoreUrl).then((result) => {
Docs.loadMore(this.loadMoreUrl).then((result) => {
const topics = this.topics.concat(result.topics.topic_list.topics);
this.setProperties({
@ -179,7 +179,7 @@ export default Controller.extend({
returnToList() {
this.set("selectedTopic", null);
getOwner(this).lookup("router:main").transitionTo("knowledgeExplorer");
getOwner(this).lookup("router:main").transitionTo("docs");
},
},
});

View File

@ -2,7 +2,7 @@ import Controller from "@ember/controller";
import { inject } from "@ember/controller";
export default Controller.extend({
indexController: inject("knowledgeExplorer.index"),
indexController: inject("docs.index"),
actions: {
updateSelectedCategories(category) {
this.indexController.send("updateSelectedCategories", category);

View File

@ -1,5 +1,5 @@
export default function () {
this.route("knowledgeExplorer", { path: "/docs" }, function () {
this.route("docs", { path: "/docs" }, function () {
this.route("index", { path: "/" });
});
}

View File

@ -3,9 +3,9 @@ import { withPluginApi } from "discourse/lib/plugin-api";
function initialize(api) {
api.decorateWidget("hamburger-menu:generalLinks", () => {
return {
route: "knowledgeExplorer",
label: "knowledge_explorer.title",
className: "knowledge-explorer-link",
route: "docs",
label: "docs.title",
className: "docs-link",
};
});
@ -13,11 +13,11 @@ function initialize(api) {
}
export default {
name: "setup-knowledge-explorer",
name: "setup-docs",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
if (!siteSettings.knowledge_explorer_enabled) {
if (!siteSettings.docs_enabled) {
return;
}
withPluginApi("0.8", (api) => initialize(api));

View File

@ -2,9 +2,9 @@ import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import Topic from "discourse/models/topic";
const KnowledgeExplorer = EmberObject.extend({});
const Docs = EmberObject.extend({});
KnowledgeExplorer.reopenClass({
Docs.reopenClass({
list(params) {
let filters = [];
if (params.filterCategories) {
@ -65,4 +65,4 @@ KnowledgeExplorer.reopenClass({
},
});
export default KnowledgeExplorer;
export default Docs;

View File

@ -1,6 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import KnowledgeExplorer from "discourse/plugins/discourse-knowledge-explorer/discourse/models/knowledge-explorer";
import Docs from "discourse/plugins/discourse-docs/discourse/models/docs";
export default DiscourseRoute.extend({
queryParams: {
@ -16,16 +16,16 @@ export default DiscourseRoute.extend({
},
},
model(params) {
this.controllerFor("knowledgeExplorer.index").set("isLoading", true);
return KnowledgeExplorer.list(params).then((result) => {
this.controllerFor("knowledgeExplorer.index").set("isLoading", false);
this.controllerFor("docs.index").set("isLoading", true);
return Docs.list(params).then((result) => {
this.controllerFor("docs.index").set("isLoading", false);
return result;
});
},
titleToken() {
const model = this.currentModel;
const pageTitle = I18n.t("knowledge_explorer.title");
const pageTitle = I18n.t("docs.title");
if (model.topic.title && model.topic.category_id) {
const categoryName = this.site.categories.findBy(
"id",

View File

@ -0,0 +1,10 @@
<a {{action "selectCategory"}} class="docs-item docs-category {{if category.active 'selected'}}">
{{#unless category.active}}
{{d-icon "plus"}}
{{/unless}}
{{#if category.active}}
{{d-icon "times-circle"}}
{{/if}}
<span class="docs-item-id category-id">{{categoryName}}</span>
<span class="docs-item-count category-count">{{category.count}}</span>
</a>

View File

@ -1,16 +1,16 @@
<span class="knowledge-explorer-search-wrapper">
<span class="docs-search-wrapper">
{{input
type="text"
value=(readonly searchTerm)
input=(action "onSearchTermChange" value="target.value")
class="no-blur knowledge-explorer-search-bar"
class="no-blur docs-search-bar"
autocorrect="off"
placeholder=(i18n "knowledge_explorer.search.placeholder")
placeholder=(i18n "docs.search.placeholder")
autocapitalize="off"
}}
{{#if searchTerm}}
{{d-button action=(action "clearSearch") class="clear-search" label="knowledge_explorer.search.clear"}}
{{d-button action=(action "clearSearch") class="clear-search" label="docs.search.clear"}}
{{else}}
{{d-icon "search"}}
{{/if}}

View File

@ -0,0 +1,10 @@
<a {{action "selectTag"}} class="docs-item docs-tag {{if tag.active 'selected'}} {{if subtag 'subtag'}}">
{{#unless tag.active}}
{{d-icon "plus"}}
{{/unless}}
{{#if tag.active}}
{{d-icon "times-circle"}}
{{/if}}
<span class="docs-item-id tag-id">{{tag.id}}</span>
<span class="docs-item-count tag-count">{{tag.count}}</span>
</a>

View File

@ -2,7 +2,7 @@
<table class="topic-list">
<thead>
<th {{action "sortListTitle"}}>
{{i18n 'knowledge_explorer.column_titles.topic'}}
{{i18n 'docs.column_titles.topic'}}
{{#if sortTitle}}
{{#if ascending}}
{{d-icon 'angle-up'}}
@ -12,7 +12,7 @@
{{/if}}
</th>
<th {{action "sortListActivity"}}>
{{i18n 'knowledge_explorer.column_titles.activity'}}
{{i18n 'docs.column_titles.activity'}}
{{#if sortActivity}}
{{#if ascending}}
{{d-icon 'angle-up'}}
@ -24,7 +24,7 @@
</thead>
<tbody>
{{#each topics as |topic|}}
{{raw "knowledge-explorer-topic-list-item" topic=topic}}
{{raw "docs-topic-list-item" topic=topic}}
{{/each}}
</tbody>
</table>

View File

@ -0,0 +1,22 @@
{{d-button
label="docs.topic.back"
class="docs-nav-link return"
action=return
}}
<div class="topic-content">
<h1>{{topic.unicode_title}}</h1>
{{mount-widget
widget="post"
model=model
args=post
}}
{{share-popup topic=model.topic}}
</div>
<a class="docs-nav-link more" href="/t/{{topic.id}}">
{{d-icon "far-comment"}} {{i18n 'docs.topic.navigate_to_topic'}}
</a>
{{plugin-outlet name="after-docs-topic"}}

View File

@ -1,10 +0,0 @@
<a {{action "selectCategory"}} class="knowledge-explorer-item knowledge-explorer-category {{if category.active 'selected'}}">
{{#unless category.active}}
{{d-icon "plus"}}
{{/unless}}
{{#if category.active}}
{{d-icon "times-circle"}}
{{/if}}
<span class="knowledge-explorer-item-id category-id">{{categoryName}}</span>
<span class="knowledge-explorer-item-count category-count">{{category.count}}</span>
</a>

View File

@ -1,10 +0,0 @@
<a {{action "selectTag"}} class="knowledge-explorer-item knowledge-explorer-tag {{if tag.active 'selected'}} {{if subtag 'subtag'}}">
{{#unless tag.active}}
{{d-icon "plus"}}
{{/unless}}
{{#if tag.active}}
{{d-icon "times-circle"}}
{{/if}}
<span class="knowledge-explorer-item-id tag-id">{{tag.id}}</span>
<span class="knowledge-explorer-item-count tag-count">{{tag.count}}</span>
</a>

View File

@ -1,22 +0,0 @@
{{d-button
label="knowledge_explorer.topic.back"
class="knowledge-explorer-nav-link return"
action=return
}}
<div class="topic-content">
<h1>{{topic.unicode_title}}</h1>
{{mount-widget
widget="post"
model=model
args=post
}}
{{share-popup topic=model.topic}}
</div>
<a class="knowledge-explorer-nav-link more" href="/t/{{topic.id}}">
{{d-icon "far-comment"}} {{i18n 'knowledge_explorer.topic.navigate_to_topic'}}
</a>
{{plugin-outlet name="after-knowledge-explorer-topic"}}

View File

@ -1,33 +1,33 @@
{{#conditional-loading-spinner condition=isLoading}}
{{#if emptyTopics}}
<span class="no-topics-found">{{html-safe (i18n 'knowledge_explorer.no_topics')}}</span>
<span class="no-topics-found">{{html-safe (i18n 'docs.no_topics')}}</span>
{{else}}
<div class="knowledge-explorer-browse">
<div class="docs-browse">
{{#if site.mobileView}}
{{#unless selectedTopic}}
{{d-button class="knowledge-explorer-expander" icon=(if expandedFilters "angle-up" "angle-down") action=(action "toggleFilters") label="knowledge_explorer.filter_button"}}
{{d-button class="docs-expander" icon=(if expandedFilters "angle-up" "angle-down") action=(action "toggleFilters") label="docs.filter_button"}}
{{/unless}}
{{/if}}
<div class="knowledge-explorer-filters">
<div class="docs-filters">
{{#if expandedFilters}}
{{#if canFilterSolved}}
<div class="knowledge-explorer-items knowledge-explorer-solved">
<label class="checkbox-label knowledge-explorer-item">
<div class="docs-items docs-solved">
<label class="checkbox-label docs-item">
{{input
type="checkbox"
checked=(readonly filterSolved)
change=(action "onChangeFilterSolved" value="target.checked")
}}
{{i18n "knowledge_explorer.filter_solved"}}
{{i18n "docs.filter_solved"}}
</label>
</div>
{{/if}}
{{#if categories}}
<div class="knowledge-explorer-items knowledge-explorer-categories">
<h3>{{i18n 'knowledge_explorer.categories'}}</h3>
<div class="docs-items docs-categories">
<h3>{{i18n 'docs.categories'}}</h3>
{{#each categories as |category|}}
{{knowledge-explorer-category
{{docs-category
category=category
selectCategory=(action "updateSelectedCategories"
tagName="")
@ -36,10 +36,10 @@
</div>
{{/if}}
{{#if tags}}
<div class="knowledge-explorer-items knowledge-explorer-tags">
<h3>{{i18n 'knowledge_explorer.tags'}}</h3>
<div class="docs-items docs-tags">
<h3>{{i18n 'docs.tags'}}</h3>
{{#each tags as |tag|}}
{{knowledge-explorer-tag
{{docs-tag
tag=tag
selectTag=(action "updateSelectedTags")
}}
@ -50,26 +50,26 @@
</div>
{{#if selectedTopic}}
{{#conditional-loading-spinner condition=isTopicLoading}}
{{knowledge-explorer-topic topic=topic return=(action "returnToList")}}
{{docs-topic topic=topic return=(action "returnToList")}}
{{/conditional-loading-spinner}}
{{else}}
<div class="knowledge-explorer-results">
<div class="docs-results">
{{#if isSearchingOrFiltered}}
{{#if emptyResults}}
<div class="result-count no-result">
{{i18n 'search.no_results'}}
</div>
{{plugin-outlet name="after-knowledge-explorer-empty-results"}}
{{plugin-outlet name="after-docs-empty-results"}}
{{else}}
<div class="result-count">
{{i18n 'knowledge_explorer.search.results'
{{i18n 'docs.search.results'
count=topicCount
}}
</div>
{{/if}}
{{/if}}
{{#unless emptyResults}}
{{knowledge-explorer-topic-list
{{docs-topic-list
topics=topics
ascending=ascending
order=orderColumn

View File

@ -0,0 +1 @@
<a data-topic-id="{{topic.id}}" class="docs-topic-link">{{{topic.fancyTitle}}}</a>

View File

@ -2,7 +2,7 @@
<td class="main-link">
<span class="link-top-line">
{{~raw "topic-status" topic=topic}}
{{~raw "knowledge-explorer-topic-link" topic=topic}}
{{~raw "docs-topic-link" topic=topic}}
</span>
<span class="link-bottom-line">
{{category-link topic.category}}

View File

@ -0,0 +1,9 @@
<div class="docs">
{{plugin-outlet name="before-docs-search" args=(hash selectCategory=(action "updateSelectedCategories"))}}
{{docs-search
searchTerm=(readonly indexController.searchTerm)
onSearch=(action "performSearch")
}}
{{outlet}}
</div>

View File

@ -1 +0,0 @@
<a data-topic-id="{{topic.id}}" class="knowledge-explorer-topic-link">{{{topic.fancyTitle}}}</a>

View File

@ -1,9 +0,0 @@
<div class="knowledge-explorer">
{{plugin-outlet name="before-knowledge-explorer-search" args=(hash selectCategory=(action "updateSelectedCategories"))}}
{{knowledge-explorer-search
searchTerm=(readonly indexController.searchTerm)
onSearch=(action "performSearch")
}}
{{outlet}}
</div>

View File

@ -1,4 +1,4 @@
.knowledge-explorer-search-wrapper {
.docs-search-wrapper {
position: relative;
width: 500px;
.d-icon {
@ -24,7 +24,7 @@
}
}
.knowledge-explorer-search {
.docs-search {
align-items: center;
background-color: var(--primary-very-low, $primary-very-low);
display: flex;
@ -34,20 +34,20 @@
// More breathing room on larger screens
margin-bottom: 2em;
}
.knowledge-explorer-search-bar {
.docs-search-bar {
height: 50px;
margin-bottom: 0px;
width: 100%;
}
}
.knowledge-explorer-browse {
.docs-browse {
display: flex;
.loading-container {
display: flex;
flex-basis: 100%;
padding: 0.625em 0 0.625em 0.625em;
}
.knowledge-explorer-results {
.docs-results {
display: flex;
flex-direction: column;
flex-basis: 100%;
@ -56,7 +56,7 @@
padding-left: 0.625em;
}
}
.knowledge-explorer-filters {
.docs-filters {
margin-top: 0.15em;
flex: 0 1 20%;
@include breakpoint(tablet, min-width) {
@ -66,7 +66,7 @@
// be more narrow than content if needed
min-width: 175px;
}
.knowledge-explorer-items {
.docs-items {
padding: 0.57em 1em 1em 0;
a {
@ -79,13 +79,13 @@
font-size: $font-up-1;
}
.knowledge-explorer-item-count {
.docs-item-count {
margin-left: auto;
color: var(--primary-high, $primary-high);
font-size: $font-down-1;
}
.knowledge-explorer-item {
.docs-item {
display: flex;
align-items: center;
cursor: pointer;
@ -121,7 +121,7 @@
font-weight: bold;
}
}
.knowledge-explorer-topic-list {
.docs-topic-list {
flex-basis: 100%;
th {
@ -145,7 +145,7 @@
font-weight: normal;
font-size: $font-down-1;
}
.knowledge-explorer-topic-link {
.docs-topic-link {
color: var(--tertiary, $tertiary);
cursor: pointer;
display: inline-block;
@ -154,10 +154,10 @@
}
}
}
.knowledge-explorer-topic {
.docs-topic {
display: flex;
flex-direction: column;
.knowledge-explorer-nav-link {
.docs-nav-link {
font-weight: 700;
&.return {
align-items: center;

View File

@ -1,60 +1,60 @@
.mobile-view {
.knowledge-explorer {
.knowledge-explorer-search-wrapper {
.docs {
.docs-search-wrapper {
display: flex;
justify-content: center;
}
.knowledge-explorer-search {
.docs-search {
font-size: $font-up-2;
padding: 0.5em 0;
.knowledge-explorer-search-bar {
.docs-search-bar {
width: calc(100vw - 2em);
}
}
.knowledge-explorer-browse {
.knowledge-explorer-items {
.docs-browse {
.docs-items {
padding-right: 0;
}
flex-direction: column;
.knowledge-explorer-results .result-count {
.docs-results .result-count {
padding-left: 0;
}
.knowledge-explorer-topic-list {
.docs-topic-list {
flex-basis: 100%;
}
.knowledge-explorer-topic-link {
.docs-topic-link {
padding-right: 0.25em;
}
.loading-container {
padding: 0.625em 0;
}
.knowledge-explorer-topic {
.docs-topic {
width: calc(100vw - 20px);
}
}
}
.knowledge-explorer-filters {
.docs-filters {
margin-top: 0;
background: var(--primary-very-low, $primary-very-low);
padding: 0 0.5em;
.knowledge-explorer-items:first-of-type {
.docs-items:first-of-type {
margin-top: 1em;
}
+ .knowledge-explorer-results {
+ .docs-results {
margin-top: 2em;
}
}
.archetype-knowledge-explorer-topic {
.knowledge-explorer-filters {
.archetype-docs-topic {
.docs-filters {
display: none;
}
}
.knowledge-explorer-expander {
.docs-expander {
margin: 1em 0 0 0;
width: 100%;
}

View File

@ -1,11 +1,11 @@
en:
js:
knowledge_explorer:
title: "Knowledge Explorer"
docs:
title: "Docs"
column_titles:
topic: "Topic"
activity: "Activity"
no_topics: "No topics in Knowledge Explorer."
no_topics: "No topics in Docs."
categories: "Categories"
tags: "Tags"
search:

View File

@ -1,6 +1,6 @@
en:
site_settings:
knowledge_explorer_enabled: "Enable the Knowledge Explorer Plugin"
knowledge_explorer_categories: "A list of category slugs to include in the knowledge explorer"
knowledge_explorer_tags: "A list of tags to include in the knowledge explorer"
knowledge_explorer_add_solved_filter: "Adds a filter for solved topics -- requires Discourse Solved to be installed and enabled"
docs_enabled: "Enable the Docs Plugin"
docs_categories: "A list of category slugs to include in docs"
docs_tags: "A list of tags to include in docs"
docs_add_solved_filter: "Adds a filter for solved topics -- requires Discourse Solved to be installed and enabled"

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
require_dependency 'knowledge_explorer_constraint'
require_dependency 'docs_constraint'
KnowledgeExplorer::Engine.routes.draw do
get '/' => 'knowledge_explorer#index', constraints: KnowledgeExplorerConstraint.new
get '.json' => 'knowledge_explorer#index', constraints: KnowledgeExplorerConstraint.new
Docs::Engine.routes.draw do
get '/' => 'docs#index', constraints: DocsConstraint.new
get '.json' => 'docs#index', constraints: DocsConstraint.new
end

View File

@ -1,15 +1,15 @@
plugins:
knowledge_explorer_enabled:
docs_enabled:
default: false
client: true
knowledge_explorer_categories:
docs_categories:
type: category_list
default: ""
client: true
knowledge_explorer_tags:
docs_tags:
type: tag_list
default: ""
client: true
knowledge_explorer_add_solved_filter:
docs_add_solved_filter:
default: false
client: true

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
#
class RenameKnowledgeExplorerSettings < ActiveRecord::Migration[6.0]
def up
execute "UPDATE site_settings SET name = 'docs_enabled' WHERE name = 'knowledge_explorer_enabled'"
execute "UPDATE site_settings SET name = 'docs_categories' WHERE name = 'knowledge_explorer_categories'"
execute "UPDATE site_settings SET name = 'docs_tags' WHERE name = 'knowledge_explorer_tags'"
execute "UPDATE site_settings SET name = 'docs_add_solved_filter' WHERE name = 'knowledge_explorer_add_solved_filter'"
end
def down
execute "UPDATE site_settings SET name = 'knowledge_explorer_enabled' WHERE name = 'docs_enabled'"
execute "UPDATE site_settings SET name = 'knowledge_explorer_categories' WHERE name = 'docs_categories'"
execute "UPDATE site_settings SET name = 'knowledge_explorer_tags' WHERE name = 'docs_tags'"
execute "UPDATE site_settings SET name = 'knowledge_explorer_add_solved_filter' WHERE name = 'docs_add_solved_filter'"
end
end

View File

@ -1,12 +1,12 @@
# frozen_string_literal: true
module ::KnowledgeExplorer
module ::Docs
class Engine < ::Rails::Engine
isolate_namespace KnowledgeExplorer
isolate_namespace Docs
config.after_initialize do
Discourse::Application.routes.append do
mount ::KnowledgeExplorer::Engine, at: '/docs'
mount ::Docs::Engine, at: '/docs'
get '/knowledge-explorer', to: redirect("/docs")
end
end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
module KnowledgeExplorer
module Docs
class Query
def initialize(user = nil, filters = {})
@user = user
@ -9,18 +9,18 @@ module KnowledgeExplorer
end
def self.categories
SiteSetting.knowledge_explorer_categories.split('|')
SiteSetting.docs_categories.split('|')
end
def self.tags
SiteSetting.knowledge_explorer_tags.split('|')
SiteSetting.docs_tags.split('|')
end
def list
# query for topics matching selected categories & tags
opts = { no_definitions: true, limit: false }
tq = TopicQuery.new(@user, opts)
results = tq.list_knowledge_explorer_topics
results = tq.list_docs_topics
results = results.left_outer_joins(:tags)
results = results.references(:categories)
results = results.where('topics.category_id IN (?)', Query.categories).or(results.where('tags.name IN (?)', Query.tags))
@ -115,7 +115,7 @@ module KnowledgeExplorer
results = results.offset(offset).limit(@limit) #results[offset...page_range]
# assemble the object
topic_query = tq.create_list(:knowledge_explorer, { unordered: true }, results)
topic_query = tq.create_list(:docs, { unordered: true }, results)
topic_list = TopicListSerializer.new(topic_query, scope: Guardian.new(@user)).as_json

7
lib/docs_constraint.rb Normal file
View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class DocsConstraint
def matches?(_request)
SiteSetting.docs_enabled
end
end

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
class KnowledgeExplorerConstraint
def matches?(_request)
SiteSetting.knowledge_explorer_enabled
end
end

View File

@ -1,31 +1,31 @@
# frozen_string_literal: true
# name: discourse-knowledge-explorer
# about: A plugin to make it easy to explore and find knowledge base-type articles in Discourse
# name: discourse-docs
# about: A plugin to make it easy to explore and find knowledge base documents in Discourse
# version: 0.1
# author: Justin DiRose
# url: https://github.com/discourse/discourse-knowledge-explorer
enabled_site_setting :knowledge_explorer_enabled
enabled_site_setting :docs_enabled
register_asset 'stylesheets/common/knowledge-explorer.scss'
register_asset 'stylesheets/mobile/knowledge-explorer.scss'
register_asset 'stylesheets/common/docs.scss'
register_asset 'stylesheets/mobile/docs.scss'
load File.expand_path('lib/knowledge_explorer/engine.rb', __dir__)
load File.expand_path('lib/knowledge_explorer/query.rb', __dir__)
load File.expand_path('lib/docs/engine.rb', __dir__)
load File.expand_path('lib/docs/query.rb', __dir__)
after_initialize do
require_dependency 'search'
if SiteSetting.knowledge_explorer_enabled
if SiteSetting.docs_enabled
if Search.respond_to? :advanced_filter
Search.advanced_filter(/in:kb/) do |posts|
selected_categories = SiteSetting.knowledge_explorer_categories.split('|')
selected_categories = SiteSetting.docs_categories.split('|')
if selected_categories
categories = Category.where('id IN (?)', selected_categories).pluck(:id)
end
selected_tags = SiteSetting.knowledge_explorer_tags.split('|')
selected_tags = SiteSetting.docs_tags.split('|')
if selected_tags
tags = Tag.where('name IN (?)', selected_tags).pluck(:id)
end
@ -34,7 +34,7 @@ after_initialize do
end
end
end
add_to_class(:topic_query, :list_knowledge_explorer_topics) do
add_to_class(:topic_query, :list_docs_topics) do
default_results(@options)
end
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe KnowledgeExplorer::KnowledgeExplorerController do
describe Docs::DocsController do
fab!(:category) { Fabricate(:category) }
fab!(:topic) { Fabricate(:topic, title: "I love carrot today", category: category) }
fab!(:topic2) { Fabricate(:topic, title: "I love pineapple today", category: category) }
@ -10,12 +10,12 @@ describe KnowledgeExplorer::KnowledgeExplorerController do
before do
SiteSetting.tagging_enabled = true
SiteSetting.knowledge_explorer_enabled = true
SiteSetting.knowledge_explorer_categories = category.id.to_s
SiteSetting.knowledge_explorer_tags = 'test'
SiteSetting.docs_enabled = true
SiteSetting.docs_categories = category.id.to_s
SiteSetting.docs_tags = 'test'
end
describe 'knowledge explorer data' do
describe 'docs data' do
context 'when any user' do
it 'should return the right response' do
get '/docs.json'
@ -40,13 +40,13 @@ describe KnowledgeExplorer::KnowledgeExplorerController do
end
end
context 'when some knowledge explorer topics are private' do
context 'when some docs topics are private' do
let!(:group) { Fabricate(:group) }
let!(:private_category) { Fabricate(:private_category, group: group) }
let!(:private_topic) { Fabricate(:topic, category: private_category) }
before do
SiteSetting.knowledge_explorer_categories = "#{category.id}|#{private_category.id}"
SiteSetting.docs_categories = "#{category.id}|#{private_category.id}"
end
it 'should not show topics in private categories without permissions' do
@ -105,7 +105,7 @@ describe KnowledgeExplorer::KnowledgeExplorerController do
let!(:topic3) { Fabricate(:topic, category: category2) }
before do
SiteSetting.knowledge_explorer_categories = "#{category.id}|#{category2.id}"
SiteSetting.docs_categories = "#{category.id}|#{category2.id}"
end
it 'should return a list filtered by category' do
@ -230,22 +230,22 @@ describe KnowledgeExplorer::KnowledgeExplorerController do
expect(response.parsed_body['topic']['id']).to eq(topic.id)
end
it 'should get topics matching a selected knowledge explorer tag or category' do
it 'should get topics matching a selected docs tag or category' do
get "/docs.json?topic=#{non_ke_topic.id}"
expect(response.parsed_body['topic']).to be_blank
end
it 'should return a KE topic when only tags are added to settings' do
SiteSetting.knowledge_explorer_categories = nil
it 'should return a docs topic when only tags are added to settings' do
SiteSetting.docs_categories = nil
get "/docs.json?topic=#{topic.id}"
expect(response.parsed_body['topic']['id']).to eq(topic.id)
end
it 'should return a KE topic when only categories are added to settings' do
SiteSetting.knowledge_explorer_tags = nil
it 'should return a docs topic when only categories are added to settings' do
SiteSetting.docs_tags = nil
get "/docs.json?topic=#{topic.id}"

View File

@ -1,10 +1,10 @@
import { acceptance, queryAll } from "helpers/qunit-helpers";
import docsFixtures from "../fixtures/docs";
acceptance("Knowledge Explorer", function (needs) {
acceptance("Docs", function (needs) {
needs.user();
needs.settings({
knowledge_explorer_enabled: true,
docs_enabled: true,
});
needs.pretender((server, helper) => {
@ -14,18 +14,12 @@ acceptance("Knowledge Explorer", function (needs) {
test("index page", async function (assert) {
await visit("/");
await click("#toggle-hamburger-menu");
await click(".knowledge-explorer-link");
await click(".docs-link");
assert.equal(queryAll(".docs-category")[0].innerText.trim(), "bug 119");
assert.equal(queryAll(".docs-tag")[0].innerText.trim(), "something 74");
assert.equal(
queryAll(".knowledge-explorer-category")[0].innerText.trim(),
"bug 119"
);
assert.equal(
queryAll(".knowledge-explorer-tag")[0].innerText.trim(),
"something 74"
);
assert.equal(
queryAll(".knowledge-explorer-topic-link")[0].innerText.trim(),
queryAll(".docs-topic-link")[0].innerText.trim(),
"Importing from Software X"
);
});