Skip to content

Commit

Permalink
renaming dup classes, stop simp. load on std. form
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoAnderson committed Oct 15, 2024
1 parent ff0cb75 commit 69ecb4d
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 89 deletions.
12 changes: 12 additions & 0 deletions src/app/core/substance-form/form-sections.constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export const formSections: { [substanceType: string]: Array<string> } = {
chemical: [
'substance-form-definition',
'substance-form-names',
'substance-form-structure',
'substance-form-moieties',
'substance-form-codes-card',
'substance-form-relationships',
'substance-form-notes',
'substance-form-properties',
'substance-form-references',
'substance-form-change-reason'
],
chemicalSimplified: [
'substance-form-definition',
'substance-form-names',
'substance-form-simplified-names',
'substance-form-structure',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class SubstanceFormNamesService extends SubstanceFormServiceBase<Array<Su
}

ngOnDestroy() {
this.subscriptions.forEach(subscription => {
subscription.unsubscribe();
});
}

initSubtanceForm(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CodeFormComponent } from './code-form.component';
import { SimplifiedCodeFormComponent } from './simplified-code-form.component';

describe('CodeFormComponent', () => {
let component: CodeFormComponent;
let fixture: ComponentFixture<CodeFormComponent>;
let component: SimplifiedCodeFormComponent;
let fixture: ComponentFixture<SimplifiedCodeFormComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CodeFormComponent ]
declarations: [ SimplifiedCodeFormComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CodeFormComponent);
fixture = TestBed.createComponent(SimplifiedCodeFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { VocabularyTerm } from '@gsrs-core/controlled-vocabulary';
import { UtilsService } from '@gsrs-core/utils';

@Component({
selector: 'app-code-form',
templateUrl: './code-form.component.html',
styleUrls: ['./code-form.component.scss']
selector: 'app-simplified-code-form',
templateUrl: './simplified-code-form.component.html',
styleUrls: ['./simplified-code-form.component.scss']
})
export class CodeFormComponent implements OnInit {
export class SimplifiedCodeFormComponent implements OnInit {
private privateCode: SubstanceCode;
@Output() codeDeleted = new EventEmitter<SubstanceCode>();
codeSystemList: Array<VocabularyTerm> = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</mat-paginator>
<div class="code" *ngFor="let code of paged; last as isLast; index as index" appScrollToTarget
[id]="'substance-code-' + index">
<app-code-form [code]="code" (codeDeleted)="deleteCode($event)" [show] = "expanded"></app-code-form>
<app-simplified-code-form [code]="code" (codeDeleted)="deleteCode($event)" [show] = "expanded"></app-simplified-code-form>
<mat-divider class="form-divider" [inset]="true" *ngIf="!isLast"></mat-divider>
</div>
<mat-paginator *ngIf="codes && codes.length > 5" [length]="filtered && filtered.length || 0" [pageIndex]="page" [pageSize]="10" showFirstLastButtons="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {combineLatest, first, Subscription} from 'rxjs';
import { SubstanceFormCodesService } from '../codes/substance-form-codes.service';

@Component({
selector: 'app-substance-form-codes-card',
selector: 'app-simplified-substance-form-codes-card',
templateUrl: './substance-form-simplified-codes-card.component.html',
styleUrls: ['./substance-form-simplified-codes-card.component.scss']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatInputModule } from '@angular/material/input';
import { CodeFormComponent } from './code-form.component';
import { SimplifiedCodeFormComponent } from './simplified-code-form.component';
import { MatTooltipModule } from '@angular/material/tooltip';

@NgModule({
Expand All @@ -32,7 +32,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
],
declarations: [
SubstanceFormSimplifiedCodesCardComponent,
CodeFormComponent
SimplifiedCodeFormComponent
]
})
export class SubstanceFormSimplifiedCodesModule { }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {SubstanceFormService} from '@gsrs-core/substance-form/substance-form.ser
import {SubstanceFormNamesService} from '@gsrs-core/substance-form/names/substance-form-names.service';

@Component({
selector: 'app-name-form',
templateUrl: './name-form.component.html',
styleUrls: ['./name-form.component.scss']
selector: 'app-simplified-name-form',
templateUrl: './simplified-name-form.component.html',
styleUrls: ['./simplified-name-form.component.scss']
})
export class NameFormComponent implements OnInit, OnDestroy {
export class SimplifiedNameFormComponent implements OnInit, OnDestroy {
private privateName: SubstanceName;
@Output() priorityUpdate = new EventEmitter<SubstanceName>();
@Output() nameDeleted = new EventEmitter<SubstanceName>();
Expand Down Expand Up @@ -48,6 +48,7 @@ export class NameFormComponent implements OnInit, OnDestroy {

// Protected access by default.
this.privateName.access = ["protected"]
console.log('this is simplified name form');
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[pageSizeOptions]="[5, 10, 25, 100]">
</mat-paginator>
<div class="name" *ngFor="let name of paged; last as isLast; index as index" appScrollToTarget [id]="'substance-name-' + index">
<app-name-form [name]="name" (priorityUpdate)="priorityUpdated($event)" (nameDeleted)="deleteName($event)" [standardized] = "showStd"></app-name-form>
<app-simplified-name-form [name]="name" (priorityUpdate)="priorityUpdated($event)" (nameDeleted)="deleteName($event)" [standardized] = "showStd"></app-simplified-name-form>
<mat-divider class="form-divider" [inset]="true" *ngIf="!isLast"></mat-divider>
</div>
<mat-paginator *ngIf="names && names.length > 5" [length]="filtered && filtered.length || 0" [pageIndex]="page" [pageSize]="10" showFirstLastButtons="true" (page)="pageChange($event, analyticsEventCategory)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {SubstanceFormNamesService} from "@gsrs-core/substance-form/names/substan
import {tr} from "cronstrue/dist/i18n/locales/tr";

@Component({
selector: 'app-substance-form-names-card',
selector: 'app-simplified-substance-form-names-card',
templateUrl: './substance-form-simplified-names-card.component.html',
styleUrls: ['./substance-form-simplified-names-card.component.scss']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatInputModule } from '@angular/material/input';
import { NameFormComponent } from './name-form.component';
import { SimplifiedNameFormComponent } from './simplified-name-form.component';
import {MatRadioModule} from '@angular/material/radio';
import {MatCheckboxModule} from '@angular/material/checkbox';
import {MatBadgeModule} from '@angular/material/badge';
Expand Down Expand Up @@ -47,7 +47,7 @@ import { ElementLabelDisplayModule } from '@gsrs-core/utils/element-label-displa
],
declarations: [
SubstanceFormSimplifiedNamesCardComponent,
NameFormComponent,
SimplifiedNameFormComponent,
]
})
export class SubstanceFormSimplifiedNamesModule { }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Subscription } from 'rxjs';
import {SubstanceFormReferencesService} from "@gsrs-core/substance-form/references/substance-form-references.service";

@Component({
selector: 'app-reference-form',
templateUrl: './reference-form.component.html',
styleUrls: ['./reference-form.component.scss']
selector: 'app-simplified-reference-form',
templateUrl: './simplified-reference-form.component.html',
styleUrls: ['./simplified-reference-form.component.scss']
})
export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy {
export class SimplifiedReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy {
@Input() reference: SubstanceReference;
@Output() referenceDeleted = new EventEmitter<SubstanceReference>();
@Input() hideDelete = false;
Expand All @@ -40,6 +40,8 @@ export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy

// Protected access by default.
this.reference.access = ["protected"]
console.log('this is simplified ref form');

}

ngAfterViewInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[pageSizeOptions]="[5, 10, 25, 100]">
</mat-paginator>
<div class="reference" *ngFor="let reference of paged; last as isLast" [id]="reference.uuid" appScrollToTarget>
<app-reference-form [reference]="reference" (referenceDeleted)="deleteReference($event)"></app-reference-form>
<app-simplified-reference-form [reference]="reference" (referenceDeleted)="deleteReference($event)"></app-simplified-reference-form>
<mat-divider class="form-divider" [inset]="true" *ngIf="!isLast"></mat-divider>
</div>
<mat-paginator *ngIf="references && references.length > 5" [length]="filtered && filtered.length || 0" [pageIndex]="page" [pageSize]="5" showFirstLastButtons="true" (page)="pageChange($event, analyticsEventCategory)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {SubstanceFormCodesService} from "@gsrs-core/substance-form/codes/substan
import {SubstanceFormStructureService} from "@gsrs-core/substance-form/structure/substance-form-structure.service";

@Component({
selector: 'app-substance-form-references-card',
selector: 'app-simplified-substance-form-references-card',
templateUrl: './substance-form-simplified-references-card.component.html',
styleUrls: ['./substance-form-simplified-references-card.component.scss']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatInputModule } from '@angular/material/input';
import {ReferenceFormComponent} from "./reference-form.component";
import {SimplifiedReferenceFormComponent} from "./simplified-reference-form.component";
import {MatTooltipModule} from "@angular/material/tooltip";

@NgModule({
Expand All @@ -32,7 +32,7 @@ import {MatTooltipModule} from "@angular/material/tooltip";
],
declarations: [
SubstanceFormSimplifiedReferencesCardComponent,
ReferenceFormComponent
SimplifiedReferenceFormComponent
]
})
export class SubstanceFormSimplifiedReferencesModule { }
45 changes: 35 additions & 10 deletions src/app/core/substance-form/substance-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {Buffer} from 'buffer';
import {AdminService} from '@gsrs-core/admin/admin.service';
import {MatButtonToggleChange} from "@angular/material/button-toggle";
import {tr} from "cronstrue/dist/i18n/locales/tr";
import { Location } from '@angular/common';


@Component({
Expand Down Expand Up @@ -133,7 +134,8 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
private dialog: MatDialog,
private authService: AuthService,
private titleService: Title,
private utilsService: UtilsService
private utilsService: UtilsService,
private location: Location
) {
this.substanceService.showImagePopup.subscribe(data => {
this.hidePopup = data;
Expand Down Expand Up @@ -310,6 +312,13 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
this.isUpdater = this.authService.hasAnyRoles('Updater', 'SuperUpdater');
this.overlayContainer = this.overlayContainerService.getContainerElement();
this.imported = false;
if(this.location.path().includes('chemical-simplified')) {
this.simplifiedForm = true;
}
const simplifiedFormSubscription = this.substanceFormService.simplifiedForm.subscribe(value=>{
this.simplifiedForm = value
})
this.subscriptions.push(simplifiedFormSubscription);
const routeSubscription = this.activatedRoute
.params
.subscribe(params => {
Expand Down Expand Up @@ -363,7 +372,11 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
this.substanceClass = response.substanceClass;
this.status = response.status;
this.substanceFormService.loadSubstance(response.substanceClass, response).pipe(take(1)).subscribe(() => {
this.setFormSections(formSections[response.substanceClass]);
if(this.simplifiedForm) {
this.setFormSections(formSections['chemicalSimplified']);
} else {
this.setFormSections(formSections[response.substanceClass]);
}
this.isLoading = false;
this.loadingService.setLoading(false);
});
Expand Down Expand Up @@ -393,7 +406,11 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
this.titleService.setTitle('Register - ' + this.subClass);

this.substanceFormService.loadSubstance(this.subClass,undefined,undefined,undefined, simplified).pipe(take(1)).subscribe(() => {
this.setFormSections(formSections[this.subClass]);
if(this.simplifiedForm) {
this.setFormSections(formSections['chemicalSimplified']);
} else {
this.setFormSections(formSections[this.subClass]);
}
this.loadingService.setLoading(false);
this.isLoading = false;
});
Expand Down Expand Up @@ -426,10 +443,6 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy

});
});
const simplifiedFormSubscription = this.substanceFormService.simplifiedForm.subscribe(value=>{
this.simplifiedForm = value
})
this.subscriptions.push(simplifiedFormSubscription);
}

isBase64(str) {
Expand Down Expand Up @@ -781,7 +794,11 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
this.substanceClass = response.substanceClass;
this.status = response.status;
this.substanceFormService.loadSubstance(response.substanceClass, response).pipe(take(1)).subscribe(() => {
this.setFormSections(formSections[response.substanceClass]);
if(this.simplifiedForm) {
this.setFormSections(formSections['chemicalSimplified']);
} else {
this.setFormSections(formSections[response.substanceClass]);
}
});
} else {
this.handleSubstanceRetrivalError();
Expand Down Expand Up @@ -816,7 +833,11 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy
this.substanceClass = response.substanceClass;
this.status = response.status;
this.substanceFormService.loadSubstance(response.substanceClass, response, 'import').pipe(take(1)).subscribe(() => {
this.setFormSections(formSections[response.substanceClass]);
if(this.simplifiedForm) {
this.setFormSections(formSections['chemicalSimplified']);
} else {
this.setFormSections(formSections[response.substanceClass]);
}
if (!same) {
setTimeout(() => {
this.forceChange = true;
Expand Down Expand Up @@ -888,7 +909,11 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy

this.scrub(response, type);
this.substanceFormService.loadSubstance(response.substanceClass, response).pipe(take(1)).subscribe(() => {
this.setFormSections(formSections[response.substanceClass]);
if(this.simplifiedForm) {
this.setFormSections(formSections['chemicalSimplified']);
} else {
this.setFormSections(formSections[response.substanceClass]);
}
this.loadingService.setLoading(false);
this.isLoading = false;
});
Expand Down

0 comments on commit 69ecb4d

Please sign in to comment.