import { Component, OnInit, ViewChild } from '@angular/core'; import { ScrollToService } from '@nicky-lenaers/ngx-scroll-to'; import { RepeatingEventFormComponent } from '../../forms/repeating-event-form/repeating-event-form.component'; import { TournamentEventsService } from 'src/app/shared/services/tournament.events.service'; import { AuthService } from 'src/app/shared/services/auth.service'; import { RepeatingEvent } from 'tournee.businesslogic'; import { Router } from '@angular/router'; import { UtilityService } from 'src/app/shared/services/utility.service'; @Component({ selector: 'app-selectable-listing-events', templateUrl: './selectable-listing-events.component.html', styleUrls: ['./selectable-listing-events.component.css'], providers: [ TournamentEventsService ] }) export class SelectableListingEventsComponent implements OnInit { @ViewChild('EventForm') EventForm: RepeatingEventFormComponent; Events: Array = []; Selected: RepeatingEvent; constructor(private _scrollToService: ScrollToService, private _events: TournamentEventsService, private _auth: AuthService, private _router: Router) { } ngOnInit() { this.refresh(); } add() { this.Selected = RepeatingEvent.create(this._auth.User); this.EventForm.initiate(RepeatingEvent.create(this._auth.User), true); this._scrollToService.scrollTo(UtilityService.scroll_to_head); } refresh() { this.hide(); this._events.get_mine() .then((result) => { this.Events = result.result.map((e) => { return new RepeatingEvent(e); }); }) .catch((err) => { console.log(err); }); } redirect($event: RepeatingEvent) { this._router.navigate(['/tournament/organiser/events', $event.id]); } hide() { this.Selected = null; this.EventForm.reset(); } edit(event: RepeatingEvent, isNew = false) { } delete(ticket: RepeatingEvent) { } }