File

src/app/modules/groups/components/group-header/group-header.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(renderer: Renderer2, resourceService: ResourceService, router: Router, groupService: GroupsService, navigationHelperService: NavigationHelperService, toasterService: ToasterService, activatedRoute: ActivatedRoute, userService: UserService, discussionService: DiscussionService, discussionTelemetryService: DiscussionTelemetryService, activateRoute: ActivatedRoute, layoutService: LayoutService)
Parameters :
Name Type Optional
renderer Renderer2 No
resourceService ResourceService No
router Router No
groupService GroupsService No
navigationHelperService NavigationHelperService No
toasterService ToasterService No
activatedRoute ActivatedRoute No
userService UserService No
discussionService DiscussionService No
discussionTelemetryService DiscussionTelemetryService No
activateRoute ActivatedRoute No
layoutService LayoutService No

Inputs

groupData
Type : IGroupCard

Outputs

handleFtuModal
Type : EventEmitter

Methods

activateGroup
activateGroup()
Returns : void
addTelemetry
addTelemetry(id, extra?, edata?)
Parameters :
Name Optional Description
id No
extra Yes
edata Yes

? - it's an object to specify the type and subtype of edata

Returns : void
assignForumData
assignForumData(routerData)
Parameters :
Name Optional
routerData No
Returns : void
assignModalStrings
assignModalStrings(title, msg, replaceStr?)
Parameters :
Name Optional
title No
msg No
replaceStr Yes
Returns : void
deActivateGroup
deActivateGroup()
Returns : void
deleteGroup
deleteGroup()
Returns : void
disableDiscussionForum
disableDiscussionForum()
Returns : void
dropdownMenu
dropdownMenu()
Returns : void
editGroup
editGroup()
Returns : void
enableDiscussionForum
enableDiscussionForum()
Returns : void
fetchForumConfig
fetchForumConfig()
Returns : void
fetchForumIds
fetchForumIds(groupId: string)
Parameters :
Name Type Optional
groupId string No
Returns : void
goBack
goBack()
Returns : void
handleEvent
handleEvent(event: literal type)
Parameters :
Name Type Optional
event literal type No
Returns : void
leaveGroup
leaveGroup()
Returns : void
navigateToPreviousPage
navigateToPreviousPage()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
toggleFtuModal
toggleFtuModal(visibility: boolean)
Parameters :
Name Type Optional Default value
visibility boolean No false
Returns : void
toggleModal
toggleModal(visibility, name?: string, eventName?: string)
Parameters :
Name Type Optional Default value
visibility No false
name string Yes
eventName string Yes
Returns : void

Properties

Public activateRoute
Type : ActivatedRoute
createForumRequest
Type : any
creator
Type : string
Public discussionTelemetryService
Type : DiscussionTelemetryService
dropdownContent
Default value : true
fetchForumConfigReq
Type : Array<IFetchForumConfig>

To fetch create-forum request payload for groups

fetchForumIdReq
Type : IFetchForumId

input data to fetch forum Ids

