Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, ViewChild } from "@angular/core";
- import { ActivatedRoute } from "@angular/router";
- import { NgForm } from "@angular/forms";
- import { EntityQuery, EntityQueryResult, TeamSummary, Team, Organization } from "app/entities";
- import { MxTableComponent, MxColumn } from "app/mx-components/mx-table/mx-table.component";
- import { AdminApiService } from "app/core/api/admin-api.service";
- import { OrgPageData } from "../../admin-resolver";
- @Component({
- templateUrl: "./team.component.html",
- host: { "class": "page-column" }
- })
- export class TeamComponent implements OnInit {
- readonly columns: MxColumn[] = [
- { name: "Name", valueKey: "name", sortable: true },
- { name: "Organization", valueKey: "organizationName", sortable: true },
- {
- name: "Users", valueKey: "userCount", sortable: true,
- link: (item: TeamSummary) => `/admin/users?organizationId=${item.organizationId}&teamId=${item.id}`
- },
- ];
- item = {} as Team;
- editing: boolean;
- data: OrgPageData;
- @ViewChild(MxTableComponent)
- table: MxTableComponent;
- @ViewChild(NgForm)
- form: NgForm;
- readonly dataSource = (query: EntityQuery) => this.adminApi.queryTeams(query, this.data.selectedOrganizationId);
- readonly submitAction = () => this.adminApi.commitTeam(this.item)
- .switchMap(() => this.table.reloadAndWait())
- .do(() => this.finishEditing())
- readonly cancelAction = () => this.finishEditing();
- readonly deleteAction = () => { this.item.active = false; return this.submitAction(); };
- constructor(private route: ActivatedRoute, private adminApi: AdminApiService) { }
- ngOnInit() {
- this.data = this.route.snapshot.data.seed;
- }
- onAdd() {
- this.item = {
- active: true,
- id: 0,
- name: null,
- organizationId: this.data.selectedOrganizationId,
- };
- this.editing = true;
- }
- onEdit(value: Team) {
- this.item = Object.assign({}, value);
- this.editing = true;
- }
- finishEditing() {
- this.editing = false;
- setTimeout(() => this.form.resetForm(), 1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement