import { ActivatedRoute, Router, NavigationEnd } from '@angular/router'; import { Modul } from '@karmed/api'; import { Component, OnInit, Input } from '@angular/core'; import { KarmedService } from '@karmed/api'; import { filter } from 'rxjs/operators'; import { GlobalemitterService } from 'src/app/services/globalemitter.service'; @Component({ selector: 'app-modul-item', templateUrl: './modul-item.component.html', styleUrls: ['./modul-item.component.css'] }) export class ModulItemComponent implements OnInit { constructor(private karmedService: KarmedService, private route: ActivatedRoute, private router: Router, private emitter: GlobalemitterService) { this.router.events .pipe(filter(event => event instanceof NavigationEnd)) .subscribe(() => { this.aktifKategori = this.route.snapshot.queryParams["cat"]; }); } @Input() public aktifKategori: number; @Input() public key: string; modul: Modul[]; ngOnInit() { if (this.emitter.subsVar == undefined) { this.emitter.subsVar = this.emitter.invokeFilterModule.subscribe(() => { this.filterModule(); }) } this.filterModule(); } filterModule() { this.aktifKategori = this.route.snapshot.queryParams["cat"] || 0; this.karmedService.getModul().subscribe(modul => { this.modul = modul; }) } showModule(modul: Modul) { if (modul.Kodu == 1001100) { this.router.navigateByUrl('/pr'); return; } this.post({ userinfo: JSON.parse(localStorage.getItem('user')).Hash }, modul.Url); } post(params, url) { var mapForm = document.createElement("form"); mapForm.target = "_blank"; mapForm.method = "POST"; mapForm.action = url; Object.keys(params).forEach(function (param) { var mapInput = document.createElement("input"); mapInput.type = "hidden"; mapInput.name = param; mapInput.setAttribute("value", params[param]); mapForm.appendChild(mapInput); }); document.body.appendChild(mapForm); mapForm.submit(); } }