| @@ -0,0 +1,19 @@ | |||
| <h2>{{ 'basic.assign-partner-01' | translate }} {{ partnerText }} {{ 'basic.assign-partner-02' | translate }}</h2> | |||
| <div class="spt-form"> | |||
| <form [formGroup]="form" (ngSubmit)="onSubmit()"> | |||
| <div class="mb-3" *ngIf="this.partnerProduct"> | |||
| <label for="partner" class="form-label">{{ 'form.partner' | translate }}:</label> | |||
| <app-search-select #productSearchSelect | |||
| [formId]="'partnerIri'" | |||
| [formLabelLangKey]="'form.partner'" | |||
| [documentForm]="form" | |||
| [getDataFunction]="getUnassignedPartners" | |||
| [displayedDataField]="'name'" | |||
| [listColDefinitions]="SearchSelectComponent.getDefaultColDefPartners()" | |||
| > | |||
| <input type="hidden" id="partner" formControlName="partnerIri" value="{{partnerProduct.partnerIri}}"/> | |||
| </app-search-select> | |||
| </div> | |||
| <button type="submit" class="btn btn-primary" [disabled]="form.invalid">{{ 'form.send' | translate }}</button> | |||
| </form> | |||
| </div> | |||
| @@ -0,0 +1,23 @@ | |||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | |||
| import { AssignPartnerComponent } from './assign-partner.component'; | |||
| describe('AssignPartnerComponent', () => { | |||
| let component: AssignPartnerComponent; | |||
| let fixture: ComponentFixture<AssignPartnerComponent>; | |||
| beforeEach(async () => { | |||
| await TestBed.configureTestingModule({ | |||
| declarations: [AssignPartnerComponent] | |||
| }) | |||
| .compileComponents(); | |||
| fixture = TestBed.createComponent(AssignPartnerComponent); | |||
| component = fixture.componentInstance; | |||
| fixture.detectChanges(); | |||
| }); | |||
| it('should create', () => { | |||
| expect(component).toBeTruthy(); | |||
| }); | |||
| }); | |||
| @@ -0,0 +1,78 @@ | |||
| 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); | |||
| } | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,8 +1,11 @@ | |||
| <div class="spt-container"> | |||
| <div *ngIf="!this.user" class="top-btn"> | |||
| <button class="btn btn-primary" (click)="openModalNewPartner()"> | |||
| <button *ngIf="bShowNewPartnerButton" class="btn btn-primary" (click)="openModalNewPartner()"> | |||
| + {{ 'basic.new' | translate }} {{ partnerColumnHeadline }} | |||
| </button> | |||
| <button *ngIf="!bShowNewPartnerButton" class="btn btn-primary" (click)="openModalAssignPartner()"> | |||
| + {{ 'basic.assign-partner-01' | translate }} {{ partnerText }} {{ 'basic.assign-partner-02' | translate }} | |||
| </button> | |||
| </div> | |||
| <app-list #listComponent | |||
| [getDataFunction]="getDataFunction" | |||
| @@ -3,8 +3,9 @@ import {AppHelperService} from "@app/_helpers/app-helper.service"; | |||
| import {Sort} from "@angular/material/sort"; | |||
| import {Observable} from "rxjs"; | |||
| import { | |||
| ContactPartnerProductJsonld, | |||
| PartnerFollowService, | |||
| PartnerJsonld, | |||
| PartnerJsonld, PartnerProductJsonld, | |||
| PartnerProductService, | |||
| PartnerService, | |||
| ProductJsonld, | |||
| @@ -19,6 +20,8 @@ import {ListComponent} from "@app/_components/list/list.component"; | |||
| import {TranslateService} from "@ngx-translate/core"; | |||
| import {ListColTypeAddress} from "@app/_components/list/list-col-type-address"; | |||
| import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; | |||
| import {AssignProductComponent} from "@app/_views/products/assign-product/assign-product.component"; | |||
| import {AssignPartnerComponent} from "@app/_views/partners/assign-partner/assign-partner.component"; | |||
| @Component({ | |||
| selector: 'app-partner-list', | |||
| @@ -32,10 +35,12 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||
| @Input("partnerType") partnerType!: string; | |||
| @ViewChild("listComponent", { static: false }) listComponent!: ListComponent; | |||
| protected bShowNewPartnerButton: boolean; | |||
| protected nameOrderFilter: OrderFilter; | |||
| protected cityOrderFilter: OrderFilter; | |||
| protected websiteOrderFilter: OrderFilter; | |||
| protected partnerColumnHeadline: string; | |||
| protected partnerText: string; | |||
| protected listColDefinitions!: ListColDefinition[]; | |||
| protected getDataFunction!: ListGetDataFunctionType; | |||
| @@ -47,16 +52,21 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||
| protected appHelperService: AppHelperService, | |||
| protected translateService: TranslateService, | |||
| ) { | |||
| this.bShowNewPartnerButton = true; | |||
| this.nameOrderFilter = OrderFilter.Asc; | |||
| this.cityOrderFilter = OrderFilter.Asc; | |||
| this.websiteOrderFilter = OrderFilter.Asc; | |||
| this.partnerColumnHeadline = ""; | |||
| this.partnerText = ""; | |||
| } | |||
| ngOnInit() { | |||
| this.translateService.get('basic.' + this.partnerType + 'One').subscribe((translation: string) => { | |||
| this.partnerColumnHeadline = translation; | |||
| }); | |||
| this.translateService.get('basic.' + this.partnerType).subscribe((translation: string) => { | |||
| this.partnerText = translation; | |||
| }); | |||
| let withSubResource: boolean = (this.user !== undefined || this.product !== undefined); | |||
| this.listColDefinitions = [ | |||
| @@ -109,6 +119,9 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||
| ) | |||
| } | |||
| this.getDataFunction = this.getGetDataFunction(); | |||
| this.bShowNewPartnerButton = | |||
| this.user === undefined && this.product === undefined; | |||
| } | |||
| ngAfterViewInit() { | |||
| @@ -206,6 +219,31 @@ export class PartnerListComponent implements OnInit, AfterViewInit { | |||
| this.appHelperService.openModal(NewPartnerComponent, { 'partner': partner }, this.getGetDataFunction); | |||
| } | |||
| openModalAssignPartner() { | |||
| let partner: PartnerJsonld = {} as PartnerJsonld; | |||
| partner.partnerType = this.partnerType as TypeEnum; | |||
| if (this.user !== undefined) { | |||
| this.appHelperService.openModal( | |||
| AssignPartnerComponent, | |||
| {'user': this.user}, | |||
| this.listComponent.getData | |||
| ); | |||
| } else if (this.product !== undefined) { | |||
| let partnerProduct: PartnerProductJsonld = {} as PartnerProductJsonld; | |||
| partnerProduct.productIri = this.product.id!; | |||
| this.appHelperService.openModal( | |||
| AssignPartnerComponent, | |||
| { | |||
| 'partnerProduct': partnerProduct, | |||
| 'partner': partner | |||
| }, | |||
| this.listComponent.getData | |||
| ); | |||
| } else { | |||
| throw new Error('data not found') | |||
| } | |||
| } | |||
| unassignPartner = (element: any)=> { | |||
| let confirmMessage = ""; | |||
| this.translateService.get('system.confirm-unassign').subscribe((translation: string) => { | |||
| @@ -19,12 +19,12 @@ import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-funct | |||
| templateUrl: './assign-product.component.html', | |||
| styleUrl: './assign-product.component.scss' | |||
| }) | |||
| export class AssignProductComponent implements OnInit, AfterViewInit { | |||
| export class AssignProductComponent implements OnInit { | |||
| @Input() public partnerIri!: string; | |||
| @Input() public partnerProduct!: PartnerProductJsonld; | |||
| @Input() public contactPartnerProduct!: ContactPartnerProductJsonld; | |||
| @Output() public submit: EventEmitter<ModalStatus> = new EventEmitter<ModalStatus>(); | |||
| @ViewChild('productSearchSelect', {static: false}) productSearchSelect!: SearchSelectComponent | |||
| @ViewChild('productSearchSelect', {static: false}) productSearchSelect!: SearchSelectComponent; | |||
| protected readonly SearchSelectComponent = SearchSelectComponent; | |||
| protected form!: FormGroup; | |||
| @@ -46,9 +46,6 @@ export class AssignProductComponent implements OnInit, AfterViewInit { | |||
| } | |||
| } | |||
| ngAfterViewInit(): void { | |||
| } | |||
| getUnassignedProducts: ListGetDataFunctionType = (index: number, pageSize: number, term?: string) => { | |||
| return this.productService.productsGetCollection( | |||
| index, | |||
| @@ -67,6 +67,7 @@ import {LoadingInterceptor} from "@app/_helpers/loading-interceptor.service"; | |||
| import {SearchSelectComponent} from './_components/search-select/search-select.component'; | |||
| import {ListComponent} from './_components/list/list.component'; | |||
| import {MatTabsModule} from "@angular/material/tabs"; | |||
| import { AssignPartnerComponent } from './_views/partners/assign-partner/assign-partner.component'; | |||
| export function apiConfigFactory(): Configuration { | |||
| @@ -157,6 +158,7 @@ export function HttpLoaderFactory(http: HttpClient) { | |||
| LinkedLabelComponent, | |||
| SearchSelectComponent, | |||
| ListComponent, | |||
| AssignPartnerComponent, | |||
| ], | |||
| providers: [ | |||
| {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, | |||
| @@ -28,6 +28,8 @@ | |||
| "comments": "Kommentare", | |||
| "users": "Benutzer", | |||
| "new": "Neuer", | |||
| "assign-partner-01": "Produkt diesem", | |||
| "assign-partner-02": "zuordnen", | |||
| "new-product": "Neues Produkt", | |||
| "assign-product": "Produkt zuordnen", | |||
| "new-document": "Neues Dokument", | |||