File

src/app/components/add-activity-to-group/add-activity-to-group.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(groupHandlerService: GroupHandlerService, commonUtilService: CommonUtilService)
Parameters :
Name Type Optional
groupHandlerService GroupHandlerService No
commonUtilService CommonUtilService No

Inputs

identifier
Type : string
pageId
Type : string

Methods

Async addActivityToGroup
addActivityToGroup(state: CsGroupAddableState)
Parameters :
Name Type Optional
state CsGroupAddableState No
Returns : any
ngOnInit
ngOnInit()
Returns : void

Properties

state$
Type : Observable<CsGroupAddableState | undefined>
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { CommonUtilService, GroupHandlerService } from '@app/services';
import { CsGroupAddableBloc, CsGroupAddableState } from '@project-sunbird/client-services/blocs';
import { Observable, of } from 'rxjs';
import { filter } from 'rxjs/operators';

@Component({
    selector: 'add-activity-to-group',
    templateUrl: './add-activity-to-group.component.html',
    styleUrls: ['./add-activity-to-group.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class AddActivityToGroupComponent implements OnInit {

    @Input() identifier: string;
    @Input() pageId: string;
    state$: Observable<CsGroupAddableState | undefined>;

    constructor(
        private groupHandlerService: GroupHandlerService,
        private commonUtilService: CommonUtilService
    ) {
    }

    ngOnInit() {
        if (CsGroupAddableBloc.instance.initialised) {
            this.state$ = CsGroupAddableBloc.instance.state$.pipe(
                filter((state) => state && state.pageIds.includes(this.pageId))
            );
        } else {
            this.state$ = of(undefined);
        }
    }

    async addActivityToGroup(state: CsGroupAddableState) {
        if (state.params.activityList) {
            const activityExist = state.params.activityList.find(activity => activity.id === this.identifier);
            if (activityExist) {
                this.commonUtilService.showToast('ACTIVITY_ALREADY_ADDED_IN_GROUP');
                return;
            }
        }
        this.groupHandlerService.addActivityToGroup(state.groupId, this.identifier, state.params.activityType,
            this.pageId, state.params.corRelation, state.params.noOfPagesToRevertOnSuccess);
    }

}
<ng-container *ngIf="(state$ | async) as state">
    <div class="text-center" *ngIf="state">
        <button class="add-to-group-button" (click)="addActivityToGroup(state);">{{'ADD_TO_GROUP_ACTIVITY' | translate}}</button>
    </div>
</ng-container>

./add-activity-to-group.component.scss

@import "src/assets/styles/_variables.scss";

.add-to-group-button {
    background-color: $blue;
    border: none;
    color: white;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    margin: 4px 0 8px;
    width: 90%;
    padding: 16px 0 16px 0;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""