Skip to content

Commit

Permalink
document editor: fix bnf import
Browse files Browse the repository at this point in the history
* Changes the sequence of editor initalization to avoid concurency
  problem with the JSONSchema loading.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Jul 23, 2020
1 parent b12ff1f commit 78d2787
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
 along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<ng-core-editor [model]="model"></ng-core-editor>
<ng-core-editor (loadingChange)="loadingChanged($event)" [model]="model"></ng-core-editor>
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, OnInit } from '@angular/core';
import {ToastrService} from 'ngx-toastr';
import { TranslateService } from '@ngx-translate/core';
import { EditorService } from '../../../service/editor.service';
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { ToastrService } from 'ngx-toastr';
import { combineLatest } from 'rxjs';
import { EditorService } from '../../../service/editor.service';

@Component({
selector: 'admin-document-editor',
Expand All @@ -30,27 +30,18 @@ import { combineLatest } from 'rxjs';
/**
* Show Document Editor with a specific input: EAN import.
*/
export class DocumentEditorComponent implements OnInit {
export class DocumentEditorComponent {

// initial editor values
model = {};

constructor(
private editorService: EditorService,
private toastrService: ToastrService,
private translateService: TranslateService,
private _route: ActivatedRoute
) { }

) {}

ngOnInit() {
combineLatest([this._route.params, this._route.queryParams])
.subscribe(([params, queryParams]) => {
if (queryParams.source != null && queryParams.pid != null) {
this.importFromExternalSource(queryParams.source, queryParams.pid);
}
}
);
}
/**
* Retrieve information about an item regarding its EAN code using EditorService
* @param source string - the external source
Expand All @@ -68,6 +59,25 @@ export class DocumentEditorComponent implements OnInit {
);
}
}
);
);
}

/**
* To be notified when the child editor loading state change.
*
* An other approach can be to display the child component only when the
* external source data are retrieved.
*
* @param value - true if the child editor component is currently loading data
*/
loadingChanged(value: boolean) {
if (value === false) {
combineLatest([this._route.params, this._route.queryParams])
.subscribe(([params, queryParams]) => {
if (queryParams.source != null && queryParams.pid != null) {
this.importFromExternalSource(queryParams.source, queryParams.pid);
}
});
}
}
}

0 comments on commit 78d2787

Please sign in to comment.