Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mountTermsSubterms(mountData): Observable<any> {
  2.     let listTermsSubterms = [];
  3.     let observableObj = Observable.create((observer: any) => {
  4.       Observable.from(mountData.terms).concatMap(term => {
  5.         return this.ciService.objectList('instance_ci_subterms', 'term_id=' + term['id'])
  6.         .map(
  7.           response => {
  8.  
  9.             let listSubterms = [];
  10.             for (let subterm of response) {
  11.               listSubterms.push(subterm.name);
  12.             }
  13.  
  14.             listTermsSubterms.push({[term['name']]: listSubterms});
  15.           })
  16.       })
  17.       .subscribe(
  18.         data => {
  19.           mountData.terms = listTermsSubterms;
  20.         },
  21.         error => {
  22.           console.log(error, 'Error inside of observableProcess')
  23.         },
  24.         () => {
  25.           observer.next(mountData);
  26.           observer.complete();
  27.         }
  28.       );
  29.     });
  30.  
  31.     return observableObj;
  32.   };
  33.  
  34.   sendFile(modelForm: any, form?: any) {
  35.  
  36.     // Converting file and add into mountData.
  37.     this.appService.convertFile(this.objFile)
  38.       .map(response => {
  39.         let mountData = {
  40.           'file': response,
  41.           'terms': []
  42.         };
  43.         return mountData;
  44.       })
  45.       // Get all terms by collection id.
  46.       .concatMap(mountData => {
  47.         return this.ciService.objectList('instance_ci_terms', 'collection_id=' + this.collectionChecked)
  48.           .map(
  49.             terms => {
  50.               mountData.terms = terms;
  51.               return mountData;
  52.             });
  53.       })
  54.       //Get all subterms of each terms and add into mountData.
  55.       .concatMap(mountData => {
  56.         return this.mountTermsSubterms(mountData);
  57.  
  58.       })
  59.       // Converting mounData object.
  60.       .concatMap(mountData => {
  61.         return this.appService.convertFile(mountData, false);
  62.       })
  63.       // Upload file.
  64.       .concatMap(response => {
  65.         let fileName = this.config.getNewName(this.objFile.name, 'json');
  66.         return this.appService.uploadFile(response, fileName);
  67.       })
  68.       .subscribe(
  69.         data => {
  70.           this.messageService.success('Arquivo enviado com sucesso.');
  71.         },
  72.         error => {
  73.           this.messageService.error('Ocorreu algum problema na durante o envio do arquivo.');
  74.           console.log(error, 'Error inside of sendFile');
  75.         }
  76.       );
  77.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement