admin-users-table.component.ts 1.88 KB
Newer Older
1
2
import Vue from 'vue';
import Component from 'vue-class-component';
3
4
5
6
7
8
9
import {IUser, User} from '@/shared/model/user.model';
import {Inject, Prop} from 'vue-property-decorator';
import OaInput from '@/components/forms/input/oa-input.vue';
import UserManagementService from '@/admin/user-management/user-management.service';
import OaButton from '@/components/button/oa-button.vue';
import Icon from '@/components/icon/icon.vue';
import {ItemFront} from "@/front/model/item-front.model";
10

11
12
13
14
15
16
17
@Component({
  components: {
    OaInput,
    OaButton,
    Icon,
  }
})
18
19
export default class AdminUsersTable extends Vue {
  @Prop()
20
21
22
23
24
25
26
27
28
29
  public authorizedUsers: User[];

  public loginSearch: string = '';

  private userSelected: IUser = new User();

  public autocompleteUsers: IUser[] = [];

  @Inject('userService')
  private userManagementService: () => UserManagementService;
30

31
  public getUserEditLink(userId: string) {
32
33
    return `/admin/user/${userId}/edit`;
  }
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

  public set currentLoginSearch(login: string) {
    this.loginSearch = login;
    if (this.loginSearch) {
      this.userManagementService()
        .findAllByLoginLike(this.loginSearch)
        .then(res => {
          this.autocompleteUsers = res.data;
        });
    }
  }

  public get currentLoginSearch(): string {
    return this.loginSearch;
  }

  public getDisplayStringAutocomplete(user: IUser) {
    return `${user.firstName} ${user.lastName} (${user.login})`;
  }

  public selectUser(user: IUser) {
    this.loginSearch = user.login;
    this.userSelected = user;
    this.autocompleteUsers = [];
  }

  public addPermission() {
    if (this.userSelected) {
      this.$emit('addPermission', this.userSelected);
      this.authorizedUsers.push(this.userSelected);
    }
  }

  public deletePermission(user: IUser) {
    this.$emit('removePermission', user);
    this.authorizedUsers = this.authorizedUsers.filter(value => value.id !== user.id);
  }
71
}