DEV: Convert core components to native class syntax (batch 7) (#28603)

Changes made using the ember-native-class-codemod, plus some manual tweaks
This commit is contained in:
David Taylor
2024-08-28 16:15:13 +01:00
committed by GitHub
parent d26d45540e
commit 4150ec960e
33 changed files with 356 additions and 332 deletions

View File

@ -1,17 +1,18 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { attributeBindings, tagName } from "@ember-decorators/component";
import $ from "jquery"; import $ from "jquery";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ @tagName("input")
tagName: "input", @attributeBindings(
type: "radio",
attributeBindings: [
"name", "name",
"type", "type",
"value", "value",
"checked:checked", "checked:checked",
"disabled:disabled", "disabled:disabled"
], )
export default class RadioButton extends Component {
type = "radio";
click() { click() {
const value = $(this.element).val(); const value = $(this.element).val();
@ -24,10 +25,10 @@ export default Component.extend({
} }
this.set("selection", value); this.set("selection", value);
} }
}, }
@discourseComputed("value", "selection") @discourseComputed("value", "selection")
checked(value, selection) { checked(value, selection) {
return value === selection; return value === selection;
}, }
}); }

View File

@ -1,5 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { gte } from "@ember/object/computed"; import { gte } from "@ember/object/computed";
export default Component.extend({
showUsername: gte("index", 1), export default class ReviewableConversationPost extends Component {
}); @gte("index", 1) showUsername;
}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableFieldEditor extends Component {}

View File

