Browse Source

Merge pull request #1138 from SwiftPredator/Enhancement/export_only_approved_dataset_option

Enhancement: Added option to export only approved datasets
pull/1160/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
d5e757b5f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 4 deletions
  1. 8
      app/api/views.py
  2. 8
      frontend/components/organisms/documents/DocumentExportForm.vue
  3. 5
      frontend/services/document.service.js
  4. 2
      frontend/store/documents.js

8
app/api/views.py

@ -374,9 +374,15 @@ class TextDownloadAPI(APIView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
format = request.query_params.get('q') format = request.query_params.get('q')
only_approved = request.query_params.get('onlyApproved')
project = get_object_or_404(Project, pk=self.kwargs['project_id']) project = get_object_or_404(Project, pk=self.kwargs['project_id'])
documents = project.documents.all()
documents = (
project.documents.exclude(annotations_approved_by = None)
if only_approved == 'true'
else project.documents.all()
)
painter = self.select_painter(format) painter = self.select_painter(format)
# jsonl-textlabel format prints text labels while jsonl format prints annotations with label ids # jsonl-textlabel format prints text labels while jsonl format prints annotations with label ids
# jsonl-textlabel format - "labels": [[0, 15, "PERSON"], ..] # jsonl-textlabel format - "labels": [[0, 15, "PERSON"], ..]
# jsonl format - "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..] # jsonl format - "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..]

8
frontend/components/organisms/documents/DocumentExportForm.vue

@ -37,6 +37,12 @@
</v-sheet> </v-sheet>
<h2>{{ $t('dataset.exportDataMessage2') }}</h2> <h2>{{ $t('dataset.exportDataMessage2') }}</h2>
<v-text-field v-model="selectedFileName" placeholder="Name the file" /> <v-text-field v-model="selectedFileName" placeholder="Name the file" />
<v-checkbox
v-model="onlyApproved"
label="Export only approved documents"
color="success"
hide-details
/>
</v-form> </v-form>
</template> </template>
</base-card> </base-card>
@ -68,6 +74,7 @@ export default {
file: null, file: null,
selectedFormat: null, selectedFormat: null,
selectedFileName: 'project_' + this.$route.params.id + '_dataset', selectedFileName: 'project_' + this.$route.params.id + '_dataset',
onlyApproved: false,
fileFormatRules, fileFormatRules,
uploadFileRules uploadFileRules
} }
@ -99,6 +106,7 @@ export default {
projectId: this.$route.params.id, projectId: this.$route.params.id,
fileName: this.selectedFileName, fileName: this.selectedFileName,
format: this.selectedFormat.type, format: this.selectedFormat.type,
onlyApproved: this.onlyApproved,
suffix: this.selectedFormat.suffix suffix: this.selectedFormat.suffix
}) })
this.reset() this.reset()

5
frontend/services/document.service.js

@ -29,7 +29,7 @@ class DocumentService {
return this.request.post(`/projects/${projectId}/docs/upload`, payload, config) return this.request.post(`/projects/${projectId}/docs/upload`, payload, config)
} }
exportFile(projectId, format) {
exportFile(projectId, format, onlyApproved) {
const headers = {} const headers = {}
if (format === 'csv') { if (format === 'csv') {
headers.Accept = 'text/csv; charset=utf-8' headers.Accept = 'text/csv; charset=utf-8'
@ -41,7 +41,8 @@ class DocumentService {
const config = { const config = {
responseType: 'blob', responseType: 'blob',
params: { params: {
q: format
q: format,
onlyApproved
}, },
headers headers
} }

2
frontend/store/documents.js

@ -122,7 +122,7 @@ export const actions = {
}, },
exportDocument({ commit }, data) { exportDocument({ commit }, data) {
commit('setLoading', true) commit('setLoading', true)
DocumentService.exportFile(data.projectId, data.format)
DocumentService.exportFile(data.projectId, data.format, data.onlyApproved)
.then((response) => { .then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data])) const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a') const link = document.createElement('a')

Loading…
Cancel
Save