-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from CatalystCode/enhancement/reduce-bundle-size
Enhancement/Reduce bundle size
- Loading branch information
Showing
14 changed files
with
154 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = ['json']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import hljs from 'highlight.js/lib/highlight'; | ||
import hljsLanguages from './hljsLanguages'; | ||
import HTTP, { newHttpClient } from './http'; | ||
import Messages from './messages.vue'; | ||
|
||
hljsLanguages.forEach((languageName) => { | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
const languageModule = require(`highlight.js/lib/languages/${languageName}`); | ||
/* eslint-enable import/no-dynamic-require, global-require */ | ||
hljs.registerLanguage(languageName, languageModule); | ||
}); | ||
|
||
export default { | ||
components: { Messages }, | ||
|
||
data: () => ({ | ||
file: '', | ||
messages: [], | ||
format: 'json', | ||
isLoading: false, | ||
isCloudUploadActive: false, | ||
canUploadFromCloud: false, | ||
}), | ||
|
||
mounted() { | ||
hljs.initHighlighting(); | ||
}, | ||
|
||
created() { | ||
newHttpClient().get('/v1/features').then((response) => { | ||
this.canUploadFromCloud = response.data.cloud_upload; | ||
}); | ||
}, | ||
|
||
computed: { | ||
projectId() { | ||
return window.location.pathname.split('/')[2]; | ||
}, | ||
|
||
postUploadUrl() { | ||
return window.location.pathname.split('/').slice(0, -1).join('/'); | ||
}, | ||
|
||
cloudUploadUrl() { | ||
return '/cloud-storage' | ||
+ `?project_id=${this.projectId}` | ||
+ `&upload_format=${this.format}` | ||
+ `&next=${encodeURIComponent('about:blank')}`; | ||
}, | ||
}, | ||
|
||
methods: { | ||
cloudUpload() { | ||
const iframeUrl = this.$refs.cloudUploadPane.contentWindow.location.href; | ||
if (iframeUrl.indexOf('/v1/cloud-upload') > -1) { | ||
this.isCloudUploadActive = false; | ||
this.$nextTick(() => { | ||
window.location.href = this.postUploadUrl; | ||
}); | ||
} | ||
}, | ||
|
||
upload() { | ||
this.isLoading = true; | ||
this.file = this.$refs.file.files[0]; | ||
const formData = new FormData(); | ||
formData.append('file', this.file); | ||
formData.append('format', this.format); | ||
HTTP.post('docs/upload', | ||
formData, | ||
{ | ||
headers: { | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
}) | ||
.then((response) => { | ||
console.log(response); // eslint-disable-line no-console | ||
this.messages = []; | ||
window.location = this.postUploadUrl; | ||
}) | ||
.catch((error) => { | ||
this.isLoading = false; | ||
this.handleError(error); | ||
}); | ||
}, | ||
|
||
handleError(error) { | ||
const problems = Array.isArray(error.response.data) | ||
? error.response.data | ||
: [error.response.data]; | ||
|
||
problems.forEach((problem) => { | ||
if ('detail' in problem) { | ||
this.messages.push(problem.detail); | ||
} else if ('text' in problem) { | ||
this.messages = problem.text; | ||
} | ||
}); | ||
}, | ||
|
||
download() { | ||
this.isLoading = true; | ||
const headers = {}; | ||
if (this.format === 'csv') { | ||
headers.Accept = 'text/csv; charset=utf-8'; | ||
headers['Content-Type'] = 'text/csv; charset=utf-8'; | ||
} else { | ||
headers.Accept = 'application/json'; | ||
headers['Content-Type'] = 'application/json'; | ||
} | ||
HTTP({ | ||
url: 'docs/download', | ||
method: 'GET', | ||
responseType: 'blob', | ||
params: { | ||
q: this.format, | ||
}, | ||
headers, | ||
}).then((response) => { | ||
const url = window.URL.createObjectURL(new Blob([response.data])); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.setAttribute('download', 'file.' + this.format); // or any other extension | ||
document.body.appendChild(link); | ||
this.isLoading = false; | ||
link.click(); | ||
}).catch((error) => { | ||
this.isLoading = false; | ||
this.handleError(error); | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters