78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { AfterViewInit, Component, Inject, OnInit, ViewChild } from '@angular/core';
|
|
import { GuiRowSelection, GuiRowSelectionMode, GuiRowSelectionType } from '@generic-ui/ngx-grid';
|
|
import Swal from 'sweetalert2';
|
|
import { GroupService } from '../../services/group.service';
|
|
import { Observable, forkJoin, of } from 'rxjs';
|
|
import { catchError, finalize } from 'rxjs/operators';
|
|
import { DirGroupTableComponent } from '../tables/dir-group-table/dir-group-table.component';
|
|
import { DirGroupService } from '../../services/dir-group.service';
|
|
import { DirGroup } from '../../models/user-management.api.models';
|
|
|
|
@Component({
|
|
selector: 'app-group-dir-import',
|
|
templateUrl: './group-dir-import.component.html',
|
|
styleUrl: './group-dir-import.component.css'
|
|
})
|
|
export class GroupDirImportComponent implements OnInit {
|
|
|
|
initWithoutData = () => { }
|
|
|
|
constructor(private gService: GroupService) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
|
|
@ViewChild('dirGroups') dirGroups!: DirGroupTableComponent;
|
|
|
|
dirGroupsRowSelection: GuiRowSelection = {
|
|
enabled: true,
|
|
type: GuiRowSelectionType.CHECKBOX,
|
|
mode: GuiRowSelectionMode.MULTIPLE
|
|
}
|
|
|
|
dirUsersRowSelection: GuiRowSelection = {
|
|
enabled: true,
|
|
type: GuiRowSelectionType.CHECKBOX,
|
|
mode: GuiRowSelectionMode.MULTIPLE
|
|
}
|
|
|
|
addSelectedGroups() {
|
|
let requests = new Array<Observable<DirGroup | null>>();
|
|
let numAdded: number = 0;
|
|
for (let row of this.dirGroups.selectedRows) {
|
|
requests.push(
|
|
this.gService.createByDir({ samaccountname: row?.source?.samaccountname }).pipe(
|
|
catchError((err) => {
|
|
return of(null);
|
|
})
|
|
)
|
|
);
|
|
}
|
|
|
|
forkJoin(requests).pipe(
|
|
// finalize is executed after all requests are completed or when an error occurs
|
|
finalize(() => {
|
|
// Show Swal notification after all requests are completed
|
|
Swal.fire({
|
|
icon: "success",
|
|
title: "Completed",
|
|
text: `${numAdded} new groups added`,
|
|
position: "center",
|
|
showConfirmButton: false,
|
|
timer: 3000
|
|
});
|
|
|
|
this.dirGroups.safelyUnselectAll();
|
|
})
|
|
).subscribe({
|
|
next: (results) => {
|
|
numAdded += results.filter(result => result !== null).length;
|
|
},
|
|
error: (err) => {
|
|
}
|
|
});
|
|
}
|
|
}
|