grafana/public/app/features/org/teams_ctrl.ts

73 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-04-09 18:24:16 -05:00
///<reference path="../../headers/common.d.ts" />
import coreModule from "app/core/core_module";
import appEvents from "app/core/app_events";
2017-04-09 18:24:16 -05:00
2017-12-08 09:25:45 -06:00
export class TeamsCtrl {
teams: any;
2017-04-09 18:24:16 -05:00
pages = [];
perPage = 50;
page = 1;
totalPages: number;
showPaging = false;
2017-12-19 06:23:09 -06:00
query: any = "";
navModel: any;
2017-04-09 18:24:16 -05:00
/** @ngInject */
2017-09-22 01:42:07 -05:00
constructor(private backendSrv, navModelSrv) {
2017-12-19 06:23:09 -06:00
this.navModel = navModelSrv.getNav("cfg", "teams", 0);
2017-04-09 18:24:16 -05:00
this.get();
}
get() {
2017-12-19 06:23:09 -06:00
this.backendSrv
.get(
`/api/teams/search?perpage=${this.perPage}&page=${this.page}&query=${
this.query
}`
)
.then(result => {
2017-12-08 09:25:45 -06:00
this.teams = result.teams;
2017-04-09 18:24:16 -05:00
this.page = result.page;
this.perPage = result.perPage;
this.totalPages = Math.ceil(result.totalCount / result.perPage);
this.showPaging = this.totalPages > 1;
this.pages = [];
2017-12-19 06:23:09 -06:00
for (var i = 1; i < this.totalPages + 1; i++) {
this.pages.push({ page: i, current: i === this.page });
2017-04-09 18:24:16 -05:00
}
});
}
navigateToPage(page) {
this.page = page.page;
this.get();
}
2017-12-08 09:25:45 -06:00
deleteTeam(team) {
2017-12-19 06:23:09 -06:00
appEvents.emit("confirm-modal", {
title: "Delete",
text: "Are you sure you want to delete Team " + team.name + "?",
2017-04-09 18:24:16 -05:00
yesText: "Delete",
icon: "fa-warning",
onConfirm: () => {
2017-12-08 09:25:45 -06:00
this.deleteTeamConfirmed(team);
2017-04-09 18:24:16 -05:00
}
});
}
2017-12-08 09:25:45 -06:00
deleteTeamConfirmed(team) {
2017-12-19 06:23:09 -06:00
this.backendSrv.delete("/api/teams/" + team.id).then(this.get.bind(this));
2017-04-09 18:24:16 -05:00
}
2017-04-19 08:35:35 -05:00
2017-12-08 09:25:45 -06:00
openTeamModal() {
2017-12-19 06:23:09 -06:00
appEvents.emit("show-modal", {
templateHtml: "<create-team-modal></create-team-modal>",
modalClass: "modal--narrow"
2017-04-19 08:35:35 -05:00
});
}
2017-04-09 18:24:16 -05:00
}
2017-12-19 06:23:09 -06:00
coreModule.controller("TeamsCtrl", TeamsCtrl);