diff --git a/client/src/app/admin/admin-routing.module.ts b/client/src/app/admin/admin-routing.module.ts index 62959a4a53505ce008e06fd2266f6b06c0224cab..772d052f07e59a1a67ae2ff5a392f900dbeb9810 100644 --- a/client/src/app/admin/admin-routing.module.ts +++ b/client/src/app/admin/admin-routing.module.ts @@ -18,8 +18,7 @@ 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: 'database', loadChildren: () => import('./database/database.module').then(m => m.DatabaseModule) }, - { path: 'settings', loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule) } + { path: 'database', loadChildren: () => import('./database/database.module').then(m => m.DatabaseModule) } ] } ]; diff --git a/client/src/app/admin/admin.component.ts b/client/src/app/admin/admin.component.ts index 039226dc1b6765eea135fbc8e40352065f56df14..d8f886749a1519025e28d8556ec5207b4e81095c 100644 --- a/client/src/app/admin/admin.component.ts +++ b/client/src/app/admin/admin.component.ts @@ -17,8 +17,6 @@ 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 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'; import { AppConfigService } from 'src/app/app-config.service'; @Component({ @@ -37,8 +35,7 @@ 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: 'Databases', icon: 'fas fa-database', routerLink: 'database/database-list'}, - { label: 'Settings', icon: 'fas fa-wrench', routerLink: 'settings'} + { label: 'Databases', icon: 'fas fa-database', routerLink: 'database/database-list'} ]; public isAuthenticated: Observable<boolean>; public userProfile: Observable<UserProfile>; @@ -57,8 +54,6 @@ export class AdminComponent implements OnInit { this.title.innerHTML = 'ANIS - Admin'; this.body.style.backgroundColor = 'white'; 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())); } getBaseHref() { diff --git a/client/src/app/admin/instance/dataset/components/attribute/criteria/search-type-list.ts b/client/src/app/admin/instance/dataset/components/attribute/criteria/search-type-list.ts new file mode 100644 index 0000000000000000000000000000000000000000..c1389b74f4518c2a1ff2775dc32b8cad6f6e7eea --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/attribute/criteria/search-type-list.ts @@ -0,0 +1,16 @@ +export const searchTypeList = [ + { label: 'Field', value: 'field', display: 10 }, + { label: 'Between', value: 'between', display: 20 }, + { label: 'Select', value: 'select', display: 30 }, + { label: 'Select multiple', value: 'select-multiple', display: 40 }, + { label: 'Datalist', value: 'datalist', display: 50 }, + { label: 'List', value: 'list', display: 60 }, + { label: 'Radio', value: 'radio', display: 70 }, + { label: 'Checkbox', value: 'checkbox', display: 80 }, + { label: 'Between date', value: 'between-date', display: 90 }, + { label: 'Date', value: 'date', display: 100 }, + { label: 'Time', value: 'time', display: 110 }, + { label: 'Date time', value: 'date-time', display: 120 }, + { label: 'JSON', value: 'json', display: 130 }, + { label: 'SVOM JSON KW', value: 'svom_json_kw', display: 140 } +]; diff --git a/client/src/app/admin/instance/dataset/components/attribute/criteria/tr-criteria.component.ts b/client/src/app/admin/instance/dataset/components/attribute/criteria/tr-criteria.component.ts index 8e85d6db6dc55a4aa9e524e92643ddd1407e91c0..8e1bd9357ea107a54ed974231db01490426692fc 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/criteria/tr-criteria.component.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/criteria/tr-criteria.component.ts @@ -10,8 +10,9 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { FormArray, FormControl, FormGroup } from '@angular/forms'; -import { Attribute, CriteriaFamily, SelectOption } from 'src/app/metamodel/models'; +import { Attribute, CriteriaFamily } from 'src/app/metamodel/models'; import { searchTypeOperators } from 'src/app/shared/utils'; +import { searchTypeList } from './search-type-list'; @Component({ selector: '[criteria]', @@ -22,13 +23,14 @@ import { searchTypeOperators } from 'src/app/shared/utils'; export class TrCriteriaComponent implements OnInit { @Input() attribute: Attribute; @Input() criteriaFamilyList: CriteriaFamily[]; - @Input() searchTypeList: SelectOption[]; @Input() attributeDistinctList: string[]; @Input() attributeDistinctListIsLoading: boolean; @Input() attributeDistinctListIsLoaded: boolean; @Output() save: EventEmitter<Attribute> = new EventEmitter(); @Output() loadAttributeDistinctList: EventEmitter<{}> = new EventEmitter(); + searchTypeList = searchTypeList; + optionsFormArray = new FormArray([]); operatorList = searchTypeOperators; diff --git a/client/src/app/admin/instance/dataset/components/attribute/detail/renderers/index.ts b/client/src/app/admin/instance/dataset/components/attribute/detail/renderers/index.ts index a39edd59e41464e0078011db22d27a0f804e7701..5d88e779669df93b295514cb7302eede2baab9ad 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/detail/renderers/index.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/detail/renderers/index.ts @@ -12,3 +12,10 @@ import { SpectraGraphRendererComponent } from './spectra-graph-renderer.componen export const detailRenderers = [ SpectraGraphRendererComponent ]; + +export * from './renderer-detail-form-factory'; + +export const rendererDetailList = [ + { label: 'Image', value: 'img', display: 10 }, + { label: 'Spectra graph', value: 'spectra_graph', display: 20 } +]; diff --git a/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.ts b/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.ts index 546161597c0b9d64c3f9875bc302bede38d40aba..c9f2246ff43a3effc112e53e23d869d15db9025d 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/detail/tr-detail.component.ts @@ -10,8 +10,8 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { Attribute, SelectOption } from 'src/app/metamodel/models'; -import { RendererDetailFormFactory } from './renderers/renderer-detail-form-factory'; +import { Attribute } from 'src/app/metamodel/models'; +import { RendererDetailFormFactory, rendererDetailList } from './renderers'; @Component({ selector: '[detail]', @@ -22,9 +22,10 @@ import { RendererDetailFormFactory } from './renderers/renderer-detail-form-fact export class TrDetailComponent implements OnInit { @Input() attribute: Attribute @Input() attributeList: Attribute[]; - @Input() rendererDetailList: SelectOption[]; @Output() save: EventEmitter<Attribute> = new EventEmitter(); + rendererDetailList = rendererDetailList; + public form = new FormGroup({ name: new FormControl({ value: '', disabled: true }), detail: new FormControl(), diff --git a/client/src/app/admin/instance/dataset/components/attribute/general/tr-general.component.ts b/client/src/app/admin/instance/dataset/components/attribute/general/tr-general.component.ts index 7b4c7ee84f43c18d0728190802c77dfc932dd00f..6182b4779246596bb9dec2a92fe3b9f2ae2c0bbc 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/general/tr-general.component.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/general/tr-general.component.ts @@ -10,7 +10,7 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; -import { Attribute, SelectOption } from 'src/app/metamodel/models'; +import { Attribute } from 'src/app/metamodel/models'; @Component({ selector: '[general]', @@ -20,7 +20,6 @@ import { Attribute, SelectOption } from 'src/app/metamodel/models'; }) export class TrGeneralComponent implements OnInit { @Input() attribute: Attribute - @Input() searchFlags: SelectOption[]; @Output() save: EventEmitter<Attribute> = new EventEmitter(); @Output() delete: EventEmitter<Attribute> = new EventEmitter(); diff --git a/client/src/app/admin/instance/dataset/components/attribute/result/renderers/index.ts b/client/src/app/admin/instance/dataset/components/attribute/result/renderers/index.ts index 218957fe9f4465e3c05a93f0fadbb55f9debd276..4e147f8613cb1083440e171f1a9b3abe1719cd8a 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/result/renderers/index.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/result/renderers/index.ts @@ -18,3 +18,13 @@ export const renderers = [ ImageRendererComponent, LinkRendererComponent ]; + +export * from './renderer-form-factory'; + +export const rendererList = [ + { label: 'Link detail page', value: 'detail-link', display: 10 }, + { label: 'Download file', value: 'download', display: 20 }, + { label: 'Link (file, web page...)', value: 'link', display: 30 }, + { label: 'Display image (png, jpg...)', value: 'image', display: 40 }, + { label: 'Display json', value: 'json', display: 50 } +]; diff --git a/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.ts b/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.ts index 1dd9d6b974a205297be698569a90a049cab381b1..86237b3da347a42c13f6a3b97576bd07e34f29ea 100644 --- a/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.ts +++ b/client/src/app/admin/instance/dataset/components/attribute/result/tr-result.component.ts @@ -10,8 +10,9 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { Attribute, SelectOption } from 'src/app/metamodel/models'; -import { RendererFormFactory } from './renderers/renderer-form-factory'; +import { Attribute } from 'src/app/metamodel/models'; +import { RendererFormFactory, rendererList } from './renderers'; + @Component({ selector: '[result]', @@ -21,9 +22,10 @@ import { RendererFormFactory } from './renderers/renderer-form-factory'; }) export class TrResultComponent implements OnInit { @Input() attribute: Attribute; - @Input() rendererList: SelectOption[]; @Output() save: EventEmitter<Attribute> = new EventEmitter(); + rendererList = rendererList; + public form = new FormGroup({ name: new FormControl({ value: '', disabled: true }), renderer: new FormControl(), diff --git a/client/src/app/admin/instance/dataset/containers/configure-dataset.component.html b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.html index 277991131c2ec55d5d62fb015d6549bb001f0d63..48e2723501dc743bce9fd66de2d468043d32068c 100644 --- a/client/src/app/admin/instance/dataset/containers/configure-dataset.component.html +++ b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.html @@ -3,7 +3,6 @@ || (criteriaFamilyListIsLoading | async) || (outputFamilyListIsLoading | async) || (outputCategoryListIsLoading | async) - || (selectOptionListIsLoading | async) || (imageListIsLoading | async) || (coneSearchConfigIsLoading | async)"> </app-spinner> @@ -13,7 +12,6 @@ && (criteriaFamilyListIsLoaded | async) && (outputFamilyListIsLoaded | async) && (outputCategoryListIsLoaded | async) - && (selectOptionListIsLoaded | async) && (imageListIsLoaded | async) && (coneSearchConfigIsLoaded | async)" class="container-fluid"> <nav aria-label="breadcrumb"> @@ -91,7 +89,6 @@ <tr *ngFor="let attribute of (attributeList | async)" general [attribute]="attribute" - [searchFlags]="selectOptionList | async | optionListBySelect:'search_flag'" (save)="editAttribute($event)" (delete)="deleteAttribute($event)"> </tr> @@ -101,7 +98,6 @@ criteria [attribute]="attribute" [criteriaFamilyList]="criteriaFamilyList | async" - [searchTypeList]="selectOptionList | async | optionListBySelect:'search_type'" [attributeDistinctList]="attributeDistinctList | async" [attributeDistinctListIsLoading]="attributeDistinctListIsLoading | async" [attributeDistinctListIsLoaded]="attributeDistinctListIsLoaded | async" @@ -121,7 +117,6 @@ <tr *ngFor="let attribute of (attributeList | async)" result [attribute]="attribute" - [rendererList]="selectOptionList | async | optionListBySelect:'renderer'" (save)="editAttribute($event)"> </tr> </app-table-result> @@ -130,7 +125,6 @@ detail [attribute]="attribute" [attributeList]="attributeList | async" - [rendererDetailList]="selectOptionList | async | optionListBySelect:'renderer_detail'" (save)="editAttribute($event)"> </tr> </app-table-detail> diff --git a/client/src/app/admin/instance/dataset/containers/configure-dataset.component.ts b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.ts index 25e9fe5ffc246d11c9fc5cf5cd123d32a5461342..51d97035d02561273765a3b1840712e39408b701 100644 --- a/client/src/app/admin/instance/dataset/containers/configure-dataset.component.ts +++ b/client/src/app/admin/instance/dataset/containers/configure-dataset.component.ts @@ -14,7 +14,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { Store } from '@ngrx/store'; -import { SelectOption, Instance, Dataset, Attribute, CriteriaFamily, OutputCategory, OutputFamily, Image, File, ConeSearchConfig } from 'src/app/metamodel/models'; +import { Instance, Dataset, Attribute, CriteriaFamily, OutputCategory, OutputFamily, Image, File, ConeSearchConfig } from 'src/app/metamodel/models'; import { Column, FileInfo, FitsImageLimits } from 'src/app/admin/store/models'; import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; import * as datasetSelector from 'src/app/metamodel/selectors/dataset.selector'; @@ -26,7 +26,6 @@ import * as outputFamilyActions from 'src/app/metamodel/actions/output-family.ac import * as outputFamilySelector from 'src/app/metamodel/selectors/output-family.selector'; import * as outputCategoryActions from 'src/app/metamodel/actions/output-category.actions'; import * as outputCategorySelector from 'src/app/metamodel/selectors/output-category.selector'; -import * as optionSelector from 'src/app/metamodel/selectors/select-option.selector'; import * as columnActions from 'src/app/admin/store/actions/column.actions'; import * as columnSelector from 'src/app/admin/store/selectors/column.selector'; import * as attributeDistinctActions from 'src/app/admin/store/actions/attribute-distinct.actions'; @@ -65,9 +64,6 @@ export class ConfigureDatasetComponent implements OnInit { public outputCategoryList: Observable<OutputCategory[]>; public outputCategoryListIsLoading: Observable<boolean>; public outputCategoryListIsLoaded: Observable<boolean>; - public selectOptionList: Observable<SelectOption[]>; - public selectOptionListIsLoading: Observable<boolean>; - public selectOptionListIsLoaded: Observable<boolean>; public columnList: Observable<Column[]>; public columnListIsLoading: Observable<boolean>; public columnListIsLoaded: Observable<boolean>; @@ -107,9 +103,6 @@ export class ConfigureDatasetComponent implements OnInit { this.outputCategoryList = store.select(outputCategorySelector.selectAllOutputCategories); this.outputCategoryListIsLoading = store.select(outputCategorySelector.selectOutputCategoryListIsLoading); this.outputCategoryListIsLoaded = store.select(outputCategorySelector.selectOutputCategoryListIsLoaded); - this.selectOptionList = store.select(optionSelector.selectAllSelectOptions); - this.selectOptionListIsLoading = store.select(optionSelector.selectSelectOptionListIsLoading); - this.selectOptionListIsLoaded = store.select(optionSelector.selectSelectOptionListIsLoaded); this.columnList = store.select(columnSelector.selectAllColumns); this.columnListIsLoading = store.select(columnSelector.selectColumnListIsLoading); this.columnListIsLoaded = store.select(columnSelector.selectColumnListIsLoaded); diff --git a/client/src/app/admin/settings/components/add-option.component.html b/client/src/app/admin/settings/components/add-option.component.html deleted file mode 100644 index 52195c4816b9ebe4835f69ce4f6d26a959bdae51..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/add-option.component.html +++ /dev/null @@ -1,18 +0,0 @@ -<button title="Add a new option" class="btn btn-outline-success" (click)="openModal(template)"> - <span class="fas fa-plus"></span> -</button> - -<ng-template #template> - <div class="modal-header"> - <h4 class="modal-title pull-left"><strong>Add a new option</strong></h4> - </div> - <div class="modal-body"> - <app-form-option (onSubmit)="onSubmit.emit($event)" #formAddOption> - <button [disabled]="!formAddOption.selectOptionForm.valid || formAddOption.selectOptionForm.pristine" (click)="modalRef.hide()" type="submit" class="btn btn-primary"> - <span class="fa fa-database"></span> Add new option - </button> - - <button (click)="modalRef.hide()" type="button" class="btn btn-danger">Cancel</button> - </app-form-option> - </div> -</ng-template> diff --git a/client/src/app/admin/settings/components/add-option.component.ts b/client/src/app/admin/settings/components/add-option.component.ts deleted file mode 100644 index 6397b4ffb7c4b4ae06731a1a2b57c969806bdefb..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/add-option.component.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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, Output, ChangeDetectionStrategy, EventEmitter, TemplateRef } from '@angular/core'; - -import { BsModalService } from 'ngx-bootstrap/modal'; -import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; - -import { SelectOption } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-add-option', - templateUrl: 'add-option.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class AddOptionComponent { - @Output() onSubmit: EventEmitter<SelectOption> = new EventEmitter(); - - modalRef: BsModalRef; - - constructor(private modalService: BsModalService) { } - - openModal(template: TemplateRef<any>) { - this.modalRef = this.modalService.show(template); - } -} \ No newline at end of file diff --git a/client/src/app/admin/settings/components/edit-option.component.html b/client/src/app/admin/settings/components/edit-option.component.html deleted file mode 100644 index 0a57daa0ae72480c7df266244880c1a5394fc625..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/edit-option.component.html +++ /dev/null @@ -1,18 +0,0 @@ -<button title="Edit this option" (click)="openModal(template)" class="btn btn-outline-primary"> - <span class="fas fa-edit"></span> -</button> - -<ng-template #template> - <div class="modal-header"> - <h4 class="modal-title pull-left"><strong>Edit option</strong></h4> - </div> - <div class="modal-body"> - <app-form-option [selectOption]="option" (onSubmit)="onSubmit.emit($event)" #formAddOption> - <button [disabled]="!formAddOption.selectOptionForm.valid || formAddOption.selectOptionForm.pristine" (click)="modalRef.hide()" type="submit" class="btn btn-primary"> - <span class="fa fa-database"></span> Edit select option - </button> - - <button (click)="modalRef.hide()" type="button" class="btn btn-danger">Cancel</button> - </app-form-option> - </div> -</ng-template> diff --git a/client/src/app/admin/settings/components/edit-option.component.ts b/client/src/app/admin/settings/components/edit-option.component.ts deleted file mode 100644 index 857bb5c03814d3e4b2ae2c0fb07d57c1e371c436..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/edit-option.component.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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, ChangeDetectionStrategy, TemplateRef, Output, EventEmitter } from '@angular/core'; - -import { BsModalService } from 'ngx-bootstrap/modal'; -import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; - -import { SelectOption } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-edit-option', - templateUrl: 'edit-option.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class EditOptionComponent { - @Input() option: SelectOption; - @Output() onSubmit: EventEmitter<SelectOption> = new EventEmitter(); - - modalRef: BsModalRef; - - constructor(private modalService: BsModalService) { } - - openModal(template: TemplateRef<any>) { - this.modalRef = this.modalService.show(template); - } -} diff --git a/client/src/app/admin/settings/components/edit-select.component.html b/client/src/app/admin/settings/components/edit-select.component.html deleted file mode 100644 index 188c393e9f8ddbf7200dac011e2ad69337e1531d..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/edit-select.component.html +++ /dev/null @@ -1,18 +0,0 @@ -<button title="Edit this select" (click)="openModal(template)" class="btn btn-outline-primary"> - <span class="fas fa-edit"></span> -</button> - -<ng-template #template> - <div class="modal-header"> - <h4 class="modal-title pull-left"><strong>Edit select</strong></h4> - </div> - <div class="modal-body"> - <app-form-select [select]="select" (onSubmit)="onSubmit.emit($event)" #formEditSelect> - <button [disabled]="!formEditSelect.selectForm.valid || formEditSelect.selectForm.pristine" (click)="modalRef.hide()" type="submit" class="btn btn-primary"> - <span class="fa fa-database"></span> Update select information - </button> - - <button (click)="modalRef.hide()" type="button" class="btn btn-danger">Cancel</button> - </app-form-select> - </div> -</ng-template> diff --git a/client/src/app/admin/settings/components/edit-select.component.ts b/client/src/app/admin/settings/components/edit-select.component.ts deleted file mode 100644 index c486f09868ba3ce9178ae7767a9f80a7c2e0b1c5..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/edit-select.component.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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, ChangeDetectionStrategy, TemplateRef, Output, EventEmitter } from '@angular/core'; - -import { BsModalService } from 'ngx-bootstrap/modal'; -import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; - -import { Select } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-edit-select', - templateUrl: 'edit-select.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class EditSelectComponent { - @Input() select: Select; - @Output() onSubmit: EventEmitter<Select> = new EventEmitter(); - - modalRef: BsModalRef; - - constructor(private modalService: BsModalService) { } - - openModal(template: TemplateRef<any>) { - this.modalRef = this.modalService.show(template); - } -} diff --git a/client/src/app/admin/settings/components/form-option.component.html b/client/src/app/admin/settings/components/form-option.component.html deleted file mode 100644 index d957337c06b74c5553175a92fa542bb474323f60..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/form-option.component.html +++ /dev/null @@ -1,17 +0,0 @@ -<form [formGroup]="selectOptionForm" (ngSubmit)="submit()" novalidate> - <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="value">Value</label> - <input type="text" class="form-control" id="value" name="value" formControlName="value"> - </div> - <div class="form-group"> - <label for="display">Display</label> - <input type="number" class="form-control" id="display" name="display" formControlName="display"> - </div> - <div class="form-group"> - <ng-content></ng-content> - </div> -</form> diff --git a/client/src/app/admin/settings/components/form-option.component.ts b/client/src/app/admin/settings/components/form-option.component.ts deleted file mode 100644 index d3677dbdc319dba3f55b5239836c548c6cd76578..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/form-option.component.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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 } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; - -import { SelectOption } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-form-option', - templateUrl: 'form-option.component.html' -}) -export class FormOptionComponent { - @Input() selectOption: SelectOption; - @Output() onSubmit: EventEmitter<SelectOption> = new EventEmitter(); - - public selectOptionForm = new FormGroup({ - label: new FormControl('', [Validators.required]), - value: new FormControl('', [Validators.required]), - display: new FormControl('', [Validators.required]) - }); - - ngOnInit() { - if (this.selectOption) { - this.selectOptionForm.patchValue(this.selectOption); - } - } - - submit() { - if (this.selectOption) { - this.onSubmit.emit({ - ...this.selectOption, - ...this.selectOptionForm.value - }); - } else { - this.onSubmit.emit(this.selectOptionForm.value); - this.selectOptionForm.reset(); - } - } -} diff --git a/client/src/app/admin/settings/components/form-select.component.html b/client/src/app/admin/settings/components/form-select.component.html deleted file mode 100644 index e53bb31aefc62ea7ab35ce1d8535486a3391eb8d..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/form-select.component.html +++ /dev/null @@ -1,13 +0,0 @@ -<form [formGroup]="selectForm" (ngSubmit)="onSubmit.emit(selectForm.getRawValue())" 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"> - <ng-content></ng-content> - </div> -</form> diff --git a/client/src/app/admin/settings/components/form-select.component.ts b/client/src/app/admin/settings/components/form-select.component.ts deleted file mode 100644 index a08dc7d6dfd5c51016f8ac180b4a09bcead7718a..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/form-select.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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, OnChanges, SimpleChanges } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; - -import { Select } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-form-select', - templateUrl: 'form-select.component.html' -}) -export class FormSelectComponent implements OnInit, OnChanges { - @Input() select: Select; - @Output() onSubmit: EventEmitter<Select> = new EventEmitter(); - - public selectForm = new FormGroup({ - name: new FormControl('', [Validators.required, Validators.pattern('[a-z1-9_]*')]), - label: new FormControl('', [Validators.required]) - }); - - ngOnInit() { - if (this.select) { - this.selectForm.setValue(this.select); - this.selectForm.controls.name.disable(); - } - } - - ngOnChanges(changes: SimpleChanges) { - this.selectForm.setValue(changes.select.currentValue); - } -} diff --git a/client/src/app/admin/settings/components/index.ts b/client/src/app/admin/settings/components/index.ts deleted file mode 100644 index bd52c048c8e15f7ae5381e8bca179cd641836b4a..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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 { SelectListComponent } from "./select-list.component"; -import { SelectButtonsComponent } from "./select-buttons.component"; -import { EditSelectComponent } from "./edit-select.component"; -import { AddOptionComponent } from "./add-option.component"; -import { EditOptionComponent } from "./edit-option.component"; -import { OptionTableComponent } from "./option-table.component"; -import { FormSelectComponent } from "./form-select.component"; -import { FormOptionComponent } from "./form-option.component"; - -export const dummiesComponents = [ - SelectListComponent, - SelectButtonsComponent, - EditSelectComponent, - AddOptionComponent, - EditOptionComponent, - OptionTableComponent, - FormSelectComponent, - FormOptionComponent -]; diff --git a/client/src/app/admin/settings/components/option-table.component.html b/client/src/app/admin/settings/components/option-table.component.html deleted file mode 100644 index a5c4b60472d17ee5be4eb3f2b4df975f351db707..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/option-table.component.html +++ /dev/null @@ -1,33 +0,0 @@ -<div class="table-responsive"> - <table class="table table-striped" aria-describedby="Settings option list"> - <thead> - <tr> - <th scope="col">Label</th> - <th scope="col">Value</th> - <th scope="col">Display</th> - <th scope="col">Edit</th> - <th scope="col">Delete</th> - </tr> - </thead> - <tbody> - <tr *ngFor="let option of optionList"> - <td class="align-middle">{{ option.label }}</td> - <td class="align-middle">{{ option.value }}</td> - <td class="align-middle">{{ option.display }}</td> - <td class="align-middle"> - <app-edit-option - [option]="option" - (onSubmit)="editOption.emit($event)"> - </app-edit-option> - </td> - <td class="align-middle"> - <app-delete-btn - [type]="'option'" - [label]="option.label" - (confirm)="deleteOption.emit(option)"> - </app-delete-btn> - </td> - </tr> - </tbody> - </table> -</div> diff --git a/client/src/app/admin/settings/components/option-table.component.ts b/client/src/app/admin/settings/components/option-table.component.ts deleted file mode 100644 index 52eabd61c149e44a81ab021e1a8e11d41be97bd8..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/option-table.component.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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 { SelectOption } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-option-table', - templateUrl: 'option-table.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class OptionTableComponent { - @Input() optionList: SelectOption[]; - @Output() editOption: EventEmitter<SelectOption> = new EventEmitter(); - @Output() deleteOption: EventEmitter<SelectOption> = new EventEmitter(); -} diff --git a/client/src/app/admin/settings/components/select-buttons.component.html b/client/src/app/admin/settings/components/select-buttons.component.html deleted file mode 100644 index eb07d5f29f050e6110702ec5db70cb5e40546f62..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/select-buttons.component.html +++ /dev/null @@ -1,14 +0,0 @@ -<app-add-option - (onSubmit)="addNewSelectOption($event)"> -</app-add-option> - -<app-edit-select - [select]="select" - (onSubmit)="editSelect.emit($event)"> -</app-edit-select> - -<app-delete-btn - [type]="'select'" - [label]="select.label" - (confirm)="deleteSelect.emit(select)"> -</app-delete-btn> diff --git a/client/src/app/admin/settings/components/select-buttons.component.ts b/client/src/app/admin/settings/components/select-buttons.component.ts deleted file mode 100644 index e4d8298d4d6ab0eae36cbc08fb0061925ab0e339..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/select-buttons.component.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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 { Select, SelectOption } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-select-buttons', - templateUrl: 'select-buttons.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class SelectButtonsComponent { - @Input() select: Select; - @Output() deleteSelect: EventEmitter<Select> = new EventEmitter(); - @Output() editSelect: EventEmitter<Select> = new EventEmitter(); - @Output() addOption: EventEmitter<SelectOption> = new EventEmitter(); - - addNewSelectOption(selectOption: SelectOption) { - this.addOption.emit({...selectOption, select_name: this.select.name}); - } -} diff --git a/client/src/app/admin/settings/components/select-list.component.html b/client/src/app/admin/settings/components/select-list.component.html deleted file mode 100644 index ec36de7115e1328d3a2b2c0b59ae7dbeea308319..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/select-list.component.html +++ /dev/null @@ -1,23 +0,0 @@ -<ul class="nav nav-tabs card-header-tabs"> - <li *ngFor="let select of selectList" class="nav-item"> - <a class="nav-link" routerLink="/admin/settings/{{select.name}}" routerLinkActive="active">{{ select.label }}</a> - </li> - <li class="nav-item"> - <a class="nav-link add-select pointer" (click)="openModal(templateForNew); $event.stopPropagation()"><span class="fas fa-plus"></span></a> - </li> -</ul> - -<ng-template #templateForNew> - <div class="modal-header"> - <h4 class="modal-title pull-left"><strong>Add new select</strong></h4> - </div> - <div class="modal-body"> - <app-form-select (onSubmit)="confirmAdd($event)" #formNewSelect> - <button [disabled]="!formNewSelect.selectForm.valid || formNewSelect.selectForm.pristine" type="submit" class="btn btn-primary"> - <span class="fa fa-database"></span> Add select - </button> - - <button (click)="modalRef.hide(); $event.stopPropagation()" type="button" class="btn btn-danger">Cancel</button> - </app-form-select> - </div> -</ng-template> diff --git a/client/src/app/admin/settings/components/select-list.component.ts b/client/src/app/admin/settings/components/select-list.component.ts deleted file mode 100644 index 08303b5050e4b87d6a7e55522ea82971a2de43e2..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/components/select-list.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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, TemplateRef } from '@angular/core'; - -import { BsModalService } from 'ngx-bootstrap/modal'; -import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; - -import { Select } from 'src/app/metamodel/models'; - -@Component({ - selector: 'app-select-list', - templateUrl: 'select-list.component.html', - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class SelectListComponent { - @Input() selectList: Select[]; - @Output() addSelect: EventEmitter<Select> = new EventEmitter(); - - modalRef: BsModalRef; - - constructor(private modalService: BsModalService) { } - - openModal(template: TemplateRef<any>) { - this.modalRef = this.modalService.show(template); - } - - confirmAdd(select: Select) { - this.addSelect.emit(select); - this.modalRef.hide(); - } -} diff --git a/client/src/app/admin/settings/containers/settings.component.html b/client/src/app/admin/settings/containers/settings.component.html deleted file mode 100644 index 5cea4545c018112980c110c41f9ae2240d7c84d6..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/containers/settings.component.html +++ /dev/null @@ -1,45 +0,0 @@ -<div class="container-fluid"> - <nav aria-label="breadcrumb"> - <ol class="breadcrumb"> - <li class="breadcrumb-item active">Settings</li> - <li *ngIf="(currentSelect | async)" class="breadcrumb-item active" aria-current="page"> - {{ (currentSelect | async).label }} - </li> - </ol> - </nav> - - <app-spinner *ngIf="(selectListIsLoading | async) || (optionListIsLoading | async)"></app-spinner> - - <ng-container *ngIf="(selectListIsLoaded | async) && (optionListIsLoaded | async)"> - <div class="card text-center"> - <div class="card-header"> - <app-select-list - [selectList]="selectList | async" - (addSelect)="addSelect($event)"> - </app-select-list> - </div> - <div *ngIf="(currentSelect | async)" class="card-body"> - <div class="row"> - <div class="col text-right"> - <app-select-buttons - [select]="currentSelect | async" - (deleteSelect)="deleteSelect($event)" - (editSelect)="editSelect($event)" - (addOption)="addOption($event)"> - </app-select-buttons> - </div> - </div> - - <div class="row mt-1"> - <div class="col-12"> - <app-option-table - [optionList]="optionList | async" - (editOption)="editOption($event)" - (deleteOption)="deleteOption($event)"> - </app-option-table> - </div> - </div> - </div> - </div> - </ng-container> -</div> diff --git a/client/src/app/admin/settings/containers/settings.component.ts b/client/src/app/admin/settings/containers/settings.component.ts deleted file mode 100644 index 6c091610dc6f1759184558c199b3233ccff6957b..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/containers/settings.component.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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 } from '@angular/core'; - -import { Observable } from 'rxjs'; -import { Store } from '@ngrx/store'; - -import { Select, SelectOption } from 'src/app/metamodel/models'; -import * as selectActions from 'src/app/metamodel/actions/select.actions'; -import * as optionActions from 'src/app/metamodel/actions/select-option.actions'; -import * as selectSelector from 'src/app/metamodel/selectors/select.selector'; -import * as optionSelector from 'src/app/metamodel/selectors/select-option.selector'; - -@Component({ - selector: 'app-settings', - templateUrl: 'settings.component.html' -}) -export class SettingsComponent { - public selectListIsLoading: Observable<boolean>; - public selectListIsLoaded: Observable<boolean>; - public selectList: Observable<Select[]>; - public optionListIsLoading: Observable<boolean>; - public optionListIsLoaded: Observable<boolean>; - public optionList: Observable<SelectOption[]>; - public currentSelect: Observable<Select>; - - constructor(private store: Store<{ }>) { - this.selectListIsLoading = store.select(selectSelector.selectSelectListIsLoading); - this.selectListIsLoaded = store.select(selectSelector.selectSelectListIsLoaded); - this.selectList = store.select(selectSelector.selectAllSelects); - this.optionListIsLoading = store.select(optionSelector.selectSelectOptionListIsLoading); - this.optionListIsLoaded = store.select(optionSelector.selectSelectOptionListIsLoaded); - this.optionList = store.select(optionSelector.getOptionBySelectName); - this.currentSelect = store.select(selectSelector.getSelectByRouteName); - } - - addSelect(select: Select) { - this.store.dispatch(selectActions.addSelect({ select })); - } - - editSelect(select: Select) { - this.store.dispatch(selectActions.editSelect({ select })); - } - - deleteSelect(select: Select) { - this.store.dispatch(selectActions.deleteSelect({ select })); - } - - addOption(selectOption: SelectOption) { - this.store.dispatch(optionActions.addSelectOption({ selectOption })); - } - - editOption(selectOption: SelectOption) { - this.store.dispatch(optionActions.editSelectOption({ selectOption })); - } - - deleteOption(selectOption: SelectOption) { - this.store.dispatch(optionActions.deleteSelectOption({ selectOption })); - } -} diff --git a/client/src/app/admin/settings/settings-routing.module.ts b/client/src/app/admin/settings/settings-routing.module.ts deleted file mode 100644 index 9a885838c0c45707843f28d9345b235da873a9a4..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/settings-routing.module.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; - -import { SettingsComponent } from './containers/settings.component'; - -const routes: Routes = [ - { path: '', component: SettingsComponent }, - { path: ':select', component: SettingsComponent } -]; - -/** - * @class - * @classdesc Settings routing module. - */ -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule] -}) -export class SettingsRoutingModule { } - -export const routedComponents = [ - SettingsComponent -]; diff --git a/client/src/app/admin/settings/settings.module.ts b/client/src/app/admin/settings/settings.module.ts deleted file mode 100644 index 4160042fe01e01957e6d56be495f613b7599b2fb..0000000000000000000000000000000000000000 --- a/client/src/app/admin/settings/settings.module.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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 { NgModule } from '@angular/core'; - -import { SharedModule } from 'src/app/shared/shared.module'; -import { SettingsRoutingModule, routedComponents } from './settings-routing.module'; -import { dummiesComponents } from './components'; - -import { AdminSharedModule } from '../admin-shared/admin-shared.module'; - -/** - * @class - * @classdesc Settings module. - */ -@NgModule({ - imports: [ - SharedModule, - SettingsRoutingModule, - AdminSharedModule - ], - declarations: [ - routedComponents, - dummiesComponents - ] -}) -export class SettingsModule { } diff --git a/client/src/app/metamodel/actions/select-option.actions.ts b/client/src/app/metamodel/actions/select-option.actions.ts deleted file mode 100644 index 05b5092a2c573cb17f62e0116beb4adae1c0233b..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/actions/select-option.actions.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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 { createAction, props } from '@ngrx/store'; - -import { SelectOption } from '../models'; - -export const loadSelectOptionList = createAction('[Metamodel] Load Select Option List'); -export const loadSelectOptionListSuccess = createAction('[Metamodel] Load Select Option List Success', props<{ selectOptions: SelectOption[] }>()); -export const loadSelectOptionListFail = createAction('[Metamodel] Load Select Option List Fail'); -export const addSelectOption = createAction('[Metamodel] Add Select Option', props<{ selectOption: SelectOption }>()); -export const addSelectOptionSuccess = createAction('[Metamodel] Add Select Option Success', props<{ selectOption: SelectOption }>()); -export const addSelectOptionFail = createAction('[Metamodel] Add Select Option Fail'); -export const editSelectOption = createAction('[Metamodel] Edit Select Option', props<{ selectOption: SelectOption }>()); -export const editSelectOptionSuccess = createAction('[Metamodel] Edit Select Option Success', props<{ selectOption: SelectOption }>()); -export const editSelectOptionFail = createAction('[Metamodel] Edit Select Option Fail'); -export const deleteSelectOption = createAction('[Metamodel] Delete Select Option', props<{ selectOption: SelectOption }>()); -export const deleteSelectOptionSuccess = createAction('[Metamodel] Delete Select Option Success', props<{ selectOption: SelectOption }>()); -export const deleteSelectOptionFail = createAction('[Metamodel] Delete Select Option Fail'); diff --git a/client/src/app/metamodel/actions/select.actions.ts b/client/src/app/metamodel/actions/select.actions.ts deleted file mode 100644 index 2cf53ad7d4b2569e8c8741b13e16b2527725e2f0..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/actions/select.actions.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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 { createAction, props } from '@ngrx/store'; - -import { Select } from '../models'; - -export const loadSelectList = createAction('[Metamodel] Load Select List'); -export const loadSelectListSuccess = createAction('[Metamodel] Load Select List Success', props<{ selects: Select[] }>()); -export const loadSelectListFail = createAction('[Metamodel] Load Select List Fail'); -export const addSelect = createAction('[Metamodel] Add Select', props<{ select: Select }>()); -export const addSelectSuccess = createAction('[Metamodel] Add Select Success', props<{ select: Select }>()); -export const addSelectFail = createAction('[Metamodel] Add Select Fail'); -export const editSelect = createAction('[Metamodel] Edit Select', props<{ select: Select }>()); -export const editSelectSuccess = createAction('[Metamodel] Edit Select Success', props<{ select: Select }>()); -export const editSelectFail = createAction('[Metamodel] Edit Select Fail'); -export const deleteSelect = createAction('[Metamodel] Delete Select', props<{ select: Select }>()); -export const deleteSelectSuccess = createAction('[Metamodel] Delete Select Success', props<{ select: Select }>()); -export const deleteSelectFail = createAction('[Metamodel] Delete Select Fail'); diff --git a/client/src/app/metamodel/effects/index.ts b/client/src/app/metamodel/effects/index.ts index 64961cd4777e5230daa9cf0592578673aa4632d9..111bd9f732e401b4dc337afedbc0a66adfb68728 100644 --- a/client/src/app/metamodel/effects/index.ts +++ b/client/src/app/metamodel/effects/index.ts @@ -17,8 +17,6 @@ import { InstanceGroupEffects } from './instance-group.effects'; import { CriteriaFamilyEffects } from './criteria-family.effects'; import { OutputCategoryEffects } from './output-category.effects'; import { OutputFamilyEffects } from './output-family.effects'; -import { SelectEffects } from './select.effects'; -import { SelectOptionEffects } from './select-option.effects'; import { ImageEffects } from './image.effects'; import { FileEffects } from './file.effects'; import { ConeSearchConfigEffects } from './cone-search-config.effects' @@ -34,8 +32,6 @@ export const metamodelEffects = [ CriteriaFamilyEffects, OutputCategoryEffects, OutputFamilyEffects, - SelectEffects, - SelectOptionEffects, ImageEffects, FileEffects, ConeSearchConfigEffects diff --git a/client/src/app/metamodel/effects/select-option.effects.spec.ts b/client/src/app/metamodel/effects/select-option.effects.spec.ts deleted file mode 100644 index 33eced9420105607bab0334566560ecd2c18cb5c..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/effects/select-option.effects.spec.ts +++ /dev/null @@ -1,288 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { provideMockActions } from '@ngrx/effects/testing'; -import { EffectsMetadata, getEffectsMetadata } from '@ngrx/effects'; -import { Observable } from 'rxjs'; -import { cold, hot } from 'jasmine-marbles'; - -import { ToastrService } from 'ngx-toastr'; -import { SelectOptionEffects } from './select-option.effects'; -import { SelectOptionService } from '../services/select-option.service'; -import * as selectOptionActions from '../actions/select-option.actions'; -import { SELECT_OPTION, SELECT_OPTION_LIST } from '../../../test-data'; - -describe('[Metamodel][Effects] SelectOptionEffects', () => { - let actions = new Observable(); - let effects: SelectOptionEffects; - let metadata: EffectsMetadata<SelectOptionEffects>; - let service: SelectOptionService; - let toastr: ToastrService; - - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [ - SelectOptionEffects, - { provide: SelectOptionService, useValue: { }}, - { provide: ToastrService, useValue: { - success: jest.fn(), - error: jest.fn() - }}, - provideMockActions(() => actions) - ] - }).compileComponents(); - effects = TestBed.inject(SelectOptionEffects); - metadata = getEffectsMetadata(effects); - service = TestBed.inject(SelectOptionService); - toastr = TestBed.inject(ToastrService); - }); - - it('should be created', () => { - expect(effects).toBeTruthy(); - }); - - describe('loadSelectOptions$ effect', () => { - it('should dispatch the loadSelectOptionListSuccess action on success', () => { - const action = selectOptionActions.loadSelectOptionList(); - const outcome = selectOptionActions.loadSelectOptionListSuccess({ selectOptions: SELECT_OPTION_LIST }); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT_OPTION_LIST }); - const expected = cold('--b', { b: outcome }); - service.retrieveSelectOptionList = jest.fn(() => response); - - expect(effects.loadSelectOptions$).toBeObservable(expected); - }); - - it('should dispatch the loadSelectOptionListFail action on HTTP failure', () => { - const action = selectOptionActions.loadSelectOptionList(); - const error = new Error(); - const outcome = selectOptionActions.loadSelectOptionListFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.retrieveSelectOptionList = jest.fn(() => response); - - expect(effects.loadSelectOptions$).toBeObservable(expected); - }); - }); - - describe('addSelectOption$ effect', () => { - it('should dispatch the addSelectOptionSuccess action on success', () => { - const action = selectOptionActions.addSelectOption({ selectOption: SELECT_OPTION }); - const outcome = selectOptionActions.addSelectOptionSuccess({ selectOption: SELECT_OPTION}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT_OPTION }); - const expected = cold('--b', { b: outcome }); - service.addSelectOption = jest.fn(() => response); - - expect(effects.addSelectOption$).toBeObservable(expected); - }); - - it('should dispatch the addSelectOptionFail action on HTTP failure', () => { - const action = selectOptionActions.addSelectOption({ selectOption: SELECT_OPTION }); - const error = new Error(); - const outcome = selectOptionActions.addSelectOptionFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.addSelectOption = jest.fn(() => response); - - expect(effects.addSelectOption$).toBeObservable(expected); - }); - }); - - describe('addSelectOptionSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.addSelectOptionSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectOptionActions.addSelectOptionSuccess({ selectOption: SELECT_OPTION }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.addSelectOptionSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select option successfully added', - 'The new select option was added into the database' - ); - }); - }); - - describe('addSelectOptionFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.addSelectOptionFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectOptionActions.addSelectOptionFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.addSelectOptionFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to add select option', - 'The new select option could not be added into the database' - ); - }); - }); - - describe('editSelectOption$ effect', () => { - it('should dispatch the editSelectOptionSuccess action on success', () => { - const action = selectOptionActions.editSelectOption({ selectOption: SELECT_OPTION }); - const outcome = selectOptionActions.editSelectOptionSuccess({ selectOption: SELECT_OPTION}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT_OPTION }); - const expected = cold('--b', { b: outcome }); - service.editSelectOption = jest.fn(() => response); - - expect(effects.editSelectOption$).toBeObservable(expected); - }); - - it('should dispatch the editSelectOptionFail action on HTTP failure', () => { - const action = selectOptionActions.editSelectOption({ selectOption: SELECT_OPTION }); - const error = new Error(); - const outcome = selectOptionActions.editSelectOptionFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.editSelectOption = jest.fn(() => response); - - expect(effects.editSelectOption$).toBeObservable(expected); - }); - }); - - describe('editSelectOptionSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.editSelectOptionSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectOptionActions.editSelectOptionSuccess({ selectOption: SELECT_OPTION }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.editSelectOptionSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select option successfully edited', - 'The existing select option has been edited into the database' - ); - }); - }); - - describe('editSelectOptionFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.editSelectOptionFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectOptionActions.editSelectOptionFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.editSelectOptionFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to edit select option', - 'The existing select option could not be edited into the database' - ); - }); - }); - - describe('deleteSelectOption$ effect', () => { - it('should dispatch the deleteSelectOptionSuccess action on success', () => { - const action = selectOptionActions.deleteSelectOption({ selectOption: SELECT_OPTION }); - const outcome = selectOptionActions.deleteSelectOptionSuccess({ selectOption: SELECT_OPTION}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT_OPTION }); - const expected = cold('--b', { b: outcome }); - service.deleteSelectOption = jest.fn(() => response); - - expect(effects.deleteSelectOption$).toBeObservable(expected); - }); - - it('should dispatch the deleteSelectOptionFail action on HTTP failure', () => { - const action = selectOptionActions.deleteSelectOption({ selectOption: SELECT_OPTION }); - const error = new Error(); - const outcome = selectOptionActions.deleteSelectOptionFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.deleteSelectOption = jest.fn(() => response); - - expect(effects.deleteSelectOption$).toBeObservable(expected); - }); - }); - - describe('deleteSelectOptionSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.deleteSelectOptionSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectOptionActions.deleteSelectOptionSuccess({ selectOption: SELECT_OPTION }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.deleteSelectOptionSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select option successfully deleted', - 'The existing select option has been deleted' - ); - }); - }); - - describe('deleteSelectOptionFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.deleteSelectOptionFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectOptionActions.deleteSelectOptionFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.deleteSelectOptionFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to delete select option', - 'The existing select option could not be deleted from the database' - ); - }); - }); -}); diff --git a/client/src/app/metamodel/effects/select-option.effects.ts b/client/src/app/metamodel/effects/select-option.effects.ts deleted file mode 100644 index 2beaf5ae6a83a22aa6e589f4f79a1081c6c3ae7e..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/effects/select-option.effects.ts +++ /dev/null @@ -1,152 +0,0 @@ -/** - * 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 { Injectable } from '@angular/core'; -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 selectOptionActions from '../actions/select-option.actions'; -import { SelectOptionService } from '../services/select-option.service'; - -/** - * @class - * @classdesc Select option effects. - */ -@Injectable() -export class SelectOptionEffects { - - /** - * Calls action to retrieve select option list. - */ - loadSelectOptions$ = createEffect((): any => - this.actions$.pipe( - ofType(selectOptionActions.loadSelectOptionList), - mergeMap(() => this.selectOptionService.retrieveSelectOptionList() - .pipe( - map(selectOptions => selectOptionActions.loadSelectOptionListSuccess({ selectOptions })), - catchError(() => of(selectOptionActions.loadSelectOptionListFail())) - ) - ) - ) - ); - - /** - * Calls action to add a select option. - */ - addSelectOption$ = createEffect((): any => - this.actions$.pipe( - ofType(selectOptionActions.addSelectOption), - mergeMap(action => this.selectOptionService.addSelectOption(action.selectOption) - .pipe( - map(selectOption => selectOptionActions.addSelectOptionSuccess({ selectOption })), - catchError(() => of(selectOptionActions.addSelectOptionFail())) - ) - ) - ) - ); - - /** - * Displays add select option success notification. - */ - addSelectOptionSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.addSelectOptionSuccess), - tap(() => this.toastr.success('Select option successfully added', 'The new select option was added into the database')) - ), { dispatch: false } - ); - - /** - * Displays add select option error notification. - */ - addSelectOptionFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.addSelectOptionFail), - tap(() => this.toastr.error('Failure to add select option', 'The new select option could not be added into the database')) - ), { dispatch: false } - ); - - /** - * Calls action to modify a select option. - */ - editSelectOption$ = createEffect((): any => - this.actions$.pipe( - ofType(selectOptionActions.editSelectOption), - mergeMap(action => this.selectOptionService.editSelectOption(action.selectOption) - .pipe( - map(selectOption => selectOptionActions.editSelectOptionSuccess({ selectOption })), - catchError(() => of(selectOptionActions.editSelectOptionFail())) - ) - ) - ) - ); - - /** - * Displays edit select option success notification. - */ - editSelectOptionSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.editSelectOptionSuccess), - tap(() => this.toastr.success('Select option successfully edited', 'The existing select option has been edited into the database')) - ), { dispatch: false } - ); - - /** - * Displays edit select option error notification. - */ - editSelectOptionFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.editSelectOptionFail), - tap(() => this.toastr.error('Failure to edit select option', 'The existing select option could not be edited into the database')) - ), { dispatch: false } - ); - - /** - * Calls action to remove a select option. - */ - deleteSelectOption$ = createEffect(():any => - this.actions$.pipe( - ofType(selectOptionActions.deleteSelectOption), - mergeMap(action => this.selectOptionService.deleteSelectOption(action.selectOption.id) - .pipe( - map(() => selectOptionActions.deleteSelectOptionSuccess({ selectOption: action.selectOption })), - catchError(() => of(selectOptionActions.deleteSelectOptionFail())) - ) - ) - ) - ); - - /** - * Displays delete select option success notification. - */ - deleteSelectOptionSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.deleteSelectOptionSuccess), - tap(() => this.toastr.success('Select option successfully deleted', 'The existing select option has been deleted')) - ), { dispatch: false } - ); - - /** - * Displays delete select option error notification. - */ - deleteSelectOptionFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectOptionActions.deleteSelectOptionFail), - tap(() => this.toastr.error('Failure to delete select option', 'The existing select option could not be deleted from the database')) - ), { dispatch: false } - ); - - constructor( - private actions$: Actions, - private selectOptionService: SelectOptionService, - private toastr: ToastrService - ) {} -} diff --git a/client/src/app/metamodel/effects/select.effects.spec.ts b/client/src/app/metamodel/effects/select.effects.spec.ts deleted file mode 100644 index 9ccc7d77fadc12a0bd57c97708da484eba6a4cca..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/effects/select.effects.spec.ts +++ /dev/null @@ -1,288 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { provideMockActions } from '@ngrx/effects/testing'; -import { EffectsMetadata, getEffectsMetadata } from '@ngrx/effects'; -import { Observable } from 'rxjs'; -import { cold, hot } from 'jasmine-marbles'; - -import { ToastrService } from 'ngx-toastr'; -import { SelectEffects } from './select.effects'; -import { SelectService } from '../services/select.service'; -import * as selectActions from '../actions/select.actions'; -import { SELECT, SELECT_LIST } from '../../../test-data'; - -describe('[Metamodel][Effects] SelectEffects', () => { - let actions = new Observable(); - let effects: SelectEffects; - let metadata: EffectsMetadata<SelectEffects>; - let service: SelectService; - let toastr: ToastrService; - - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [ - SelectEffects, - { provide: SelectService, useValue: { }}, - { provide: ToastrService, useValue: { - success: jest.fn(), - error: jest.fn() - }}, - provideMockActions(() => actions) - ] - }).compileComponents(); - effects = TestBed.inject(SelectEffects); - metadata = getEffectsMetadata(effects); - service = TestBed.inject(SelectService); - toastr = TestBed.inject(ToastrService); - }); - - it('should be created', () => { - expect(effects).toBeTruthy(); - }); - - describe('loadSelects$ effect', () => { - it('should dispatch the loadSelectListSuccess action on success', () => { - const action = selectActions.loadSelectList(); - const outcome = selectActions.loadSelectListSuccess({ selects: SELECT_LIST }); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT_LIST }); - const expected = cold('--b', { b: outcome }); - service.retrieveSelectList = jest.fn(() => response); - - expect(effects.loadSelects$).toBeObservable(expected); - }); - - it('should dispatch the loadSelectListFail action on HTTP failure', () => { - const action = selectActions.loadSelectList(); - const error = new Error(); - const outcome = selectActions.loadSelectListFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.retrieveSelectList = jest.fn(() => response); - - expect(effects.loadSelects$).toBeObservable(expected); - }); - }); - - describe('addSelect$ effect', () => { - it('should dispatch the addSelectSuccess action on success', () => { - const action = selectActions.addSelect({ select: SELECT }); - const outcome = selectActions.addSelectSuccess({ select: SELECT}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT }); - const expected = cold('--b', { b: outcome }); - service.addSelect = jest.fn(() => response); - - expect(effects.addSelect$).toBeObservable(expected); - }); - - it('should dispatch the addSelectFail action on HTTP failure', () => { - const action = selectActions.addSelect({ select: SELECT }); - const error = new Error(); - const outcome = selectActions.addSelectFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.addSelect = jest.fn(() => response); - - expect(effects.addSelect$).toBeObservable(expected); - }); - }); - - describe('addSelectSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.addSelectSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectActions.addSelectSuccess({ select: SELECT }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.addSelectSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select successfully added', - 'The new select was added into the database' - ); - }); - }); - - describe('addSelectFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.addSelectFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectActions.addSelectFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.addSelectFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to add select', - 'The new select could not be added into the database' - ); - }); - }); - - describe('editSelect$ effect', () => { - it('should dispatch the editSelectSuccess action on success', () => { - const action = selectActions.editSelect({ select: SELECT }); - const outcome = selectActions.editSelectSuccess({ select: SELECT}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT }); - const expected = cold('--b', { b: outcome }); - service.editSelect = jest.fn(() => response); - - expect(effects.editSelect$).toBeObservable(expected); - }); - - it('should dispatch the editSelectFail action on HTTP failure', () => { - const action = selectActions.editSelect({ select: SELECT }); - const error = new Error(); - const outcome = selectActions.editSelectFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.editSelect = jest.fn(() => response); - - expect(effects.editSelect$).toBeObservable(expected); - }); - }); - - describe('editSelectSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.editSelectSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectActions.editSelectSuccess({ select: SELECT }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.editSelectSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select successfully edited', - 'The existing select has been edited into the database' - ); - }); - }); - - describe('editSelectFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.editSelectFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectActions.editSelectFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.editSelectFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to edit select', - 'The existing select could not be edited into the database' - ); - }); - }); - - describe('deleteSelect$ effect', () => { - it('should dispatch the deleteSelectSuccess action on success', () => { - const action = selectActions.deleteSelect({ select: SELECT }); - const outcome = selectActions.deleteSelectSuccess({ select: SELECT}); - - actions = hot('-a', { a: action }); - const response = cold('-a|', { a: SELECT }); - const expected = cold('--b', { b: outcome }); - service.deleteSelect = jest.fn(() => response); - - expect(effects.deleteSelect$).toBeObservable(expected); - }); - - it('should dispatch the deleteSelectFail action on HTTP failure', () => { - const action = selectActions.deleteSelect({ select: SELECT }); - const error = new Error(); - const outcome = selectActions.deleteSelectFail(); - - actions = hot('-a', { a: action }); - const response = cold('-#|', { }, error); - const expected = cold('--b', { b: outcome }); - service.deleteSelect = jest.fn(() => response); - - expect(effects.deleteSelect$).toBeObservable(expected); - }); - }); - - describe('deleteSelectSuccess$ effect', () => { - it('should not dispatch', () => { - expect(metadata.deleteSelectSuccess$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display a success notification', () => { - const toastrSpy = jest.spyOn(toastr, 'success'); - const action = selectActions.deleteSelectSuccess({ select: SELECT }); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.deleteSelectSuccess$).toBeObservable(expected); - expect(toastrSpy).toHaveBeenCalledTimes(1); - expect(toastrSpy).toHaveBeenCalledWith( - 'Select successfully deleted', - 'The existing select has been deleted' - ); - }); - }); - - describe('deleteSelectFail$ effect', () => { - it('should not dispatch', () => { - expect(metadata.deleteSelectFail$).toEqual( - expect.objectContaining({ dispatch: false }) - ); - }); - - it('should display an error notification', () => { - const spy = jest.spyOn(toastr, 'error'); - const action = selectActions.deleteSelectFail(); - - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.deleteSelectFail$).toBeObservable(expected); - expect(spy).toHaveBeenCalledTimes(1); - expect(spy).toHaveBeenCalledWith( - 'Failure to delete select', - 'The existing select could not be deleted from the database' - ); - }); - }); -}); diff --git a/client/src/app/metamodel/effects/select.effects.ts b/client/src/app/metamodel/effects/select.effects.ts deleted file mode 100644 index c4a21e361d5b0bc916e862217c1604c05048eae0..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/effects/select.effects.ts +++ /dev/null @@ -1,152 +0,0 @@ -/** - * 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 { Injectable } from '@angular/core'; -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 selectActions from '../actions/select.actions'; -import { SelectService } from '../services/select.service'; - -/** - * @class - * @classdesc Select effects. - */ -@Injectable() -export class SelectEffects { - - /** - * Calls action to retrieve select list. - */ - loadSelects$ = createEffect((): any => - this.actions$.pipe( - ofType(selectActions.loadSelectList), - mergeMap(() => this.selectService.retrieveSelectList() - .pipe( - map(selects => selectActions.loadSelectListSuccess({ selects })), - catchError(() => of(selectActions.loadSelectListFail())) - ) - ) - ) - ); - - /** - * Calls action to add a select. - */ - addSelect$ = createEffect((): any => - this.actions$.pipe( - ofType(selectActions.addSelect), - mergeMap(action => this.selectService.addSelect(action.select) - .pipe( - map(select => selectActions.addSelectSuccess({ select })), - catchError(() => of(selectActions.addSelectFail())) - ) - ) - ) - ); - - /** - * Displays add select success notification. - */ - addSelectSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.addSelectSuccess), - tap(() => this.toastr.success('Select successfully added', 'The new select was added into the database')) - ), { dispatch: false } - ); - - /** - * Displays add select error notification. - */ - addSelectFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.addSelectFail), - tap(() => this.toastr.error('Failure to add select', 'The new select could not be added into the database')) - ), { dispatch: false } - ); - - /** - * Calls action to modify a select. - */ - editSelect$ = createEffect((): any => - this.actions$.pipe( - ofType(selectActions.editSelect), - mergeMap(action => this.selectService.editSelect(action.select) - .pipe( - map(select => selectActions.editSelectSuccess({ select })), - catchError(() => of(selectActions.editSelectFail())) - ) - ) - ) - ); - - /** - * Displays edit select success notification. - */ - editSelectSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.editSelectSuccess), - tap(() => this.toastr.success('Select successfully edited', 'The existing select has been edited into the database')) - ), { dispatch: false } - ); - - /** - * Displays edit select success notification. - */ - editSelectFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.editSelectFail), - tap(() => this.toastr.error('Failure to edit select', 'The existing select could not be edited into the database')) - ), { dispatch: false } - ); - - /** - * Calls action to remove a select. - */ - deleteSelect$ = createEffect((): any => - this.actions$.pipe( - ofType(selectActions.deleteSelect), - mergeMap(action => this.selectService.deleteSelect(action.select.name) - .pipe( - map(() => selectActions.deleteSelectSuccess({ select: action.select })), - catchError(() => of(selectActions.deleteSelectFail())) - ) - ) - ) - ); - - /** - * Displays delete select success notification. - */ - deleteSelectSuccess$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.deleteSelectSuccess), - tap(() => this.toastr.success('Select successfully deleted', 'The existing select has been deleted')) - ), { dispatch: false } - ); - - /** - * Displays delete select error notification. - */ - deleteSelectFail$ = createEffect(() => - this.actions$.pipe( - ofType(selectActions.deleteSelectFail), - tap(() => this.toastr.error('Failure to delete select', 'The existing select could not be deleted from the database')) - ), { dispatch: false } - ); - - constructor( - private actions$: Actions, - private selectService: SelectService, - private toastr: ToastrService - ) {} -} diff --git a/client/src/app/metamodel/metamodel.reducer.ts b/client/src/app/metamodel/metamodel.reducer.ts index 8bbd0bc2c3cfd6709c92fc65c513a057dd117206..2cccdfc3787cfaac8e61e759cd38e77e93f7daa0 100644 --- a/client/src/app/metamodel/metamodel.reducer.ts +++ b/client/src/app/metamodel/metamodel.reducer.ts @@ -20,8 +20,6 @@ import * as attribute from './reducers/attribute.reducer'; import * as criteriaFamily from './reducers/criteria-family.reducer'; import * as outputCategory from './reducers/output-category.reducer'; import * as outputFamily from './reducers/output-family.reducer'; -import * as select from './reducers/select.reducer'; -import * as selectOption from './reducers/select-option.reducer'; import * as image from './reducers/image.reducer'; import * as file from './reducers/file.reducer'; import * as coneSearchConfig from './reducers/cone-search-config.reducer'; @@ -42,8 +40,6 @@ export interface State { criteriaFamily: criteriaFamily.State; outputCategory: outputCategory.State; outputFamily: outputFamily.State; - select: select.State; - selectOption: selectOption.State; image: image.State; file: file.State; coneSearchConfig: coneSearchConfig.State; @@ -60,8 +56,6 @@ const reducers = { criteriaFamily: criteriaFamily.criteriaFamilyReducer, outputCategory: outputCategory.outputCategoryReducer, outputFamily: outputFamily.outputFamilyReducer, - select: select.selectReducer, - selectOption: selectOption.selectOptionReducer, image: image.imageReducer, file: file.fileReducer, coneSearchConfig: coneSearchConfig.coneSearchConfigReducer diff --git a/client/src/app/metamodel/models/index.ts b/client/src/app/metamodel/models/index.ts index e0f6870def5b2349a3d201e7e714c8cdef12f93d..82f01695472cea1a22424bf1a7465fdcd6f168b5 100644 --- a/client/src/app/metamodel/models/index.ts +++ b/client/src/app/metamodel/models/index.ts @@ -18,8 +18,6 @@ export * from './option.model'; export * from './criteria-family.model'; export * from './output-category.model'; export * from './output-family.model'; -export * from './select.model'; -export * from './select-option.model'; export * from './image.model'; export * from './renderers'; export * from './detail-renderers'; diff --git a/client/src/app/metamodel/models/select-option.model.ts b/client/src/app/metamodel/models/select-option.model.ts deleted file mode 100644 index bb3473f08f3b095e7b8985fe355acab0587b5799..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/models/select-option.model.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * 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. - */ - -/** - * Interface for select option. - * - * @interface SelectOption - */ -export interface SelectOption { - id: number; - label: string; - value: string; - display: number; - select_name: string; -} diff --git a/client/src/app/metamodel/models/select.model.ts b/client/src/app/metamodel/models/select.model.ts deleted file mode 100644 index 4bdb3d403ae6b2c5238f4240f11bccba687da673..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/models/select.model.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * 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. - */ - -/** - * Interface for select. - * - * @interface Select - */ -export interface Select { - name: string; - label: string; -} diff --git a/client/src/app/metamodel/reducers/select-option.reducer.spec.ts b/client/src/app/metamodel/reducers/select-option.reducer.spec.ts deleted file mode 100644 index 000a74966ba13f3292949a801719dc165431b6b8..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/reducers/select-option.reducer.spec.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { Action } from '@ngrx/store'; - -import * as fromSelectOption from './select-option.reducer'; -import * as selectOptionActions from '../actions/select-option.actions'; -import { SELECT_OPTION, SELECT_OPTION_LIST } from '../../../test-data'; - -describe('[Metamodel][Reducers] SelectOption reducer', () => { - it('unknown action should return the default state', () => { - const { initialState } = fromSelectOption; - const action = { type: 'Unknown' }; - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state).toBe(initialState); - }); - - it('loadSelectOptionList action should set selectOptionListIsLoading to true', () => { - const { initialState } = fromSelectOption; - const action = selectOptionActions.loadSelectOptionList(); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual({ }); - expect(state.selectOptionListIsLoading).toEqual(true); - expect(state.selectOptionListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('loadSelectOptionListSuccess action should add selectOption list, set selectOptionListIsLoading to false and set selectOptionListIsLoaded to true', () => { - const { initialState } = fromSelectOption; - const action = selectOptionActions.loadSelectOptionListSuccess({ selectOptions: SELECT_OPTION_LIST }); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(2); - expect(state.ids).toContain(1); - expect(state.ids).toContain(2); - expect(Object.keys(state.entities).length).toEqual(2); - expect(state.selectOptionListIsLoading).toEqual(false); - expect(state.selectOptionListIsLoaded).toEqual(true); - expect(state).not.toBe(initialState); - }); - - it('loadSelectOptionListFail action should set selectOptionListIsLoading to false', () => { - const { initialState } = fromSelectOption; - const action = selectOptionActions.loadSelectOptionListFail(); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual({ }); - expect(state.selectOptionListIsLoading).toEqual(false); - expect(state.selectOptionListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('addSelectOptionSuccess action should add a selectOption', () => { - const { initialState } = fromSelectOption; - const action = selectOptionActions.addSelectOptionSuccess({ selectOption: SELECT_OPTION }); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(1); - expect(state.ids).toContain(1); - expect(Object.keys(state.entities).length).toEqual(1); - expect(state.selectOptionListIsLoading).toEqual(false); - expect(state.selectOptionListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('editSelectOptionSuccess action should modify a selectOption', () => { - const initialState = { - ...fromSelectOption.initialState, - ids: [1], - entities: { 1: { ...SELECT_OPTION, label: 'label' }} - }; - const action = selectOptionActions.editSelectOptionSuccess({ selectOption: SELECT_OPTION }); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(1); - expect(state.ids).toContain(1); - expect(Object.keys(state.entities).length).toEqual(1); - expect(state.entities[1]).toEqual(SELECT_OPTION); - expect(state.selectOptionListIsLoading).toEqual(false); - expect(state.selectOptionListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('deleteSelectOptionSuccess action should modify a selectOption', () => { - const initialState = { - ...fromSelectOption.initialState, - ids: [1], - entities: { 1: SELECT_OPTION } - }; - const action = selectOptionActions.deleteSelectOptionSuccess({ selectOption: SELECT_OPTION }); - const state = fromSelectOption.selectOptionReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual( { }); - expect(state.selectOptionListIsLoading).toEqual(false); - expect(state.selectOptionListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('should get selectOptionListIsLoading', () => { - const action = {} as Action; - const state = fromSelectOption.selectOptionReducer(undefined, action); - - expect(fromSelectOption.selectSelectOptionListIsLoading(state)).toEqual(false); - }); - - it('should get selectOptionListIsLoaded', () => { - const action = {} as Action; - const state = fromSelectOption.selectOptionReducer(undefined, action); - - expect(fromSelectOption.selectSelectOptionListIsLoaded(state)).toEqual(false); - }); -}); diff --git a/client/src/app/metamodel/reducers/select-option.reducer.ts b/client/src/app/metamodel/reducers/select-option.reducer.ts deleted file mode 100644 index f6468561d435d3f003482acd019e685171be1f65..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/reducers/select-option.reducer.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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 { createReducer, on } from '@ngrx/store'; -import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'; - -import { SelectOption } from '../models'; -import * as selectOptionActions from '../actions/select-option.actions'; - -/** - * Interface for select option state. - * - * @interface State - */ -export interface State extends EntityState<SelectOption> { - selectOptionListIsLoading: boolean; - selectOptionListIsLoaded: boolean; -} - -export const adapter: EntityAdapter<SelectOption> = createEntityAdapter<SelectOption>({ - selectId: (selectOption: SelectOption) => selectOption.id, - sortComparer: (a: SelectOption, b: SelectOption) => a.display - b.display -}); - -export const initialState: State = adapter.getInitialState({ - selectOptionListIsLoading: false, - selectOptionListIsLoaded: false -}); - -export const selectOptionReducer = createReducer( - initialState, - on(selectOptionActions.loadSelectOptionList, (state) => { - return { - ...state, - selectOptionListIsLoading: true - } - }), - on(selectOptionActions.loadSelectOptionListSuccess, (state, { selectOptions }) => { - return adapter.setAll( - selectOptions, - { - ...state, - selectOptionListIsLoading: false, - selectOptionListIsLoaded: true - } - ); - }), - on(selectOptionActions.loadSelectOptionListFail, (state) => { - return { - ...state, - selectOptionListIsLoading: false - } - }), - on(selectOptionActions.addSelectOptionSuccess, (state, { selectOption }) => { - return adapter.addOne(selectOption, state) - }), - on(selectOptionActions.editSelectOptionSuccess, (state, { selectOption }) => { - return adapter.setOne(selectOption, state) - }), - on(selectOptionActions.deleteSelectOptionSuccess, (state, { selectOption }) => { - return adapter.removeOne(selectOption.id, state) - }) -); - -const { - selectIds, - selectEntities, - selectAll, - selectTotal, -} = adapter.getSelectors(); - -export const selectSelectOptionIds = selectIds; -export const selectSelectOptionEntities = selectEntities; -export const selectAllSelectOptions = selectAll; -export const selectSelectOptionTotal = selectTotal; - -export const selectSelectOptionListIsLoading = (state: State) => state.selectOptionListIsLoading; -export const selectSelectOptionListIsLoaded = (state: State) => state.selectOptionListIsLoaded; diff --git a/client/src/app/metamodel/reducers/select.reducer.spec.ts b/client/src/app/metamodel/reducers/select.reducer.spec.ts deleted file mode 100644 index 2e21a6f55ffd4e830d4a118dd2ec666340400457..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/reducers/select.reducer.spec.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { Action } from '@ngrx/store'; - -import * as fromSelect from './select.reducer'; -import * as selectActions from '../actions/select.actions'; -import { SELECT, SELECT_LIST } from '../../../test-data'; - -describe('[Metamodel][Reducers] Select reducer', () => { - it('unknown action should return the default state', () => { - const { initialState } = fromSelect; - const action = { type: 'Unknown' }; - const state = fromSelect.selectReducer(initialState, action); - expect(state).toBe(initialState); - }); - - it('loadSelectList action should set selectListIsLoading to true', () => { - const { initialState } = fromSelect; - const action = selectActions.loadSelectList(); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual({ }); - expect(state.selectListIsLoading).toEqual(true); - expect(state.selectListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('loadSelectListSuccess action should add select list, set selectListIsLoading to false and set selectListIsLoaded to true', () => { - const { initialState } = fromSelect; - const action = selectActions.loadSelectListSuccess({ selects: SELECT_LIST }); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(2); - expect(state.ids).toContain('select-one'); - expect(state.ids).toContain('select-two'); - expect(Object.keys(state.entities).length).toEqual(2); - expect(state.selectListIsLoading).toEqual(false); - expect(state.selectListIsLoaded).toEqual(true); - expect(state).not.toBe(initialState); - }); - - it('loadSelectListFail action should set selectListIsLoading to false', () => { - const { initialState } = fromSelect; - const action = selectActions.loadSelectListFail(); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual({ }); - expect(state.selectListIsLoading).toEqual(false); - expect(state.selectListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('addSelectSuccess action should add a select', () => { - const { initialState } = fromSelect; - const action = selectActions.addSelectSuccess({ select: SELECT }); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(1); - expect(state.ids).toContain('mySelect'); - expect(Object.keys(state.entities).length).toEqual(1); - expect(state.selectListIsLoading).toEqual(false); - expect(state.selectListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('editSelectSuccess action should modify a select', () => { - const initialState = { - ...fromSelect.initialState, - ids: ['mySelect'], - entities: { 'mySelect': { ...SELECT, label: 'label' }} - }; - const action = selectActions.editSelectSuccess({ select: SELECT }); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(1); - expect(state.ids).toContain('mySelect'); - expect(Object.keys(state.entities).length).toEqual(1); - expect(state.entities['mySelect']).toEqual(SELECT); - expect(state.selectListIsLoading).toEqual(false); - expect(state.selectListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('deleteSelectSuccess action should modify a select', () => { - const initialState = { - ...fromSelect.initialState, - ids: ['mySelect'], - entities: { 'mySelect': SELECT } - }; - const action = selectActions.deleteSelectSuccess({ select: SELECT }); - const state = fromSelect.selectReducer(initialState, action); - expect(state.ids.length).toEqual(0); - expect(state.entities).toEqual( { }); - expect(state.selectListIsLoading).toEqual(false); - expect(state.selectListIsLoaded).toEqual(false); - expect(state).not.toBe(initialState); - }); - - it('should get selectListIsLoading', () => { - const action = {} as Action; - const state = fromSelect.selectReducer(undefined, action); - - expect(fromSelect.selectSelectListIsLoading(state)).toEqual(false); - }); - - it('should get selectListIsLoaded', () => { - const action = {} as Action; - const state = fromSelect.selectReducer(undefined, action); - - expect(fromSelect.selectSelectListIsLoaded(state)).toEqual(false); - }); -}); diff --git a/client/src/app/metamodel/reducers/select.reducer.ts b/client/src/app/metamodel/reducers/select.reducer.ts deleted file mode 100644 index 942f69e83a343c42f3d9bd1538f88921e447db47..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/reducers/select.reducer.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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 { createReducer, on } from '@ngrx/store'; -import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'; - -import { Select } from '../models'; -import * as selectActions from '../actions/select.actions'; - -/** - * Interface for select state. - * - * @interface State - */ -export interface State extends EntityState<Select> { - selectListIsLoading: boolean; - selectListIsLoaded: boolean; -} - -export const adapter: EntityAdapter<Select> = createEntityAdapter<Select>({ - selectId: (select: Select) => select.name, - sortComparer: (a: Select, b: Select) => a.name.localeCompare(b.name) -}); - -export const initialState: State = adapter.getInitialState({ - selectListIsLoading: false, - selectListIsLoaded: false -}); - -export const selectReducer = createReducer( - initialState, - on(selectActions.loadSelectList, (state) => { - return { - ...state, - selectListIsLoading: true - } - }), - on(selectActions.loadSelectListSuccess, (state, { selects }) => { - return adapter.setAll( - selects, - { - ...state, - selectListIsLoading: false, - selectListIsLoaded: true - } - ); - }), - on(selectActions.loadSelectListFail, (state) => { - return { - ...state, - selectListIsLoading: false - } - }), - on(selectActions.addSelectSuccess, (state, { select }) => { - return adapter.addOne(select, state) - }), - on(selectActions.editSelectSuccess, (state, { select }) => { - return adapter.setOne(select, state) - }), - on(selectActions.deleteSelectSuccess, (state, { select }) => { - return adapter.removeOne(select.name, state) - }) -); - -const { - selectIds, - selectEntities, - selectAll, - selectTotal, -} = adapter.getSelectors(); - -export const selectSelectIds = selectIds; -export const selectSelectEntities = selectEntities; -export const selectAllSelects = selectAll; -export const selectSelectTotal = selectTotal; - -export const selectSelectListIsLoading = (state: State) => state.selectListIsLoading; -export const selectSelectListIsLoaded = (state: State) => state.selectListIsLoaded; diff --git a/client/src/app/metamodel/selectors/select-option.selector.spec.ts b/client/src/app/metamodel/selectors/select-option.selector.spec.ts deleted file mode 100644 index e9933201627e0a6d2d3e918d5e99e68b1f6f1142..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/selectors/select-option.selector.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import * as selectOptionSelector from './select-option.selector'; -import * as fromSelectOption from '../reducers/select-option.reducer'; -import { SELECT_OPTION } from '../../../test-data'; - -describe('[Metamodel][Selector] Select option selector', () => { - it('should get selectOption state', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionState(state)).toEqual(state.metamodel.selectOption); - }); - - it('should get selectOption IDs', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionIds(state).length).toEqual(0); - }); - - it('should get selectOption entities', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionEntities(state)).toEqual({ }); - }); - - it('should get all selectOption', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectAllSelectOptions(state).length).toEqual(0); - }); - - it('should get selectOption count', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionTotal(state)).toEqual(0); - }); - - it('should get selectOptionListIsLoading', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionListIsLoading(state)).toBe(false); - }); - - it('should get selectOptionListIsLoaded', () => { - const state = { metamodel: { selectOption: { ...fromSelectOption.initialState }}}; - expect(selectOptionSelector.selectSelectOptionListIsLoaded(state)).toBe(false); - }); - - it('should get select option by select name', () => { - const state = { - router: { state: { params: { select: 'name_one' }}}, - metamodel: { - selectOption: { - ...fromSelectOption.initialState, - ids: [1], - entities: { 1: SELECT_OPTION } - } - } - }; - expect(selectOptionSelector.getOptionBySelectName(state)).toEqual([SELECT_OPTION]); - }); -}); diff --git a/client/src/app/metamodel/selectors/select-option.selector.ts b/client/src/app/metamodel/selectors/select-option.selector.ts deleted file mode 100644 index 9282bfeb1d2709c93447376a471459068a996480..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/selectors/select-option.selector.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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 { createSelector } from '@ngrx/store'; - -import * as reducer from '../metamodel.reducer'; -import * as fromSelectOption from '../reducers/select-option.reducer'; - -export const selectSelectOptionState = createSelector( - reducer.getMetamodelState, - (state: reducer.State) => state.selectOption -); - -export const selectSelectOptionIds = createSelector( - selectSelectOptionState, - fromSelectOption.selectSelectOptionIds -); - -export const selectSelectOptionEntities = createSelector( - selectSelectOptionState, - fromSelectOption.selectSelectOptionEntities -); - -export const selectAllSelectOptions = createSelector( - selectSelectOptionState, - fromSelectOption.selectAllSelectOptions -); - -export const selectSelectOptionTotal = createSelector( - selectSelectOptionState, - fromSelectOption.selectSelectOptionTotal -); - -export const selectSelectOptionListIsLoading = createSelector( - selectSelectOptionState, - fromSelectOption.selectSelectOptionListIsLoading -); - -export const selectSelectOptionListIsLoaded = createSelector( - selectSelectOptionState, - fromSelectOption.selectSelectOptionListIsLoaded -); - -export const getOptionBySelectName = createSelector( - selectAllSelectOptions, - reducer.selectRouterState, - (optionList, router) => optionList.filter(option => option.select_name === router.state.params.select) -) diff --git a/client/src/app/metamodel/selectors/select.selector.spec.ts b/client/src/app/metamodel/selectors/select.selector.spec.ts deleted file mode 100644 index 227e38e6f8475fa96b6319b7defea9309d896b1c..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/selectors/select.selector.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import * as selectSelector from './select.selector'; -import * as fromSelect from '../reducers/select.reducer'; -import { SELECT } from '../../../test-data'; - -describe('[Metamodel][Selector] Select selector', () => { - it('should get select state', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectState(state)).toEqual(state.metamodel.select); - }); - - it('should get select IDs', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectIds(state).length).toEqual(0); - }); - - it('should get select entities', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectEntities(state)).toEqual({ }); - }); - - it('should get all selects', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectAllSelects(state).length).toEqual(0); - }); - - it('should get select count', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectTotal(state)).toEqual(0); - }); - - it('should get selectListIsLoading', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectListIsLoading(state)).toBe(false); - }); - - it('should get selectListIsLoaded', () => { - const state = { metamodel: { select: { ...fromSelect.initialState }}}; - expect(selectSelector.selectSelectListIsLoaded(state)).toBe(false); - }); - - it('should get select by route', () => { - const state = { - router: { state: { params: { select: 'mySelect' }}}, - metamodel: { - select: { - ...fromSelect.initialState, - ids: ['mySelect'], - entities: { 'mySelect': SELECT } - } - } - }; - expect(selectSelector.getSelectByRouteName(state)).toEqual(SELECT); - }); -}); diff --git a/client/src/app/metamodel/selectors/select.selector.ts b/client/src/app/metamodel/selectors/select.selector.ts deleted file mode 100644 index c60a9923cd2453bafa574e1bc7ad4d0b1813549c..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/selectors/select.selector.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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 { createSelector } from '@ngrx/store'; - -import * as reducer from '../metamodel.reducer'; -import * as fromSelect from '../reducers/select.reducer'; - -export const selectSelectState = createSelector( - reducer.getMetamodelState, - (state: reducer.State) => state.select -); - -export const selectSelectIds = createSelector( - selectSelectState, - fromSelect.selectSelectIds -); - -export const selectSelectEntities = createSelector( - selectSelectState, - fromSelect.selectSelectEntities -); - -export const selectAllSelects = createSelector( - selectSelectState, - fromSelect.selectAllSelects -); - -export const selectSelectTotal = createSelector( - selectSelectState, - fromSelect.selectSelectTotal -); - -export const selectSelectListIsLoading = createSelector( - selectSelectState, - fromSelect.selectSelectListIsLoading -); - -export const selectSelectListIsLoaded = createSelector( - selectSelectState, - fromSelect.selectSelectListIsLoaded -); - -export const getSelectByRouteName = createSelector( - selectSelectEntities, - reducer.selectRouterState, - (entities, router) => entities[router.state.params.select] -); diff --git a/client/src/app/metamodel/services/index.ts b/client/src/app/metamodel/services/index.ts index 09bc41998f8e4b0fc94a201eaba90073e0402587..c24336c01c0642c22818a75ee76c8be5670a9f0e 100644 --- a/client/src/app/metamodel/services/index.ts +++ b/client/src/app/metamodel/services/index.ts @@ -17,8 +17,6 @@ import { AttributeService } from './attribute.service'; import { CriteriaFamilyService } from './criteria-family.service'; import { OutputCategoryService } from './output-category.service'; import { OutputFamilyService } from './output-family.service'; -import { SelectService } from './select.service'; -import { SelectOptionService } from './select-option.service'; import { ImageService } from './image.service'; import { FileService } from './file.service'; import { ConeSearchConfigService } from './cone-search-config.service'; @@ -34,8 +32,6 @@ export const metamodelServices = [ CriteriaFamilyService, OutputCategoryService, OutputFamilyService, - SelectService, - SelectOptionService, ImageService, FileService, ConeSearchConfigService diff --git a/client/src/app/metamodel/services/select-option.service.spec.ts b/client/src/app/metamodel/services/select-option.service.spec.ts deleted file mode 100644 index e079e3b0583462fb612e2917cca884937bd8df07..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/services/select-option.service.spec.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; - -import { SelectOptionService } from './select-option.service'; -import { AppConfigService } from 'src/app/app-config.service'; -import { SelectOption } from '../models'; -import { SELECT_OPTION } from '../../../test-data'; - -describe('[Instance][Metamodel][Services] SelectOptionService', () => { - let service: SelectOptionService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], - providers: [ - { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, - SelectOptionService - ] - }); - service = TestBed.inject(SelectOptionService); - }); - - it('#retrieveSelectOptionList() should return an Observable<SelectOption[]>', - inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { - const mockResponse = []; - - service.retrieveSelectOptionList().subscribe((event: SelectOption[]) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/option'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('GET'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#addSelectOption() should return an Observable<SelectOption>', - inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { - const mockResponse = SELECT_OPTION; - - service.addSelectOption(SELECT_OPTION).subscribe((event: SelectOption) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/option'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('POST'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#editSelectOption() should return an Observable<SelectOption>', - inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { - const mockResponse = SELECT_OPTION; - - service.editSelectOption(SELECT_OPTION).subscribe((event: SelectOption) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/option/1'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('PUT'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#deleteSelectOption() should return an Observable<object>', - inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { - const mockResponse = {}; - - service.deleteSelectOption(1).subscribe((event: object) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/option/1'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('DELETE'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); -}); diff --git a/client/src/app/metamodel/services/select-option.service.ts b/client/src/app/metamodel/services/select-option.service.ts deleted file mode 100644 index 904a627fff4c326583cb1aa7cc3356ec211999a0..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/services/select-option.service.ts +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; - -import { Observable } from 'rxjs'; - -import { SelectOption } from '../models'; -import { AppConfigService } from 'src/app/app-config.service'; - -/** - * @class - * @classdesc Select option service. - */ -@Injectable() -export class SelectOptionService { - constructor(private http: HttpClient, private config: AppConfigService) { } - - /** - * Retrieves select option list. - * - * @return Observable<SelectOption[]> - */ - retrieveSelectOptionList(): Observable<SelectOption[]> { - return this.http.get<SelectOption[]>(`${this.config.apiUrl}/option`); - } - - /** - * Adds a new select option. - * - * @param {SelectOption} settingsSelectOption - The select option. - * - * @return Observable<SelectOption> - */ - addSelectOption(settingsSelectOption: SelectOption): Observable<SelectOption> { - return this.http.post<SelectOption>(`${this.config.apiUrl}/option`, settingsSelectOption); - } - - /** - * Modifies a new select option. - * - * @param {SelectOption} settingsSelectOption - The select option. - * - * @return Observable<SelectOption> - */ - editSelectOption(settingsSelectOption: SelectOption): Observable<SelectOption> { - return this.http.put<SelectOption>(`${this.config.apiUrl}/option/${settingsSelectOption.id}`, settingsSelectOption); - } - - /** - * Removes a select option. - * - * @param {number} id - The select option ID. - */ - deleteSelectOption(id: number): Observable<object> { - return this.http.delete(`${this.config.apiUrl}/option/${id}`); - } -} diff --git a/client/src/app/metamodel/services/select.service.spec.ts b/client/src/app/metamodel/services/select.service.spec.ts deleted file mode 100644 index ab449586c7eae1da626aedcd58503db57c4997b5..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/services/select.service.spec.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; - -import { SelectService } from './select.service'; -import { AppConfigService } from 'src/app/app-config.service'; -import { Select } from '../models'; -import { SELECT } from '../../../test-data'; - -describe('[Instance][Metamodel][Services] SelectService', () => { - let service: SelectService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], - providers: [ - { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, - SelectService - ] - }); - service = TestBed.inject(SelectService); - }); - - it('#retrieveSelectList() should return an Observable<Select[]>', - inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { - const mockResponse = []; - - service.retrieveSelectList().subscribe((event: Select[]) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/select'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('GET'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#addSelect() should return an Observable<Select>', - inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { - const mockResponse = SELECT; - - service.addSelect(SELECT).subscribe((event: Select) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/select'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('POST'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#editSelect() should return an Observable<Select>', - inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { - const mockResponse = SELECT; - - service.editSelect(SELECT).subscribe((event: Select) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/select/mySelect'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('PUT'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); - - it('#deleteSelect() should return an Observable<object>', - inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { - const mockResponse = {}; - - service.deleteSelect('mySelect').subscribe((event: object) => { - expect(event).toEqual(mockResponse); - }); - - const mockRequest = httpMock.expectOne('http://testing.com/select/mySelect'); - - expect(mockRequest.cancelled).toBeFalsy(); - expect(mockRequest.request.method).toEqual('DELETE'); - expect(mockRequest.request.responseType).toEqual('json'); - mockRequest.flush(mockResponse); - - httpMock.verify(); - } - ) - ); -}); diff --git a/client/src/app/metamodel/services/select.service.ts b/client/src/app/metamodel/services/select.service.ts deleted file mode 100644 index 337ed1b2bd66f581ed85987f11b373c09cf0a641..0000000000000000000000000000000000000000 --- a/client/src/app/metamodel/services/select.service.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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 { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; - -import { Observable } from 'rxjs'; - -import { Select } from '../models'; -import { AppConfigService } from 'src/app/app-config.service'; - -/** - * @class - * @classdesc Select service. - */ -@Injectable() -export class SelectService { - constructor(private http: HttpClient, private config: AppConfigService) { } - - /** - * Retrieves select list. - * - * @return Observable<Select[]> - */ - retrieveSelectList(): Observable<Select[]> { - return this.http.get<Select[]>(`${this.config.apiUrl}/select`); - } - - /** - * Adds a new select. - * - * @param {Select} select - The select. - * - * @return Observable<Select> - */ - addSelect(select: Select): Observable<Select> { - return this.http.post<Select>(`${this.config.apiUrl}/select`, select); - } - - /** - * Modifies a select. - * - * @param {Select} select - The select. - * - * @return Observable<Select> - */ - editSelect(select: Select): Observable<Select> { - return this.http.put<Select>(`${this.config.apiUrl}/select/${select.name}`, select); - } - - /** - * Removes a select. - * - * @param {string} name - The select name. - * - * @return Observable<object> - */ - deleteSelect(name: string): Observable<object> { - return this.http.delete(`${this.config.apiUrl}/select/${name}`); - } -} diff --git a/client/src/app/shared/pipes/index.ts b/client/src/app/shared/pipes/index.ts index 5be7de758f5cdea1ebbe9999b26a615b70fb5211..6f5205846b9ae9917c7d1b1ec71919e4d4b5290d 100644 --- a/client/src/app/shared/pipes/index.ts +++ b/client/src/app/shared/pipes/index.ts @@ -9,7 +9,6 @@ import { DatasetListByFamilyPipe } from './dataset-list-by-family.pipe'; import { AttributeListByFamilyPipe } from './attribute-list-by-family.pipe'; -import { OptionListBySelectPipe } from './option-list-by-select.pipe'; import { OutputFamilyByIdPipe } from './output-family-by-id.pipe'; import { DatasetByNamePipe } from './dataset-by-name.pipe'; import { InstanceByNamePipe } from './instance-by-name.pipe'; @@ -18,7 +17,6 @@ import { AuthImagePipe } from './auth-image.pipe'; export const sharedPipes = [ DatasetListByFamilyPipe, AttributeListByFamilyPipe, - OptionListBySelectPipe, OutputFamilyByIdPipe, DatasetByNamePipe, InstanceByNamePipe, diff --git a/client/src/app/shared/pipes/option-list-by-select.pipe.spec.ts b/client/src/app/shared/pipes/option-list-by-select.pipe.spec.ts deleted file mode 100644 index 8b83383e895b31068c82fed7aa7b4bdd0c0868f3..0000000000000000000000000000000000000000 --- a/client/src/app/shared/pipes/option-list-by-select.pipe.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { OptionListBySelectPipe } from './option-list-by-select.pipe'; -import { SELECT_OPTION_LIST } from '../../../test-data'; - -describe('[Shared][Pipes] OptionListBySelect', () => { - let pipe = new OptionListBySelectPipe(); - - it('should return options corresponding to the given select name', () => { - expect(pipe.transform(SELECT_OPTION_LIST, 'name_one')).toContain(SELECT_OPTION_LIST[1]); - expect(pipe.transform(SELECT_OPTION_LIST, 'name_one').length).toEqual(1); - }); -}); diff --git a/client/src/app/shared/pipes/option-list-by-select.pipe.ts b/client/src/app/shared/pipes/option-list-by-select.pipe.ts deleted file mode 100644 index 7805487d44d1e498cace2c7b13373565d7253e88..0000000000000000000000000000000000000000 --- a/client/src/app/shared/pipes/option-list-by-select.pipe.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * 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 { Pipe, PipeTransform } from '@angular/core'; - -import { SelectOption } from 'src/app/metamodel/models'; - -/** - * @class - * @classdesc Returns options corresponding to the given select name. - * - * @example - * // returns options that matching with the select name among the option list - * {{ optionList | optionListBySelect:'search_flag' }} - */ -@Pipe({ name: 'optionListBySelect' }) -export class OptionListBySelectPipe implements PipeTransform { - transform(optionList: SelectOption[], selectName: string): SelectOption[] { - return optionList.filter(option => option.select_name === selectName); - } -} diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh index b5e4adbe1e41d4439b13ddf1d79aa1757e6563ec..905a1ca64357249e0bd607c11aea1f94cf6f7040 100644 --- a/conf-dev/create-db.sh +++ b/conf-dev/create-db.sh @@ -4,35 +4,6 @@ set -e # Create the settings database (only tables) ./vendor/bin/doctrine orm:schema-tool:create -# Add settings for anis-admin GUI -curl -d '{"name":"search_type","label":"Search Type"}' --header 'Content-Type: application/json' -X POST http://localhost/select -curl -d '{"name":"renderer","label":"Renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/select -curl -d '{"name":"renderer_detail","label":"Renderer detail"}' --header 'Content-Type: application/json' -X POST http://localhost/select - -curl -d '{"label":"Field","value":"field","display":10,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Between","value":"between","display":20,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Select","value":"select","display":30,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Select multiple","value":"select-multiple","display":40,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Datalist","value":"datalist","display":50,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"List","value":"list","display":60,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Radio","value":"radio","display":70,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Checkbox","value":"checkbox","display":80,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Between date","value":"between-date","display":90,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Date","value":"date","display":100,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Time","value":"time","display":110,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Date time","value":"date-time","display":120,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"JSON","value":"json","display":130,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"SVOM JSON KW","value":"svom_json_kw","display":140,"select_name":"search_type"}' --header 'Content-Type: application/json' -X POST http://localhost/option - -curl -d '{"label":"Link detail page","value":"detail-link","display":10,"select_name":"renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Download file","value":"download","display":20,"select_name":"renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Link (file, web page...)","value":"link","display":30,"select_name":"renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Display image (png, jpg...)","value":"image","display":40,"select_name":"renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Display json","value":"json","display":50,"select_name":"renderer"}' --header 'Content-Type: application/json' -X POST http://localhost/option - -curl -d '{"label":"Image","value":"img","display":10,"select_name":"renderer_detail"}' --header 'Content-Type: application/json' -X POST http://localhost/option -curl -d '{"label":"Spectra graph","value":"spectra_graph","display":20,"select_name":"renderer_detail"}' --header 'Content-Type: application/json' -X POST http://localhost/option - # Add anis_test database curl -d '{"label":"Test","dbname":"anis_test","dbtype":"pdo_pgsql","dbhost":"db","dbport":5432,"dblogin":"anis","dbpassword":"anis"}' --header 'Content-Type: application/json' -X POST http://localhost/database diff --git a/server/app/dependencies.php b/server/app/dependencies.php index 2ae9343cd21f981912d86842963e3b064278d3ee..994388f37e4bc123ab59b62f8994d076a30dc551 100644 --- a/server/app/dependencies.php +++ b/server/app/dependencies.php @@ -77,22 +77,6 @@ $container->set('App\Action\ClientSettingsAction', function (ContainerInterface return new App\Action\ClientSettingsAction($c->get(SETTINGS)); }); -$container->set('App\Action\SelectListAction', function (ContainerInterface $c) { - return new App\Action\SelectListAction($c->get('em')); -}); - -$container->set('App\Action\SelectAction', function (ContainerInterface $c) { - return new App\Action\SelectAction($c->get('em')); -}); - -$container->set('App\Action\OptionListAction', function (ContainerInterface $c) { - return new App\Action\OptionListAction($c->get('em')); -}); - -$container->set('App\Action\OptionAction', function (ContainerInterface $c) { - return new App\Action\OptionAction($c->get('em')); -}); - $container->set('App\Action\DatabaseListAction', function (ContainerInterface $c) { return new App\Action\DatabaseListAction($c->get('em')); }); diff --git a/server/doctrine-proxy/__CG__AppEntityOption.php b/server/doctrine-proxy/__CG__AppEntityOption.php deleted file mode 100644 index f101582d195f2863b3aeefd1c9ee2c28e664ad4b..0000000000000000000000000000000000000000 --- a/server/doctrine-proxy/__CG__AppEntityOption.php +++ /dev/null @@ -1,283 +0,0 @@ -<?php - -namespace DoctrineProxies\__CG__\App\Entity; - - -/** - * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR - */ -class Option extends \App\Entity\Option implements \Doctrine\ORM\Proxy\Proxy -{ - /** - * @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with - * three parameters, being respectively the proxy object to be initialized, the method that triggered the - * initialization process and an array of ordered parameters that were passed to that method. - * - * @see \Doctrine\Common\Proxy\Proxy::__setInitializer - */ - public $__initializer__; - - /** - * @var \Closure the callback responsible of loading properties that need to be copied in the cloned object - * - * @see \Doctrine\Common\Proxy\Proxy::__setCloner - */ - public $__cloner__; - - /** - * @var boolean flag indicating if this object was already initialized - * - * @see \Doctrine\Persistence\Proxy::__isInitialized - */ - public $__isInitialized__ = false; - - /** - * @var array<string, null> properties to be lazy loaded, indexed by property name - */ - public static $lazyPropertiesNames = array ( -); - - /** - * @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names - * - * @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties - */ - public static $lazyPropertiesDefaults = array ( -); - - - - public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null) - { - - $this->__initializer__ = $initializer; - $this->__cloner__ = $cloner; - } - - - - - - - - /** - * - * @return array - */ - public function __sleep() - { - if ($this->__isInitialized__) { - return ['__isInitialized__', 'id', 'label', 'value', 'display', 'select']; - } - - return ['__isInitialized__', 'id', 'label', 'value', 'display', 'select']; - } - - /** - * - */ - public function __wakeup() - { - if ( ! $this->__isInitialized__) { - $this->__initializer__ = function (Option $proxy) { - $proxy->__setInitializer(null); - $proxy->__setCloner(null); - - $existingProperties = get_object_vars($proxy); - - foreach ($proxy::$lazyPropertiesDefaults as $property => $defaultValue) { - if ( ! array_key_exists($property, $existingProperties)) { - $proxy->$property = $defaultValue; - } - } - }; - - } - } - - /** - * - */ - public function __clone() - { - $this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', []); - } - - /** - * Forces initialization of the proxy - */ - public function __load() - { - $this->__initializer__ && $this->__initializer__->__invoke($this, '__load', []); - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __isInitialized() - { - return $this->__isInitialized__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setInitialized($initialized) - { - $this->__isInitialized__ = $initialized; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setInitializer(\Closure $initializer = null) - { - $this->__initializer__ = $initializer; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __getInitializer() - { - return $this->__initializer__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setCloner(\Closure $cloner = null) - { - $this->__cloner__ = $cloner; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific cloning logic - */ - public function __getCloner() - { - return $this->__cloner__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - * @deprecated no longer in use - generated code now relies on internal components rather than generated public API - * @static - */ - public function __getLazyProperties() - { - return self::$lazyPropertiesDefaults; - } - - - /** - * {@inheritDoc} - */ - public function getId() - { - if ($this->__isInitialized__ === false) { - return (int) parent::getId(); - } - - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []); - - return parent::getId(); - } - - /** - * {@inheritDoc} - */ - public function getLabel(): string - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLabel', []); - - return parent::getLabel(); - } - - /** - * {@inheritDoc} - */ - public function setLabel(string $label): void - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLabel', [$label]); - - parent::setLabel($label); - } - - /** - * {@inheritDoc} - */ - public function getValue(): string - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getValue', []); - - return parent::getValue(); - } - - /** - * {@inheritDoc} - */ - public function setValue(string $value): void - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'setValue', [$value]); - - parent::setValue($value); - } - - /** - * {@inheritDoc} - */ - public function getDisplay(): int - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDisplay', []); - - return parent::getDisplay(); - } - - /** - * {@inheritDoc} - */ - public function setDisplay(int $display): void - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'setDisplay', [$display]); - - parent::setDisplay($display); - } - - /** - * {@inheritDoc} - */ - public function getSelect(): \App\Entity\Select - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSelect', []); - - return parent::getSelect(); - } - - /** - * {@inheritDoc} - */ - public function jsonSerialize(): array - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'jsonSerialize', []); - - return parent::jsonSerialize(); - } - -} diff --git a/server/doctrine-proxy/__CG__AppEntitySelect.php b/server/doctrine-proxy/__CG__AppEntitySelect.php deleted file mode 100644 index 00df23065298acf482a35cc3a1685f7eb5badc2c..0000000000000000000000000000000000000000 --- a/server/doctrine-proxy/__CG__AppEntitySelect.php +++ /dev/null @@ -1,228 +0,0 @@ -<?php - -namespace DoctrineProxies\__CG__\App\Entity; - - -/** - * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR - */ -class Select extends \App\Entity\Select implements \Doctrine\ORM\Proxy\Proxy -{ - /** - * @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with - * three parameters, being respectively the proxy object to be initialized, the method that triggered the - * initialization process and an array of ordered parameters that were passed to that method. - * - * @see \Doctrine\Common\Proxy\Proxy::__setInitializer - */ - public $__initializer__; - - /** - * @var \Closure the callback responsible of loading properties that need to be copied in the cloned object - * - * @see \Doctrine\Common\Proxy\Proxy::__setCloner - */ - public $__cloner__; - - /** - * @var boolean flag indicating if this object was already initialized - * - * @see \Doctrine\Persistence\Proxy::__isInitialized - */ - public $__isInitialized__ = false; - - /** - * @var array<string, null> properties to be lazy loaded, indexed by property name - */ - public static $lazyPropertiesNames = array ( -); - - /** - * @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names - * - * @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties - */ - public static $lazyPropertiesDefaults = array ( -); - - - - public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null) - { - - $this->__initializer__ = $initializer; - $this->__cloner__ = $cloner; - } - - - - - - - - /** - * - * @return array - */ - public function __sleep() - { - if ($this->__isInitialized__) { - return ['__isInitialized__', 'name', 'label', 'options']; - } - - return ['__isInitialized__', 'name', 'label', 'options']; - } - - /** - * - */ - public function __wakeup() - { - if ( ! $this->__isInitialized__) { - $this->__initializer__ = function (Select $proxy) { - $proxy->__setInitializer(null); - $proxy->__setCloner(null); - - $existingProperties = get_object_vars($proxy); - - foreach ($proxy::$lazyPropertiesDefaults as $property => $defaultValue) { - if ( ! array_key_exists($property, $existingProperties)) { - $proxy->$property = $defaultValue; - } - } - }; - - } - } - - /** - * - */ - public function __clone() - { - $this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', []); - } - - /** - * Forces initialization of the proxy - */ - public function __load() - { - $this->__initializer__ && $this->__initializer__->__invoke($this, '__load', []); - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __isInitialized() - { - return $this->__isInitialized__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setInitialized($initialized) - { - $this->__isInitialized__ = $initialized; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setInitializer(\Closure $initializer = null) - { - $this->__initializer__ = $initializer; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __getInitializer() - { - return $this->__initializer__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - */ - public function __setCloner(\Closure $cloner = null) - { - $this->__cloner__ = $cloner; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific cloning logic - */ - public function __getCloner() - { - return $this->__cloner__; - } - - /** - * {@inheritDoc} - * @internal generated method: use only when explicitly handling proxy specific loading logic - * @deprecated no longer in use - generated code now relies on internal components rather than generated public API - * @static - */ - public function __getLazyProperties() - { - return self::$lazyPropertiesDefaults; - } - - - /** - * {@inheritDoc} - */ - public function getName(): string - { - if ($this->__isInitialized__ === false) { - return parent::getName(); - } - - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getName', []); - - return parent::getName(); - } - - /** - * {@inheritDoc} - */ - public function getLabel(): string - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLabel', []); - - return parent::getLabel(); - } - - /** - * {@inheritDoc} - */ - public function setLabel(string $label): void - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLabel', [$label]); - - parent::setLabel($label); - } - - /** - * {@inheritDoc} - */ - public function jsonSerialize(): array - { - - $this->__initializer__ && $this->__initializer__->__invoke($this, 'jsonSerialize', []); - - return parent::jsonSerialize(); - } - -} diff --git a/server/src/Action/OptionAction.php b/server/src/Action/OptionAction.php deleted file mode 100644 index 06a9b37b5446489863e644355f93158e90ad11d9..0000000000000000000000000000000000000000 --- a/server/src/Action/OptionAction.php +++ /dev/null @@ -1,103 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Action; - -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; -use Slim\Exception\HttpNotFoundException; -use Slim\Exception\HttpBadRequestException; -use App\Entity\Option; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Action - */ -final class OptionAction extends AbstractAction -{ - /** - * `GET` Returns one option by ID - * `PUT` Edit one option - * `DELETE` Delete one option - * - * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request - * @param ResponseInterface $response PSR-7 This object represents the HTTP response - * @param string[] $args This table contains information transmitted in the URL (see routes.php) - * - * @return ResponseInterface - */ - public function __invoke( - ServerRequestInterface $request, - ResponseInterface $response, - array $args - ): ResponseInterface { - if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS'); - } - - // Search the correct option with primary key (ID) - $option = $this->em->find('App\Entity\Option', $args['id']); - - // If option is not found 404 - if (is_null($option)) { - throw new HttpNotFoundException( - $request, - 'Option with id ' . $args['id'] . ' is not found' - ); - } - - if ($request->getMethod() === GET) { - $payload = json_encode($option); - } - - if ($request->getMethod() === PUT) { - $parsedBody = $request->getParsedBody(); - - // If mandatories empty fields 400 - foreach (array('label', 'value', 'display') as $a) { - if (!array_key_exists($a, $parsedBody)) { - throw new HttpBadRequestException( - $request, - 'Param ' . $a . ' needed to edit the option' - ); - } - } - - $this->editOption($option, $parsedBody); - $payload = json_encode($option); - } - - if ($request->getMethod() === DELETE) { - $id = $option->getId(); - $this->em->remove($option); - $this->em->flush(); - $payload = json_encode(array('message' => 'Option with id ' . $id . ' is removed!')); - } - - $response->getBody()->write($payload); - return $response; - } - - /** - * Update option object with setters - * - * @param Option $option The option object to update - * @param array $parsedBody Contains the new values ​​of the option sent by the user - */ - private function editOption(Option $option, array $parsedBody): void - { - $option->setLabel($parsedBody['label']); - $option->setValue($parsedBody['value']); - $option->setDisplay($parsedBody['display']); - $this->em->flush(); - } -} diff --git a/server/src/Action/OptionListAction.php b/server/src/Action/OptionListAction.php deleted file mode 100644 index fb5c1328aacb090c6ac3baf319e4f173fa0cdb56..0000000000000000000000000000000000000000 --- a/server/src/Action/OptionListAction.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Action; - -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; -use Slim\Exception\HttpNotFoundException; -use Slim\Exception\HttpBadRequestException; -use App\Entity\Select; -use App\Entity\Option; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Action - */ -final class OptionListAction extends AbstractAction -{ - /** - * `GET` Returns a list of all option available for one select - * `POST` Add a new option for a select - * - * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request - * @param ResponseInterface $response PSR-7 This object represents the HTTP response - * @param string[] $args This table contains information transmitted in the URL (see routes.php) - * - * @return ResponseInterface - */ - public function __invoke( - ServerRequestInterface $request, - ResponseInterface $response, - array $args - ): ResponseInterface { - if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); - } - - if ($request->getMethod() === GET) { - $optionList = $this->em->getRepository('App\Entity\Option')->findAll(); - $payload = json_encode($optionList); - } - - if ($request->getMethod() === POST) { - $parsedBody = $request->getParsedBody(); - - // To work this action needs user information to update - foreach (array('label', 'value', 'display', 'select_name') as $a) { - if (!array_key_exists($a, $parsedBody)) { - throw new HttpBadRequestException( - $request, - 'Param ' . $a . ' needed to add a new option' - ); - } - } - - // Search the correct select with primary key (name) - $selectName = $parsedBody['select_name']; - $select = $this->em->find('App\Entity\Select', $selectName); - - // If select is not found 404 - if (is_null($select)) { - throw new HttpNotFoundException( - $request, - 'Select with name ' . $selectName . ' is not found' - ); - } - - $option = $this->postOption($select, $parsedBody); - $payload = json_encode($option); - $response = $response->withStatus(201); - } - - $response->getBody()->write($payload); - return $response; - } - - /** - * @param Select $select Select on which the option is added - * @param array $parsedBody Contains the values ​​of the new option sent by the user - * - * @return Option - */ - private function postOption(Select $select, array $parsedBody): Option - { - $option = new Option($select); - $option->setLabel($parsedBody['label']); - $option->setValue($parsedBody['value']); - $option->setDisplay($parsedBody['display']); - - $this->em->persist($option); - $this->em->flush(); - - return $option; - } -} diff --git a/server/src/Action/SelectAction.php b/server/src/Action/SelectAction.php deleted file mode 100644 index 96f0f7b5e4a043cc0f0404d8ddee6e5ae352625c..0000000000000000000000000000000000000000 --- a/server/src/Action/SelectAction.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Action; - -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; -use Slim\Exception\HttpNotFoundException; -use Slim\Exception\HttpBadRequestException; -use App\Entity\Select; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Action - */ -final class SelectAction extends AbstractAction -{ - /** - * `GET` Returns one select by ID - * `PUT` Edit one select - * `DELETE` Delete one select - * - * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request - * @param ResponseInterface $response PSR-7 This object represents the HTTP response - * @param string[] $args This table contains information transmitted in the URL (see routes.php) - * - * @return ResponseInterface - */ - public function __invoke( - ServerRequestInterface $request, - ResponseInterface $response, - array $args - ): ResponseInterface { - if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS'); - } - - // Search the correct select with primary key (name) - $select = $this->em->find('App\Entity\Select', $args['name']); - - // If select is not found 404 - if (is_null($select)) { - throw new HttpNotFoundException( - $request, - 'Select with name ' . $args['name'] . ' is not found' - ); - } - - if ($request->getMethod() === GET) { - $payload = json_encode($select); - } - - if ($request->getMethod() === PUT) { - $parsedBody = $request->getParsedBody(); - - // If mandatories empty fields 400 - foreach (array('label') as $a) { - if (!array_key_exists($a, $parsedBody)) { - throw new HttpBadRequestException( - $request, - 'Param ' . $a . ' needed to edit the select' - ); - } - } - - $this->editSelect($select, $parsedBody); - $payload = json_encode($select); - } - - if ($request->getMethod() === DELETE) { - $name = $select->getName(); - $this->em->remove($select); - $this->em->flush(); - $payload = json_encode(array('message' => 'Select with name ' . $name . ' is removed!')); - } - - $response->getBody()->write($payload); - return $response; - } - - /** - * Update select object with setters - * - * @param Select $select The select object to update - * @param array $parsedBody Contains the new values ​​of the select sent by the user - */ - private function editSelect(Select $select, array $parsedBody): void - { - $select->setLabel($parsedBody['label']); - $this->em->flush(); - } -} diff --git a/server/src/Action/SelectListAction.php b/server/src/Action/SelectListAction.php deleted file mode 100644 index 40ff23ec7755b30090b29057d925c4f5b3480a6e..0000000000000000000000000000000000000000 --- a/server/src/Action/SelectListAction.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Action; - -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; -use Slim\Exception\HttpBadRequestException; -use App\Entity\Select; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Action - */ -final class SelectListAction extends AbstractAction -{ - /** - * `GET` Returns a list of all select listed in the metamodel database - * `POST` Add a new select - * - * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request - * @param ResponseInterface $response PSR-7 This object represents the HTTP response - * @param string[] $args This table contains information transmitted in the URL (see routes.php) - * - * @return ResponseInterface - */ - public function __invoke( - ServerRequestInterface $request, - ResponseInterface $response, - array $args - ): ResponseInterface { - if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); - } - - if ($request->getMethod() === GET) { - $selectList = $this->em->getRepository('App\Entity\Select')->findAll(); - $payload = json_encode($selectList); - } - - if ($request->getMethod() === POST) { - $parsedBody = $request->getParsedBody(); - - // To work this action needs user information to update - foreach (array('name', 'label') as $a) { - if (!array_key_exists($a, $parsedBody)) { - throw new HttpBadRequestException( - $request, - 'Param ' . $a . ' needed to add a new select' - ); - } - } - - $select = $this->postSelect($parsedBody); - $payload = json_encode($select); - $response = $response->withStatus(201); - } - - $response->getBody()->write($payload); - return $response; - } - - /** - * Add a new select into the settings database - * - * @param array $parsedBody Contains the values ​​of the new select - */ - private function postSelect(array $parsedBody): Select - { - $select = new Select($parsedBody['name']); - $select->setLabel($parsedBody['label']); - - $this->em->persist($select); - $this->em->flush(); - - return $select; - } -} diff --git a/server/src/Entity/Option.php b/server/src/Entity/Option.php deleted file mode 100644 index 3f979ab29b6de0254f4bbf855b905e853320dd98..0000000000000000000000000000000000000000 --- a/server/src/Entity/Option.php +++ /dev/null @@ -1,117 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Entity; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Entity - * - * @Entity - * @Table(name="settings_option") - */ -class Option implements \JsonSerializable -{ - /** - * @var integer - * - * @Id - * @Column(type="integer", nullable=false) - * @GeneratedValue - */ - protected $id; - - /** - * @var string - * - * @Column(type="string", nullable=false) - */ - protected $label; - - /** - * @var string - * - * @Column(type="string", nullable=false) - */ - protected $value; - - /** - * @var integer - * - * @Column(type="integer", nullable=false) - */ - protected $display; - - /** - * @var Select - * - * @ManyToOne(targetEntity="Select", inversedBy="options") - * @JoinColumn(name="select_name", referencedColumnName="name", nullable=false, onDelete="CASCADE") - */ - protected $select; - - public function __construct(Select $select) - { - $this->select = $select; - } - - public function getId() - { - return $this->id; - } - - public function getLabel(): string - { - return $this->label; - } - - public function setLabel(string $label): void - { - $this->label = $label; - } - - public function getValue(): string - { - return $this->value; - } - - public function setValue(string $value): void - { - $this->value = $value; - } - - public function getDisplay(): int - { - return $this->display; - } - - public function setDisplay(int $display): void - { - $this->display = (int) $display; - } - - public function getSelect(): Select - { - return $this->select; - } - - public function jsonSerialize(): array - { - return [ - 'id' => $this->getId(), - 'label' => $this->getLabel(), - 'value' => $this->getValue(), - 'display' => $this->getDisplay(), - 'select_name' => $this->getSelect()->getName() - ]; - } -} diff --git a/server/src/Entity/Select.php b/server/src/Entity/Select.php deleted file mode 100644 index 19ff96115e29d81d60e72b17a89e8b84fc4d9700..0000000000000000000000000000000000000000 --- a/server/src/Entity/Select.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php - -/* - * This file is part of Anis Server. - * - * (c) 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. - */ -declare(strict_types=1); - -namespace App\Entity; - -/** - * @author François Agneray <francois.agneray@lam.fr> - * @package App\Entity - * - * @Entity - * @Table(name="settings_select") - */ -class Select implements \JsonSerializable -{ - /** - * @var string - * - * @Id - * @Column(type="string", nullable=false) - */ - protected $name; - - /** - * @var string - * - * @Column(type="string", nullable=false) - */ - protected $label; - - /** - * @var Option[] - * - * @OneToMany(targetEntity="Option", mappedBy="select") - */ - protected $options; - - public function __construct(string $name) - { - $this->name = $name; - } - - public function getName(): string - { - return $this->name; - } - - public function getLabel(): string - { - return $this->label; - } - - public function setLabel(string $label): void - { - $this->label = $label; - } - - public function jsonSerialize(): array - { - return [ - 'name' => $this->getName(), - 'label' => $this->getLabel() - ]; - } -}