github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/components/user-list-component.ts (about)

     1  import { Component, Input, OnInit } from '@angular/core';
     2  
     3  import { Router } from '@angular/router';
     4  import { User } from './user';
     5  import { UserService } from './user.service';
     6  
     7  
     8  @Component({
     9      moduleId: module.id,
    10      selector: 'users',
    11      templateUrl: '/app/components/user-list.html',
    12      styleUrls: ['../../app/components/user.css'],
    13      providers: [UserService]
    14  })
    15  
    16  
    17  export class UsersComponent implements OnInit {
    18      users: User[];
    19      selectedUser: User;
    20      @Input() alias: string;
    21      @Input() email: string;
    22      @Input() password: string;
    23  
    24      constructor(private UserService: UserService, private router: Router) { }
    25  
    26  
    27      getUsers(): void {
    28          this.UserService.getUsers().then(Users => this.users = Users);
    29      }
    30  
    31      add(alias: string, email: string, password: string): void {
    32          email = email.trim();
    33          if (!email) { return; };
    34          this.UserService.create(alias, email, password)
    35              .then(User => {
    36                  this.getUsers(); // refresh user list 
    37              });
    38      }
    39  
    40      delete(user: User): void {
    41          console.log('delete user ' + user.alias + ' ' + user.email + ' ' + user.userID);
    42          this.UserService
    43              .delete(user.userID)
    44              .then(() => {
    45                  this.users = this.users.filter(h => h !== user );
    46                  if (this.selectedUser === user ) {
    47                      this.selectedUser = null;
    48                  }
    49              });
    50      }
    51  
    52      ngOnInit(): void {
    53          this.getUsers();
    54      }
    55  
    56      onSelect(User: User): void {
    57          this.selectedUser = User;
    58      }
    59  
    60      gotoDetail(): void {
    61          this.router.navigate(['/userdetail', this.selectedUser.userID]);
    62      }
    63  }