forumIds
Type : Array<number>
Default value : []
layoutConfiguration
Type : any
Public layoutService
Type : LayoutService
modal
Decorators :
@ViewChild('modal')
Public msg
Type : string
Public name
Type : string
Public resourceService
Type : ResourceService
showEditModal
Type : boolean
showLeaveGroupModal
Default value : false
showLoader
Default value : false
showModal
Default value : false
Public title
Type : string
Public unsubscribe
Default value : new Subject<void>()
Private unsubscribe$
Default value : new Subject<void>()
Public UPDATE_GROUP
Default value : UPDATE_GROUP
import { GroupEntityStatus } from '@project-sunbird/client-services/models/group';
import { actions } from './../../interfaces/group';
import { Router, ActivatedRoute } from '@angular/router';
import { Component, ViewChild, Input, Renderer2, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { ResourceService, NavigationHelperService, ToasterService, LayoutService } from '@sunbird/shared';
import { MY_GROUPS, GROUP_DETAILS, IGroupCard, IFetchForumId, EDIT_GROUP, IFetchForumConfig } from './../../interfaces';
import { GroupsService } from '../../services';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '@sunbird/core';
import { DiscussionService } from '../../../discussion/services/discussion/discussion.service';
import { DiscussionTelemetryService } from '../../../shared/services/discussion-telemetry/discussion-telemetry.service';
import { UPDATE_GROUP, SELECT_DELETE, SELECT_DEACTIVATE, SELECT_NO, DELETE_SUCCESS } from '../../interfaces/telemetryConstants';
@Component({
  selector: 'app-group-header',
  templateUrl: './group-header.component.html',
  styleUrls: ['./group-header.component.scss']
})
export class GroupHeaderComponent implements OnInit, OnDestroy {
  dropdownContent = true;
  @ViewChild('modal') modal;
  @Input() groupData: IGroupCard;
  @Output() handleFtuModal = new EventEmitter();
  showModal = false;
  showEditModal: boolean;
  creator: string;
  showLeaveGroupModal = false;
  showLoader = false;
  public title: string;
  public msg: string;
  public name: string;
  private unsubscribe$ = new Subject<void>();
  forumIds: Array<number> = [];
  createForumRequest: any;
  public UPDATE_GROUP = UPDATE_GROUP;
  layoutConfiguration: any;
  public unsubscribe = new Subject<void>();
    /**
   * input data to fetch forum Ids
   */
  fetchForumIdReq: IFetchForumId;

  /**
   * To fetch create-forum request payload for groups
   */
  fetchForumConfigReq: Array<IFetchForumConfig>;

  constructor(private renderer: Renderer2, public resourceService: ResourceService, private router: Router,
    private groupService: GroupsService, private navigationHelperService: NavigationHelperService, private toasterService: ToasterService,
    private activatedRoute: ActivatedRoute, private userService: UserService, private discussionService: DiscussionService,
    public discussionTelemetryService: DiscussionTelemetryService, public activateRoute: ActivatedRoute, public layoutService: LayoutService) {
    this.renderer.listen('window', 'click', (e: Event) => {
      if (e.target['tabIndex'] === -1 && e.target['id'] !== 'group-actions') {
        this.dropdownContent = true;
      }
    });
  }

  ngOnInit () {

    this.fetchForumIdReq = {
      type: 'group',
      identifier: [ this.groupData.id ]
    };
    this.fetchForumConfig();
    this.fetchForumIds(this.groupData.id);
    this.creator = _.capitalize(_.get(_.find(this.groupData['members'], {userId: this.groupData['createdBy']}), 'name'));
    this.groupService.showMenu.subscribe(data => {
      this.dropdownContent = data !== 'group';
    });
    this.groupService.showActivateModal.subscribe((data: {name: string, eventName: string}) => {
      this.toggleModal(true, data.name, data.eventName);
    });

    this.groupService.updateEvent.pipe(takeUntil(this.unsubscribe$)).subscribe((status: GroupEntityStatus) => {
      this.groupData.active = this.groupService.updateGroupStatus(this.groupData, status);
    });

    this.layoutConfiguration = this.layoutService.initlayoutConfig();
    this.layoutService.switchableLayout().
      pipe(takeUntil(this.unsubscribe)).subscribe(layoutConfig => {
        if (layoutConfig != null) {
          this.layoutConfiguration = layoutConfig.layout;
        }
      });

  }

  navigateToPreviousPage() {
    setTimeout(() => {
      this.showLoader = false;
      this.goBack();
    }, 1500);
  }

  editGroup() {
    this.router.navigate([`${MY_GROUPS}/${GROUP_DETAILS}`, _.get(this.groupData, 'id'), EDIT_GROUP]);
  }

  goBack() {
    this.navigationHelperService.goBack();
  }

  dropdownMenu() {
    this.dropdownContent = !this.dropdownContent;
  }

  toggleFtuModal(visibility: boolean = false) {
    this.handleFtuModal.emit(visibility);
  }

   /**
   * @description - To set the telemetry Intract event data
   * @param  {} edata? - it's an object to specify the type and subtype of edata
   */
  addTelemetry(id, extra?, edata?) {
    this.groupService.addTelemetry({id, extra, edata}, this.activatedRoute.snapshot, [], _.get(this.groupData, 'id'));
  }
  toggleModal(visibility = false, name?: string, eventName?: string) {
    this.showModal = visibility;
    this.groupService.emitMenuVisibility('group');
    this.name = name;
    switch (name) {
      case actions.DELETE:
        this.addTelemetry('delete-group', {status: _.get(this.groupData, 'status')}, {type: SELECT_DELETE});
        this.assignModalStrings(this.resourceService.frmelmnts.lbl.deleteGroup, this.resourceService.messages.imsg.m0082, '{groupName}');
        break;
      case actions.DEACTIVATE:
        this.addTelemetry('deactivate-group', {status: _.get(this.groupData, 'status')}, {type: SELECT_DEACTIVATE});
        this.assignModalStrings(this.resourceService.frmelmnts.lbl.deactivategrpques, this.resourceService.frmelmnts.msg.deactivategrpmsg);
        break;
      case actions.ACTIVATE:
        this.addTelemetry((eventName ? eventName : 'activate-group-menu'), {status: _.get(this.groupData, 'status')});
        this.assignModalStrings(this.resourceService.frmelmnts.lbl.activategrpques, this.resourceService.frmelmnts.msg.activategrppopup);
        break;
      case actions.DISABLE_FORUM:
        this.addTelemetry('disable-discussion-forum', {status: _.get(this.groupData, 'status')});
        this.assignModalStrings('Disable discussion forum ?', 'Disabling forum will remove all the discussion. Do you want to continue');
        break;
    }
  }


  assignModalStrings(title, msg, replaceStr?) {
    this.title = title;
    this.msg = replaceStr ? msg.replace(replaceStr, this.groupData.name) : msg;
  }

  handleEvent(event: {name: string, action?: boolean}) {
    this.showModal = false;
    this.showLoader = event.action;
    if (!event.action) {
      this.addTelemetry(`cancel-${event.name}-group`, {status: _.get(this.groupData, 'status')}, {type: SELECT_NO});
      return;
    }
    switch (event.name) {
      case actions.DELETE:
        this.deleteGroup();
        break;
      case actions.DEACTIVATE:
        this.deActivateGroup();
        break;
      case actions.ACTIVATE:
        this.activateGroup();
        break;
      case actions.DISABLE_FORUM:
        this.disableDiscussionForum();
        break;
    }
  }

  leaveGroup() {
    this.showLoader = true;
    /* istanbul ignore else */
    if (!this.groupService.isCurrentUserCreator) {
      this.groupService.removeMembers(this.groupData.id, [this.userService.userid])
        .pipe(takeUntil(this.unsubscribe$))
        .subscribe(resp => {
          this.showLoader = false;
          this.toasterService.success(this.resourceService.messages.smsg.leaveGroup);
          this.goBack();
        }, error => {
          this.showLoader = false;
          this.toasterService.error(this.resourceService.messages.emsg.leaveGroup);
        });
    }
    // TODO: leave group API integration and add telemetry
  }

  deleteGroup() {
      this.groupService.deleteGroupById(_.get(this.groupData, 'id')).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
        // tslint:disable-next-line:max-line-length
        this.addTelemetry('confirm-delete-group', {status: 'inactive', prevstatus: _.get(this.groupData, 'status')}, {type: DELETE_SUCCESS});
        this.toasterService.success(this.resourceService.messages.smsg.grpdeletesuccess);
        this.navigateToPreviousPage();
      }, err => {
        this.addTelemetry('confirm-delete-group', {status: _.get(this.groupData, 'status')});
        this.toasterService.error(this.resourceService.messages.emsg.m003);
        this.navigateToPreviousPage();
      });
  }

  deActivateGroup() {
    this.groupService.deActivateGroupById(_.get(this.groupData, 'id')).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
      this.addTelemetry('confirm-deactivate-group', {status: 'suspended', prevstatus: _.get(this.groupData, 'status')});
      this.toasterService.success(this.resourceService.frmelmnts.msg.deactivategrpsuccess);
      this.showLoader = false;
      this.groupData.active = this.groupService.updateGroupStatus(this.groupData, GroupEntityStatus.SUSPENDED);
      this.groupService.emitUpdateEvent(GroupEntityStatus.SUSPENDED);
    }, err => {
      this.addTelemetry('confirm-deactivate-group', {status: _.get(this.groupData, 'status')});
      this.showLoader = false;
      this.toasterService.error(this.resourceService.frmelmnts.msg.deactivategrpfailed);
    });
  }

  activateGroup() {
    this.groupService.activateGroupById(_.get(this.groupData, 'id')).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
      this.addTelemetry('confirm-activate-group', {status: 'active', prevstatus: _.get(this.groupData, 'status')});
      this.toasterService.success(this.resourceService.frmelmnts.msg.activategrpsuccess);
      this.showLoader = false;
      this.groupData.active = this.groupService.updateGroupStatus(this.groupData, GroupEntityStatus.ACTIVE);
      this.groupService.emitUpdateEvent(GroupEntityStatus.ACTIVE);
    }, err => {
      this.addTelemetry('confirm-activate-group', {status: _.get(this.groupData, 'status')});
      this.showLoader = false;
      this.toasterService.error(this.resourceService.frmelmnts.msg.activategrpfailed);
    });
  }

  fetchForumConfig() {
    this.fetchForumConfigReq = [{
      type: 'group',
      identifier: this.groupData.id
  }];
    const subType = 'group';
    this.discussionService.fetchForumConfig(subType).subscribe((formData: any) => {
      this.createForumRequest = formData[0];
      this.createForumRequest['category']['context'] =  this.fetchForumConfigReq;
    }, error => {
      this.toasterService.error(this.resourceService.messages.emsg.m0005);
    });
  }

    fetchForumIds(groupId: string) {
      const request = {
        identifier: [ groupId ],
        type: 'group'
      };
      this.discussionService.getForumIds(request).subscribe(forumDetails => {
        this.forumIds = _.map(_.get(forumDetails, 'result'), 'cid');
      }, error => {
        this.toasterService.error(this.resourceService.messages.emsg.m0005);
      });
    }

    disableDiscussionForum() {
      this.addTelemetry('confirm-disable-forum', {status: _.get(this.groupData, 'status')});
      const requestBody = {
        'sbType': 'group',
        'sbIdentifier': this.groupData.id,
        'cid': this.forumIds
      };
      this.discussionService.removeForum(requestBody).subscribe(resp => {
        this.showLoader = false;
        this.toasterService.success('Disabled discussion forum successfully');
        this.fetchForumIds(this.groupData.id);
      }, error => {
        this.showLoader = false;
        this.toasterService.error(this.resourceService.messages.emsg.m0005);
      });

    }

    enableDiscussionForum() {
      this.addTelemetry('confirm-enable-forum', {status: _.get(this.groupData, 'status')});
      this.showLoader = true;
      this.discussionService.createForum(this.createForumRequest).subscribe(resp => {
        this.showLoader = false;
        this.toasterService.success('Enabled discussion forum successfully');
        this.fetchForumIds(this.groupData.id);
      }, error => {
        this.showLoader = false;
        this.toasterService.error(this.resourceService.messages.emsg.m0005);
      });
    }
    /**
     * @description - navigate to the DF Page when the event is emited from the access-discussion component
     * @param  {} routerData
     */
    assignForumData(routerData) {
      this.router.navigate(['/discussion-forum'], {
        queryParams: {
          categories: JSON.stringify({ result: routerData.forumIds }),
          userId: routerData.userId
        }
      });
    }

  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }
}
<div class="ui container d-flex flex-ai-center py-8">
  <app-back-button></app-back-button>
  <div class="d-flex flex-ai-center flex-jc-space-between flex-w-wrap w-100">
    <div class="d-flex flex-dc mx-16">
      <h4 class="mb-4 font-weight-bold sb__ellipsis sb__ellipsis--one d-flex">{{groupData?.name}}</h4>
      <div class="fsmall">{{resourceService?.frmelmnts?.lbl?.groupCreatedBy | interpolate:'{name}': creator}}</div>
    </div>
    <div class="d-flex flex-ai-end flex-w-wrap content-header__buttons">

      <!--Forum Icon-->
      <app-access-discussion [forumIds]="forumIds" [fetchForumIdReq]="fetchForumIdReq"
        (routerData)="assignForumData($event)"> </app-access-discussion>
      <div class="d-flex flex-ai-center flex-w-wrap content-header__buttons">
        <!-- <button class="sb-btn sb-btn-normal sb-btn-link-primary min-w-auto p-0 px-8" type="button"
          (click)="toggleFtuModal(true);addTelemetry('member-ftu-popup')">
          <i class="icon-svg icon-svg--sm icon-info" aria-hidden="true">
            <svg class="icon icon-svg--primary">
              <use xlink:href="./assets/images/sprite.svg#info"></use>
            </svg>
          </i>
        </button> -->
        <div class="kabab-menu" id="group-actions" tabindex="0" (click)="dropdownMenu();addTelemetry('kebab-menu')">
        </div>
        <div class="kabab-menu-dropdown-content" [hidden]="dropdownContent">


          <!-- dropdownContent btn Labels -->
          <!-- admin -->
          <div *ngIf="groupData?.isAdmin">
            <!-- when group is active -->
            <div *ngIf="groupData?.active">
              <div class="d-flex flex-ai-center list p-8 w-100" tabindex="0"
                (click)="editGroup();addTelemetry('edit-group', '', { type: UPDATE_GROUP})">
                {{resourceService?.frmelmnts?.lbl?.editGroup}}
              </div>
              <div class="d-flex flex-ai-center list p-8 w-100 fnormal" tabindex="0"
                (click)="toggleModal(true, 'deActivate')">
                {{resourceService?.frmelmnts?.btn?.deactivategrp}}
              </div>
              <div class="d-flex flex-ai-center list p-8 w-100 fnormal" *ngIf="forumIds.length === 0" tabindex="0"
                (click)="enableDiscussionForum()">
                {{resourceService?.frmelmnts?.lbl?.enableDiscussionForum}}
              </div>
              <div class="d-flex flex-ai-center list p-8 w-100 fnormal" *ngIf="forumIds.length > 0" tabindex="0"
                (click)="toggleModal(true, 'disableDiscussionForum')">
                {{resourceService?.frmelmnts?.lbl?.disableDiscussionForum}}
              </div>
            </div>

            <!-- when group is suspended -->
            <div *ngIf="!groupData?.active">
              <div class="d-flex flex-ai-center list p-8 w-100 fnormal" tabindex="0"
                (click)="toggleModal(true, 'activate');">
                {{resourceService?.frmelmnts.lbl.activategrp}}
              </div>
            </div>
          </div>

          <!-- member -->
          <div *ngIf="!groupData?.isCreator">
            <div class="d-flex flex-ai-center list sb-color-error p-8 w-100" tabindex="0"
              (click)="showLeaveGroupModal=true;dropdownMenu()">
              {{resourceService?.frmelmnts?.lbl?.leaveGroup}}
            </div>
          </div>

          <!-- creator -->
          <div *ngIf="groupData?.isCreator">
            <div class="d-flex flex-ai-center list sb-color-error p-8 w-100" tabindex="0"
              (click)="toggleModal(true, 'delete');">{{resourceService?.frmelmnts?.lbl?.deleteGroup}}
            </div>
          </div>

          <!-- end dropdownContent btn Labels -->

        </div>
      </div>
    </div>
  </div>
</div>


<app-modal *ngIf="showModal" [title]="title" [msg]="msg" [name]="name" (handleEvent)="handleEvent($event)"></app-modal>


<app-member-actions *ngIf="showLeaveGroupModal" [action]="'leaveFromGroup'" [groupName]="groupData?.name"
  (modalClose)="showLeaveGroupModal=false" (actionConfirm)="leaveGroup()"></app-member-actions>

<app-loader *ngIf="showLoader" [data]="{loaderMessage: resourceService?.messages?.fmsg?.m0087}"> </app-loader>

./group-header.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
@use "pages/kabab-menu" as *;
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""