File

src/lib/services/config.service.ts

Index

Properties
Methods

Constructor

constructor(activatedRoute: ActivatedRoute, discussionService: DiscussionService)
Parameters :
Name Type Optional
activatedRoute ActivatedRoute No
discussionService DiscussionService No

Methods

Public getBannerOption
getBannerOption()
Returns : any
Public getCategories
getCategories()
Returns : any
Public getCategoryid
getCategoryid()
Returns : string
Public getConfig
getConfig()
Returns : IdiscussionConfig
Public getContext
getContext()
Returns : any
Public getHeaderOption
getHeaderOption()
Returns : any
Public getRouterSlug
getRouterSlug()
Returns : any
Public hasContext
hasContext()
Returns : any
ngOnInit
ngOnInit()
Returns : void
setCategoryid
setCategoryid(id)
Parameters :
Name Optional
id No
Returns : void
setConfig
setConfig(activatedRoute)
Parameters :
Name Optional
activatedRoute No
Returns : void
setConfigFromParams
setConfigFromParams(activatedRoute)
Parameters :
Name Optional
activatedRoute No
Returns : void
setConfigFromWidgetBaseClass
setConfigFromWidgetBaseClass(config)
Parameters :
Name Optional
config No
Returns : void

Properties

Private _config
Type : IdiscussionConfig
Public activatedRoute
Type : ActivatedRoute
categoryId
Type : string
Public checkContext
Type : boolean
getContextData
Type : any
getParams
Type : IdiscussionConfig
hasContextData
Type : any
paramsSubscription
Type : Subscription
Public queryParams
setCategoryId
Default value : new ReplaySubject(1)
import { DiscussionService } from './discussion.service';
import { Injectable, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ReplaySubject, Subscription } from 'rxjs';
import * as _ from 'lodash'
import { IdiscussionConfig } from '../models/discussion-config.model';

@Injectable({
  providedIn: 'root'
})
export class ConfigService implements OnInit {

  paramsSubscription: Subscription;
  private _config: IdiscussionConfig;
  public checkContext: boolean;
  public queryParams;
  getContextData: any;
  hasContextData: any;
  getParams: IdiscussionConfig;
  setCategoryId = new ReplaySubject(1)
  categoryId: string

  constructor(
    public activatedRoute: ActivatedRoute,
    private discussionService: DiscussionService,
  ) { }

  ngOnInit() {

  }

  setConfig(activatedRoute) {
    activatedRoute.data.subscribe((config) => {
    this._config = config.data;
    });
  }

  setConfigFromParams(activatedRoute) {
    activatedRoute.queryParams.subscribe((params) => {
      const obj: IdiscussionConfig = {
        userId : _.get(params, 'userId'),
        categories : JSON.parse(_.get(params, 'categories'))
      };
      this._config = obj;
    });
  }

  setConfigFromWidgetBaseClass(config){
    this._config = config
  }

  public getConfig() {
    return this._config;
  }

  public getCategories() {
    this.getParams = this.getConfig()
    return _.get(this.getParams, 'categories')
  }

  public hasContext() {
    this.hasContextData = this.getCategories() ?
      (this.getCategories().result ? this.getCategories().result.length : null)
      : null
    return this.hasContextData
  }

  public getContext() {
    this.getContextData = this.getCategories() ?
      (this.getCategories().result ? this.getCategories().result : null)
      : null
    return this.getContextData
  }

  setCategoryid(id) {
    this.categoryId = id
    this.setCategoryId.next(id)
  }


  public getHeaderOption() {
    return this._config.headerOptions !== undefined ? this._config.headerOptions : true;
  }

  public getBannerOption() {
    return this._config.bannerOption ? this._config.bannerOption : false;
  }

  public getCategoryid() {
    return this.categoryId
  }

  public getRouterSlug() {
    return this._config.routerSlug ? this._config.routerSlug : '';
  }
}

results matching ""

    No results matching ""