mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:59:39 +08:00

`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/(lib|utils)/*` into `discourse/lib/*`, adds shims for the imports, and updates existing uses in core.
37 lines
1003 B
JavaScript
37 lines
1003 B
JavaScript
import { ajax } from "discourse/lib/ajax";
|
|
import discourseComputed from "discourse/lib/decorators";
|
|
import DiscourseURL from "discourse/lib/url";
|
|
import Category from "discourse/models/category";
|
|
import RestModel from "discourse/models/rest";
|
|
|
|
export default class Permalink extends RestModel {
|
|
static findAll(filter) {
|
|
return ajax("/admin/permalinks.json").then(function (permalinks) {
|
|
let allLinks = permalinks.map((p) => Permalink.create(p));
|
|
|
|
let filteredLinks = filter
|
|
? allLinks.filter(
|
|
(p) => p.url.includes(filter) || p.external_url?.includes(filter)
|
|
)
|
|
: allLinks;
|
|
|
|
return { allLinks, filteredLinks };
|
|
});
|
|
}
|
|
|
|
@discourseComputed("category_id")
|
|
category(category_id) {
|
|
return Category.findById(category_id);
|
|
}
|
|
|
|
@discourseComputed("external_url")
|
|
linkIsExternal(external_url) {
|
|
return !DiscourseURL.isInternal(external_url);
|
|
}
|
|
|
|
@discourseComputed("url")
|
|
key(url) {
|
|
return url.replace("/", "_");
|
|
}
|
|
}
|