2018-07-07 05:08:10 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
2018-07-10 15:19:29 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2018-07-09 18:22:32 +02:00
|
|
|
|
2021-07-19 10:47:34 +02:00
|
|
|
import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { ExportService } from 'jslib-common/abstractions/export.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-07-21 11:32:27 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
2018-07-07 05:08:10 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
import { Organization } from 'jslib-common/models/domain/organization';
|
|
|
|
import { EventResponse } from 'jslib-common/models/response/eventResponse';
|
2018-07-06 16:21:08 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { EventService } from '../../services/event.service';
|
2018-07-09 17:47:57 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
import { BaseEventsComponent } from '../../common/base.events.component';
|
|
|
|
|
2018-07-06 16:21:08 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-org-events',
|
|
|
|
templateUrl: 'events.component.html',
|
|
|
|
})
|
2021-07-21 11:32:27 +02:00
|
|
|
export class EventsComponent extends BaseEventsComponent implements OnInit {
|
|
|
|
exportFileName: string = 'org-events';
|
2018-07-07 05:08:10 +02:00
|
|
|
organizationId: string;
|
2021-07-21 11:32:27 +02:00
|
|
|
organization: Organization;
|
2018-07-07 05:08:10 +02:00
|
|
|
|
2018-07-09 18:22:32 +02:00
|
|
|
private orgUsersUserIdMap = new Map<string, any>();
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
constructor(private apiService: ApiService, private route: ActivatedRoute, eventService: EventService,
|
2021-12-07 20:41:45 +01:00
|
|
|
i18nService: I18nService, private userService: UserService,
|
2021-07-21 11:32:27 +02:00
|
|
|
exportService: ExportService, platformUtilsService: PlatformUtilsService, private router: Router,
|
|
|
|
logService: LogService, private userNamePipe: UserNamePipe) {
|
2021-12-07 20:41:45 +01:00
|
|
|
super(eventService, i18nService, exportService, platformUtilsService, logService);
|
2021-07-21 11:32:27 +02:00
|
|
|
}
|
2018-07-07 05:08:10 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.route.parent.parent.params.subscribe(async params => {
|
2018-07-07 05:08:10 +02:00
|
|
|
this.organizationId = params.organizationId;
|
2021-07-21 11:32:27 +02:00
|
|
|
this.organization = await this.userService.getOrganization(this.organizationId);
|
|
|
|
if (this.organization == null || !this.organization.useEvents) {
|
2018-07-10 15:19:29 +02:00
|
|
|
this.router.navigate(['/organizations', this.organizationId]);
|
|
|
|
return;
|
|
|
|
}
|
2021-07-21 11:32:27 +02:00
|
|
|
|
2018-07-07 05:08:10 +02:00
|
|
|
await this.load();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2018-07-09 18:22:32 +02:00
|
|
|
const response = await this.apiService.getOrganizationUsers(this.organizationId);
|
2021-02-03 18:41:33 +01:00
|
|
|
response.data.forEach(u => {
|
2021-07-19 10:47:34 +02:00
|
|
|
const name = this.userNamePipe.transform(u);
|
2018-07-09 18:22:32 +02:00
|
|
|
this.orgUsersUserIdMap.set(u.userId, { name: name, email: u.email });
|
|
|
|
});
|
2021-06-02 14:21:57 +02:00
|
|
|
|
2021-07-28 18:40:01 +02:00
|
|
|
if (this.organization.providerId != null) {
|
|
|
|
try {
|
|
|
|
const provider = await this.userService.getProvider(this.organization.providerId);
|
|
|
|
if (provider != null && (await this.userService.getProvider(this.organization.providerId)).canManageUsers) {
|
|
|
|
const providerUsersResponse = await this.apiService.getProviderUsers(this.organization.providerId);
|
|
|
|
providerUsersResponse.data.forEach(u => {
|
|
|
|
const name = this.userNamePipe.transform(u);
|
|
|
|
this.orgUsersUserIdMap.set(u.userId, { name: `${name} (${this.organization.providerName})`, email: u.email });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.logService.warning(e);
|
|
|
|
}
|
2021-06-02 14:21:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
await this.loadEvents(true);
|
|
|
|
this.loaded = true;
|
2021-05-14 01:39:53 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
protected requestEvents(startDate: string, endDate: string, continuationToken: string) {
|
|
|
|
return this.apiService.getEventsOrganization(this.organizationId, startDate, endDate, continuationToken);
|
2021-06-02 14:21:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
protected getUserName(r: EventResponse, userId: string) {
|
|
|
|
if (userId == null) {
|
|
|
|
return null;
|
2021-06-02 14:21:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
if (this.orgUsersUserIdMap.has(userId)) {
|
|
|
|
return this.orgUsersUserIdMap.get(userId);
|
|
|
|
}
|
2018-07-09 17:47:57 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
if (r.providerId != null && r.providerId === this.organization.providerId) {
|
|
|
|
return {
|
|
|
|
'name': this.organization.providerName,
|
|
|
|
};
|
2018-07-09 17:47:57 +02:00
|
|
|
}
|
2021-05-14 01:39:53 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
return null;
|
2021-05-14 01:39:53 +02:00
|
|
|
}
|
2018-07-07 05:08:10 +02:00
|
|
|
}
|