File

src/lib/components/discuss-all/discuss-all.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(router: Router, route: ActivatedRoute, discussionService: DiscussionService, configService: ConfigService, activatedRoute: ActivatedRoute, telemetryUtils: TelemetryUtilsService, navigationService: NavigationServiceService)
Parameters :
Name Type Optional
router Router No
route ActivatedRoute No
discussionService DiscussionService No
configService ConfigService No
activatedRoute ActivatedRoute No
telemetryUtils TelemetryUtilsService No
navigationService NavigationServiceService No

Inputs

categoryAction
Type : any
context
Type : any

Outputs

stateChange
Type : EventEmitter<any>

Methods

acceptData
acceptData(singleTagDetails)
Parameters :
Name Optional
singleTagDetails No
Returns : void
closeModal
closeModal(event)
Parameters :
Name Optional
event No
Returns : void
fetchAllTags
fetchAllTags()
Returns : void
fillPopular
fillPopular(page?: any)
Parameters :
Name Type Optional
page any Yes
Returns : any
fillrecent
fillrecent(_page?: any)
Parameters :
Name Type Optional
_page any Yes
Returns : void
filter
filter(key: string | "recent" | "popular")
Parameters :
Name Type Optional
key string | "recent" | "popular" No
Returns : void
getContextBasedDiscussion
getContextBasedDiscussion(cid: any)
Parameters :
Name Type Optional
cid any No
Returns : void
getContextBasedTags
getContextBasedTags(cid: any)
Parameters :
Name Type Optional
cid any No
Returns : void
getContextData
getContextData(cid: any)
Parameters :
Name Type Optional
cid any No
Returns : any
getDiscussionList
getDiscussionList(slug: string)
Parameters :
Name Type Optional
slug string No
Returns : void
Async getForumIds
getForumIds()
Returns : any
getRecentData
getRecentData()
Returns : any
loadDiscussionData
loadDiscussionData()
Returns : void
logTelemetry
logTelemetry(event)
Parameters :
Name Optional
event No
Returns : void
navigateToDiscussionDetails
navigateToDiscussionDetails(discussionData)
Parameters :
Name Optional
discussionData No
Returns : void
ngOnInit
ngOnInit()
Returns : void
refreshData
refreshData(page?: any)
Parameters :
Name Type Optional
page any Yes
Returns : void
startDiscussion
startDiscussion()
Returns : void

Properties

Public activatedRoute
Type : ActivatedRoute
allTopics
Type : any
categoryId
Type : string
cIds
Type : any
Default value : []
currentActivePage
Type : number
Default value : 1
currentFilter
Type : string
Default value : 'recent'
data
discussionList
Type : any[]
fetchNewData
getParams
Type : any
isTopicCreator
Default value : false
isWidget
Type : boolean
paramsSubscription
Type : Subscription
routeParams
Type : any
Public router
Type : Router
showLoader
Default value : false
showStartDiscussionModal
Default value : false
startDiscussionCategoryId
Type : any
sticky
Default value : false
trendingTags
Type : NSDiscussData.ITag[]
import { CONTEXT_PROPS } from './../../services/discussion.service';
import { Component, EventEmitter, Input, OnInit, Output, TemplateRef } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { DiscussionService } from '../../services/discussion.service';
import { ConfigService } from '../../services/config.service';
import { TelemetryUtilsService } from './../../telemetry-utils.service';
import * as CONSTANTS from './../../common/constants.json';
/* tslint:disable */
import * as _ from 'lodash'
import { NSDiscussData } from '../../models/discuss.model';
import { DiscussStartComponent } from '../discuss-start/discuss-start.component';
import { Subscription } from 'rxjs';
import { NavigationServiceService } from '../../navigation-service.service';
// import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';

/* tslint:enable */

@Component({
  selector: 'lib-discuss-all',
  templateUrl: './discuss-all.component.html',
  styleUrls: ['./discuss-all.component.scss']
})
export class DiscussAllComponent implements OnInit {

  @Input() context: any
  @Input() categoryAction;

  @Output() stateChange: EventEmitter<any> = new EventEmitter();

  discussionList: any[];
  routeParams: any;
  showStartDiscussionModal = false;
  categoryId: string;
  isTopicCreator = false;
  showLoader = false;
  currentFilter = 'recent'
  currentActivePage: number = 1;
  fetchNewData: false;
  // modalRef: BsModalRef;
  paramsSubscription: Subscription;
  getParams: any;
  cIds: any = [];
  allTopics: any;
  trendingTags!: NSDiscussData.ITag[];
  sticky = false;
  data
  startDiscussionCategoryId: any;
  isWidget: boolean;

  constructor(
    public router: Router,
    private route: ActivatedRoute,
    private discussionService: DiscussionService,
    private configService: ConfigService,
    public activatedRoute: ActivatedRoute,
    private telemetryUtils: TelemetryUtilsService,
    private navigationService: NavigationServiceService
    // private modalService: BsModalService
  ) { }

  ngOnInit() {
    this.telemetryUtils.logImpression(NSDiscussData.IPageName.HOME);
    if (this.context) {
      this.isWidget  = true
      this.getForumIds()
    } else {
      this.cIds = this.configService.getCategories().result
      this.loadDiscussionData()
    }
  }

  async getForumIds() {
    let body = {
      "identifier":
        this.context.contextIdArr
      ,
      "type": this.context.contextType
    }
    let resp = await this.discussionService.getForumIds(body)
    if (resp.result.length > 0) {
      resp.result.forEach(forum => {
        this.cIds.push(forum.cid)
      });
    } else {
      this.discussionService.createForum(this.context.categoryObj).subscribe(((data: any) => {
        data.result.forEach(forum => {
          this.cIds.push(forum.newCid)
        });
      }))

    }
    this.loadDiscussionData()
  }

  loadDiscussionData() {
    // debugger
    // this.cIds = this.context ? this.context.categories : this.configService.getCategories()
    this.categoryId = this.discussionService.getContext(CONTEXT_PROPS.cid);
    if (this.configService.hasContext() || this.context) {
      this.getContextBasedDiscussion(this.cIds)
      // This is to show context based trending tags
      this.getContextBasedTags(this.cIds);
    } else {
      // this.currentActivePage = 1
      this.refreshData();
      // This is to show trending tags
      this.fetchAllTags();
    }
  }

  navigateToDiscussionDetails(discussionData) {

    const matchedTopic = _.find(this.telemetryUtils.getContext(), { type: 'Topic' });
    if (matchedTopic) {
      this.telemetryUtils.deleteContext(matchedTopic);
    }

    this.telemetryUtils.uppendContext({
      id: _.get(discussionData, 'tid'),
      type: 'Topic'
    });

    const slug = _.trim(_.get(discussionData, 'slug'));
    // tslint:disable-next-line: max-line-length
    const input = { data: { url: `${this.configService.getRouterSlug()}${CONSTANTS.ROUTES.TOPIC}${slug}`, queryParams: {} }, action: CONSTANTS.CATEGORY_DETAILS, }
    this.navigationService.navigate(input);
    this.stateChange.emit({ action: CONSTANTS.CATEGORY_DETAILS, title: discussionData.title, tid: discussionData.tid });

    // this.router.navigate([`${this.configService.getRouterSlug()}${CONSTANTS.ROUTES.TOPIC}${slug}`], { queryParamsHandling: "merge" });
  }

  acceptData(singleTagDetails) {
    // debugger
    if(this.context){
    singleTagDetails.cIds =  this.cIds;
    }
    this.stateChange.emit(singleTagDetails);
  }

