Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mountTermsSubterms(mountData): Observable<any> {
- let listTermsSubterms = [];
- let observableObj = Observable.create((observer: any) => {
- Observable.from(mountData.terms).concatMap(term => {
- return this.ciService.objectList('instance_ci_subterms', 'term_id=' + term['id'])
- .map(
- response => {
- let listSubterms = [];
- for (let subterm of response) {
- listSubterms.push(subterm.name);
- }
- listTermsSubterms.push({[term['name']]: listSubterms});
- })
- })
- .subscribe(
- data => {
- mountData.terms = listTermsSubterms;
- },
- error => {
- console.log(error, 'Error inside of observableProcess')
- },
- () => {
- observer.next(mountData);
- observer.complete();
- }
- );
- });
- return observableObj;
- };
- sendFile(modelForm: any, form?: any) {
- // Converting file and add into mountData.
- this.appService.convertFile(this.objFile)
- .map(response => {
- let mountData = {
- 'file': response,
- 'terms': []
- };
- return mountData;
- })
- // Get all terms by collection id.
- .concatMap(mountData => {
- return this.ciService.objectList('instance_ci_terms', 'collection_id=' + this.collectionChecked)
- .map(
- terms => {
- mountData.terms = terms;
- return mountData;
- });
- })
- //Get all subterms of each terms and add into mountData.
- .concatMap(mountData => {
- return this.mountTermsSubterms(mountData);
- })
- // Converting mounData object.
- .concatMap(mountData => {
- return this.appService.convertFile(mountData, false);
- })
- // Upload file.
- .concatMap(response => {
- let fileName = this.config.getNewName(this.objFile.name, 'json');
- return this.appService.uploadFile(response, fileName);
- })
- .subscribe(
- data => {
- this.messageService.success('Arquivo enviado com sucesso.');
- },
- error => {
- this.messageService.error('Ocorreu algum problema na durante o envio do arquivo.');
- console.log(error, 'Error inside of sendFile');
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement