Skip to content

Commit

Permalink
add and manage container members
Browse files Browse the repository at this point in the history
  • Loading branch information
RastislavHudak committed May 17, 2019
1 parent 1f0f18a commit 678f6ad
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 19 deletions.
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"es6-promise": "^4.2.5",
"growl": "^1.10.5",
"moment": "^2.24.0",
"phaidra-vue-components": "^0.3.33",
"phaidra-vue-components": "^0.3.34",
"qs": "^6.6.0",
"vue": "^2.6.6",
"vue-i18n": "^7.8.1",
Expand Down
222 changes: 222 additions & 0 deletions src/components/AddMember.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<template>
<v-flex>
<v-flex>
<v-breadcrumbs :items="breadcrumbs" divider="/"></v-breadcrumbs>
</v-flex>
<v-card>
<v-toolbar flat>
<v-toolbar-title>{{ $t('Add member of') }} {{this.parentpid}}</v-toolbar-title>
<v-divider class="mx-3" inset vertical></v-divider>
<v-checkbox class="pt-4 pl-4" v-model="isthumbnail" :label="$t('Container thumbnail')"></v-checkbox>
<v-spacer></v-spacer>
</v-toolbar>
<v-card-text>
<p-i-form
:form="form"
:templating="false"
v-on:object-created="objectCreated($event)"
v-on:load-form="form = $event"
v-on:form-input-p-select="handleSelect($event)"
></p-i-form>
</v-card-text>
</v-card>
</v-flex>
</template>

<script>
import fields from 'phaidra-vue-components/src/utils/fields'
export default {
name: 'add-member',
data () {
return {
parentpid: '',
memberpid: '',
isthumbnail: false,
form: {
sections: [
{
title: '',
id: 1,
type: 'digitalobject',
fields: []
}
]
}
}
},
computed: {
breadcrumbs () {
let bc = [
{
text: this.$t('Search'),
to: { name: 'search', path: '/' }
},
{
text: this.$t('Detailpage') + ' ' + this.parentpid,
to: { name: 'detail', params: { pid: this.parentpid } }
},
{
text: this.$t('Add member of') + ' ' + this.parentpid,
disabled: true
}
]
return bc
},
vocabularies: function () {
return this.$store.state.vocabulary.vocabularies
}
},
methods: {
getResourceTypeFromMimeType: function (mime) {
switch (mime) {
case 'image/jpeg':
case 'image/tiff':
case 'image/gif':
case 'image/png':
case 'image/x-ms-bmp':
// picture
return 'https://pid.phaidra.org/vocabulary/44TN-P1S0'
case 'audio/wav':
case 'audio/mpeg':
case 'audio/flac':
case 'audio/ogg':
// audio
return 'https://pid.phaidra.org/vocabulary/8YB5-1M0J'
case 'application/pdf':
// document
return 'https://pid.phaidra.org/vocabulary/69ZZ-2KGX'
case 'video/mpeg':
case 'video/avi':
case 'video/mp4':
case 'video/quicktime':
case 'video/x-matroska':
// video
return 'https://pid.phaidra.org/vocabulary/B0Y6-GYT8'
// eg application/x-iso9660-image
default:
// data
return 'https://pid.phaidra.org/vocabulary/7AVS-Y482'
}
},
handleSelect: function (val) {
var i
var j
var k
if (val.predicate === 'ebucore:hasMimeType') {
for (i = 0; i < this.form.sections.length; i++) {
var mime
if (this.form.sections[i].fields) {
for (j = 0; j < this.form.sections[i].fields.length; j++) {
if (this.form.sections[i].fields[j].predicate === 'ebucore:hasMimeType') {
mime = this.form.sections[i].fields[j].value
}
}
}
var resourcetype = this.getResourceTypeFromMimeType(mime)
if (this.form.sections[i].fields) {
for (j = 0; j < this.form.sections[i].fields.length; j++) {
if (this.form.sections[i].fields[j].predicate === 'dcterms:type') {
var rt = this.form.sections[i].fields[j]
rt.value = resourcetype
var preflabels
for (k = 0; k < this.vocabularies['resourcetype'].terms.length; k++) {
if (this.vocabularies['resourcetype'].terms[k]['@id'] === rt.value) {
preflabels = this.vocabularies['resourcetype'].terms[k]['skos:prefLabel']
}
}
rt['skos:prefLabel'] = []
Object.entries(preflabels).forEach(([key, value]) => {
rt['skos:prefLabel'].push({ '@value': value, '@language': key })
})
}
}
}
this.form.sections.splice(i, 1, this.form.sections[i])
}
}
},
objectCreated: function (event) {
this.memberpid = event
this.$store.commit('setAlerts', [{ type: 'success', msg: this.$t('Upload successful') + ' ' + event }])
// add membership relation
var self = this
var httpFormData = new FormData()
this.loading = true
httpFormData.append('predicate', 'http://pcdm.org/models#hasMember')
httpFormData.append('object', 'info:fedora/' + self.memberpid)
var url = self.$store.state.settings.instance.api + '/object/' + self.parentpid + '/relationship/add'
var promise = fetch(url, {
method: 'POST',
mode: 'cors',
headers: {
'X-XSRF-TOKEN': self.$store.state.user.token
},
body: httpFormData
})
.then(function (response) { return response.json() })
.then(function (json) {
if (self.isthumbnail) {
httpFormData = new FormData()
httpFormData.append('predicate', 'http://phaidra.org/XML/V1.0/relations#isThumbnailFor')
httpFormData.append('object', 'info:fedora/' + self.parentpid)
url = self.$store.state.settings.instance.api + '/object/' + self.memberpid + '/relationship/add'
var promise2 = fetch(url, {
method: 'POST',
mode: 'cors',
headers: {
'X-XSRF-TOKEN': self.$store.state.user.token
},
body: httpFormData
})
.then(function (response) { return response.json() })
.then(function (json) {
self.loading = false
self.$router.push({ name: 'detail', params: { pid: self.parentpid } })
})
.catch(function (error) {
console.log(error)
})
return promise2
} else {
self.loading = false
self.$router.push({ name: 'detail', params: { pid: self.parentpid } })
}
})
.catch(function (error) {
console.log(error)
})
return promise
}
},
mounted: function () {
var rt = fields.getField('resource-type')
rt.value = 'https://pid.phaidra.org/vocabulary/7AVS-Y482'
this.form.sections[0].fields.push(rt)
this.form.sections[0].fields.push(fields.getField('file'))
this.form.sections[0].fields.push(fields.getField('title'))
this.form.sections[0].fields.push(fields.getField('description'))
var mt = fields.getField('mime-type')
mt.required = true
this.form.sections[0].fields.push(mt)
this.form.sections[0].fields.push(fields.getField('digitization-note'))
this.form.sections[0].fields.push(fields.getField('role'))
this.form.sections[0].fields.push(fields.getField('license'))
this.form.sections[0].fields.push(fields.getField('rights'))
},
beforeRouteEnter: function (to, from, next) {
next(vm => {
vm.parentpid = from.params.pid
})
},
beforeRouteUpdate: function (to, from, next) {
this.parentpid = from.params.pid
}
}
</script>

33 changes: 30 additions & 3 deletions src/components/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<v-flex v-if="dshash['JSON-LD']">
<p-d-jsonld
:jsonld="displayjsonld[doc.pid]"
:jsonld="displayjsonld[doc.pid]" :pid="doc.pid"
></p-d-jsonld>
</v-flex>

