Commit e6e53539 authored by François Agneray's avatar François Agneray
Browse files

Delete survey entity

parent 5b8358b1
......@@ -18,7 +18,6 @@ const routes: Routes = [
path: '', component: AdminComponent, canActivate: [AdminAuthGuard], children: [
{ path: '', redirectTo: 'instance/instance-list', pathMatch: 'full' },
{ path: 'instance', loadChildren: () => import('./instance/instance.module').then(m => m.InstanceModule) },
{ path: 'survey', loadChildren: () => import('./survey/survey.module').then(m => m.SurveyModule) },
{ path: 'database', loadChildren: () => import('./database/database.module').then(m => m.DatabaseModule) },
{ path: 'settings', loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule) }
]
......
......@@ -16,7 +16,6 @@ import * as fromRouter from '@ngrx/router-store';
import { UserProfile } from 'src/app/auth/user-profile.model';
import * as authActions from 'src/app/auth/auth.actions';
import * as authSelector from 'src/app/auth/auth.selector';
import * as surveyActions from 'src/app/metamodel/actions/survey.actions';
import * as databaseActions from 'src/app/metamodel/actions/database.actions';
import * as selectActions from 'src/app/metamodel/actions/select.actions';
import * as optionActions from 'src/app/metamodel/actions/select-option.actions';
......@@ -39,7 +38,6 @@ export class AdminComponent implements OnInit {
public body: HTMLBodyElement = document.querySelector('body');
public links = [
{ label: 'Instances', icon: 'fas fa-object-group', routerLink: 'instance/instance-list' },
{ label: 'Surveys', icon: 'fas fa-table', routerLink: 'survey/survey-list'},
{ label: 'Databases', icon: 'fas fa-database', routerLink: 'database/database-list'},
{ label: 'Settings', icon: 'fas fa-wrench', routerLink: 'settings'}
];
......@@ -59,7 +57,6 @@ export class AdminComponent implements OnInit {
this.favIcon.href = 'favicon.ico';
this.title.innerHTML = 'ANIS - Admin';
this.body.style.backgroundColor = 'white';
Promise.resolve(null).then(() => this.store.dispatch(surveyActions.loadSurveyList()));
Promise.resolve(null).then(() => this.store.dispatch(databaseActions.loadDatabaseList()));
Promise.resolve(null).then(() => this.store.dispatch(selectActions.loadSelectList()));
Promise.resolve(null).then(() => this.store.dispatch(optionActions.loadSelectOptionList()));
......
......@@ -10,7 +10,6 @@
<th scope="col">Port</th>
<th scope="col">Login</th>
<th scope="col">Password</th>
<th scope="col">Nb surveys</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
......@@ -25,7 +24,6 @@
<td class="align-middle">{{ database.dbport }}</td>
<td class="align-middle">{{ database.dblogin }}</td>
<td class="align-middle">*******</td>
<td class="align-middle">{{ getNbSurveyByDatabase(database.id) }}</td>
<td class="align-middle">
<a title="Edit this database" routerLink="/admin/database/edit-database/{{database.id}}" class="btn btn-outline-primary">
<span class="fas fa-edit"></span>
......@@ -33,7 +31,6 @@
</td>
<td class="align-middle">
<app-delete-btn
[disabled]="!isNoSurveyAttachedToDatabase(database.id)"
[type]="'database'"
[label]="database.label"
(confirm)="deleteDatabase.emit(database)">
......
......@@ -9,7 +9,7 @@
import { Component, Input, Output, ChangeDetectionStrategy, EventEmitter } from '@angular/core';
import { Database, Survey } from 'src/app/metamodel/models';
import { Database } from 'src/app/metamodel/models';
@Component({
selector: 'app-database-table',
......@@ -18,14 +18,5 @@ import { Database, Survey } from 'src/app/metamodel/models';
})
export class DatabaseTableComponent {
@Input() databaseList: Database[];
@Input() surveyList: Survey[];
@Output() deleteDatabase: EventEmitter<Database> = new EventEmitter();
isNoSurveyAttachedToDatabase(idDatabase: number): boolean {
return this.getNbSurveyByDatabase(idDatabase) === 0;
}
getNbSurveyByDatabase(idDatabase: number): number {
return this.surveyList.filter(p => p.id_database === idDatabase).length
}
}
......@@ -5,9 +5,9 @@
</ol>
</nav>
<app-spinner *ngIf="(surveyListIsLoading | async) || (databaseListIsLoading | async)"></app-spinner>
<app-spinner *ngIf="(databaseListIsLoading | async)"></app-spinner>
<ng-container *ngIf="(surveyListIsLoaded | async) && (databaseListIsLoaded | async)">
<ng-container *ngIf="(databaseListIsLoaded | async)">
<div class="row">
<div class="col-12">
<button title="Add a new database" class="btn btn-outline-success float-right" routerLink="/admin/database/new-database">
......@@ -19,8 +19,7 @@
<div class="row mt-1">
<div class="col-12">
<app-database-table
[databaseList]="databaseList | async"
[surveyList]="surveyList | async"
[databaseList]="databaseList | async"
(deleteDatabase)="deleteDatabase($event)">
</app-database-table>
</div>
......
......@@ -11,10 +11,9 @@ import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { Database, Survey } from 'src/app/metamodel/models';
import { Database } from 'src/app/metamodel/models';
import * as databaseActions from 'src/app/metamodel/actions/database.actions';
import * as databaseSelector from 'src/app/metamodel/selectors/database.selector';
import * as surveySelector from 'src/app/metamodel/selectors/survey.selector';
@Component({
selector: 'app-database-list',
......@@ -24,17 +23,11 @@ export class DatabaseListComponent {
public databaseListIsLoading: Observable<boolean>;
public databaseListIsLoaded: Observable<boolean>;
public databaseList: Observable<Database[]>;
public surveyListIsLoading: Observable<boolean>;
public surveyListIsLoaded: Observable<boolean>;
public surveyList: Observable<Survey[]>;
constructor(private store: Store<{ }>) {
this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading);
this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded);
this.databaseList = store.select(databaseSelector.selectAllDatabases);
this.surveyListIsLoading = store.select(surveySelector.selectSurveyListIsLoading);
this.surveyListIsLoaded = store.select(surveySelector.selectSurveyListIsLoaded);
this.surveyList = store.select(surveySelector.selectAllSurveys);
}
deleteDatabase(database: Database) {
......
......@@ -10,10 +10,10 @@
<input type="text" class="form-control" id="label" name="label" formControlName="label">
</div>
<div class="form-group">
<label for="survey_name">Survey</label>
<select class="form-control" id="survey_name" name="survey_name" formControlName="survey_name" (change)="onChangeSurvey()">
<label for="id_database">Database</label>
<select class="form-control" id="id_database" name="id_database" formControlName="id_database" (change)="onChangeDatabase()">
<option></option>
<option *ngFor="let survey of surveyList" [ngValue]="survey.name">{{ survey.label }}</option>
<option *ngFor="let database of databaseList" [ngValue]="database.id">{{ database.label }}</option>
</select>
</div>
<div class="form-group">
......
......@@ -10,7 +10,7 @@
import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Instance, Dataset, Survey, DatasetFamily, Attribute, Image } from 'src/app/metamodel/models';
import { Instance, Dataset, DatasetFamily, Database } from 'src/app/metamodel/models';
import { FileInfo } from 'src/app/admin/store/models';
@Component({
......@@ -20,7 +20,7 @@ import { FileInfo } from 'src/app/admin/store/models';
export class DatasetFormComponent implements OnInit, OnChanges {
@Input() instance: Instance;
@Input() dataset: Dataset;
@Input() surveyList: Survey[];
@Input() databaseList: Database[];
@Input() tableListIsLoading: boolean;
@Input() tableListIsLoaded: boolean;
@Input() tableList: string[];
......@@ -29,7 +29,7 @@ export class DatasetFormComponent implements OnInit, OnChanges {
@Input() files: FileInfo[];
@Input() filesIsLoading: boolean;
@Input() filesIsLoaded: boolean;
@Output() changeSurvey: EventEmitter<number> = new EventEmitter();
@Output() changeDatabase: EventEmitter<number> = new EventEmitter();
@Output() loadRootDirectory: EventEmitter<string> = new EventEmitter();
@Output() onSubmit: EventEmitter<Dataset> = new EventEmitter();
......@@ -43,7 +43,7 @@ export class DatasetFormComponent implements OnInit, OnChanges {
display: new FormControl('', [Validators.required]),
data_path: new FormControl(''),
public: new FormControl('', [Validators.required]),
survey_name: new FormControl('', [Validators.required]),
id_database: new FormControl('', [Validators.required]),
id_dataset_family: new FormControl('', [Validators.required]),
download_enabled: new FormControl(true),
download_json: new FormControl(true),
......@@ -88,12 +88,12 @@ export class DatasetFormComponent implements OnInit, OnChanges {
}
}
onChangeSurvey() {
const surveyName = this.form.controls.survey_name.value;
if (!surveyName) {
onChangeDatabase() {
const idDatabase = this.form.controls.id_database.value;
if (!idDatabase) {
this.form.controls.table_ref.disable();
} else {
this.changeSurvey.emit(this.surveyList.find(survey => survey.name === surveyName).id_database);
this.changeDatabase.emit(idDatabase);
}
}
......
......@@ -15,18 +15,18 @@
</div>
<div class="container">
<app-spinner *ngIf="(surveyListIsLoading | async)
|| (datasetListIsLoading | async)
|| (datasetFamilyListIsLoading | async)"></app-spinner>
<app-spinner *ngIf="(datasetListIsLoading | async)
|| (datasetFamilyListIsLoading | async)
|| (databaseListIsLoading | async)"></app-spinner>
<div *ngIf="(surveyListIsLoaded | async)
&& (datasetListIsLoaded | async)
&& (datasetFamilyListIsLoaded | async)" class="row">
<div *ngIf="(datasetListIsLoaded | async)
&& (datasetFamilyListIsLoaded | async)
&& (databaseListIsLoaded | async)" class="row">
<div class="col-12">
<app-dataset-form
[instance]="instance | async"
[dataset]="datasetList | async | datasetByName:(datasetSelected | async)"
[surveyList]="surveyList | async"
[databaseList]="databaseList | async"
[tableListIsLoading]="tableListIsLoading | async"
[tableListIsLoaded]="tableListIsLoaded | async"
[tableList]="tableList | async"
......@@ -34,7 +34,7 @@
[files]="files | async"
[filesIsLoading]="filesIsLoading | async"
[filesIsLoaded]="filesIsLoaded | async"
(changeSurvey)="loadTableList($event)"
(changeDatabase)="loadTableList($event)"
(loadRootDirectory)="loadRootDirectory($event)"
(onSubmit)="editDataset($event)"
#formDataset>
......
......@@ -12,12 +12,10 @@ import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { Instance, Survey, DatasetFamily, Dataset } from 'src/app/metamodel/models';
import { Instance, DatasetFamily, Dataset, Database } from 'src/app/metamodel/models';
import { FileInfo } from 'src/app/admin/store/models';
import * as datasetSelector from 'src/app/metamodel/selectors/dataset.selector';
import * as datasetActions from 'src/app/metamodel/actions/dataset.actions';
import * as attributeActions from 'src/app/metamodel/actions/attribute.actions';
import * as surveySelector from 'src/app/metamodel/selectors/survey.selector';
import * as tableActions from 'src/app/admin/store/actions/table.actions';
import * as tableSelector from 'src/app/admin/store/selectors/table.selector';
import * as datasetFamilySelector from 'src/app/metamodel/selectors/dataset-family.selector';
......@@ -25,6 +23,7 @@ import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector
import * as adminFileExplorerActions from 'src/app/admin/store/actions/admin-file-explorer.actions';
import * as adminFileExplorerSelector from 'src/app/admin/store/selectors/admin-file-explorer.selector';
import * as imageActions from 'src/app/metamodel/actions/image.actions';
import * as databaseSelector from 'src/app/metamodel/selectors/database.selector';
@Component({
selector: 'app-edit-dataset',
......@@ -36,9 +35,9 @@ export class EditDatasetComponent implements OnInit {
public datasetList: Observable<Dataset[]>;
public datasetListIsLoading: Observable<boolean>;
public datasetListIsLoaded: Observable<boolean>;
public surveyListIsLoading: Observable<boolean>;
public surveyListIsLoaded: Observable<boolean>;
public surveyList: Observable<Survey[]>;
public databaseList: Observable<Database[]>;
public databaseListIsLoading: Observable<boolean>;
public databaseListIsLoaded: Observable<boolean>;
public tableListIsLoading: Observable<boolean>;
public tableListIsLoaded: Observable<boolean>;
public tableList: Observable<string[]>;
......@@ -55,9 +54,9 @@ export class EditDatasetComponent implements OnInit {
this.datasetList = store.select(datasetSelector.selectAllDatasets);
this.datasetListIsLoading = store.select(datasetSelector.selectDatasetListIsLoading);
this.datasetListIsLoaded = store.select(datasetSelector.selectDatasetListIsLoaded);
this.surveyListIsLoading = store.select(surveySelector.selectSurveyListIsLoading);
this.surveyListIsLoaded = store.select(surveySelector.selectSurveyListIsLoaded);
this.surveyList = store.select(surveySelector.selectAllSurveys);
this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading);
this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded);
this.databaseList = store.select(databaseSelector.selectAllDatabases);
this.tableListIsLoading = store.select(tableSelector.selectTableListIsLoading);
this.tableListIsLoaded = store.select(tableSelector.selectTableListIsLoaded);
this.tableList = store.select(tableSelector.selectAllTables);
......
......@@ -15,13 +15,13 @@
</div>
<div class="container">
<app-spinner *ngIf="(surveyListIsLoading | async) || (datasetFamilyListIsLoading | async)"></app-spinner>
<app-spinner *ngIf="(datasetFamilyListIsLoading | async) || (databaseListIsLoading | async)"></app-spinner>
<div *ngIf="(surveyListIsLoaded | async) && (datasetFamilyListIsLoaded | async)" class="row">
<div *ngIf="(datasetFamilyListIsLoaded | async) && (databaseListIsLoaded | async)" class="row">
<div class="col-12">
<app-dataset-form
[instance]="instance | async"
[surveyList]="surveyList | async"
[databaseList]="databaseList | async"
[tableListIsLoading]="tableListIsLoading | async"
[tableListIsLoaded]="tableListIsLoaded | async"
[tableList]="tableList | async"
......@@ -30,7 +30,7 @@
[files]="files | async"
[filesIsLoading]="filesIsLoading | async"
[filesIsLoaded]="filesIsLoaded | async"
(changeSurvey)="loadTableList($event)"
(changeDatabase)="loadTableList($event)"
(loadRootDirectory)="loadRootDirectory($event)"
(onSubmit)="addNewDataset($event)"
#formDataset>
......
......@@ -14,9 +14,8 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { Instance, Survey, DatasetFamily, Dataset } from 'src/app/metamodel/models';
import { Instance, DatasetFamily, Dataset, Database } from 'src/app/metamodel/models';
import { FileInfo } from 'src/app/admin/store/models';
import * as surveySelector from 'src/app/metamodel/selectors/survey.selector';
import * as tableActions from 'src/app/admin/store/actions/table.actions';
import * as tableSelector from 'src/app/admin/store/selectors/table.selector';
import * as datasetFamilySelector from 'src/app/metamodel/selectors/dataset-family.selector';
......@@ -24,6 +23,7 @@ import * as datasetActions from 'src/app/metamodel/actions/dataset.actions';
import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector';
import * as adminFileExplorerActions from 'src/app/admin/store/actions/admin-file-explorer.actions';
import * as adminFileExplorerSelector from 'src/app/admin/store/selectors/admin-file-explorer.selector';
import * as databaseSelector from 'src/app/metamodel/selectors/database.selector';
@Component({
selector: 'app-new-dataset',
......@@ -31,9 +31,9 @@ import * as adminFileExplorerSelector from 'src/app/admin/store/selectors/admin-
})
export class NewDatasetComponent implements OnInit {
public instance: Observable<Instance>;
public surveyListIsLoading: Observable<boolean>;
public surveyListIsLoaded: Observable<boolean>;
public surveyList: Observable<Survey[]>;
public databaseList: Observable<Database[]>;
public databaseListIsLoading: Observable<boolean>;
public databaseListIsLoaded: Observable<boolean>;
public tableListIsLoading: Observable<boolean>;
public tableListIsLoaded: Observable<boolean>;
public tableList: Observable<string[]>;
......@@ -47,9 +47,9 @@ export class NewDatasetComponent implements OnInit {
constructor(private store: Store<{ }>, private route: ActivatedRoute) {
this.instance = store.select(instanceSelector.selectInstanceByRouteName);
this.surveyListIsLoading = store.select(surveySelector.selectSurveyListIsLoading);
this.surveyListIsLoaded = store.select(surveySelector.selectSurveyListIsLoaded);
this.surveyList = store.select(surveySelector.selectAllSurveys);
this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading);
this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded);
this.databaseList = store.select(databaseSelector.selectAllDatabases);
this.tableListIsLoading = store.select(tableSelector.selectTableListIsLoading);
this.tableListIsLoaded = store.select(tableSelector.selectTableListIsLoaded);
this.tableList = store.select(tableSelector.selectAllTables);
......
/**
* 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.
*/
import { SurveyTableComponent } from "./survey-table.component";
import { SurveyFormComponent } from "./survey-form.component";
export const dummiesComponents = [
SurveyTableComponent,
SurveyFormComponent
];
<form [formGroup]="form" (ngSubmit)="submit()" novalidate>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" formControlName="name">
</div>
<div class="form-group">
<label for="label">Label</label>
<input type="text" class="form-control" id="label" name="label" formControlName="label">
</div>
<div class="form-group">
<label for="id_database">Database</label>
<select class="form-control" id="id_database" name="id_database" formControlName="id_database">
<option></option>
<option *ngFor="let database of databaseList" [ngValue]="database.id">{{database.label}}</option>
</select>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" rows="5" id="description" name="description" formControlName="description"></textarea>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label for="link">Link</label>
<input type="text" class="form-control" id="link" name="link" formControlName="link">
</div>
<div class="col-md-6">
<strong>Test it</strong>
<br>
<p style="margin-top: 13px;">
<a [href]="form.controls.link.value" target="_blank">
<span class="fa fa-link"></span> {{ form.controls.link.value }}
</a>
</p>
</div>
</div>
</div>
<div class="form-group">
<label for="manager">Manager</label>
<input type="text" class="form-control" id="manager" name="manager" formControlName="manager">
</div>
<div class="form-group">
<ng-content></ng-content>
</div>
</form>
/**
* 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.
*/
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Survey, Database } from 'src/app/metamodel/models';
@Component({
selector: 'app-survey-form',
templateUrl: 'survey-form.component.html'
})
export class SurveyFormComponent implements OnInit {
@Input() survey: Survey;
@Input() databaseList: Database[];
@Output() onSubmit: EventEmitter<Survey> = new EventEmitter();
public form = new FormGroup({
name: new FormControl('', [Validators.required]),
label: new FormControl('', [Validators.required]),
id_database: new FormControl('', [Validators.required]),
description: new FormControl('', [Validators.required]),
link: new FormControl('', [Validators.required]),
manager: new FormControl('', [Validators.required])
});
ngOnInit() {
if (this.survey) {
this.form.patchValue(this.survey);
}
}
submit() {
if (this.survey) {
this.onSubmit.emit({
...this.survey,
...this.form.value
});
} else {
this.onSubmit.emit(this.form.value);
}
}
}
<div class="table-responsive">
<table class="table table-striped" aria-describedby="Survey list">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Label</th>
<th scope="col">Description</th>
<th scope="col">Link</th>
<th scope="col">Manager</th>
<th scope="col">Database</th>
<th scope="col">Nb datasets</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let survey of surveyList">
<td class="align-middle">{{ survey.name }}</td>
<td class="align-middle">{{ survey.label }}</td>
<td class="align-middle">{{ survey.description }}</td>
<td class="align-middle"><a [href]="survey.link" target="_blank">{{ survey.link }}</a></td>
<td class="align-middle">{{ survey.manager }}</td>
<td class="align-middle">{{ getDatabaseById(survey.id_database).label }}</td>
<td class="align-middle">{{ survey.nb_datasets }}</td>
<td class="align-middle">
<a title="Edit this survey" routerLink="/admin/survey/edit-survey/{{survey.name}}" class="btn btn-outline-primary">
<span class="fas fa-edit"></span>
</a>
</td>
<td class="align-middle">
<app-delete-btn
[disabled]="survey.nb_datasets > 0"
[type]="'survey'"
[label]="survey.label"
(confirm)="deleteSurvey.emit(survey)">
</app-delete-btn>
</td>
</tr>
</tbody>
</table>
</div>
/**
* 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.
*/
import { Component, Input, Output, ChangeDetectionStrategy, EventEmitter } from '@angular/core';
import { Survey, Database } from 'src/app/metamodel/models';
@Component({
selector: 'app-survey-table',
templateUrl: 'survey-table.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SurveyTableComponent {
@Input() surveyList: Survey[];
@Input() databaseList: Database[];
@Output() deleteSurvey: EventEmitter<Survey> = new EventEmitter();
getDatabaseById(idDatabase: number): Database {
return this.databaseList.find(database => database.id === idDatabase);
}
}
<div class="container-fluid">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a routerLink="/admin/survey/survey-list">Surveys</a></li>
<li *ngIf="(surveyListIsLoaded | async)" class="breadcrumb-item active" aria-current="page">Edit survey {{ (survey | async).name }}</li>
</ol>
</nav>
</div>
<div class="container">
<app-spinner *ngIf="(databaseListIsLoading | async) || (surveyListIsLoading | async)"></app-spinner>
<div *ngIf="(databaseListIsLoaded | async) && (surveyListIsLoaded | async)" class="row">
<div class="col-12">
<app-survey-form [survey]="survey | async" [databaseList]="databaseList | async" (onSubmit)="editSurvey($event)" #formSurvey>
<button [disabled]="!formSurvey.form.valid || formSurvey.form.pristine" type="submit" class="btn btn-primary">
<span class="fa fa-database"></span> Update survey information
</button>
&nbsp;
<a routerLink="/admin/survey/survey-list" type="button" class="btn btn-danger">Cancel</a>
</app-survey-form>