Browse Source

Embed django-cloud-browser in data import page

pull/213/head
Clemens Wolff 6 years ago
parent
commit
d520ff7724
4 changed files with 37 additions and 4 deletions
  1. 9
      app/server/api.py
  2. 13
      app/server/static/components/mixin.js
  3. 12
      app/server/static/components/upload.pug
  4. 7
      app/server/tests/test_api.py

9
app/server/api.py

@ -251,7 +251,14 @@ class CloudUploadAPI(APIView):
)
next_url = request.query_params.get('next')
return redirect(next_url) if next_url else Response(status=status.HTTP_201_CREATED)
if next_url == 'about:blank':
return Response(data='', content_type='text/plain', status=status.HTTP_201_CREATED)
if next_url:
return redirect(next_url)
return Response(status=status.HTTP_201_CREATED)
@classmethod
def get_cloud_object_as_io(cls, container_name, object_name):

13
app/server/static/components/mixin.js

@ -227,6 +227,7 @@ export const uploadMixin = {
messages: [],
format: 'json',
isLoading: false,
isCloudUploadActive: false,
canUploadFromCloud: false,
}),
@ -253,11 +254,21 @@ export const uploadMixin = {
return '/cloud-storage'
+ `?project_id=${this.projectId}`
+ `&upload_format=${this.format}`
+ `&next=${encodeURIComponent(this.postUploadUrl)}`;
+ `&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];

12
app/server/static/components/upload.pug

@ -43,10 +43,18 @@ div.columns(v-cloak="")
span.file-name {{ file.name }}
div.control(v-if="canUploadFromCloud")
a.button(
v-bind:href="cloudUploadUrl"
button.button(
v-on:click="isCloudUploadActive = !isCloudUploadActive"
v-bind:class="{'is-loading': isLoading}"
)
span.file-icon
i.fa.fa-cloud-upload-alt
span Browse cloud…
div(v-if="isCloudUploadActive")
iframe(
ref="cloudUploadPane"
v-bind:src="cloudUploadUrl"
v-on:load="cloudUpload"
style="width: 100%; height: 20em;"
)

7
app/server/tests/test_api.py

@ -846,6 +846,13 @@ class TestCloudUploader(TestUploader):
file_format='json',
expected_status=status.HTTP_302_FOUND)
def test_can_upload_with_redirect_to_blank(self):
self.upload_test_helper(project_id=self.classification_project.id,
filename='example.jsonl',
next='about:blank',
file_format='json',
expected_status=status.HTTP_201_CREATED)
class TestFeatures(APITestCase):
@classmethod

Loading…
Cancel
Save