Skip to content
Snippets Groups Projects
criteria.component.ts 3.61 KiB
Newer Older
  • Learn to ignore specific revisions
  • François Agneray's avatar
    François Agneray committed
    /**
     * This file is part of Anis Client.
     *
     * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */
    
    
    François Agneray's avatar
    François Agneray committed
    import { Component } from '@angular/core';
    
    François Agneray's avatar
    François Agneray committed
    
    
    François Agneray's avatar
    François Agneray committed
    import { Store } from '@ngrx/store';
    import { Observable } from 'rxjs';
    
    
    François Agneray's avatar
    François Agneray committed
    import { AbstractSearchComponent } from './abstract-search.component';
    
    import { ConeSearch, Criterion, Resolver, SvomKeyword } from '../../store/models';
    
    François Agneray's avatar
    François Agneray committed
    import * as searchActions from '../../store/actions/search.actions';
    
    François Agneray's avatar
    François Agneray committed
    import * as coneSearchActions from '../../store/actions/cone-search.actions';
    import * as coneSearchSelector from '../../store/selectors/cone-search.selector';
    
    import * as svomJsonKwActions from '../../store/actions/svom-json-kw.actions';
    import * as svomJsonKwSelector from '../../store/selectors/svom-json-kw.selector';
    
    François Agneray's avatar
    François Agneray committed
    
    /**
     * @class
     * @classdesc Search criteria container.
     */
    
    @Component({
        selector: 'app-criteria',
        templateUrl: 'criteria.component.html'
    })
    
    François Agneray's avatar
    François Agneray committed
    export class CriteriaComponent extends AbstractSearchComponent {
    
    François Agneray's avatar
    François Agneray committed
        public resolver: Observable<Resolver>;
        public resolverIsLoading: Observable<boolean>;
        public resolverIsLoaded: Observable<boolean>;
    
        public svomKeywords: Observable<SvomKeyword[]>;
    
    François Agneray's avatar
    François Agneray committed
    
        constructor(protected store: Store<{ }>) {
            super(store);
            this.resolver = this.store.select(coneSearchSelector.selectResolver);
            this.resolverIsLoading = this.store.select(coneSearchSelector.selectResolverIsLoading);
            this.resolverIsLoaded = this.store.select(coneSearchSelector.selectResolverIsLoaded);
    
            this.svomKeywords = this.store.select(svomJsonKwSelector.selectSvomKeywords);
    
        ngOnInit(): void {
            // Create a micro task that is processed after the current synchronous code
            // This micro task prevent the expression has changed after view init error
    
    François Agneray's avatar
    François Agneray committed
            Promise.resolve(null).then(() => this.store.dispatch(searchActions.changeStep({ step: 'criteria' })));
            Promise.resolve(null).then(() => this.store.dispatch(searchActions.checkCriteria()));
    
    François Agneray's avatar
    François Agneray committed
            super.ngOnInit();
    
    François Agneray's avatar
    François Agneray committed
        }
    
        /**
         * Dispatches action to add the given criterion to the search.
         *
         * @param  {Criterion} criterion - The criterion.
         */
        addCriterion(criterion: Criterion): void {
            this.store.dispatch(searchActions.addCriterion({ criterion }));
        }
    
        /**
         * Dispatches action to remove the given criterion ID to the search.
         *
         * @param  {number} idCriterion - The criterion ID.
         */
        deleteCriterion(idCriterion: number): void {
            this.store.dispatch(searchActions.deleteCriterion({ idCriterion }));
        }
    
        /**
         * Dispatches action to add cone search.
         *
         * @param  {ConeSearch} coneSearch - The cone search.
         */
    
    François Agneray's avatar
    François Agneray committed
        addConeSearch(coneSearch: ConeSearch): void {
            this.store.dispatch(coneSearchActions.addConeSearch({ coneSearch }));
        }
    
    
        /**
         * Dispatches action to remove the cone search.
         */
    
    François Agneray's avatar
    François Agneray committed
        deleteConeSearch(): void {
            this.store.dispatch(coneSearchActions.deleteConeSearch());
        }
    
    
        /**
         * Dispatches action to retrieve object coordinates.
         *
         * @param  {string} name - The object name.
         */
    
    François Agneray's avatar
    François Agneray committed
        retrieveCoordinates(name: string): void {
            this.store.dispatch(coneSearchActions.retrieveCoordinates({ name }));
        }
    
    
        selectSvomAcronym(acronymSelected: string): void {
            this.store.dispatch(svomJsonKwActions.selectAcronym({ acronymSelected }));
        }
    
        resetSvomKeywords(): void {
            Promise.resolve(null).then(() => this.store.dispatch(svomJsonKwActions.resetKw()));
        }
    
    François Agneray's avatar
    François Agneray committed
    }