Expand All @@ -53,9 +53,28 @@
</center>
<v-card-text class="ma-2">
<p-d-jsonld
:jsonld="displayjsonld[member.pid]"
:jsonld="displayjsonld[member.pid]" :pid="member.pid"
></p-d-jsonld>
</v-card-text>
<v-divider light v-if="canRead"></v-divider>
<v-card-actions class="pa-3" v-if="canRead">
<v-spacer></v-spacer>
<v-btn v-if="member.cmodel === 'Picture'" target="_blank" :href="'https://' + instance.baseurl + '/imageserver/' + member.pid" primary>{{ $t('View') }}</v-btn>
<v-btn :href="getMemberDownloadUrl(member)" primary>{{ $t('Download') }}</v-btn>
<v-menu offset-y v-if="canWrite">
<template v-slot:activator="{ on }">
<v-btn color="primary" dark v-on="on">{{ $t('Edit') }}<v-icon right dark>arrow_drop_down</v-icon></v-btn>
</template>
<v-list>
<v-list-tile :to="{ name: 'metadataeditor', params: { pid: member.pid } }">
<v-list-tile-title>{{ $t('Edit metadata') }}</v-list-tile-title>
</v-list-tile>
<v-list-tile :to="{ name: 'manage', params: { pid: member.pid } }">
<v-list-tile-title>{{ $t('Manage object') }}</v-list-tile-title>
</v-list-tile>
</v-list>
</v-menu>
</v-card-actions>
</v-card>
</v-flex>

Expand Down Expand Up @@ -219,7 +238,7 @@
<v-divider></v-divider>
</v-card>

<v-card flat v-if="canWrite">
<v-card flat v-if="canWrite">
<v-card-text>
<v-layout column>
<v-flex>
Expand All @@ -229,6 +248,7 @@
<v-layout column>
<router-link class="mb-1" :to="{ name: 'metadataeditor' }">{{ $t('Edit metadata') }}</router-link>
<router-link class="mb-1" :to="{ name: 'manage' }">{{ $t('Manage object') }}</router-link>
<router-link class="mb-1" :to="{ name: 'addmember' }">{{ $t('Upload container member') }}</router-link>
</v-layout>
</v-flex>
</v-layout>
Expand Down Expand Up @@ -505,6 +525,13 @@ export default {
.catch(function (error) {
console.log(error)
})
},
getMemberDownloadUrl: function (member) {
if (member.cmodel === 'Asset' || member.cmodel === 'Video') {
return this.instance.fedora + '/objects/' + member.pid + '/methods/bdef:Content/download'
} else {
return this.instance.api + '/object/' + member.pid + '/diss/Content/download'
}
}
},
beforeRouteEnter: function (to, from, next) {
Expand Down
20 changes: 13 additions & 7 deletions src/components/SubmitEmpty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:form="form"
v-on:load-form="form = $event"
v-on:object-created="objectCreated($event)"
v-on:add-phaidrasubject-section="addPhaidrasubjectSection($event)"
></p-i-form>
</v-card-text>
</v-card>
Expand Down Expand Up @@ -127,6 +128,17 @@ export default {
return 'https://pid.phaidra.org/vocabulary/7AVS-Y482'
}
},
addPhaidrasubjectSection: function (afterSection) {
let s = {
title: 'Subject',
type: 'phaidra:Subject',
id: this.form.sections.length + 1,
removable: true,
multiplicable: true,
fields: []
}
this.form.sections.splice(this.form.sections.indexOf(afterSection) + 1, 0, s)
},
objectCreated: function (event) {
this.$store.commit('setAlerts', [{ type: 'success', msg: 'Object ' + event + ' created' }])
this.$router.push({ name: 'detail', params: { pid: event } })
Expand All @@ -137,15 +149,9 @@ export default {
sections: [
{
title: 'Digital object',
type: 'digitalobject',
id: 1,
fields: []
},
{
title: 'Subject',
type: 'phaidra:Subject',
id: 2,
multiplicable: true,
fields: []
}
]
}
Expand Down
Loading

0 comments on commit 678f6ad

Please sign in to comment.