diff --git a/client/src/app/admin/admin-routing.module.ts b/client/src/app/admin/admin-routing.module.ts index 8730cc45ff86b32fc54410f961086c0fcbd40278..e9674a64db4c99554665654a76fb0d1b727667ff 100644 --- a/client/src/app/admin/admin-routing.module.ts +++ b/client/src/app/admin/admin-routing.module.ts @@ -3,9 +3,13 @@ import { RouterModule, Routes } from '@angular/router'; import { AdminComponent } from './containers/admin.component'; import { InstanceListComponent } from './containers/instance/instance-list.component'; +import { DatabaseListComponent } from './containers/database/database-list.component'; +import { NewDatabaseComponent } from './containers/database/new-database.component'; +import { EditDatabaseComponent } from './containers/database/edit-database.component'; import { SurveyComponent } from './containers/survey/survey.component'; import { SurveyListComponent } from './containers/survey/survey-list.component'; -import { DatabaseListComponent } from './containers/database/database-list.component'; +import { NewSurveyComponent } from './containers/survey/new-survey.component'; +import { EditSurveyComponent } from './containers/survey/edit-survey.component'; import { SettingsComponent } from './containers/settings/settings.component'; const routes: Routes = [ @@ -15,11 +19,15 @@ const routes: Routes = [ { path: 'instance-list', component: InstanceListComponent }, { path: 'survey', component: SurveyComponent, children: [ - { path: '', redirectTo: 'survey-list', pathMatch: 'full' }, - { path: 'survey-list', component: SurveyListComponent }, - { path: 'database-list', component: DatabaseListComponent } + { path: '', redirectTo: 'database-list', pathMatch: 'full' }, + { path: 'database-list', component: DatabaseListComponent }, + { path: 'survey-list', component: SurveyListComponent } ] }, + { path: 'new-database', component: NewDatabaseComponent }, + { path: 'edit-database/:id', component: EditDatabaseComponent }, + { path: 'new-survey', component: NewSurveyComponent }, + { path: 'edit-survey/:name', component: EditSurveyComponent }, { path: 'settings', component: SettingsComponent }, { path: 'settings/:select', component: SettingsComponent } ] @@ -37,6 +45,10 @@ export const routedComponents = [ InstanceListComponent, SurveyComponent, SurveyListComponent, + NewSurveyComponent, + EditSurveyComponent, DatabaseListComponent, + NewDatabaseComponent, + EditDatabaseComponent, SettingsComponent ]; diff --git a/client/src/app/admin/components/database/form-database.component.html b/client/src/app/admin/components/database/database-form.component.html similarity index 94% rename from client/src/app/admin/components/database/form-database.component.html rename to client/src/app/admin/components/database/database-form.component.html index 0b8c30b81863c305ad263712866eb7f3f62b66f3..e346a1da61694e5bf9dc8a25b3757eba57690401 100644 --- a/client/src/app/admin/components/database/form-database.component.html +++ b/client/src/app/admin/components/database/database-form.component.html @@ -1,4 +1,4 @@ -<form [formGroup]="databaseForm" (ngSubmit)="onSubmit.emit(databaseForm.getRawValue())" novalidate> +<form [formGroup]="form" (ngSubmit)="submit()" novalidate> <div class="form-group"> <label for="label">Label</label> <input type="text" class="form-control" id="label" name="label" formControlName="label"> diff --git a/client/src/app/admin/components/database/form-database.component.ts b/client/src/app/admin/components/database/database-form.component.ts similarity index 57% rename from client/src/app/admin/components/database/form-database.component.ts rename to client/src/app/admin/components/database/database-form.component.ts index d891c3b0a452e63b3fbc8024618adf5cefdc5d4a..6883073c46f38c7b08bf2f0759ca799d0ce8137a 100644 --- a/client/src/app/admin/components/database/form-database.component.ts +++ b/client/src/app/admin/components/database/database-form.component.ts @@ -1,17 +1,17 @@ -import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { Database } from 'src/app/metamodel/store/models'; @Component({ - selector: 'app-form-database', - templateUrl: 'form-database.component.html' + selector: 'app-database-form', + templateUrl: 'database-form.component.html' }) -export class FormDatabaseComponent { +export class DatabaseFormComponent implements OnInit { @Input() database: Database; @Output() onSubmit: EventEmitter<Database> = new EventEmitter(); - public databaseForm = new FormGroup({ + public form = new FormGroup({ label: new FormControl('', [Validators.required]), dbname: new FormControl('', [Validators.required]), dbtype: new FormControl('', [Validators.required]), @@ -23,8 +23,18 @@ export class FormDatabaseComponent { ngOnInit() { if (this.database) { - this.databaseForm.setValue(this.database); - this.databaseForm.controls.name.disable(); + this.form.patchValue(this.database); + } + } + + submit() { + if (this.database) { + this.onSubmit.emit({ + ...this.database, + ...this.form.value + }); + } else { + this.onSubmit.emit(this.form.value); } } } diff --git a/client/src/app/admin/components/database/database-table.component.html b/client/src/app/admin/components/database/database-table.component.html index 51d8a27b1d23547ceb684dcc39232d59f1a23989..c4734e54576e999628366865b9d3c6a58d6f01b3 100644 --- a/client/src/app/admin/components/database/database-table.component.html +++ b/client/src/app/admin/components/database/database-table.component.html @@ -27,7 +27,7 @@ <td class="align-middle">*******</td> <td class="align-middle">{{ getNbSurveyByDatabase(database.id) }}</td> <td class="align-middle"> - <a title="Edit this database" routerLink="/edit-database/{{database.id}}" class="btn btn-outline-primary"> + <a title="Edit this database" routerLink="/admin/edit-database/{{database.id}}" class="btn btn-outline-primary"> <span class="fas fa-edit"></span> </a> </td> diff --git a/client/src/app/admin/components/database/index.ts b/client/src/app/admin/components/database/index.ts index 64ff7dd9a2dcebbb417b542a949484482fb4c44c..ec055f55d2b147a8ae2e5bc935098f6bedaa0d57 100644 --- a/client/src/app/admin/components/database/index.ts +++ b/client/src/app/admin/components/database/index.ts @@ -1,7 +1,7 @@ import { DatabaseTableComponent } from "./database-table.component"; -import { FormDatabaseComponent } from "./form-database.component"; +import { DatabaseFormComponent } from "./database-form.component"; export const databseComponents = [ DatabaseTableComponent, - FormDatabaseComponent + DatabaseFormComponent ]; diff --git a/client/src/app/admin/components/index.ts b/client/src/app/admin/components/index.ts index eb4e5e217f21cede1a8248ef4fd140b9a27981e0..9dc7074df85422c07da131d89330e5af66f882ad 100644 --- a/client/src/app/admin/components/index.ts +++ b/client/src/app/admin/components/index.ts @@ -1,13 +1,13 @@ import { sharedComponents } from "./shared"; import { databseComponents } from "./database"; +import { surveyComponents } from "./survey"; import { InstanceCardComponent } from "./instance/instance-card.component"; -import { SurveyTableComponent } from "./survey/survey-table.component"; import { settingsComponents } from './settings'; export const dummiesComponents = [ sharedComponents, databseComponents, + surveyComponents, InstanceCardComponent, - SurveyTableComponent, settingsComponents ]; diff --git a/client/src/app/admin/components/survey/index.ts b/client/src/app/admin/components/survey/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..896736ffc010359fdf9073c69814eac0b1f14f9f --- /dev/null +++ b/client/src/app/admin/components/survey/index.ts @@ -0,0 +1,7 @@ +import { SurveyTableComponent } from "./survey-table.component"; +import { SurveyFormComponent } from "./survey-form.component"; + +export const surveyComponents = [ + SurveyTableComponent, + SurveyFormComponent +]; diff --git a/client/src/app/admin/components/survey/survey-form.component.html b/client/src/app/admin/components/survey/survey-form.component.html new file mode 100644 index 0000000000000000000000000000000000000000..ae53465a55ce3a0e9a04c002449f03cb47d148d1 --- /dev/null +++ b/client/src/app/admin/components/survey/survey-form.component.html @@ -0,0 +1,45 @@ +<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" [value]="database.id" [selected]="survey && database.id === survey.id_database">{{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"> + <b>Test it</b> + <br> + <p style="margin-top: 13px;"> + <a [href]="form.controls.link.value" target="_blank"> + <i class="fa fa-link"></i> {{ 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> diff --git a/client/src/app/admin/components/survey/survey-form.component.ts b/client/src/app/admin/components/survey/survey-form.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..3af1111ce214b5e020197677a72eb19abe866b84 --- /dev/null +++ b/client/src/app/admin/components/survey/survey-form.component.ts @@ -0,0 +1,40 @@ +import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; + +import { Survey, Database } from 'src/app/metamodel/store/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); + } + } +} diff --git a/client/src/app/admin/components/survey/survey-table.component.html b/client/src/app/admin/components/survey/survey-table.component.html index a30dc3701f796870de2585d3b844eccd06c2c7ae..e92d696d3a3a4d4735e914fd4202f6902c5469ae 100644 --- a/client/src/app/admin/components/survey/survey-table.component.html +++ b/client/src/app/admin/components/survey/survey-table.component.html @@ -23,7 +23,7 @@ <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="/edit-survey/{{survey.name}}" class="btn btn-outline-primary"> + <a title="Edit this survey" routerLink="/admin/edit-survey/{{survey.name}}" class="btn btn-outline-primary"> <span class="fas fa-edit"></span> </a> </td> diff --git a/client/src/app/admin/containers/database/database-list.component.html b/client/src/app/admin/containers/database/database-list.component.html index 3059a3ac691592651bb27e1fe6786e439c5cf58d..de6db50724d91397ab72b1fb95b16143cd54c78b 100644 --- a/client/src/app/admin/containers/database/database-list.component.html +++ b/client/src/app/admin/containers/database/database-list.component.html @@ -3,7 +3,7 @@ <div *ngIf="(surveyListIsLoaded | async) && (databaseListIsLoaded | async)"> <div class="row"> <div class="col-12"> - <button title="Add a new database" class="btn btn-outline-success float-right" routerLink="/new-database"> + <button title="Add a new database" class="btn btn-outline-success float-right" routerLink="/admin/new-database"> <span class="fas fa-plus"></span> New database </button> </div> diff --git a/client/src/app/admin/containers/database/database-list.component.ts b/client/src/app/admin/containers/database/database-list.component.ts index d892e1d3ff90676dc861515ecacd1b21eb559882..895c09e24fb5bb926d4f4b9329363af63227aa6d 100644 --- a/client/src/app/admin/containers/database/database-list.component.ts +++ b/client/src/app/admin/containers/database/database-list.component.ts @@ -35,6 +35,6 @@ export class DatabaseListComponent implements OnInit { } deleteDatabase(database: Database) { - // this.store.dispatch(new databaseActions.DeleteDatabaseAction(database)); + this.store.dispatch(databaseActions.deleteDatabase({ database })); } } diff --git a/client/src/app/admin/containers/database/edit-database.component.html b/client/src/app/admin/containers/database/edit-database.component.html new file mode 100644 index 0000000000000000000000000000000000000000..3b12c7a932741bdf11602239fe8f79869205f899 --- /dev/null +++ b/client/src/app/admin/containers/database/edit-database.component.html @@ -0,0 +1,24 @@ +<div class="container-fluid"> + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a routerLink="/survey/database-list">Databases</a></li> + <li *ngIf="(databaseListIsLoaded | async)" class="breadcrumb-item active" aria-current="page">Edit database {{ (database | async).label }}</li> + </ol> + </nav> +</div> + +<div class="container"> + <app-spinner *ngIf="(databaseListIsLoading | async)"></app-spinner> + + <div *ngIf="databaseListIsLoaded | async" class="row"> + <div class="col-12"> + <app-database-form [database]="database | async" (onSubmit)="editDatabase($event)" #formDatabase> + <button [disabled]="!formDatabase.form.valid || formDatabase.form.pristine" type="submit" class="btn btn-primary"> + <i class="fa fa-database"></i> Update database information + </button> + + <a routerLink="/admin/survey/database-list" class="btn btn-danger">Cancel</a> + </app-database-form> + </div> + </div> +</div> diff --git a/client/src/app/admin/containers/database/edit-database.component.ts b/client/src/app/admin/containers/database/edit-database.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..396a76c94a113c86f5fd023c6f79a172dc46ed8f --- /dev/null +++ b/client/src/app/admin/containers/database/edit-database.component.ts @@ -0,0 +1,31 @@ +import { Component, OnInit} from '@angular/core'; +import { Observable } from 'rxjs'; +import { Store } from '@ngrx/store'; + +import { Database } from 'src/app/metamodel/store/models'; +import * as databaseActions from 'src/app/metamodel/store/actions/database.actions'; +import * as databaseSelector from 'src/app/metamodel/store/selectors/database.selector'; + +@Component({ + selector: 'app-edit-database', + templateUrl: 'edit-database.component.html' +}) +export class EditDatabaseComponent implements OnInit { + public databaseListIsLoading: Observable<boolean>; + public databaseListIsLoaded: Observable<boolean>; + public database: Observable<Database>; + + constructor(private store: Store<{ }>) { + this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading); + this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded); + this.database = store.select(databaseSelector.selectDatabaseByRouteId); + } + + ngOnInit() { + this.store.dispatch(databaseActions.loadDatabaseList()); + } + + editDatabase(database: Database) { + this.store.dispatch(databaseActions.editDatabase({ database })); + } +} diff --git a/client/src/app/admin/containers/database/new-database.component.html b/client/src/app/admin/containers/database/new-database.component.html new file mode 100644 index 0000000000000000000000000000000000000000..4bbd42a91cecf6dc176b3779e1ed587d36801e58 --- /dev/null +++ b/client/src/app/admin/containers/database/new-database.component.html @@ -0,0 +1,22 @@ +<div class="container-fluid"> + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a routerLink="/survey/database-list">Databases</a></li> + <li class="breadcrumb-item active" aria-current="page">New database</li> + </ol> + </nav> +</div> + +<div class="container"> + <div class="row"> + <div class="col-12"> + <app-database-form (onSubmit)="addNewDatabase($event)" #formDatabase> + <button [disabled]="!formDatabase.form.valid || formDatabase.form.pristine" type="submit" class="btn btn-primary"> + <i class="fa fa-database"></i> Add the new database + </button> + + <a routerLink="/admin/survey/database-list" type="button" class="btn btn-danger">Cancel</a> + </app-database-form> + </div> + </div> +</div> diff --git a/client/src/app/admin/containers/database/new-database.component.ts b/client/src/app/admin/containers/database/new-database.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..b588d861a91e27fd7bbf39ea507a40ef415ff743 --- /dev/null +++ b/client/src/app/admin/containers/database/new-database.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; +import { Store } from '@ngrx/store'; + +import { Database } from 'src/app/metamodel/store/models'; +import * as databaseActions from 'src/app/metamodel/store/actions/database.actions'; + +@Component({ + selector: 'app-new-database', + templateUrl: 'new-database.component.html' +}) +export class NewDatabaseComponent { + constructor(private store: Store<{ }>) { } + + addNewDatabase(database: Database) { + this.store.dispatch(databaseActions.addDatabase({ database })); + } +} diff --git a/client/src/app/admin/containers/survey/edit-survey.component.html b/client/src/app/admin/containers/survey/edit-survey.component.html new file mode 100644 index 0000000000000000000000000000000000000000..3ee4393e3a3c6bf9355fecd800c1c3da5ef12611 --- /dev/null +++ b/client/src/app/admin/containers/survey/edit-survey.component.html @@ -0,0 +1,24 @@ +<div class="container-fluid"> + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a routerLink="/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"> + <i class="fa fa-database"></i> Update survey information + </button> + + <a routerLink="/survey/survey-list" type="button" class="btn btn-danger">Cancel</a> + </app-survey-form> + </div> + </div> +</div> diff --git a/client/src/app/admin/containers/survey/edit-survey.component.ts b/client/src/app/admin/containers/survey/edit-survey.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..8df926f866bed9492699d04a16708de30245ec16 --- /dev/null +++ b/client/src/app/admin/containers/survey/edit-survey.component.ts @@ -0,0 +1,40 @@ +import { Component, OnInit} from '@angular/core'; +import { Observable } from 'rxjs'; +import { Store } from '@ngrx/store'; + +import { Survey, Database } from 'src/app/metamodel/store/models'; +import * as surveyActions from 'src/app/metamodel/store/actions/survey.actions'; +import * as databaseActions from 'src/app/metamodel/store/actions/database.actions'; +import * as surveySelector from 'src/app/metamodel/store/selectors/survey.selector'; +import * as databaseSelector from 'src/app/metamodel/store/selectors/database.selector'; + +@Component({ + selector: 'app-edit-survey', + templateUrl: 'edit-survey.component.html' +}) +export class EditSurveyComponent implements OnInit { + public surveyListIsLoading: Observable<boolean>; + public surveyListIsLoaded: Observable<boolean>; + public survey: Observable<Survey>; + public databaseListIsLoading: Observable<boolean>; + public databaseListIsLoaded: Observable<boolean>; + public databaseList: Observable<Database[]>; + + constructor(private store: Store<{ }>) { + this.surveyListIsLoading = store.select(surveySelector.selectSurveyListIsLoading); + this.surveyListIsLoaded = store.select(surveySelector.selectSurveyListIsLoaded); + this.survey = store.select(surveySelector.selectSurveyByRouteName); + this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading); + this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded); + this.databaseList = this.store.select(databaseSelector.selectAllDatabases); + } + + ngOnInit() { + this.store.dispatch(surveyActions.loadSurveyList()); + this.store.dispatch(databaseActions.loadDatabaseList()); + } + + editSurvey(survey: Survey) { + this.store.dispatch(surveyActions.editSurvey({ survey })); + } +} diff --git a/client/src/app/admin/containers/survey/new-survey.component.html b/client/src/app/admin/containers/survey/new-survey.component.html new file mode 100644 index 0000000000000000000000000000000000000000..1b61f92361c1933e7091ac3dfda0f7609f4a35d3 --- /dev/null +++ b/client/src/app/admin/containers/survey/new-survey.component.html @@ -0,0 +1,24 @@ +<div class="container-fluid"> + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item"><a routerLink="/survey/survey-list">Surveys</a></li> + <li class="breadcrumb-item active" aria-current="page">New survey</li> + </ol> + </nav> +</div> + +<div class="container"> + <app-spinner *ngIf="databaseListIsLoading | async"></app-spinner> + + <div *ngIf="databaseListIsLoaded | async" class="row"> + <div class="col-12"> + <app-survey-form [databaseList]="databaseList | async" (onSubmit)="addNewSurvey($event)" #formSurvey> + <button [disabled]="!formSurvey.form.valid || formSurvey.form.pristine" type="submit" class="btn btn-primary"> + <i class="fa fa-database"></i> Add the new survey + </button> + + <a routerLink="/admin/survey/survey-list" type="button" class="btn btn-danger">Cancel</a> + </app-survey-form> + </div> + </div> +</div> diff --git a/client/src/app/admin/containers/survey/new-survey.component.ts b/client/src/app/admin/containers/survey/new-survey.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..d383ad42bca26a3a3c6bab28dffd3d974f3b0494 --- /dev/null +++ b/client/src/app/admin/containers/survey/new-survey.component.ts @@ -0,0 +1,32 @@ +import { Component, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { Store } from '@ngrx/store'; + +import { Survey, Database } from 'src/app/metamodel/store/models' +import * as surveyActions from 'src/app/metamodel/store/actions/survey.actions'; +import * as databaseActions from 'src/app/metamodel/store/actions/database.actions'; +import * as databaseSelector from 'src/app/metamodel/store/selectors/database.selector'; + +@Component({ + selector: 'app-new-survey', + templateUrl: 'new-survey.component.html' +}) +export class NewSurveyComponent implements OnInit { + public databaseListIsLoading: Observable<boolean>; + public databaseListIsLoaded: Observable<boolean>; + public databaseList: Observable<Database[]>; + + constructor(private store: Store<{ }>) { + this.databaseListIsLoading = store.select(databaseSelector.selectDatabaseListIsLoading); + this.databaseListIsLoaded = store.select(databaseSelector.selectDatabaseListIsLoaded); + this.databaseList = store.select(databaseSelector.selectAllDatabases); + } + + ngOnInit() { + this.store.dispatch(databaseActions.loadDatabaseList()); + } + + addNewSurvey(survey: Survey) { + this.store.dispatch(surveyActions.addSurvey({ survey })); + } +} diff --git a/client/src/app/admin/containers/survey/survey-list.component.html b/client/src/app/admin/containers/survey/survey-list.component.html index 55f3cb566ed3c2f1862e35e0f31a127326c94a31..88b84d50ff2ad65ee5afb03e4c284396f8d9e994 100644 --- a/client/src/app/admin/containers/survey/survey-list.component.html +++ b/client/src/app/admin/containers/survey/survey-list.component.html @@ -3,7 +3,7 @@ <div *ngIf="(surveyListIsLoaded | async) && (databaseListIsLoaded | async)"> <div class="row"> <div class="col-12"> - <button title="Add a new survey" class="btn btn-outline-success float-right" routerLink="/new-survey"> + <button title="Add a new survey" class="btn btn-outline-success float-right" routerLink="/admin/new-survey"> <span class="fas fa-plus"></span> New survey </button> </div> diff --git a/client/src/app/admin/containers/survey/survey-list.component.ts b/client/src/app/admin/containers/survey/survey-list.component.ts index 276c6619d613a6d885014d608e0378e9575f2f32..58a9697de2625c24742e7ef60d45bc827493456f 100644 --- a/client/src/app/admin/containers/survey/survey-list.component.ts +++ b/client/src/app/admin/containers/survey/survey-list.component.ts @@ -35,6 +35,6 @@ export class SurveyListComponent implements OnInit { } deleteSurvey(survey: Survey) { - // this.store.dispatch(new surveyActions.DeleteSurveyAction(survey)); + this.store.dispatch(surveyActions.deleteSurvey({ survey })); } } diff --git a/client/src/app/admin/containers/survey/survey.component.html b/client/src/app/admin/containers/survey/survey.component.html index 009c950909d454002676459519fe8f101da25bf2..ee1e4b2740cf69e6c1d7a3c88caa0e91f4c9aff8 100644 --- a/client/src/app/admin/containers/survey/survey.component.html +++ b/client/src/app/admin/containers/survey/survey.component.html @@ -1,8 +1,8 @@ <div class="container-fluid"> <nav aria-label="breadcrumb"> <ol class="breadcrumb"> - <li *ngIf="isSurveyList()" class="breadcrumb-item active" aria-current="page">Surveys</li> <li *ngIf="isDatabaseList()" class="breadcrumb-item active" aria-current="page">Databases</li> + <li *ngIf="isSurveyList()" class="breadcrumb-item active" aria-current="page">Surveys</li> </ol> </nav> </div> @@ -12,10 +12,10 @@ <div class="card-header"> <ul class="nav nav-tabs card-header-tabs"> <li class="nav-item"> - <a class="nav-link" routerLink="survey-list" routerLinkActive="active">Survey list</a> + <a class="nav-link" routerLink="database-list" routerLinkActive="active">Database list</a> </li> <li class="nav-item"> - <a class="nav-link" routerLink="database-list" routerLinkActive="active">Database list</a> + <a class="nav-link" routerLink="survey-list" routerLinkActive="active">Survey list</a> </li> </ul> </div> diff --git a/client/src/app/metamodel/store/effects/database.effects.ts b/client/src/app/metamodel/store/effects/database.effects.ts index 7e43a8bdfd67a012f0a44c594b409bf04d9449c7..ddbb25c6af2469872a891f7d2621e3e293a1c6bd 100644 --- a/client/src/app/metamodel/store/effects/database.effects.ts +++ b/client/src/app/metamodel/store/effects/database.effects.ts @@ -1,8 +1,9 @@ import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { map, tap, mergeMap, catchError } from 'rxjs/operators'; - import { ToastrService } from 'ngx-toastr'; import * as databaseActions from '../actions/database.actions'; @@ -37,7 +38,10 @@ export class DatabaseEffects { addDatabaseSuccess$ = createEffect(() => this.actions$.pipe( ofType(databaseActions.addDatabaseSuccess), - tap(() => this.toastr.success('Database successfully added', 'The new database was added into the database')) + tap(() => { + this.router.navigate(['/admin/survey/database-list']); + this.toastr.success('Database successfully added', 'The new database was added into the database') + }) ), { dispatch: false} ); @@ -63,7 +67,10 @@ export class DatabaseEffects { editDatabaseSuccess$ = createEffect(() => this.actions$.pipe( ofType(databaseActions.editDatabaseSuccess), - tap(() => this.toastr.success('Database successfully edited', 'The existing database has been edited into the database')) + tap(() => { + this.router.navigate(['/admin/survey/database-list']); + this.toastr.success('Database successfully edited', 'The existing database has been edited into the database') + }) ), { dispatch: false} ); @@ -103,6 +110,7 @@ export class DatabaseEffects { constructor( private actions$: Actions, private databaseService: DatabaseService, + private router: Router, private toastr: ToastrService ) {} } diff --git a/client/src/app/metamodel/store/effects/survey.effects.ts b/client/src/app/metamodel/store/effects/survey.effects.ts index fb139db49bbb286ffbbce55a4f18f54132c15004..bd48a421ae2f7da64f070339d11210bacb444b8c 100644 --- a/client/src/app/metamodel/store/effects/survey.effects.ts +++ b/client/src/app/metamodel/store/effects/survey.effects.ts @@ -1,8 +1,9 @@ import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { map, tap, mergeMap, catchError } from 'rxjs/operators'; - import { ToastrService } from 'ngx-toastr'; import * as surveyActions from '../actions/survey.actions'; @@ -37,7 +38,10 @@ export class SurveyEffects { addSurveySuccess$ = createEffect(() => this.actions$.pipe( ofType(surveyActions.addSurveySuccess), - tap(() => this.toastr.success('Survey successfully added', 'The new survey was added into the database')) + tap(() => { + this.router.navigate(['/admin/survey/survey-list']); + this.toastr.success('Survey successfully added', 'The new survey was added into the database') + }) ), { dispatch: false} ); @@ -63,7 +67,10 @@ export class SurveyEffects { editSurveySuccess$ = createEffect(() => this.actions$.pipe( ofType(surveyActions.editSurveySuccess), - tap(() => this.toastr.success('Survey successfully edited', 'The existing survey has been edited into the database')) + tap(() => { + this.router.navigate(['/admin/survey/survey-list']); + this.toastr.success('Survey successfully edited', 'The existing survey has been edited into the database') + }) ), { dispatch: false} ); @@ -103,6 +110,7 @@ export class SurveyEffects { constructor( private actions$: Actions, private surveyService: SurveyService, + private router: Router, private toastr: ToastrService ) {} } diff --git a/client/src/app/metamodel/store/selectors/database.selector.ts b/client/src/app/metamodel/store/selectors/database.selector.ts index 0f1acfb76371fc378298099b27cd8201e0b8b492..79a01e19ff0b0ff07594bc061149292ad75e2ae0 100644 --- a/client/src/app/metamodel/store/selectors/database.selector.ts +++ b/client/src/app/metamodel/store/selectors/database.selector.ts @@ -37,3 +37,9 @@ export const selectDatabaseListIsLoaded = createSelector( selectDatabaseState, fromDatabase.selectDatabaseListIsLoaded ); + +export const selectDatabaseByRouteId = createSelector( + selectDatabaseEntities, + reducer.selectRouterState, + (entities, router) => entities[router.state.params.id] +); diff --git a/client/src/app/metamodel/store/selectors/survey.selector.ts b/client/src/app/metamodel/store/selectors/survey.selector.ts index c6b87928815cf9ed8fd3fd28a79a33843ee91fce..16f26ac651bfb89e80e653726b0181240700be48 100644 --- a/client/src/app/metamodel/store/selectors/survey.selector.ts +++ b/client/src/app/metamodel/store/selectors/survey.selector.ts @@ -37,3 +37,9 @@ export const selectSurveyListIsLoaded = createSelector( selectSurveyState, fromSurvey.selectSurveyListIsLoaded ); + +export const selectSurveyByRouteName = createSelector( + selectSurveyEntities, + reducer.selectRouterState, + (entities, router) => entities[router.state.params.name] +);