مرحبًا بالجميع،
أود تعديل فئة مسار Ember (/app/assets/javascripts/discourse/routes/tags-show.js.es6) بنفس الطريقة التي نعدل بها فئات المتحكم والمكون باستخدام pluginAPI.
مثال على تعديل متحكم composer.js.es6 هو كما يلي:
<script type="text/discourse-plugin" version="0.8">
api.modifyClass('controller:composer', {
actions: {
newActionHere() { }
}
});
</script>
هل من الممكن تعديل فئة مسار Ember بنفس الطريقة؟
justin
(Justin DiRose)
9 مارس 2020، 1:27م
2
أعتقد أن هذا ممكن — أظن أنه يعمل عبر route:route-name. هل جربت ذلك؟
route:route-name يعمل، ولكن عند محاولة تجاوز الإجراء createTopic كما هو موضح أدناه:
<script type="text/discourse-plugin" version="0.8">
api.modifyClass('route:tags-show', {
actions: {
createTopic() {
const controller = this.controllerFor("tags.show");
if (controller.get("list.draft")) {
this.openTopicDraft(controller.get("list"));
} else {
this.controllerFor("composer")
.open({
categoryId: controller.get("category.id"),
action: Composer.CREATE_TOPIC,
draftKey: controller.get("list.draft_key"),
draftSequence: controller.get("list.draft_sequence")
})
.then(() => {
// ملء حقل إدخال الوسوم مسبقًا
if (controller.get("model.id")) {
const composerModel = this.controllerFor("composer").get("model");
composerModel.set(
"tags",
_.compact(
_.flatten([
controller.get("model.id"),
controller.get("additionalTags")
])
)
);
}
});
}
}
}
});
</script>
يظهر الخطأ التالي:
ReferenceError: Composer is not defined
Johani
(Joe)
10 مارس 2020، 10:12م
4
يحدث هذا لأن Composer غير مُعرَّف في الكود الخاص بك. إذا نظرت إلى مسار tags-show، ستجد أن Composer مُعرَّف في الأعلى.
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/routes/tags-show.js.es6#L2
ومع ذلك، بما أنك تقوم بذلك داخل وسوم سكريبت في المظهر، فلا يمكنك استخدام import. سيتعين عليك استخدام require بدلاً من ذلك.
لذا، يجب أن يعمل الأمر إذا أضفت شيئًا مثل هذا إلى بداية الكود الخاص بك:
const Composer = require("discourse/models/composer");
مع ذلك، أوصي بشدة بأن تخصص بعض الوقت لقراءة
Complex theme javascript can be split into multiple files, to keep things nicely organised.
To use this functionality, simply add files to the /javascripts folder in your theme directory. These files can not be edited from the Discourse UI, so you must use the Theme CLI or source the theme from git .
Javascript files are treated exactly the same as they are in core/plugins, so you should follow the same file/folder structure. Theme files are loaded after core/plugins, so if the filenames match,…
وتجربة هذه الطريقة الجديدة لإنشاء المظاهر. إنها أسهل بكثير في متابعة الأمثلة الموجودة في النواة بهذه الطريقة.