|
- import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
- import {
- ContactPartnerProductJsonld,
- ContactPartnerProductService, PartnerJsonld,
- PartnerProductJsonld,
- PartnerProductService, PartnerService,
- ProductService
- } from "@app/core/api/v1";
- import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer";
- import {FormGroup} from "@angular/forms";
- import {partnerProductForm} from "@app/_forms/apiForms";
- import {AppHelperService} from "@app/_helpers/app-helper.service";
- import {ModalStatus} from "@app/_helpers/modal.states";
- import {SearchSelectComponent} from "@app/_components/search-select/search-select.component";
- import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type";
- import {TranslateService} from "@ngx-translate/core";
-
- @Component({
- selector: 'app-assign-partner',
- templateUrl: './assign-partner.component.html',
- styleUrl: './assign-partner.component.scss'
- })
- export class AssignPartnerComponent implements OnInit {
- @Input() public partner!: PartnerJsonld;
- @Input() public productIri!: string;
- @Input() public partnerProduct!: PartnerProductJsonld;
- @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>();
- @ViewChild('productSearchSelect', {static: false}) productSearchSelect!: SearchSelectComponent;
- protected readonly SearchSelectComponent = SearchSelectComponent;
-
- protected partnerText: string;
- protected form!: FormGroup;
-
- constructor(
- protected partnerService: PartnerService,
- protected partnerProductService: PartnerProductService,
- protected appHelperService: AppHelperService,
- protected translateService: TranslateService,
- ) {
- this.partnerText = "";
- }
-
- ngOnInit(): void {
- this.translateService.get('basic.' + this.partner.partnerType).subscribe((translation: string) => {
- this.partnerText = translation;
- });
- if (this.partnerProduct !== undefined) {
- this.form = FormGroupInitializer.initFormGroup(partnerProductForm, this.partnerProduct);
- }
- }
-
- // TODO: Wie kriegen wir die Partner raus, die dieses Produkt bereits haben?
- getUnassignedPartners: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => {
- return this.partnerService.partnersGetCollection(
- index,
- pageSize,
- undefined,
- undefined,
- term,
- //this.appHelperService.extractId(this.partnerProduct.partnerIri)
- );
- }
-
- onSubmit() {
- if (this.form.valid) {
- if (this.partnerProduct !== undefined) {
- this.partnerProductService.partnerProductsPost(
- this.form.value as PartnerProductJsonld
- ).subscribe(
- data => {
- this.form.reset();
- this.submit.emit(ModalStatus.Submitted);
- }
- )
- }
- }
- }
- }
|