@ -1,7 +1,8 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object";
export default Component.extend({ export default class ReviewableFieldTags extends Component {
actions: { @action
onChange(tags) { onChange(tags) {
this.set("value", tags); this.set("value", tags);
@ -11,6 +12,5 @@ export default Component.extend({
value: tags, value: tags,
}, },
}); });
}, }
}, }
});

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableFieldText extends Component {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableFieldTextarea extends Component {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableField extends Component {}

View File

@ -1,5 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { filterBy } from "@ember/object/computed"; import { filterBy } from "@ember/object/computed";
export default Component.extend({
filteredHistories: filterBy("histories", "created", false), export default class ReviewableHistories extends Component {
}); @filterBy("histories", "created", false) filteredHistories;
}

View File

@ -3,6 +3,7 @@ import { action, set } from "@ember/object";
import { getOwner } from "@ember/owner"; import { getOwner } from "@ember/owner";
import { service } from "@ember/service"; import { service } from "@ember/service";
import { classify, dasherize } from "@ember/string"; import { classify, dasherize } from "@ember/string";
import { tagName } from "@ember-decorators/component";
import ExplainReviewableModal from "discourse/components/modal/explain-reviewable"; import ExplainReviewableModal from "discourse/components/modal/explain-reviewable";
import RejectReasonReviewableModal from "discourse/components/modal/reject-reason-reviewable"; import RejectReasonReviewableModal from "discourse/components/modal/reject-reason-reviewable";
import ReviseAndRejectPostReviewable from "discourse/components/modal/revise-and-reject-post-reviewable"; import ReviseAndRejectPostReviewable from "discourse/components/modal/revise-and-reject-post-reviewable";
@ -41,17 +42,18 @@ export function registerReviewableActionModal(actionName, modalClass) {
actionModalClassMap[actionName] = modalClass; actionModalClassMap[actionName] = modalClass;
} }
export default Component.extend({ @tagName("")
adminTools: optionalService(), export default class ReviewableItem extends Component {
dialog: service(), @service dialog;
modal: service(), @service modal;
siteSettings: service(), @service siteSettings;
currentUser: service(), @service currentUser;
composer: service(), @service composer;
tagName: "", @optionalService adminTools;
updating: null,
editing: false, updating = null;
_updates: null, editing = false;
_updates = null;
@discourseComputed( @discourseComputed(
"reviewable.type", "reviewable.type",
@ -71,12 +73,12 @@ export default Component.extend({
} }
return classes; return classes;
}, }
@discourseComputed("reviewable.created_from_flag", "reviewable.status") @discourseComputed("reviewable.created_from_flag", "reviewable.status")
displayContextQuestion(createdFromFlag, status) { displayContextQuestion(createdFromFlag, status) {
return createdFromFlag && status === 0; return createdFromFlag && status === 0;
}, }
@discourseComputed( @discourseComputed(
"reviewable.topic", "reviewable.topic",
@ -85,12 +87,12 @@ export default Component.extend({
) )
topicId(topic, topicId, removedTopicId) { topicId(topic, topicId, removedTopicId) {
return (topic && topic.id) || topicId || removedTopicId; return (topic && topic.id) || topicId || removedTopicId;
}, }
@discourseComputed("siteSettings.reviewable_claiming", "topicId") @discourseComputed("siteSettings.reviewable_claiming", "topicId")
claimEnabled(claimMode, topicId) { claimEnabled(claimMode, topicId) {
return claimMode !== "disabled" && !!topicId; return claimMode !== "disabled" && !!topicId;
}, }
@discourseComputed( @discourseComputed(
"claimEnabled", "claimEnabled",
@ -107,7 +109,7 @@ export default Component.extend({
} }
return claimMode !== "required"; return claimMode !== "required";
}, }
@discourseComputed( @discourseComputed(
"siteSettings.reviewable_claiming", "siteSettings.reviewable_claiming",
@ -125,7 +127,7 @@ export default Component.extend({
return claimMode === "optional" return claimMode === "optional"
? I18n.t("review.claim_help.optional") ? I18n.t("review.claim_help.optional")
: I18n.t("review.claim_help.required"); : I18n.t("review.claim_help.required");
}, }
// Find a component to render, if one exists. For example: // Find a component to render, if one exists. For example:
// `ReviewableUser` will return `reviewable-user` // `ReviewableUser` will return `reviewable-user`
@ -142,12 +144,12 @@ export default Component.extend({
owner.hasRegistration(`template:components/${dasherized}`); owner.hasRegistration(`template:components/${dasherized}`);
_components[type] = componentExists ? dasherized : null; _components[type] = componentExists ? dasherized : null;
return _components[type]; return _components[type];
}, }
@discourseComputed("_updates.category_id", "reviewable.category.id") @discourseComputed("_updates.category_id", "reviewable.category.id")
tagCategoryId(updatedCategoryId, categoryId) { tagCategoryId(updatedCategoryId, categoryId) {
return updatedCategoryId || categoryId; return updatedCategoryId || categoryId;
}, }
@bind @bind
_performConfirmed(performableAction, additionalData = {}) { _performConfirmed(performableAction, additionalData = {}) {
@ -219,15 +221,15 @@ export default Component.extend({
} else { } else {
return performAction(); return performAction();
} }
}, }
clientSuspend(reviewable, performAction) { clientSuspend(reviewable, performAction) {
this._penalize("showSuspendModal", reviewable, performAction); this._penalize("showSuspendModal", reviewable, performAction);
}, }
clientSilence(reviewable, performAction) { clientSilence(reviewable, performAction) {
this._penalize("showSilenceModal", reviewable, performAction); this._penalize("showSilenceModal", reviewable, performAction);
}, }
async clientEdit(reviewable, performAction) { async clientEdit(reviewable, performAction) {
if (!this.currentUser) { if (!this.currentUser) {
@ -255,7 +257,7 @@ export default Component.extend({
this.composer.open(opts); this.composer.open(opts);
return performAction(); return performAction();
}, }
_penalize(adminToolMethod, reviewable, performAction) { _penalize(adminToolMethod, reviewable, performAction) {
let adminTools = this.adminTools; let adminTools = this.adminTools;
@ -269,7 +271,7 @@ export default Component.extend({
before: performAction, before: performAction,
}); });
} }
}, }
@action @action
explainReviewable(reviewable, event) { explainReviewable(reviewable, event) {
@ -277,18 +279,20 @@ export default Component.extend({
this.modal.show(ExplainReviewableModal, { this.modal.show(ExplainReviewableModal, {
model: { reviewable }, model: { reviewable },
}); });
}, }
actions: { @action
edit() { edit() {
this.set("editing", true); this.set("editing", true);
this.set("_updates", { payload: {} }); this.set("_updates", { payload: {} });
}, }
@action
cancelEdit() { cancelEdit() {
this.set("editing", false); this.set("editing", false);
}, }
@action
saveEdit() { saveEdit() {
let updates = this._updates; let updates = this._updates;
@ -306,8 +310,9 @@ export default Component.extend({
.then(() => this.set("editing", false)) .then(() => this.set("editing", false))
.catch(popupAjaxError) .catch(popupAjaxError)
.finally(() => this.set("updating", false)); .finally(() => this.set("updating", false));
}, }
@action
categoryChanged(categoryId) { categoryChanged(categoryId) {
let category = Category.findById(categoryId); let category = Category.findById(categoryId);
@ -316,21 +321,21 @@ export default Component.extend({
} }
set(this._updates, "category_id", category.id); set(this._updates, "category_id", category.id);
}, }
@action
valueChanged(fieldId, event) { valueChanged(fieldId, event) {
set(this._updates, fieldId, event.target.value); set(this._updates, fieldId, event.target.value);
}, }
@action
perform(performableAction) { perform(performableAction) {
if (this.updating) { if (this.updating) {
return; return;
} }
const message = performableAction.get("confirm_message"); const message = performableAction.get("confirm_message");
const requireRejectReason = performableAction.get( const requireRejectReason = performableAction.get("require_reject_reason");
"require_reject_reason"
);
const actionModalClass = requireRejectReason const actionModalClass = requireRejectReason
? RejectReasonReviewableModal ? RejectReasonReviewableModal
: actionModalClassMap[performableAction.server_action]; : actionModalClassMap[performableAction.server_action];
@ -351,6 +356,5 @@ export default Component.extend({
} else { } else {
return this._performConfirmed(performableAction); return this._performConfirmed(performableAction);
} }
}, }
}, }
});

View File

@ -7,20 +7,20 @@ import { longDate } from "discourse/lib/formatter";
import { historyHeat } from "discourse/widgets/post-edits-indicator"; import { historyHeat } from "discourse/widgets/post-edits-indicator";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ export default class ReviewablePostEdits extends Component {
modal: service(), @service modal;
hasEdits: gt("reviewable.post_version", 1), @gt("reviewable.post_version", 1) hasEdits;
@discourseComputed("reviewable.post_updated_at") @discourseComputed("reviewable.post_updated_at")
historyClass(updatedAt) { historyClass(updatedAt) {
return historyHeat(this.siteSettings, new Date(updatedAt)); return historyHeat(this.siteSettings, new Date(updatedAt));
}, }
@discourseComputed("reviewable.post_updated_at") @discourseComputed("reviewable.post_updated_at")
editedDate(updatedAt) { editedDate(updatedAt) {
return longDate(updatedAt); return longDate(updatedAt);
}, }
@action @action
showEditHistory(event) { showEditHistory(event) {
@ -36,5 +36,5 @@ export default Component.extend({
}, },
}); });
}); });
}, }
}); }

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewablePostHeader extends Component {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewablePost extends Component {}

View File

@ -1,11 +1,11 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { gt } from "@ember/object/computed"; import { gt } from "@ember/object/computed";
import { tagName } from "@ember-decorators/component";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ @tagName("")
tagName: "", export default class ReviewableScore extends Component {
@gt("rs.status", 0) showStatus;
showStatus: gt("rs.status", 0),
@discourseComputed("rs.score_type.title", "reviewable.target_created_by") @discourseComputed("rs.score_type.title", "reviewable.target_created_by")
title(title, targetCreatedBy) { title(title, targetCreatedBy) {
@ -17,5 +17,5 @@ export default Component.extend({
} }
return title; return title;
}, }
}); }

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableScores extends Component {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableTags extends Component {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class ReviewableTopicLink extends Component {}

View File

@ -1,9 +1,9 @@
import Component from "@ember/component"; import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ export default class ReviewableUser extends Component {
@discourseComputed("reviewable.user_fields") @discourseComputed("reviewable.user_fields")
userFields(fields) { userFields(fields) {
return this.site.collectUserFields(fields); return this.site.collectUserFields(fields);
}, }
}); }

View File

@ -1,19 +1,19 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { or } from "@ember/object/computed"; import { or } from "@ember/object/computed";
import { classNames } from "@ember-decorators/component";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ @classNames("controls", "save-button")
classNames: ["controls", "save-button"], export default class SaveControls extends Component {
@or("model.isSaving", "saveDisabled") buttonDisabled;
buttonDisabled: or("model.isSaving", "saveDisabled"),
didInsertElement() { didInsertElement() {
this._super(...arguments); super.didInsertElement(...arguments);
this.set("saved", false); this.set("saved", false);
}, }
@discourseComputed("model.isSaving") @discourseComputed("model.isSaving")
savingText(saving) { savingText(saving) {
return saving ? "saving" : "save"; return saving ? "saving" : "save";
}, }
}); }

View File

@ -3,40 +3,40 @@ import { next } from "@ember/runloop";
import $ from "jquery"; import $ from "jquery";
import Scrolling from "discourse/mixins/scrolling"; import Scrolling from "discourse/mixins/scrolling";
export default Component.extend(Scrolling, { export default class ScrollTracker extends Component.extend(Scrolling) {
didReceiveAttrs() { didReceiveAttrs() {
this._super(...arguments); super.didReceiveAttrs(...arguments);
this.set("trackerName", `scroll-tracker-${this.name}`); this.set("trackerName", `scroll-tracker-${this.name}`);
}, }
didInsertElement() { didInsertElement() {
this._super(...arguments); super.didInsertElement(...arguments);
this.bindScrolling(); this.bindScrolling();
}, }
didRender() { didRender() {
this._super(...arguments); super.didRender(...arguments);
const data = this.session.get(this.trackerName); const data = this.session.get(this.trackerName);
if (data && data.position >= 0 && data.tag === this.tag) { if (data && data.position >= 0 && data.tag === this.tag) {
next(() => $(window).scrollTop(data.position + 1)); next(() => $(window).scrollTop(data.position + 1));
} }
}, }
willDestroyElement() { willDestroyElement() {
this._super(...arguments); super.willDestroyElement(...arguments);
this.unbindScrolling(); this.unbindScrolling();
}, }
scrolled() { scrolled() {
this._super(...arguments); super.scrolled(...arguments);
this.session.set(this.trackerName, { this.session.set(this.trackerName, {
position: $(window).scrollTop(), position: $(window).scrollTop(),
tag: this.tag, tag: this.tag,
}); });
}, }
}); }

View File

@ -32,14 +32,15 @@ function findTopView(posts, viewportTop, postsWrapperTop, min, max) {
return min; return min;
} }
export default MountWidget.extend({ export default class ScrollingPostStream extends MountWidget {
screenTrack: service(), @service screenTrack;
widget: "post-stream",
_topVisible: null, widget = "post-stream";
_bottomVisible: null, _topVisible = null;
_currentPostObj: null, _bottomVisible = null;
_currentVisible: null, _currentPostObj = null;
_currentPercent: null, _currentVisible = null;
_currentPercent = null;
buildArgs() { buildArgs() {
return this.getProperties( return this.getProperties(
@ -56,7 +57,7 @@ export default MountWidget.extend({
"lastReadPostNumber", "lastReadPostNumber",
"highestPostNumber" "highestPostNumber"
); );
}, }
scrolled() { scrolled() {
if (this.isDestroyed || this.isDestroying) { if (this.isDestroyed || this.isDestroying) {
@ -279,11 +280,11 @@ export default MountWidget.extend({
this._previouslyNearby = newPrev; this._previouslyNearby = newPrev;
this.screenTrack.setOnscreen(onscreenPostNumbers, readPostNumbers); this.screenTrack.setOnscreen(onscreenPostNumbers, readPostNumbers);
}, }
_scrollTriggered() { _scrollTriggered() {
scheduleOnce("afterRender", this, this.scrolled); scheduleOnce("afterRender", this, this.scrolled);
}, }
_posted(staged) { _posted(staged) {
this.queueRerender(() => { this.queueRerender(() => {
@ -292,7 +293,7 @@ export default MountWidget.extend({
DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true }); DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true });
} }
}); });
}, }
_refresh(args) { _refresh(args) {
if (args) { if (args) {
@ -316,15 +317,15 @@ export default MountWidget.extend({
} }
this.queueRerender(); this.queueRerender();
this._scrollTriggered(); this._scrollTriggered();
}, }
@bind @bind
_debouncedScroll() { _debouncedScroll() {
discourseDebounce(this, this._scrollTriggered, DEBOUNCE_DELAY); discourseDebounce(this, this._scrollTriggered, DEBOUNCE_DELAY);
}, }
didInsertElement() { didInsertElement() {
this._super(...arguments); super.didInsertElement(...arguments);
this._previouslyNearby = new Set(); this._previouslyNearby = new Set();
this.appEvents.on("post-stream:refresh", this, "_debouncedScroll"); this.appEvents.on("post-stream:refresh", this, "_debouncedScroll");
@ -357,10 +358,10 @@ export default MountWidget.extend({
DiscourseURL.routeTo(this.location.pathname); DiscourseURL.routeTo(this.location.pathname);
} }
}; };
}, }
willDestroyElement() { willDestroyElement() {
this._super(...arguments); super.willDestroyElement(...arguments);
document.removeEventListener("touchmove", this._debouncedScroll); document.removeEventListener("touchmove", this._debouncedScroll);
window.removeEventListener("scroll", this._debouncedScroll); window.removeEventListener("scroll", this._debouncedScroll);
@ -375,12 +376,12 @@ export default MountWidget.extend({
); );
this.appEvents.off("post-stream:refresh", this, "_refresh"); this.appEvents.off("post-stream:refresh", this, "_refresh");
this.appEvents.off("post-stream:posted", this, "_posted"); this.appEvents.off("post-stream:posted", this, "_posted");
}, }
didUpdateAttrs() { didUpdateAttrs() {
this._super(...arguments); super.didUpdateAttrs(...arguments);
this._refresh({ force: true }); this._refresh({ force: true });
}, }
_handleWidgetButtonHoverState(event) { _handleWidgetButtonHoverState(event) {
if (event.target.classList.contains("widget-button")) { if (event.target.classList.contains("widget-button")) {
@ -391,11 +392,11 @@ export default MountWidget.extend({
}); });
event.target.classList.add("d-hover"); event.target.classList.add("d-hover");
} }
}, }
_removeWidgetButtonHoverState() { _removeWidgetButtonHoverState() {
document.querySelectorAll("button.widget-button").forEach((button) => { document.querySelectorAll("button.widget-button").forEach((button) => {
button.classList.remove("d-hover"); button.classList.remove("d-hover");
}); });
}, }
}); }

View File

@ -1,5 +1,10 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import {
attributeBindings,
classNames,
tagName,
} from "@ember-decorators/component";
import { escapeExpression } from "discourse/lib/utilities"; import { escapeExpression } from "discourse/lib/utilities";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
@ -79,14 +84,14 @@ export function addAdvancedSearchOptions(options) {
_extraOptions.push(options); _extraOptions.push(options);
} }
export default Component.extend({ @tagName("details")
tagName: "details", @attributeBindings("expandFilters:open")
attributeBindings: ["expandFilters:open"], @classNames("advanced-filters")
classNames: ["advanced-filters"], export default class SearchAdvancedOptions extends Component {
category: null, category = null;
init() { init() {
this._super(...arguments); super.init(...arguments);
this.setProperties({ this.setProperties({
searchedTerms: { searchedTerms: {
@ -120,10 +125,10 @@ export default Component.extend({
postTimeOptions: postTimeOptions(), postTimeOptions: postTimeOptions(),
showAllTagsCheckbox: false, showAllTagsCheckbox: false,
}); });
}, }
didReceiveAttrs() { didReceiveAttrs() {
this._super(...arguments); super.didReceiveAttrs(...arguments);
this.setSearchedTermValue("searchedTerms.username", REGEXP_USERNAME_PREFIX); this.setSearchedTermValue("searchedTerms.username", REGEXP_USERNAME_PREFIX);
this.setSearchedTermValueForCategory(); this.setSearchedTermValueForCategory();
@ -192,7 +197,7 @@ export default Component.extend({
"searchedTerms.max_views", "searchedTerms.max_views",
REGEXP_MAX_VIEWS_PREFIX REGEXP_MAX_VIEWS_PREFIX
); );
}, }
findSearchTerms() { findSearchTerms() {
const searchTerm = escapeExpression(this.searchTerm); const searchTerm = escapeExpression(this.searchTerm);
@ -213,7 +218,7 @@ export default Component.extend({
}); });
return result; return result;
}, }
filterBlocks(regexPrefix) { filterBlocks(regexPrefix) {
const blocks = this.findSearchTerms(); const blocks = this.findSearchTerms();
@ -229,7 +234,7 @@ export default Component.extend({
}); });
return result; return result;
}, }
setSearchedTermValue(key, replaceRegEx, matchRegEx = null) { setSearchedTermValue(key, replaceRegEx, matchRegEx = null) {
matchRegEx = matchRegEx || replaceRegEx; matchRegEx = matchRegEx || replaceRegEx;
@ -245,7 +250,7 @@ export default Component.extend({
} else if (val && val.length !== 0) { } else if (val && val.length !== 0) {
this.set(key, null); this.set(key, null);
} }
}, }
setSearchedTermSpecialInValue(key, replaceRegEx) { setSearchedTermSpecialInValue(key, replaceRegEx) {
const match = this.filterBlocks(replaceRegEx); const match = this.filterBlocks(replaceRegEx);
@ -257,7 +262,7 @@ export default Component.extend({
} else if (this.get(key) !== false) { } else if (this.get(key) !== false) {
this.set(key, false); this.set(key, false);
} }
}, }
setSearchedTermValueForCategory() { setSearchedTermValueForCategory() {
const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX); const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX);
@ -296,7 +301,7 @@ export default Component.extend({
} else { } else {
this.set("searchedTerms.category", null); this.set("searchedTerms.category", null);
} }
}, }
setSearchedTermValueForTags() { setSearchedTermValueForTags() {
if (!this.siteSettings.tagging_enabled) { if (!this.siteSettings.tagging_enabled) {
@ -324,7 +329,7 @@ export default Component.extend({
} else if (!tags) { } else if (!tags) {
this.set("searchedTerms.tags", null); this.set("searchedTerms.tags", null);
} }
}, }
setSearchedTermValueForPostTime() { setSearchedTermValueForPostTime() {
const match = this.filterBlocks(REGEXP_POST_TIME_PREFIX); const match = this.filterBlocks(REGEXP_POST_TIME_PREFIX);
@ -351,7 +356,7 @@ export default Component.extend({
this.set("searchedTerms.time.when", "before"); this.set("searchedTerms.time.when", "before");
this.set("searchedTerms.time.days", null); this.set("searchedTerms.time.days", null);
} }
}, }
updateInRegex(regex, filter) { updateInRegex(regex, filter) {
const match = this.filterBlocks(regex); const match = this.filterBlocks(regex);
@ -367,43 +372,43 @@ export default Component.extend({
searchTerm = searchTerm.replace(match, ""); searchTerm = searchTerm.replace(match, "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
@action @action
onChangeSearchTermMinPostCount(value) { onChangeSearchTermMinPostCount(value) {
this.set("searchedTerms.min_posts", value.length ? value : null); this.set("searchedTerms.min_posts", value.length ? value : null);
this._updateSearchTermForMinPostCount(); this._updateSearchTermForMinPostCount();
}, }
@action @action
onChangeSearchTermMaxPostCount(value) { onChangeSearchTermMaxPostCount(value) {
this.set("searchedTerms.max_posts", value.length ? value : null); this.set("searchedTerms.max_posts", value.length ? value : null);
this._updateSearchTermForMaxPostCount(); this._updateSearchTermForMaxPostCount();
}, }
@action @action
onChangeSearchTermMinViews(value) { onChangeSearchTermMinViews(value) {
this.set("searchedTerms.min_views", value.length ? value : null); this.set("searchedTerms.min_views", value.length ? value : null);
this._updateSearchTermForMinViews(); this._updateSearchTermForMinViews();
}, }
@action @action
onChangeSearchTermMaxViews(value) { onChangeSearchTermMaxViews(value) {
this.set("searchedTerms.max_views", value.length ? value : null); this.set("searchedTerms.max_views", value.length ? value : null);
this._updateSearchTermForMaxViews(); this._updateSearchTermForMaxViews();
}, }
@action @action
onChangeSearchTermForIn(value) { onChangeSearchTermForIn(value) {
this.set("searchedTerms.in", value); this.set("searchedTerms.in", value);
this._updateSearchTermForIn(); this._updateSearchTermForIn();
}, }
@action @action
onChangeSearchTermForStatus(value) { onChangeSearchTermForStatus(value) {
this.set("searchedTerms.status", value); this.set("searchedTerms.status", value);
this._updateSearchTermForStatus(); this._updateSearchTermForStatus();
}, }
@action @action
onChangeWhenTime(time) { onChangeWhenTime(time) {
@ -411,7 +416,7 @@ export default Component.extend({
this.set("searchedTerms.time.when", time); this.set("searchedTerms.time.when", time);
this._updateSearchTermForPostTime(); this._updateSearchTermForPostTime();
} }
}, }
@action @action
onChangeWhenDate(date) { onChangeWhenDate(date) {
@ -419,7 +424,7 @@ export default Component.extend({
this.set("searchedTerms.time.days", date.format("YYYY-MM-DD")); this.set("searchedTerms.time.days", date.format("YYYY-MM-DD"));
this._updateSearchTermForPostTime(); this._updateSearchTermForPostTime();
} }
}, }
@action @action
onChangeSearchTermForCategory(categoryId) { onChangeSearchTermForCategory(categoryId) {
@ -433,55 +438,55 @@ export default Component.extend({
} }
this._updateSearchTermForCategory(); this._updateSearchTermForCategory();
}, }
@action @action
onChangeSearchTermForUsername(username) { onChangeSearchTermForUsername(username) {
this.set("searchedTerms.username", username.length ? username : null); this.set("searchedTerms.username", username.length ? username : null);
this._updateSearchTermForUsername(); this._updateSearchTermForUsername();
}, }
@action @action
onChangeSearchTermForTags(tags) { onChangeSearchTermForTags(tags) {
this.set("searchedTerms.tags", tags.length ? tags : null); this.set("searchedTerms.tags", tags.length ? tags : null);
this._updateSearchTermForTags(); this._updateSearchTermForTags();
}, }
@action @action
onChangeSearchTermForAllTags(checked) { onChangeSearchTermForAllTags(checked) {
this.set("searchedTerms.special.all_tags", checked); this.set("searchedTerms.special.all_tags", checked);
this._updateSearchTermForTags(); this._updateSearchTermForTags();
}, }
@action @action
onChangeSearchTermForSpecialInLikes(checked) { onChangeSearchTermForSpecialInLikes(checked) {
this.set("searchedTerms.special.in.likes", checked); this.set("searchedTerms.special.in.likes", checked);
this.updateInRegex(REGEXP_SPECIAL_IN_LIKES_MATCH, "likes"); this.updateInRegex(REGEXP_SPECIAL_IN_LIKES_MATCH, "likes");
}, }
@action @action
onChangeSearchTermForSpecialInMessages(checked) { onChangeSearchTermForSpecialInMessages(checked) {
this.set("searchedTerms.special.in.messages", checked); this.set("searchedTerms.special.in.messages", checked);
this.updateInRegex(REGEXP_SPECIAL_IN_MESSAGES_MATCH, "messages"); this.updateInRegex(REGEXP_SPECIAL_IN_MESSAGES_MATCH, "messages");
}, }
@action @action
onChangeSearchTermForSpecialInSeen(checked) { onChangeSearchTermForSpecialInSeen(checked) {
this.set("searchedTerms.special.in.seen", checked); this.set("searchedTerms.special.in.seen", checked);
this.updateInRegex(REGEXP_SPECIAL_IN_SEEN_MATCH, "seen"); this.updateInRegex(REGEXP_SPECIAL_IN_SEEN_MATCH, "seen");
}, }
@action @action
onChangeSearchTermForSpecialInTitle(checked) { onChangeSearchTermForSpecialInTitle(checked) {
this.set("searchedTerms.special.in.title", checked); this.set("searchedTerms.special.in.title", checked);
this.updateInRegex(REGEXP_SPECIAL_IN_TITLE_MATCH, "title"); this.updateInRegex(REGEXP_SPECIAL_IN_TITLE_MATCH, "title");
}, }
@action @action
onChangeSearchedTermField(path, updateFnName, value) { onChangeSearchedTermField(path, updateFnName, value) {
this.set(`searchedTerms.${path}`, value); this.set(`searchedTerms.${path}`, value);
this[updateFnName](); this[updateFnName]();
}, }
_updateSearchTermForTags() { _updateSearchTermForTags() {
const match = this.filterBlocks(REGEXP_TAGS_PREFIX); const match = this.filterBlocks(REGEXP_TAGS_PREFIX);
@ -507,7 +512,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForCategory() { _updateSearchTermForCategory() {
const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX); const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX);
@ -566,7 +571,7 @@ export default Component.extend({
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForUsername() { _updateSearchTermForUsername() {
const match = this.filterBlocks(REGEXP_USERNAME_PREFIX); const match = this.filterBlocks(REGEXP_USERNAME_PREFIX);
@ -585,7 +590,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForPostTime() { _updateSearchTermForPostTime() {
const match = this.filterBlocks(REGEXP_POST_TIME_PREFIX); const match = this.filterBlocks(REGEXP_POST_TIME_PREFIX);
@ -605,7 +610,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForIn() { _updateSearchTermForIn() {
let regExpInMatch = this.inOptions.map((option) => option.value).join("|"); let regExpInMatch = this.inOptions.map((option) => option.value).join("|");
@ -631,7 +636,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match, ""); searchTerm = searchTerm.replace(match, "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForStatus() { _updateSearchTermForStatus() {
let regExpStatusMatch = this.statusOptions let regExpStatusMatch = this.statusOptions
@ -658,7 +663,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForMinPostCount() { _updateSearchTermForMinPostCount() {
const match = this.filterBlocks(REGEXP_MIN_POSTS_PREFIX); const match = this.filterBlocks(REGEXP_MIN_POSTS_PREFIX);
@ -680,7 +685,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForMaxPostCount() { _updateSearchTermForMaxPostCount() {
const match = this.filterBlocks(REGEXP_MAX_POSTS_PREFIX); const match = this.filterBlocks(REGEXP_MAX_POSTS_PREFIX);
@ -702,7 +707,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForMinViews() { _updateSearchTermForMinViews() {
const match = this.filterBlocks(REGEXP_MIN_VIEWS_PREFIX); const match = this.filterBlocks(REGEXP_MIN_VIEWS_PREFIX);
@ -724,7 +729,7 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTermForMaxViews() { _updateSearchTermForMaxViews() {
const match = this.filterBlocks(REGEXP_MAX_VIEWS_PREFIX); const match = this.filterBlocks(REGEXP_MAX_VIEWS_PREFIX);
@ -746,9 +751,9 @@ export default Component.extend({
searchTerm = searchTerm.replace(match[0], ""); searchTerm = searchTerm.replace(match[0], "");
this._updateSearchTerm(searchTerm); this._updateSearchTerm(searchTerm);
} }
}, }
_updateSearchTerm(searchTerm) { _updateSearchTerm(searchTerm) {
this.onChangeSearchTerm(searchTerm.trim()); this.onChangeSearchTerm(searchTerm.trim());
}, }
}); }

View File

@ -1,5 +1,5 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { tagName } from "@ember-decorators/component";
export default Component.extend({ @tagName("")
tagName: "", export default class SearchResultEntries extends Component {}
});

View File

@ -1,14 +1,20 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import {
attributeBindings,
classNameBindings,
classNames,
tagName,
} from "@ember-decorators/component";
import { wantsNewWindow } from "discourse/lib/intercept-click"; import { wantsNewWindow } from "discourse/lib/intercept-click";
import { logSearchLinkClick } from "discourse/lib/search"; import { logSearchLinkClick } from "discourse/lib/search";
export default Component.extend({ @tagName("div")
tagName: "div", @classNames("fps-result")
classNames: ["fps-result"], @classNameBindings("bulkSelectEnabled")
classNameBindings: ["bulkSelectEnabled"], @attributeBindings("role")
attributeBindings: ["role"], export default class SearchResultEntry extends Component {
role: "listitem", role = "listitem";
@action @action
logClick(topicId, event) { logClick(topicId, event) {
@ -24,5 +30,5 @@ export default Component.extend({
searchResultType: "topic", searchResultType: "topic",
}); });
} }
}, }
}); }

View File

@ -1,16 +1,17 @@
import { on } from "@ember-decorators/object";
import $ from "jquery"; import $ from "jquery";
import TextField from "discourse/components/text-field"; import TextField from "discourse/components/text-field";
import { applySearchAutocomplete } from "discourse/lib/search"; import { applySearchAutocomplete } from "discourse/lib/search";
import discourseComputed, { on } from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
export default TextField.extend({ export default class SearchTextField extends TextField {
autocomplete: "off", autocomplete = "off";
@discourseComputed("searchService.searchContextEnabled") @discourseComputed("searchService.searchContextEnabled")
placeholder(searchContextEnabled) { placeholder(searchContextEnabled) {
return searchContextEnabled ? "" : I18n.t("search.full_page_title"); return searchContextEnabled ? "" : I18n.t("search.full_page_title");
}, }
@on("didInsertElement") @on("didInsertElement")
becomeFocused() { becomeFocused() {
@ -24,5 +25,5 @@ export default TextField.extend({
// at the top of the page // at the top of the page
$(window).scrollTop(0); $(window).scrollTop(0);
$searchInput.focus(); $searchInput.focus();
}, }
}); }

View File

@ -4,7 +4,7 @@ import { SECOND_FACTOR_METHODS } from "discourse/models/user";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
export default Component.extend({ export default class SecondFactorForm extends Component {
@discourseComputed("secondFactorMethod") @discourseComputed("secondFactorMethod")
secondFactorTitle(secondFactorMethod) { secondFactorTitle(secondFactorMethod) {
switch (secondFactorMethod) { switch (secondFactorMethod) {
@ -15,7 +15,7 @@ export default Component.extend({
case SECOND_FACTOR_METHODS.BACKUP_CODE: case SECOND_FACTOR_METHODS.BACKUP_CODE:
return I18n.t("login.second_factor_backup_title"); return I18n.t("login.second_factor_backup_title");
} }
}, }
@discourseComputed("secondFactorMethod") @discourseComputed("secondFactorMethod")
secondFactorDescription(secondFactorMethod) { secondFactorDescription(secondFactorMethod) {
@ -27,7 +27,7 @@ export default Component.extend({
case SECOND_FACTOR_METHODS.BACKUP_CODE: case SECOND_FACTOR_METHODS.BACKUP_CODE:
return I18n.t("login.second_factor_backup_description"); return I18n.t("login.second_factor_backup_description");
} }
}, }
@discourseComputed("secondFactorMethod", "isLogin") @discourseComputed("secondFactorMethod", "isLogin")
linkText(secondFactorMethod, isLogin) { linkText(secondFactorMethod, isLogin) {
@ -40,7 +40,7 @@ export default Component.extend({
? "user.second_factor_backup.use" ? "user.second_factor_backup.use"
: "user.second_factor.use"; : "user.second_factor.use";
} }
}, }
@discourseComputed("backupEnabled", "totpEnabled", "secondFactorMethod") @discourseComputed("backupEnabled", "totpEnabled", "secondFactorMethod")
showToggleMethodLink(backupEnabled, totpEnabled, secondFactorMethod) { showToggleMethodLink(backupEnabled, totpEnabled, secondFactorMethod) {
@ -49,7 +49,7 @@ export default Component.extend({
totpEnabled && totpEnabled &&
secondFactorMethod !== SECOND_FACTOR_METHODS.SECURITY_KEY secondFactorMethod !== SECOND_FACTOR_METHODS.SECURITY_KEY
); );
}, }
@action @action
toggleSecondFactorMethod(event) { toggleSecondFactorMethod(event) {
@ -61,5 +61,5 @@ export default Component.extend({
} else { } else {
this.set("secondFactorMethod", SECOND_FACTOR_METHODS.TOTP); this.set("secondFactorMethod", SECOND_FACTOR_METHODS.TOTP);
} }
}, }
}); }

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class SelectedPosts extends Component {}

View File

@ -8,11 +8,12 @@ import discourseLater from "discourse-common/lib/later";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
export default Component.extend({ export default class SharePanel extends Component {
tagName: null, tagName = null;
type: alias("panel.model.type"),
topic: alias("panel.model.topic"), @alias("panel.model.type") type;
privateCategory: alias("panel.model.topic.category.read_restricted"), @alias("panel.model.topic") topic;
@alias("panel.model.topic.category.read_restricted") privateCategory;
@discourseComputed("topic.{isPrivateMessage,invisible,category}") @discourseComputed("topic.{isPrivateMessage,invisible,category}")
sources(topic) { sources(topic) {
@ -22,13 +23,13 @@ export default Component.extend({
(topic && topic.invisible) || (topic && topic.invisible) ||
this.privateCategory; this.privateCategory;
return Sharing.activeSources(this.siteSettings.share_links, privateContext); return Sharing.activeSources(this.siteSettings.share_links, privateContext);
}, }
@discourseComputed("type", "topic.title") @discourseComputed("type", "topic.title")
shareTitle(type, topicTitle) { shareTitle(type, topicTitle) {
topicTitle = escapeExpression(topicTitle); topicTitle = escapeExpression(topicTitle);
return I18n.t("share.topic_html", { topicTitle }); return I18n.t("share.topic_html", { topicTitle });
}, }
@discourseComputed("panel.model.shareUrl", "topic.shareUrl") @discourseComputed("panel.model.shareUrl", "topic.shareUrl")
shareUrl(forcedShareUrl, shareUrl) { shareUrl(forcedShareUrl, shareUrl) {
@ -45,10 +46,10 @@ export default Component.extend({
} }
return encodeURI(shareUrl); return encodeURI(shareUrl);
}, }
didInsertElement() { didInsertElement() {
this._super(...arguments); super.didInsertElement(...arguments);
discourseLater(() => { discourseLater(() => {
if (this.element) { if (this.element) {
const textArea = this.element.querySelector(".topic-share-url"); const textArea = this.element.querySelector(".topic-share-url");
@ -57,7 +58,7 @@ export default Component.extend({
textArea.setSelectionRange(0, this.shareUrl.length); textArea.setSelectionRange(0, this.shareUrl.length);
} }
}, 200); }, 200);
}, }
@action @action
share(source) { share(source) {
@ -65,5 +66,5 @@ export default Component.extend({
url: this.shareUrl, url: this.shareUrl,
title: this.topic.get("title"), title: this.topic.get("title"),
}); });
}, }
}); }

View File

@ -1,23 +1,27 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object";
import { service } from "@ember/service"; import { service } from "@ember/service";
import { tagName } from "@ember-decorators/component";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
export default Component.extend({ @tagName("")
tagName: "", export default class SharedDraftControls extends Component {
dialog: service(), @service dialog;
publishing: false,
publishing = false;
@discourseComputed("topic.destination_category_id") @discourseComputed("topic.destination_category_id")
validCategory(destCatId) { validCategory(destCatId) {
return destCatId && destCatId !== this.site.shared_drafts_category_id; return destCatId && destCatId !== this.site.shared_drafts_category_id;
}, }
actions: { @action
updateDestinationCategory(categoryId) { updateDestinationCategory(categoryId) {
return this.topic.updateDestinationCategory(categoryId); return this.topic.updateDestinationCategory(categoryId);
}, }
@action
publish() { publish() {
this.dialog.yesNoConfirm({ this.dialog.yesNoConfirm({
message: I18n.t("shared_drafts.confirm_publish"), message: I18n.t("shared_drafts.confirm_publish"),
@ -38,6 +42,5 @@ export default Component.extend({
}); });
}, },
}); });
}, }
}, }
});

View File

@ -1,29 +1,29 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { on } from "@ember/object/evented"; import { on } from "@ember-decorators/object";
import discourseLater from "discourse-common/lib/later"; import discourseLater from "discourse-common/lib/later";
export default Component.extend({ export default class SignupCta extends Component {
action: "showCreateAccount", action = "showCreateAccount";
@action @action
neverShow(event) { neverShow(event) {
event?.preventDefault(); event?.preventDefault();
this.keyValueStore.setItem("anon-cta-never", "t"); this.keyValueStore.setItem("anon-cta-never", "t");
this.session.set("showSignupCta", false); this.session.set("showSignupCta", false);
}, }
actions: { @action
hideForSession() { hideForSession() {
this.session.set("hideSignupCta", true); this.session.set("hideSignupCta", true);
this.keyValueStore.setItem("anon-cta-hidden", Date.now()); this.keyValueStore.setItem("anon-cta-hidden", Date.now());
discourseLater(() => this.session.set("showSignupCta", false), 20 * 1000); discourseLater(() => this.session.set("showSignupCta", false), 20 * 1000);
}, }
},
_turnOffIfHidden: on("willDestroyElement", function () { @on("willDestroyElement")
_turnOffIfHidden() {
if (this.session.get("hideSignupCta")) { if (this.session.get("hideSignupCta")) {
this.session.set("showSignupCta", false); this.session.set("showSignupCta", false);
} }
}), }
}); }

View File

@ -5,21 +5,21 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import Topic from "discourse/models/topic"; import Topic from "discourse/models/topic";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({ export default class SlowModeInfo extends Component {
@discourseComputed("topic.slow_mode_seconds") @discourseComputed("topic.slow_mode_seconds")
durationText(seconds) { durationText(seconds) {
return durationTextFromSeconds(seconds); return durationTextFromSeconds(seconds);
}, }
@discourseComputed("topic.slow_mode_seconds", "topic.closed") @discourseComputed("topic.slow_mode_seconds", "topic.closed")
showSlowModeNotice(seconds, closed) { showSlowModeNotice(seconds, closed) {
return seconds > 0 && !closed; return seconds > 0 && !closed;
}, }
@action @action
disableSlowMode() { disableSlowMode() {
Topic.setSlowMode(this.topic.id, 0) Topic.setSlowMode(this.topic.id, 0)
.catch(popupAjaxError) .catch(popupAjaxError)
.then(() => this.set("topic.slow_mode_seconds", 0)); .then(() => this.set("topic.slow_mode_seconds", 0));
}, }
}); }

View File

@ -1,3 +1,3 @@
import CategoryListItem from "discourse/components/category-list-item"; import CategoryListItem from "discourse/components/category-list-item";
export default CategoryListItem.extend({}); export default class SubCategoryItem extends CategoryListItem {}

View File

@ -1,3 +1,3 @@
import CategoryListItem from "discourse/components/category-list-item"; import CategoryListItem from "discourse/components/category-list-item";
export default CategoryListItem.extend({}); export default class SubCategoryRow extends CategoryListItem {}

View File

@ -1,3 +1,3 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({}); export default class SubcategoriesWithFeaturedTopics extends Component {}