Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { NgForm } from "@angular/forms";
  4. import { EntityQuery, EntityQueryResult, TeamSummary, Team, Organization } from "app/entities";
  5. import { MxTableComponent, MxColumn } from "app/mx-components/mx-table/mx-table.component";
  6. import { AdminApiService } from "app/core/api/admin-api.service";
  7. import { OrgPageData } from "../../admin-resolver";
  8.  
  9. @Component({
  10.   templateUrl: "./team.component.html",
  11.   host: { "class": "page-column" }
  12. })
  13. export class TeamComponent implements OnInit {
  14.  
  15.   readonly columns: MxColumn[] = [
  16.     { name: "Name", valueKey: "name", sortable: true },
  17.     { name: "Organization", valueKey: "organizationName", sortable: true },
  18.     {
  19.       name: "Users", valueKey: "userCount", sortable: true,
  20.       link: (item: TeamSummary) => `/admin/users?organizationId=${item.organizationId}&teamId=${item.id}`
  21.     },
  22.   ];
  23.  
  24.   item = {} as Team;
  25.   editing: boolean;
  26.   data: OrgPageData;
  27.  
  28.   @ViewChild(MxTableComponent)
  29.   table: MxTableComponent;
  30.  
  31.   @ViewChild(NgForm)
  32.   form: NgForm;
  33.  
  34.   readonly dataSource = (query: EntityQuery) => this.adminApi.queryTeams(query, this.data.selectedOrganizationId);
  35.   readonly submitAction = () => this.adminApi.commitTeam(this.item)
  36.     .switchMap(() => this.table.reloadAndWait())
  37.     .do(() => this.finishEditing())
  38.   readonly cancelAction = () => this.finishEditing();
  39.   readonly deleteAction = () => { this.item.active = false; return this.submitAction(); };
  40.  
  41.   constructor(private route: ActivatedRoute, private adminApi: AdminApiService) { }
  42.  
  43.   ngOnInit() {
  44.     this.data = this.route.snapshot.data.seed;
  45.   }
  46.  
  47.   onAdd() {
  48.     this.item = {
  49.       active: true,
  50.       id: 0,
  51.       name: null,
  52.       organizationId: this.data.selectedOrganizationId,
  53.     };
  54.     this.editing = true;
  55.   }
  56.  
  57.   onEdit(value: Team) {
  58.     this.item = Object.assign({}, value);
  59.     this.editing = true;
  60.   }
  61.  
  62.   finishEditing() {
  63.     this.editing = false;
  64.     setTimeout(() => this.form.resetForm(), 1000);
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement