import { Component, Input, Inject } from '@angular/core'; import { CollectionService } from '../collection/collection.service'; import { Profile_CONSTANTS } from '../shared/profile.constants'; import { MatDialogConfig, MatDialog } from '@angular/material'; import { ViewIframeDialog } from '../view-iframe/view-iframe.component'; @Component({ selector: 'rss-collection-group', templateUrl: './collection-group.component.html', styleUrls: ['../shared/shared.component.scss'], providers: [CollectionService] }) export class CollectionGroupComponent { @Input('environment') environment: any; @Input('campusCode') campusCode: any; @Input('collectionConfig') collectionConfig: any; @Input('loggedInUser') loggedInUser: any; public autosuggestConfig: any; public alreadyExists: boolean = false; constructor(public dialog: MatDialog, public collectionService: CollectionService, @Inject(Profile_CONSTANTS) private constants) { } ngOnInit() { this.collectionService.setEnvironment(this.environment); this.autosuggestConfig = { placeholder: this.constants.collection.groups.placeholder, value: this.constants.collection.groups.autoSuggestValue, text: this.constants.collection.groups.autoSuggestText, url: this.collectionService.searchGroupURL(this.campusCode), noDataMessage: this.constants.collection.messages.noGroupFound } } public isCollectionAdminOnly() { return (this.loggedInUser.roles.includes(this.constants.roles.CollectionsAdmin.value) && !this.loggedInUser.roles.includes(this.constants.roles.ServiceDesk.value)) ? true : false; } public addGroup = (group: any) => { if (this.isGroupExists(group)) { this.showAlreadyExistMessage(); } else { this.alreadyExists = false; this.collectionService.addGroupToCollection(this.collectionConfig.collectionId, group.groupId) .subscribe(res => { this.collectionConfig.listGroups.push(group); }); } } public viewGroup = (group) => { this.collectionConfig.viewGroup = group; const dialogConfig = new MatDialogConfig(); dialogConfig.width = '800px'; dialogConfig.data = { head: group.groupName, environment: this.environment, group: group }; let dialogRef = this.dialog.open(ViewIframeDialog, dialogConfig); dialogRef.afterClosed().subscribe(result => { }); } public removeGroup = (group) => { this.collectionService.removeGroupfromCollection(this.collectionConfig.collectionId, group.groupId) .subscribe(res => { this.collectionConfig.listGroups = this.collectionConfig.listGroups.filter(ogroup => ogroup !== group); }); } public isGroupExists = (group) => { if (this.collectionConfig.listGroups) return (this.collectionConfig.listGroups.find((item) => (item.groupId === group.groupId)) !== undefined); else return false; } public showAlreadyExistMessage = () => { this.alreadyExists = true; } public hideAlreadyExists = (data) => { this.alreadyExists = false; } public isRUA = (group) => { if (group.tags.includes(this.constants.collection.groups.RUATag)) return true; else return false; } }