Skip to content

Commit

Permalink
added download file button, changed link to id for search link
Browse files Browse the repository at this point in the history
  • Loading branch information
moisbo committed May 12, 2022
1 parent 4e3f758 commit 4cf5d83
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
10 changes: 6 additions & 4 deletions api/src/indexer/indexCollections.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ export async function indexCollections({configuration, repository, client}) {
try {
let rootConformsTos = await getRootConformsTos({
conforms: 'https://github.com/Language-Research-Technology/ro-crate-profile#Collection',
//members: 'arcp://name,farms-to-freeways/corpus/root'
//members: 'arcp://name,sydney-speaks/corpus/root' // Add a crateId to test the indexer.
});
//Use this block to test cases where a conformsTo conforms to another collection
// const rootConformsTos2 = await getRootConformsTos({
// const rootConformsToCrateId = await getRootConformsTos({
// conforms: 'https://github.com/Language-Research-Technology/ro-crate-profile#Collection',
// crateId: 'arcp://name,sydney-speaks/corpus/root' // Add a crateId to test the indexer.
// crateId: 'arcp://name,farms-to-freeways/corpus/root'
// //crateId: 'arcp://name,sydney-speaks/corpus/root' // Add a crateId to test the indexer.
// });
// if (rootConformsTos2.length > 0) {
// rootConformsTos = rootConformsTos.concat(rootConformsTos2);
// if (rootConformsToCrateId.length > 0) {
// rootConformsTos = rootConformsTos.concat(rootConformsToCrateId);
// }
let i = 0;
const index = 'items';
Expand Down
2 changes: 1 addition & 1 deletion api/src/indexer/indexFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function indexFiles({crateId, item, hasFile, parent, crate, client,
}
}
const normalFileItem = crate.getNormalizedTree(fileItem, 1);
//TODO: Maybe search for stream pipes in elastic`
//TODO: Maybe search for stream pipes in elastic
normalFileItem['_text'] = fileContent;
normalFileItem._root = {'@id': root['@id'], name: root.name}
try {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/DocSubElement.component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<!--TODO: convert the following to vue router-->
<el-row v-else v-if="this.value">
<el-col :span="24">
<a class="break-words underline text-blue-600 hover:text-blue-800 visited:text-purple-600"
:href="getURL()">
{{ this.value }}</a>
<a class="break-words text-blue-600 hover:text-blue-800 visited:text-purple-600"
:href="getURL()" >
<el-button :type="'default'">Search Link</el-button></a>
</el-col>
</el-row>
</span>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/Open.component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export default {
id: '',
name: '',
parent: '',
parentTitle: ''
parentTitle: '',
loading: false
}
},
async mounted() {
Expand Down
64 changes: 61 additions & 3 deletions ui/src/components/View.component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,36 @@
<el-link v-if="this.isFile() && !this.cannotOpenFile" :href="this.fileUrl" :underline="false">
<el-button>Preview File</el-button>
</el-link>
<el-link v-loading="this.loading" v-if="this.isFile() && !this.cannotOpenFile" :underline="false"
v-on:click="this.downloadFileUrl()">
<el-button>Download</el-button>
</el-link>
<el-button v-if="this.notAuthorized" v-on:click="openRequestModal()">Request Access</el-button>
</el-button-group>
<view-doc :crateId="this.crateId" :meta="this.metadata" :root="this.root"/>
<view-members v-if="getMembers()" :crateId="this.crateId" :limitMembers=10
:conformsToName="'Collections'" :conformsTo="'https://github.com/Language-Research-Technology/ro-crate-profile%23Collection'"/>
:conformsToName="'Collections'"
:conformsTo="'https://github.com/Language-Research-Technology/ro-crate-profile%23Collection'"/>
<view-members-search v-if="getMembers()" :crateId="this.crateId" :limitMembers=10
:conformsToName="'Repository Objects'" :conformsTo="'RepositoryObject'"/>
:conformsToName="'Repository Objects'" :conformsTo="'RepositoryObject'"/>
<el-row>
&nbsp;
</el-row>

</el-col>
</el-row>
<div v-else>
<view-doc-error/>
</div>
<request-dialog :dialogVisible="this.openDocModal" v-on:close="this.openDocModal = false"/>
<el-dialog v-model="errorDialogVisible" width="30%" center>
<span>{{ this.errorDialogText }}</span>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="errorDialogVisible = false">Close</el-button>
</span>
</template>
</el-dialog>
</template>

<script>
Expand Down Expand Up @@ -84,7 +98,10 @@ export default {
parentName: '',
error: '',
notAuthorized: false,
openDocModal: false
openDocModal: false,
loading: false,
errorDialogVisible: false,
errorDialogText: ''
}
},
async mounted() {
Expand All @@ -105,6 +122,10 @@ export default {
this.setParentLink();
this.getMembers();
} catch (e) {
this.errorDialogVisible = true;
this.errorDialogTitle = 'Error';
this.errorDialogText = e.message;
this.loading = false;
console.error(e);
}
},
Expand Down Expand Up @@ -166,6 +187,43 @@ export default {
}
}
},
async downloadFileUrl() {
if (this.isFile()) {
try {
this.loading = true;
const crateId = this.crateId?.['@value'];
const filePath = this.metadata?.['@id'];
if (filePath && crateId) {
let url = `/object/open?id=${encodeURIComponent(crateId)}&path=${encodeURIComponent(filePath)}`;
const link = document.createElement("a");
link.download = filePath;
let response = await this.$http.get({route: url});
if (response.status !== 200) {
this.errorDialogVisible = true;
this.errorDialogTitle = 'Download Error';
this.errorDialogText = response.statusText;
} else {
const data = await response.blob();
link.href = window.URL.createObjectURL(data);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
} else {
this.errorDialogVisible = true;
this.errorDialogTitle = 'Download Error';
this.errorDialogText = 'No path found for that file';
}
this.loading = false;
} catch (e) {
this.errorDialogVisible = true;
this.errorDialogTitle = 'Download Error';
this.errorDialogText = e.message;
this.loading = false;
}
}
},
getMembers() {
console.log(this.conformsTo);
return this.conformsTo === 'Collection' || this.conformsTo === 'Dataset';
Expand Down

0 comments on commit 4cf5d83

Please sign in to comment.