2023-10-11 02:38:59 +08:00
|
|
|
import Controller from "@ember/controller";
|
2023-03-15 17:42:12 +08:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { not } from "@ember/object/computed";
|
2019-07-16 01:47:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { propertyEqual } from "discourse/lib/computed";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2019-07-16 01:47:44 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminCustomizeRobotsTxtController extends Controller.extend(
|
|
|
|
bufferedProperty("model")
|
|
|
|
) {
|
|
|
|
saved = false;
|
|
|
|
isSaving = false;
|
|
|
|
|
|
|
|
@propertyEqual("model.robots_txt", "buffered.robots_txt") saveDisabled;
|
2019-07-16 01:47:44 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@not("model.overridden") resetDisabled;
|
2019-07-16 01:47:44 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.setProperties({
|
|
|
|
isSaving: true,
|
|
|
|
saved: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
ajax("robots.json", {
|
|
|
|
type: "PUT",
|
|
|
|
data: { robots_txt: this.buffered.get("robots_txt") },
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
this.commitBuffer();
|
|
|
|
this.set("saved", true);
|
|
|
|
this.set("model.overridden", data.overridden);
|
2019-07-16 01:47:44 +08:00
|
|
|
})
|
2023-03-15 17:42:12 +08:00
|
|
|
.finally(() => this.set("isSaving", false));
|
|
|
|
}
|
2019-07-16 01:47:44 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
reset() {
|
|
|
|
this.setProperties({
|
|
|
|
isSaving: true,
|
|
|
|
saved: false,
|
|
|
|
});
|
|
|
|
ajax("robots.json", { type: "DELETE" })
|
|
|
|
.then((data) => {
|
|
|
|
this.buffered.set("robots_txt", data.robots_txt);
|
|
|
|
this.commitBuffer();
|
|
|
|
this.set("saved", true);
|
|
|
|
this.set("model.overridden", false);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("isSaving", false));
|
|
|
|
}
|
|
|
|
}
|