|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import view from "./view.js"; |
| 3 | +import Utility from '../../utility'; |
| 4 | +import Services from '../../services'; |
| 5 | +import ReduxStore from "../../redux/store"; |
| 6 | +import Actions from "../../redux/main/actions"; |
| 7 | + |
| 8 | + |
| 9 | +class MetadataSpUploadZip extends Component { |
| 10 | + |
| 11 | + constructor(props) { |
| 12 | + super(props); |
| 13 | + |
| 14 | + this.state = { |
| 15 | + detailview: false, |
| 16 | + file: null, |
| 17 | + loading: false, |
| 18 | + loaded: false, |
| 19 | + fileName: null, |
| 20 | + fileSize: null, |
| 21 | + fileType: null, |
| 22 | + check: "extra", |
| 23 | + profile: "spid-sp-ag-public-full", |
| 24 | + production: true, |
| 25 | + report: null |
| 26 | + }; |
| 27 | + } |
| 28 | + |
| 29 | + componentDidMount() { |
| 30 | + let service = Services.getMainService(); |
| 31 | + let store = ReduxStore.getMain(); |
| 32 | + let storeState = store.getState(); |
| 33 | + } |
| 34 | + |
| 35 | + render() { |
| 36 | + return view(this); |
| 37 | + } |
| 38 | + |
| 39 | + setDetailView(detailed) { |
| 40 | + this.setState({ |
| 41 | + detailview: detailed |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + setCheck(check) { |
| 46 | + this.setState({ |
| 47 | + check: check |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + setProfile(profile) { |
| 52 | + this.setState({ |
| 53 | + profile: profile |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + setProduction(production) { |
| 58 | + this.setState({ |
| 59 | + production: production |
| 60 | + }); |
| 61 | + this.setState({ |
| 62 | + production: production |
| 63 | + }, ()=> { |
| 64 | + this.uploadMetadataZip(this.state.file); |
| 65 | + }); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + uploadMetadataZip(metadata_zip) { |
| 70 | + |
| 71 | + let service = Services.getMainService(); |
| 72 | + |
| 73 | + this.setState({ |
| 74 | + file: metadata_zip, |
| 75 | + loading: true, |
| 76 | + loaded: false, |
| 77 | + fileName: metadata_zip.name, |
| 78 | + fileSize: metadata_zip.size, |
| 79 | + fileType: metadata_zip.type, |
| 80 | + report: null |
| 81 | + }); |
| 82 | + |
| 83 | + Utility.blockUI(true); |
| 84 | + service.uploadFile( |
| 85 | + metadata_zip, |
| 86 | + this.state.check, |
| 87 | + this.state.profile, |
| 88 | + this.state.production? 'Y':'N', |
| 89 | + |
| 90 | + (progress)=> { |
| 91 | + let progress_percent = Math.round((parseInt(progress.loaded)*100)/parseInt(progress.total)); |
| 92 | + if(progress_percent<100) { |
| 93 | + this.setState({ |
| 94 | + progress_message: "Uploading ZIP file...", |
| 95 | + progress: progress_percent + "%" |
| 96 | + }); |
| 97 | + } else { |
| 98 | + this.setState({ |
| 99 | + progress_message: "Validating all metadata. Please wait...", |
| 100 | + progress: "" |
| 101 | + }); |
| 102 | + } |
| 103 | + }, |
| 104 | + (progress)=> { |
| 105 | + let progress_percent = Math.round((parseInt(progress.loaded)*100)/parseInt(progress.total)); |
| 106 | + this.setState({ |
| 107 | + progress_message: "Downloading report...", |
| 108 | + progress: progress_percent + '%' |
| 109 | + }); |
| 110 | + }, |
| 111 | + (report)=> { |
| 112 | + this.setState({ |
| 113 | + file: metadata_zip, |
| 114 | + loading: false, |
| 115 | + loaded: true, |
| 116 | + progress: 0, |
| 117 | + check: report.check, |
| 118 | + profile: report.profile, |
| 119 | + production: report.production, |
| 120 | + report: report |
| 121 | + }); |
| 122 | + |
| 123 | + Utility.blockUI(false); |
| 124 | + }, |
| 125 | + (error)=> { |
| 126 | + Utility.showModal({ |
| 127 | + title: "Errore", |
| 128 | + body: error, |
| 129 | + isOpen: true |
| 130 | + }); |
| 131 | + this.setState({ |
| 132 | + file: null, |
| 133 | + loading: false, |
| 134 | + loaded: false, |
| 135 | + fileName: null, |
| 136 | + fileSize: null, |
| 137 | + fileType: null, |
| 138 | + check: "extra", |
| 139 | + profile: "spid-sp-ag-public-full", |
| 140 | + production: true, |
| 141 | + report: null |
| 142 | + }); |
| 143 | + |
| 144 | + Utility.blockUI(false); |
| 145 | + } |
| 146 | + ); |
| 147 | + } |
| 148 | + |
| 149 | + openMetadata(metadata) { |
| 150 | + let service = Services.getMainService(); |
| 151 | + let store = ReduxStore.getMain(); |
| 152 | + |
| 153 | + Utility.blockUI(true); |
| 154 | + service.setSessionMetadata(metadata, |
| 155 | + (success)=> { |
| 156 | + store.dispatch(Actions.setMetadataSpURL(metadata.url)); |
| 157 | + store.dispatch(Actions.setMetadataSpXML(metadata.xml)); |
| 158 | + this.props.history.push('/metadata-sp-download'); |
| 159 | + Utility.blockUI(false); |
| 160 | + }, |
| 161 | + (error)=> { |
| 162 | + Utility.showModal({ |
| 163 | + title: "Errore", |
| 164 | + body: error, |
| 165 | + isOpen: true |
| 166 | + }); |
| 167 | + Utility.blockUI(false); |
| 168 | + } |
| 169 | + ); |
| 170 | + } |
| 171 | + |
| 172 | + print() { |
| 173 | + Utility.print(this.state.fileName); |
| 174 | + } |
| 175 | + |
| 176 | +} |
| 177 | + |
| 178 | +export default MetadataSpUploadZip; |
0 commit comments