2017-12-20 05:33:33 -06:00
|
|
|
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-20 05:33:33 -06:00
|
|
|
query: any = '';
|
2017-06-05 17:47:25 -05:00
|
|
|
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-20 05:33:33 -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
|
2017-12-21 01:39:31 -06:00
|
|
|
.get(`/api/teams/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
|
2017-12-19 06:23:09 -06:00
|
|
|
.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-20 05:33:33 -06:00
|
|
|
appEvents.emit('confirm-modal', {
|
|
|
|
title: 'Delete',
|
|
|
|
text: 'Are you sure you want to delete Team ' + team.name + '?',
|
|
|
|
yesText: 'Delete',
|
|
|
|
icon: 'fa-warning',
|
2017-04-09 18:24:16 -05:00
|
|
|
onConfirm: () => {
|
2017-12-08 09:25:45 -06:00
|
|
|
this.deleteTeamConfirmed(team);
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-04-09 18:24:16 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-08 09:25:45 -06:00
|
|
|
deleteTeamConfirmed(team) {
|
2017-12-20 05:33:33 -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-20 05:33:33 -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-20 05:33:33 -06:00
|
|
|
coreModule.controller('TeamsCtrl', TeamsCtrl);
|