  getDiscussionList(slug: string) {
    this.showLoader = true;
    // TODO : this.currentActivePage shoulb be dynamic when pagination will be implemented
    this.discussionService.getContextBasedTopic(slug, this.currentActivePage).subscribe(data => {
      this.showLoader = false;
      this.isTopicCreator = _.get(data, 'privileges.topics:create') === true ? true : false;
      this.discussionList = _.union(_.get(data, 'topics'), _.get(data, 'children'));
    }, error => {
      this.showLoader = false;
      // TODO: Toaster
      console.log('error fetching topic list', error);
    });
  }

  filter(key: string | 'recent' | 'popular') {
    if (key) {
      this.currentFilter = key;
      switch (key) {
        case 'recent':
          this.cIds.length ? this.getContextData(this.cIds.result) : this.fillrecent()
          break;
        case 'popular':
          this.cIds.length ? this.getContextData(this.cIds.result) : this.fillPopular()
          break;
        default:
          break;
      }
    }
  }

  fillrecent(_page?: any) {
    this.getRecentData();
  }

  fillPopular(page?: any) {
    this.showLoader = true;
    return this.discussionService.fetchPopularD(page).subscribe((response: any) => {
      this.showLoader = false;
      this.discussionList = [];
      _.filter(response.topics, (topic) => {
        if (topic.user.uid !== 0 && topic.cid !== 1 ) {
          this.discussionList.push(topic);
        }
      });
      // this.discussionList = _.get(response, 'topics')
    }, error => {
      this.showLoader = false;
      // TODO: Toaster
      console.log('error fetching topic list', error);
    });
  }

  getContextBasedDiscussion(cid: any) {
    this.currentFilter === 'recent' ? this.getContextData(cid) : this.getContextData(cid)
  }

  refreshData(page?: any) {
    this.currentFilter === 'recent' ? this.getRecentData() : this.fillPopular(page)
  }

  getRecentData() {
    this.showLoader = true;
    return this.discussionService.fetchRecentPost().subscribe(
      (data: any) => {
        this.showLoader = false;
        this.discussionList = [];
        _.filter(data.topics, (topic) => {
          if (topic.user.uid !== 0 && topic.cid !== 1) {
            this.discussionList.push(topic);
          }
        });
        this.discussionList = _.get(data, 'posts');
      }, error => {
        this.showLoader = false;
        // TODO: Toaster
        console.log('error fetching topic list', error);
      });
  }

  getContextData(cid: any) {
    this.showLoader = true;
    const req = {
      // request: {
      cids: cid
      // }
    };
    return this.discussionService.getContextBasedDiscussion(req).subscribe(
      (data: any) => {
        this.showLoader = false;
        let result = data.result
        let res = result.filter((elem) => {
          return (elem.statusCode !== 404)
        })
        this.allTopics = _.map(res, (topic) => topic.topics);
        this.discussionList = _.flatten(this.allTopics)
      }, error => {
        this.showLoader = false;
        // TODO: Toaster
        console.log('error fetching topic list', error);
      });
  }

  fetchAllTags() {
    this.showLoader = true;
    this.discussionService.fetchAllTag().subscribe(data => {
      this.showLoader = false;
      this.trendingTags = _.get(data, 'tags');
    }, error => {
      this.showLoader = false;
      // TODO: toaster
      console.log('error fetching tags');
    });
  }

  getContextBasedTags(cid: any) {
    const req = {
      cids: cid
    }
    this.showLoader = true;
    this.discussionService.contextBasedTags(req).subscribe(data => {
      this.showLoader = false;
      this.trendingTags = _.get(data, 'result');
    }, error => {
      this.showLoader = false;
      // TODO: toaster
      console.log('error fetching tags');
    });
  }

  // startDiscussion(template: TemplateRef<any>) {
  //   this.modalRef = this.modalService.show(template);

  // this.showStartDiscussionModal = true;
  // this.bsModalRef = this.modalService.show(DiscussStartComponent);

  // this.bsModalRef.content.onClose().subscribe(
  //   console.log('completed')
  // );
  // }

  startDiscussion() {
    debugger
    this.showStartDiscussionModal = true;
    if (this.context) {
      this.startDiscussionCategoryId = this.cIds;
    }

  }

  logTelemetry(event) {
    this.telemetryUtils.logInteract(event, NSDiscussData.IPageName.HOME);
  }

  closeModal(event) {
    if (_.get(event, 'message') === 'success') {
      if (this.context) {
        this.getContextBasedDiscussion(this.cIds)
      } else {
        this.refreshData()
      }
      // this.getDiscussionList(_.get(this.routeParams, 'slug'));
    }
    this.showStartDiscussionModal = false;
  }
}
<div class="main-div">

    <!-- <button (click)="startDiscussion();logTelemetry($event)" class="df-btn df-btn-normal df-btn-primary" data-toggle="modal"
        data-target="#myModal" id="start-discussion">Start Discussion</button> -->


    <div class="flex flex-1 custom discussion_outer_box">
        <div class="flex flex-3 flex-column discussion_main_box">
            <div (click)="startDiscussion();logTelemetry($event)" data-toggle="modal"
            data-target="#myModal" id="start-discussion">
                <a href="javascript:void(0)" class="flex flex-1 cursor-pointer margin-fix height-48" i18n-aria-label role="link">
                  <div
                    class="flex flex-1 items-center border discuss border-solid discuss-border ws-mat-primary-background-op100 ">
                    <div class="w-full discuss truncate">
                      <span class="overflow ml-4 start-btn-hint mb-0 mat-body-1">Ask a question or post an idea</span>
                    </div>
                    <div class="discuss-home text-white flex items-center justify-center cursor-pointer mat-subheading-2">
                      Start discussion
                    </div>
                  </div>
                  <!-- <div class="text-box">Ask a question or post an idea</div> 
              <div class="buton">start discussion</div> -->
                </a>
              </div>

            <ng-container>
                <div class="flex flex-1 flex-row margin-fix tab_margin">
                    <div class="flex flex-1 filter max-height-60">
                        <a href="javascript:void(0)" role="link" class="filter-option" [ngClass]="{'tabs-active' : currentFilter === 'recent',
          ' font-medium':currentFilter !== 'recent'}" mat-button (click)="filter('recent')" role="button">Recent</a>
                        <a href="javascript:void(0)"  role="link" class="filter-option" [ngClass]="{'tabs-active' : currentFilter === 'popular',
          ' font-medium':currentFilter !== 'popular'}" mat-button (click)="filter('popular')" role="button">Popular</a>
                        <a href="javascript:void(0)"  role="link" class="filter-option watching_link"  mat-button role="button">Watching</a>
                    </div>
                    <div class="flex items-center">
                        <a class="all_category_link mat-subheading-2 margin-remove">All categories </a>
                    </div>
                </div>
            </ng-container>
            <!-- <lib-app-loader *ngIf="showLoader"></lib-app-loader> -->


            <ng-container *ngIf="discussionList  && discussionList.length > 0">
                <div (click)="navigateToDiscussionDetails(data);logTelemetry($event)"
                    *ngFor="let data of discussionList" id="discuss-card">
                    <lib-discuss-card [discussionData]="data"></lib-discuss-card>
                </div>
            </ng-container>

            <ng-container *ngIf=" !(discussionList && discussionList.length > 0)">
                <div class="no-card-content" tabindex="0">
                    <div class="no-data-label">No Data</div>
                    <div>
                        <span>&nbsp;</span>
                    </div>
                </div>
            </ng-container>
            <!-- <div class="flex flex-1 flex-column margin-fix pagination-container">
            <ws-app-pagination [pager]="pager" (changePage)="navigateWithPage($event)"></ws-app-pagination>
        </div> -->
        </div>
        <div *ngIf="!isWidget" class="flex flex-1 right_tag_box" #stickyMenu [class.sticky]="sticky">
            <lib-discuss-trending-tags [tags]="trendingTags" (stateChange)="acceptData($event)"></lib-discuss-trending-tags>
        </div>
    </div>

    <lib-discuss-start (close)="closeModal($event)" *ngIf="showStartDiscussionModal" [categoryId]="startDiscussionCategoryId">
    </lib-discuss-start>
