Skip to content

Commit

Permalink
DEV: Convert to native class syntax (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq authored Nov 29, 2024
1 parent 74bcfb8 commit 872dddd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { A } from "@ember/array";
import Controller from "@ember/controller";
import EmberObject from "@ember/object";
import EmberObject, { action } from "@ember/object";
import { Promise } from "rsvp";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse-common/utils/decorators";

const prefix = "/admin/plugins/code-review";

export default Controller.extend({
organizations: null,
loading: true,
export default class AdminPluginsCodeReviewController extends Controller {
organizations = null;
loading = true;

async loadOrganizations() {
try {
Expand All @@ -33,7 +33,7 @@ export default Controller.extend({
} finally {
this.set("loading", false);
}
},
}

async loadOrganizationRepos(organization) {
try {
Expand Down Expand Up @@ -65,7 +65,7 @@ export default Controller.extend({
} finally {
this.set("loading", false);
}
},
}

async hasConfiguredWebhook(orgName, repo) {
if (repo.receivedWebhookState) {
Expand All @@ -78,7 +78,7 @@ export default Controller.extend({

repo.set("receivedWebhookState", true);
repo.set("hasConfiguredWebhook", response["has_configured_webhook"]);
},
}

@discourseComputed("loadError")
configureWebhooksTitle(loadError) {
Expand All @@ -87,40 +87,37 @@ export default Controller.extend({
}

return "code_review.webhooks_load_error";
},

actions: {
async configureWebhook(organization, repo) {
if (repo.hasConfiguredWebhook === false) {
let response = await ajax(
`${prefix}/organizations/${organization.name}/repos/${repo.name}/configure-webhook.json`,
{
type: "POST",
}
);

repo.set("hasConfiguredWebhook", response["has_configured_webhook"]);
}
},

async configureWebhooks() {
for (const organization of this.organizations) {
for (const repo of organization.repos) {
if (repo.hasConfiguredWebhook === false) {
let response = await ajax(
`${prefix}/organizations/${organization.name}/repos/${repo.name}/configure-webhook.json`,
{
type: "POST",
}
);

repo.set(
"hasConfiguredWebhook",
response["has_configured_webhook"]
);
}
}

@action
async configureWebhook(organization, repo) {
if (repo.hasConfiguredWebhook === false) {
let response = await ajax(
`${prefix}/organizations/${organization.name}/repos/${repo.name}/configure-webhook.json`,
{
type: "POST",
}
);

repo.set("hasConfiguredWebhook", response["has_configured_webhook"]);
}
}

@action
async configureWebhooks() {
for (const organization of this.organizations) {
for (const repo of organization.repos) {
if (repo.hasConfiguredWebhook === false) {
let response = await ajax(
`${prefix}/organizations/${organization.name}/repos/${repo.name}/configure-webhook.json`,
{
type: "POST",
}
);

repo.set("hasConfiguredWebhook", response["has_configured_webhook"]);
}
}
},
},
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import DiscourseRoute from "discourse/routes/discourse";

export default DiscourseRoute.extend({
controllerName: "admin-plugins-code-review",
export default class AdminPluginsCodeReview extends DiscourseRoute {
controllerName = "admin-plugins-code-review";

activate() {
this.controllerFor(this.controllerName).loadOrganizations();
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UserTopicListRoute from "discourse/routes/user-topic-list";
import I18n from "I18n";

export default UserTopicListRoute.extend({
export default class UserActivityApprovalGiven extends UserTopicListRoute {
model() {
const username = this.modelFor("user").username_lower;
return this.store
Expand All @@ -16,7 +16,7 @@ export default UserTopicListRoute.extend({
model.set("emptyState", this.emptyState());
return model;
});
},
}

emptyState() {
const user = this.modelFor("user");
Expand All @@ -31,5 +31,5 @@ export default UserTopicListRoute.extend({
}
const body = "";
return { title, body };
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UserTopicListRoute from "discourse/routes/user-topic-list";
import I18n from "I18n";

export default UserTopicListRoute.extend({
export default class UserActivityApprovalPending extends UserTopicListRoute {
model() {
const username = this.modelFor("user").username_lower;
return this.store
Expand All @@ -16,7 +16,7 @@ export default UserTopicListRoute.extend({
model.set("emptyState", this.emptyState());
return model;
});
},
}

emptyState() {
const user = this.modelFor("user");
Expand All @@ -31,5 +31,5 @@ export default UserTopicListRoute.extend({
}
const body = "";
return { title, body };
},
});
}
}

0 comments on commit 872dddd

Please sign in to comment.