File

src/app/modules/profile/home/home.ts

Description

Просмотр профиля (своего и чужого)

Implements

OnInit

Metadata

selector profile-home
styleUrls home.scss
templateUrl ./home.html

Index

Properties
Methods

Constructor

constructor(profileService: ProfileService, route: ActivatedRoute, router: Router)

Конструктор

Parameters :
Name Type Description
profileService ProfileService
route ActivatedRoute
router Router

Methods

getProfile
getProfile(id: number|)

Получить профиль

Parameters :
Name Type Description
id number
Returns : void
ngOnInit
ngOnInit()

Получение данных профиля

Returns : void

Properties

defaultImage
defaultImage: string
Type : string
Default value : assets/images/default_image.svg

Изображение по-умолчанию

header
header: string
Type : string

Заголовок

loading
loading: boolean
Type : boolean

Индикатор загрузки основных данных

myProfile
myProfile: boolean
Type : boolean
Default value : false

Свой профиль или чужой

profile
profile: any
Type : any

Данные профиля

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { ProfileService } from 'glx.ui/components/kernel/services/profile.service';
import 'rxjs/add/operator/switchMap';

/**
 * Просмотр профиля (своего и чужого)
 */
@Component({
  selector: 'profile-home',
  templateUrl: './home.html',
  styleUrls: ['./home.scss']
})
export class ProfileHomeComponent implements OnInit {
  /**
   * Заголовок
   * @type {string}
   */
  header: string = '';
  /**
   * Данные профиля
   */
  profile: any;
  /**
   * Изображение по-умолчанию
   * @type {string}
   */
  defaultImage: string = 'assets/images/default_image.svg';
  /**
   * Свой профиль или чужой
   * @type {boolean}
   */
  myProfile: boolean = false;
  /**
   * Индикатор загрузки основных данных
   * @type {boolean}
   */
  loading: boolean;

  /**
   * Конструктор
   * @param {ProfileService} profileService
   * @param {ActivatedRoute} route
   * @param {Router} router
   */
  constructor(private profileService: ProfileService, private route: ActivatedRoute, private router: Router) {
  }

  /**
   * Получение данных профиля
   */
  ngOnInit() {
    this.loading = true;
    this.route.parent.params.subscribe(params => {
      const id = +params['id'];
      this.myProfile = !(id && id > 0);
      this.getProfile(id);
    });
  }

  /**
   * Получить профиль
   * @param {number} id
   */
  getProfile(id?: number | undefined) {
    if (id && id > 0) {
      this.route.params
        .switchMap((params: Params) => this.profileService.get(id))
        .subscribe((data: any) => {
            this.profile = data;
            this.header = data.user.fullname;
          },
          error => {
            console.error(error);
          },
          () => {
            this.loading = false;
          });
    } else {
      this.profileService.getCurrent()
        .subscribe(
          data => {
            this.profile = data;
            this.header = data.user.fullname;
          },
          error => {
            console.error(error);
          },
          () => {
            this.loading = false;
          });
    }
  }
}
<glx-page-title-bx [header]="header"></glx-page-title-bx>
<div>
  <glx-loading-banner [loading]="loading" [svg]="true" text="Подождите, идет загрузка..."></glx-loading-banner>
  <glx-profile-viewer [profile]="profile" [defaultImage]="defaultImage"
                      imagePrefix="/bitrix/galaktika/galaktika.vuzapi/public/"
                      [myProfile]="myProfile" *ngIf="!loading"></glx-profile-viewer>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""