Files
enerport-web-app/src/app/pages/organizations/organizations.ts
Murat Özkorkmaz e901aefbf5 Several fixes
- added organizations
- added industries
- added logo in 2 colors for light and dark theme
- improved authorization to allow multi tenancy
2025-11-13 19:56:50 +01:00

121 lines
4.5 KiB
TypeScript

import { Component } from '@angular/core';
import { Button } from 'primeng/button';
import { Dialog } from 'primeng/dialog';
import { IconField } from 'primeng/iconfield';
import { InputIcon } from 'primeng/inputicon';
import { InputText } from 'primeng/inputtext';
import { MessageService } from 'primeng/api';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Select } from 'primeng/select';
import { ProjectStatus } from '@/pages/service/project-status.service';
import { Router } from '@angular/router';
import { Table, TableModule } from 'primeng/table';
import { Organization, OrganizationService } from '@/pages/service/organization.service';
import { Industry, IndustryService } from '@/pages/service/industry.service';
import { IsRoleAllowedPipe } from '@/pipes/is-role-allowed-pipe';
@Component({
selector: 'app-organizations',
imports: [Button, Dialog, IconField, InputIcon, InputText, ReactiveFormsModule, Select, FormsModule, TableModule, IsRoleAllowedPipe],
templateUrl: './organizations.html',
styleUrl: './organizations.scss',
providers: [MessageService]
})
export class Organizations {
organizations: Organization[] = [];
organizationIndustries: Industry[] = [];
projectStatuses: ProjectStatus[] = [];
addNewOrganizationDialogVisible = false;
statuses: any;
measures: any;
// for new organization dialog
organizationIndustryOptionsForNewOrganization: any = [];
newOrganizationName: string | undefined;
newOrganizationOwner: string | undefined;
newOrganizationIndustry: Industry | undefined;
protected loading: boolean = true;
protected searchValue: string | undefined;
constructor(
private router: Router,
private organizationService: OrganizationService,
private industryService: IndustryService,
private messageService: MessageService
) {}
ngOnInit(): void {
this.statuses = [{ label: 'Alle', value: 'all' }, ...this.projectStatuses];
this.measures = [{ label: 'Alle', value: 'all' }, ...this.organizationIndustries];
this.organizationService.getOrganizations().subscribe((organizations) => {
console.debug('Organizations', organizations);
this.organizations = organizations;
this.loading = false;
});
this.industryService.getIndustries().subscribe((industries) => {
console.debug('Industries', industries);
this.organizationIndustries = industries;
});
}
navigateToDetails(id: string | undefined) {
this.router.navigate(['/projects', id]);
}
clear(table: Table) {
table.clear();
this.searchValue = '';
}
filterGlobal(table: Table, eventTarget: EventTarget | null) {
table.filterGlobal((eventTarget as HTMLInputElement).value, 'contains');
}
showDialog() {
this.industryService.getIndustries().subscribe((industries) => {
this.organizationIndustryOptionsForNewOrganization = [];
this.organizationIndustries.forEach((projectType) => {
this.organizationIndustryOptionsForNewOrganization.push({
id: projectType.id,
name: projectType.name
});
});
});
this.organizationIndustryOptionsForNewOrganization = this.organizationIndustries;
this.addNewOrganizationDialogVisible = true;
}
createNewOrganization() {
let newOrganization = this.organizationService.getOrganizationInstance(this.newOrganizationName, this.newOrganizationIndustry, this.newOrganizationOwner);
this.organizationService.create(newOrganization).subscribe({
next: (arg) => {
this.messageService.add({
severity: 'success',
summary: 'Erfolgreich',
detail: 'Organisation erfolgreich angelegt',
life: 3000
});
this.organizations = [...this.organizations, newOrganization];
this.addNewOrganizationDialogVisible = false;
},
error: (err) => {
this.messageService.add({
severity: 'danger',
summary: 'Fehler',
detail: 'Beim Anlegen der Organisation ist ein Fehler aufgetreten.',
life: 3000
});
console.log('Error while creating organization -- Error: ' + err + ' -- Organization: ', newOrganization);
}
});
}
}