안녕하세요,
pluginAPI를 사용하여 Controller와 Component 클래스를 수정하는 것과 동일한 방식으로 Ember Route 클래스(/app/assets/javascripts/discourse/routes/tags-show.js.es6)를 수정하고 싶습니다.
아래와 같이 composer.js.es6 컨트롤러를 수정하는 예시가 있습니다:
<script type="text/discourse-plugin" version="0.8">
api.modifyClass('controller:composer', {
actions: {
newActionHere() { }
}
});
</script>
Ember Route 클래스도 동일한 방식으로 수정할 수 있나요?
justin
(Justin DiRose)
3월 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)
3월 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,…
이렇게 하면 코어에서 예제를 따르는 것이 훨씬 쉽습니다.