</div>

./discuss-all.component.scss

// @import 'ws-common';
// @import 'ws-vars';
// @import 'ws-mixins';
// @import "node_modules/bootstrap/scss/bootstrap";

.fade:not(.show) {
  opacity: 1 !important;
}

.buton {
  display: flex;
  border: 0.0625rem solid;
  flex: 1;
  background: var(--red);
  align-content: center;
  text-align: center;
}

.sticky {
  position: fixed;
  top: 0;
  overflow: hidden;
  z-index: 10;
  width: 100%;
}

.text-box {
  display: flex;
  border: 0.0625rem solid;
  flex: 3;
  align-content: center;
  text-align: center;
}

// .margin-fix {
//   @include breakpoint-xs {
//     margin: 0 $size-l 0 $size-l;
//   }

//   @include breakpoint-s {
//     margin: 0 $size-l 0 $size-l;
//   }
// }

.overflow {
  // @include breakpoint-xs {
  //   width: 10em;
  //   // outline: 1px solid #000;
  //   margin: 0 0 2em 0;
  //   text-overflow: ellipsis !important;
  //   /**
  //  * Required properties to achieve text-overflow
  //  */
  //   white-space: nowrap;
  //   overflow: hidden;
  // }
  overflow: hidden;
}

// .custom {

// height: 48px;
// max-height: 48px;
// @include breakpoint-xs {
//   flex-direction: column;
// }

// @include breakpoint-s {
//   flex-direction: column;
// }
// }

// .pagination-container {
//   // margin-top: $size-l;

// }

.font-medium {
  font-weight: 500 !important;
}

.discuss-border {
  border-radius: 0.25rem;
  /*.75rem;*/
  border: 0.0625rem solid var(--gray-200);
  flex: 1;
  // max-width: 500px;
  /* border-color: #cecece;*/
}

.discuss .mat-form-field-wrapper {
  padding-bottom: 0px;

  .mat-form-field-infix {
    border-top-width: 0.25rem !important;
    padding: 0px;
    padding-bottom: 0.25rem;
  }

}

.discuss-home {
  background: var(--primary) 0% 0% no-repeat padding-box;
  border-radius: 0px 0.25rem 0.25rem 0px;
  padding: 0.875rem 2rem;
  // text-decoration: underline;
  /* flex: 1; */
  min-width: fit-content;
  margin: 0 1rem 1rem;
}

.flex-3 {
  flex: 3;
}

.filter {
  .filter-option {
    // margin: $size-xs $size-m;
    /* border-bottom: darkslateblue; */
    border-radius: 0;
    border-bottom-width: 0.125rem;
    border-top-width: 0;
    border-left-width: 0;
    border-right-width: 0;
    border-bottom: 0.0625rem solid var(--black);
  }
  .filter-option.tabs-active {
    border-bottom: 0.1875rem solid var(--blue);
  }
}

// .max-height-60 {
//   max-height: 60px;
// }

// .height-48 {
//   max-height: 48px;
// }

.start-btn-hint{
  display: block;
  margin-bottom: 0;
  padding: 1rem;
}
.tab_margin {
  margin-bottom: 1rem !important;
}
a.all_category_link {
 color:  var(--primary);
 display: none;
}

.watching_link{
  display: none;
}

@media (max-width: 768px) {

  .main-div {
    display: block!important;
    width:100%!important;
    padding: 0px 0px!important;
  }
  .discussion_outer_box  {
    display: block!important;
  }
  .discussion_main_box, .right_tag_box {
    width: 100%;
    display: block!important;
    float: none;
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""