File

src/app/root/companies/company/company.component.ts

Implements

OnInit

Metadata

selector crm-company
styleUrls company.component.scss
templateUrl ./company.component.html

Index

Properties
Methods

Constructor

constructor(confirmDialogService: ConfirmDialogService, permissionsService: PermissionsService, route: ActivatedRoute, companyService: CompanyService, authService: AuthService)
Parameters :
Name Type Optional Description
confirmDialogService ConfirmDialogService
permissionsService PermissionsService
route ActivatedRoute
companyService CompanyService
authService AuthService

Methods

ngOnInit
ngOnInit()
Returns : void
onActivateUser
onActivateUser(profile: Profile)
Parameters :
Name Type Optional Description
profile Profile
Returns : void
onDeactivateUser
onDeactivateUser(profile: Profile)
Parameters :
Name Type Optional Description
profile Profile
Returns : void
showActions
showActions(profile: Profile)
Parameters :
Name Type Optional Description
profile Profile
Returns : boolean

Properties

companyId
companyId: number
Type : number
profiles
profiles: Profile[]
Type : Profile[]
Default value : []
userStates
userStates:
Default value : UserStates
import {Component, OnInit} from "@angular/core";
import {Profile} from "../../../core/models/profile/profile.model";
import {UserStates} from "../../../core/models/auth/user-state.type";
import {ConfirmDialogService} from "../../../core/confirm-dialog/confirm-dialog.service";
import {PermissionsService} from "../../../core/auth/permissions.service";
import {Actions} from "../../../core/models/auth/action.type";
import {ActivatedRoute} from "@angular/router";
import {CompanyService} from "./company.service";
import {AuthService} from "../../../core/auth/auth.service";

@Component({
  selector: 'crm-company',
  templateUrl: './company.component.html',
  styleUrls: ['./company.component.scss']
})
export class CompanyComponent implements OnInit {

  profiles: Profile[] = [];

  userStates = UserStates;

  companyId: number;

  constructor(private confirmDialogService: ConfirmDialogService,
              private permissionsService: PermissionsService,
              private route: ActivatedRoute,
              private companyService: CompanyService,
              private authService: AuthService) {
  }

  ngOnInit() {
    this.companyId = +this.route.snapshot.params['id'];
    this.companyService.getCompanyUsers(this.companyId).subscribe(
      profiles => this.profiles = profiles,
      error => console.log(error)
    )
  }

  showActions(profile: Profile) {
    return this.permissionsService.isAllow(Actions.CompanyManagement) && profile.userId !== this.authService.getUser().id
  }


  onActivateUser(profile: Profile) {
    this.confirmDialogService.ask('You really want activate ' + profile.nickname, 'Activate', 'User activation').then(
      confirm => {
        this.companyService.activateUser(profile.userId).subscribe(
          ok => profile.user.state = UserStates.Activated,
          error => console.error(error)
        )
      },
      cancel => console.log('cancel')
    )
  }

  onDeactivateUser(profile: Profile) {
    this.confirmDialogService.ask('You really want deactivate ' + profile.nickname, 'Deactivate', 'User deactivation').then(
      confirm => {
        this.companyService.deactivateUser(profile.userId).subscribe(
          ok => profile.user.state = UserStates.Deactivated,
          error => console.error(error)
        )
      },
      cancel => console.log('cancel')
    )
  }

}
<div class="card">
  <div class="card-block">
    <p class="h5 text-muted">Users</p>

    <table class="table table-hover table-outline m-b-0">
      <thead class="thead-default">
      <tr>
        <th class="text-xs-center"><i class="icon-people"></i></th>
        <th>Nickname</th>
        <th>Name</th>
        <th>Email</th>
        <th>Role</th>
        <th></th>
        <th></th>
      </tr>
      </thead>
      <tbody>
      <tr *ngFor="let profile of profiles">
        <td class="text-xs-center">
          <div class="avatar">
            <img alt="{{profile.nickname}}" class="img-avatar" src="{{profile.avatarUrl}}">
          </div>
        </td>
        <td>
          {{profile.nickname}}
        </td>
        <td>
          {{profile.firstName}} {{profile.lastName}}
        </td>
        <td>
          {{profile.user.email}}
        </td>
        <td>
          {{profile.user.role.name}}
        </td>
        <td class="text-xs-center">
          <a class="btn btn-link" [routerLink]="['/contacts', profile.userId]"
             [queryParams]="{email: profile.user.email}">Contacts</a>
          <a class="btn btn-link" [routerLink]="['/orders', 'list', profile.userId]"
             [queryParams]="{email: profile.user.email}">Orders</a>
          <a class="btn btn-link" [routerLink]="['/reports', 'user', profile.userId]"
             [queryParams]="{email: profile.user.email}">Reports</a>
        </td>
        <td>
          <div *ngIf="showActions(profile)">
            <button class="btn btn-danger" (click)="onDeactivateUser(profile)"
                    *ngIf="profile.user.state === userStates.Activated">Deactivate
            </button>
            <button class="btn btn-success" (click)="onActivateUser(profile)"
                    *ngIf="profile.user.state === userStates.Deactivated">Activate
            </button>
          </div>
          <div *ngIf="!showActions(profile)">
            {{profile.user.state}}
          </div>
        </td>
      </tr>

      </tbody>
    </table>

  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""