25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

79 satır
2.8 KiB

  1. import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
  2. import {
  3. ContactPartnerProductJsonld,
  4. ContactPartnerProductService, PartnerJsonld,
  5. PartnerProductJsonld,
  6. PartnerProductService, PartnerService,
  7. ProductService
  8. } from "@app/core/api/v1";
  9. import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer";
  10. import {FormGroup} from "@angular/forms";
  11. import {partnerProductForm} from "@app/_forms/apiForms";
  12. import {AppHelperService} from "@app/_helpers/app-helper.service";
  13. import {ModalStatus} from "@app/_helpers/modal.states";
  14. import {SearchSelectComponent} from "@app/_components/search-select/search-select.component";
  15. import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type";
  16. import {TranslateService} from "@ngx-translate/core";
  17. @Component({
  18. selector: 'app-assign-partner',
  19. templateUrl: './assign-partner.component.html',
  20. styleUrl: './assign-partner.component.scss'
  21. })
  22. export class AssignPartnerComponent implements OnInit {
  23. @Input() public partner!: PartnerJsonld;
  24. @Input() public productIri!: string;
  25. @Input() public partnerProduct!: PartnerProductJsonld;
  26. @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>();
  27. @ViewChild('productSearchSelect', {static: false}) productSearchSelect!: SearchSelectComponent;
  28. protected readonly SearchSelectComponent = SearchSelectComponent;
  29. protected partnerText: string;
  30. protected form!: FormGroup;
  31. constructor(
  32. protected partnerService: PartnerService,
  33. protected partnerProductService: PartnerProductService,
  34. protected appHelperService: AppHelperService,
  35. protected translateService: TranslateService,
  36. ) {
  37. this.partnerText = "";
  38. }
  39. ngOnInit(): void {
  40. this.translateService.get('basic.' + this.partner.partnerType).subscribe((translation: string) => {
  41. this.partnerText = translation;
  42. });
  43. if (this.partnerProduct !== undefined) {
  44. this.form = FormGroupInitializer.initFormGroup(partnerProductForm, this.partnerProduct);
  45. }
  46. }
  47. // TODO: Wie kriegen wir die Partner raus, die dieses Produkt bereits haben?
  48. getUnassignedPartners: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => {
  49. return this.partnerService.partnersGetCollection(
  50. index,
  51. pageSize,
  52. undefined,
  53. undefined,
  54. term,
  55. //this.appHelperService.extractId(this.partnerProduct.partnerIri)
  56. );
  57. }
  58. onSubmit() {
  59. if (this.form.valid) {
  60. if (this.partnerProduct !== undefined) {
  61. this.partnerProductService.partnerProductsPost(
  62. this.form.value as PartnerProductJsonld
  63. ).subscribe(
  64. data => {
  65. this.form.reset();
  66. this.submit.emit(ModalStatus.Submitted);
  67. }
  68. )
  69. }
  70. }
  71. }
  72. }