import { Component , OnInit , NgModule , TemplateRef , ViewChild , ViewContainerRef } from '@angular/core' ; import { Router , ActivatedRoute , Params , ParamMap } from '@angular/router' ; import { Http , HttpModule , Response } from '@angular/http' ; import { FormsModule } from '@angular/forms' ; import { DIDService } from './did.service' ; import { DocumentService } from '../message/document/document.service' ; import { FileUploader , FileUploaderOptions } from 'ng2-file-upload' ; import { AppService } from '../../app.service' ; import 'rxjs/add/operator/toPromise' ; @ Component ( { selector : 'ngx-import-did-component' , templateUrl : './import-did-component.html' , styleUrls : [ './import-did-component.scss' ] , } ) export class ImportDIDComponent implements OnInit { constructor ( private http , private route , private did_service , private router , private app_service , private document_service ) { } form1 : any = { } ; file : any ; document_id : any ; document : any ; URL = `${ this . app_service . apiUrlDocument }/${ this . document_id }/media` ; public uploader : FileUploader = new FileUploader ( { url : this . URL , disableMultipart : true } ) ; ngOnInit ( ) { this . uploader . onBeforeUploadItem = ( item ) => { item . method = 'PUT' ; item . url = this . URL ; item . withCredentials = false ; } ; this . uploader . onAfterAddingFile = ( response ) => { this . file = response ; } ; const authHeader = this . app_service . upload_Header ; const uploadOptions = < FileUploaderOptions > { headers : authHeader } ; this . uploader . setOptions ( uploadOptions ) ; this . uploader . onSuccessItem = ( item , response , status , headers ) => { } ; } addDocument ( ) { this . document_service . add_Document ( this . document ) . then ( response => { const document_id = response ; this . URL = `${ this . app_service . apiUrlDocument }/${ document_id }/media` ; this . upload ( ) ; this . router . navigate ( [ '../../did' ] , { relativeTo : this . route } ) ; } ) ; } upload ( ) { this . file . upload ( ) ; } private hasBaseDropZoneOver = false ; private hasAnotherDropZoneOver = false ; private fileOverBase ( e ) { this . hasBaseDropZoneOver = e ; } private fileOverAnother ( e ) { this . hasAnotherDropZoneOver = e ; } private handleError ( error ) { console . error ( 'An error occurred' , error ) ; return Promise . reject ( error . message || error ) ; } }