Skip to content
Snippets Groups Projects
dataset-form.component.ts 5.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * 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, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
    
    import { FormGroup, FormControl, Validators } from '@angular/forms';
    
    
    import { Instance, Dataset, Survey, DatasetFamily, FileInfo, Attribute } from 'src/app/metamodel/models';
    
    
    @Component({
        selector: 'app-dataset-form',
        templateUrl: 'dataset-form.component.html'
    })
    
    François Agneray's avatar
    François Agneray committed
    export class DatasetFormComponent implements OnInit, OnChanges {
    
        @Input() instance: Instance;
    
        @Input() dataset: Dataset;
        @Input() surveyList: Survey[];
    
    François Agneray's avatar
    François Agneray committed
        @Input() tableListIsLoading: boolean;
        @Input() tableListIsLoaded: boolean;
    
        @Input() tableList: string[];
        @Input() datasetFamilyList: DatasetFamily[];
    
    François Agneray's avatar
    François Agneray committed
        @Input() idDatasetFamily: number;
    
        @Input() rootDirectory: FileInfo[];
        @Input() rootDirectoryIsLoading: boolean;
        @Input() rootDirectoryIsLoaded: boolean;
        @Input() attributeList: Attribute[];
    
        @Output() changeSurvey: EventEmitter<number> = new EventEmitter();
    
        @Output() loadRootDirectory: EventEmitter<string> = new EventEmitter();
    
    François Agneray's avatar
    François Agneray committed
        @Output() onSubmit: EventEmitter<Dataset> = new EventEmitter();
    
    
        public isNewDataset = true;
    
        public imageFormGroup = new FormGroup({
    
        });
    
        public coneSearchFormGroup = new FormGroup({
            cone_search_enabled: new FormControl(false),
            cone_search_opened: new FormControl({value: false, disabled: true}),
            cone_search_column_ra: new FormControl({value: false, disabled: true}),
            cone_search_column_dec: new FormControl({value: false, disabled: true}),
            cone_search_plot_enabled: new FormControl({value: false, disabled: true}),
            cone_search_sdss_enabled: new FormControl({value: false, disabled: true}),
            cone_search_sdss_display: new FormControl({value: false, disabled: true}),
            cone_search_background: new FormControl({value: [], disabled: true})
        });
    
        public downloadFormGroup = new FormGroup({
            download_enabled: new FormControl(true),
            download_opened: new FormControl(false),
            download_csv: new FormControl(true),
            download_ascii: new FormControl(true),
            download_vo: new FormControl(false),
            download_archive: new FormControl(false)
        });
    
        public summaryFormGroup = new FormGroup({
            summary_enabled: new FormControl(false),
            summary_opened: new FormControl({value: false, disabled: true})
    
    François Agneray's avatar
    François Agneray committed
        });
    
    
        public serverlinkFormGroup = new FormGroup({
            server_link_enabled: new FormControl(false),
            server_link_opened: new FormControl({value: false, disabled: true})
        });
    
        public sampFormGroup = new FormGroup({
            samp_enabled: new FormControl(false),
            samp_opened: new FormControl({value: false, disabled: true})
        });
    
        public datatableFormGroup = new FormGroup({
            datatable_enabled: new FormControl(true),
            datatable_opened: new FormControl(true),
            datatable_selectable_rows: new FormControl(false)
    
    François Agneray's avatar
    François Agneray committed
        });
    
    
        public form = new FormGroup({
            name: new FormControl('', [Validators.required]),
            label: new FormControl('', [Validators.required]),
            survey_name: new FormControl('', [Validators.required]),
            table_ref: new FormControl('', [Validators.required]),
            id_dataset_family: new FormControl('', [Validators.required]),
            description: new FormControl('', [Validators.required]),
    
            data_path: new FormControl(''),
    
            display: new FormControl('', [Validators.required]),
            public: new FormControl('', [Validators.required]),
    
    François Agneray's avatar
    François Agneray committed
            config: new FormGroup({
    
                cone_search: this.coneSearchFormGroup,
                download: this.downloadFormGroup,
                summary: this.summaryFormGroup,
                server_link: this.serverlinkFormGroup,
                samp: this.sampFormGroup,
                datatable: this.datatableFormGroup
    
    François Agneray's avatar
    François Agneray committed
            })
    
    François Agneray's avatar
    François Agneray committed
        ngOnInit() {
            if (this.dataset) {
    
                this.isNewDataset = false;
    
    François Agneray's avatar
    François Agneray committed
                this.form.patchValue(this.dataset);
    
    François Agneray's avatar
    François Agneray committed
            this.form.controls.table_ref.disable();
            if (this.idDatasetFamily) {
                this.form.controls.id_dataset_family.setValue(this.idDatasetFamily);
    
    François Agneray's avatar
    François Agneray committed
        ngOnChanges(changes: SimpleChanges) {
            if (changes.tableListIsLoaded && changes.tableListIsLoaded.currentValue) {
                this.form.controls.table_ref.enable();
    
            } else {
    
    François Agneray's avatar
    François Agneray committed
                this.form.controls.table_ref.disable();
    
    François Agneray's avatar
    François Agneray committed
        submit() {
    
            if (this.dataset) {
                this.onSubmit.emit({
                    ...this.dataset,
                    ...this.form.getRawValue()
                });
            } else {
                this.onSubmit.emit(this.form.getRawValue());
            }
    
    François Agneray's avatar
    François Agneray committed
        onChangeSurvey() {
            const surveyName = this.form.controls.survey_name.value;
            if (!surveyName) {
                this.form.controls.table_ref.disable();
            } else {
                this.changeSurvey.emit(this.surveyList.find(survey => survey.name === surveyName).id_database);
    
    
        onChangeDataPath(path: string) {
            this.loadRootDirectory.emit(this.instance.data_path + path);
            this.form.markAsDirty();
        }