Add document upload to project entry
This commit is contained in:
parent
244f7405f6
commit
d7a3dd74c2
File diff suppressed because it is too large
Load Diff
|
|
@ -2,46 +2,24 @@
|
||||||
<div class="document-form" ref="documentform">
|
<div class="document-form" ref="documentform">
|
||||||
<div v-if="!value.url" ref="uploadcare-panel"></div>
|
<div v-if="!value.url" ref="uploadcare-panel"></div>
|
||||||
<div v-if="value.url">
|
<div v-if="value.url">
|
||||||
<a :href="previewUrl">{{previewUrl}}</a>
|
<a :href="previewUrl" target="_blank">{{previewUrl}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import uploadcare from 'uploadcare-widget';
|
import {uploadcare} from '@/helpers/uploadcare';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
props: ['value', 'index'],
|
props: ['value', 'index'],
|
||||||
mounted() {
|
mounted() {
|
||||||
const uploadcarePanel = uploadcare.openPanel(this.$refs['uploadcare-panel'], null, {
|
uploadcare(this, url => {
|
||||||
tabs: ['file'],
|
this.$emit('link-change-url', url, this.index)
|
||||||
});
|
|
||||||
|
|
||||||
// HACK to change the text of the Uploadcare dynamically we need to change the text here directly
|
|
||||||
setTimeout(() => {
|
|
||||||
const formElem = this.$refs['documentform'];
|
|
||||||
if (formElem.getElementsByClassName('uploadcare--text_size_extra-large').length > 1) {
|
|
||||||
formElem.getElementsByClassName('uploadcare--text_size_extra-large')[1].innerText = 'Ziehen Sie ein Dokument hier hinein';
|
|
||||||
formElem.getElementsByClassName('uploadcare--tab__action-button')[0].innerText = 'Wählen Sie ein lokales Dokument';
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
uploadcarePanel.done(panelResult => {
|
|
||||||
panelResult.done(fileInfo => {
|
|
||||||
let urlWithFilename = fileInfo.cdnUrl + fileInfo.name;
|
|
||||||
this.$emit('link-change-url', urlWithFilename, this.index)
|
|
||||||
});
|
|
||||||
|
|
||||||
panelResult.progress(p => {
|
|
||||||
});
|
|
||||||
|
|
||||||
panelResult.fail(uploadResult => {
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
previewUrl: function() {
|
previewUrl: function () {
|
||||||
if (this.value && this.value.url) {
|
if (this.value && this.value.url) {
|
||||||
return this.value.url;
|
return this.value.url;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<text-form-with-help-text title="Nächste Schritte" :value="nextSteps" @change="nextSteps = $event"
|
<text-form-with-help-text title="Nächste Schritte" :value="nextSteps" @change="nextSteps = $event"
|
||||||
help-text="Wie geht es weiter? Wer macht was?">
|
help-text="Wie geht es weiter? Wer macht was?">
|
||||||
</text-form-with-help-text>
|
</text-form-with-help-text>
|
||||||
|
<document-form :value="document" :index="0" @link-change-url="setDocumentUrl"></document-form>
|
||||||
</div>
|
</div>
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
<a class="button button--primary" data-cy="modal-save-button" v-on:click="save">Speichern</a>
|
<a class="button button--primary" data-cy="modal-save-button" v-on:click="save">Speichern</a>
|
||||||
|
|
@ -24,9 +25,11 @@
|
||||||
|
|
||||||
import NEW_PROJECT_ENTRY_MUTATION from '@/graphql/gql/mutations/addProjectEntry.gql';
|
import NEW_PROJECT_ENTRY_MUTATION from '@/graphql/gql/mutations/addProjectEntry.gql';
|
||||||
import PROJECT_QUERY from '@/graphql/gql/projectQuery.gql';
|
import PROJECT_QUERY from '@/graphql/gql/projectQuery.gql';
|
||||||
|
import DocumentForm from '@/components/content-forms/DocumentForm';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
DocumentForm,
|
||||||
Modal,
|
Modal,
|
||||||
TextFormWithHelpText
|
TextFormWithHelpText
|
||||||
},
|
},
|
||||||
|
|
@ -37,10 +40,18 @@
|
||||||
},
|
},
|
||||||
slug() {
|
slug() {
|
||||||
return this.$route.params.slug;
|
return this.$route.params.slug;
|
||||||
|
},
|
||||||
|
document() {
|
||||||
|
return this.documentUrl > '' ? {
|
||||||
|
url: this.documentUrl
|
||||||
|
} : {};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
setDocumentUrl(url) {
|
||||||
|
this.documentUrl = url;
|
||||||
|
},
|
||||||
save() {
|
save() {
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
mutation: NEW_PROJECT_ENTRY_MUTATION,
|
mutation: NEW_PROJECT_ENTRY_MUTATION,
|
||||||
|
|
@ -50,6 +61,7 @@
|
||||||
nextSteps: this.nextSteps,
|
nextSteps: this.nextSteps,
|
||||||
activity: this.activity,
|
activity: this.activity,
|
||||||
reflection: this.reflection,
|
reflection: this.reflection,
|
||||||
|
documentUrl: this.documentUrl,
|
||||||
project: this.project
|
project: this.project
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +92,8 @@
|
||||||
return {
|
return {
|
||||||
activity: '',
|
activity: '',
|
||||||
reflection: '',
|
reflection: '',
|
||||||
nextSteps: ''
|
nextSteps: '',
|
||||||
|
documentUrl: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
<p class="project-entry__paragraph">
|
<p class="project-entry__paragraph">
|
||||||
{{nextSteps}}
|
{{nextSteps}}
|
||||||
</p>
|
</p>
|
||||||
|
<p class="project-entry__paragraph" v-if="documentUrl">
|
||||||
|
<a target="_blank" class="project-entry__link" :href="documentUrl">Dokument anzeigen</a>
|
||||||
|
</p>
|
||||||
<div class="project-entry__date">
|
<div class="project-entry__date">
|
||||||
{{created | date }}
|
{{created | date }}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -22,13 +25,14 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: ['activity', 'reflection', 'nextSteps', 'created']
|
props: ['activity', 'reflection', 'nextSteps', 'documentUrl', 'created']
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@import "@/styles/_variables.scss";
|
@import "@/styles/_variables.scss";
|
||||||
@import "@/styles/_functions.scss";
|
@import "@/styles/_functions.scss";
|
||||||
|
@import "@/styles/_mixins.scss";
|
||||||
|
|
||||||
.project-entry {
|
.project-entry {
|
||||||
background-color: $color-white;
|
background-color: $color-white;
|
||||||
|
|
@ -49,5 +53,10 @@
|
||||||
color: $color-grey;
|
color: $color-grey;
|
||||||
font-size: toRem(17px);
|
font-size: toRem(17px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__link {
|
||||||
|
cursor: pointer;
|
||||||
|
@include heading-4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,6 @@ fragment ProjectEntryParts on ProjectEntryNode {
|
||||||
activity
|
activity
|
||||||
reflection
|
reflection
|
||||||
nextSteps
|
nextSteps
|
||||||
|
documentUrl
|
||||||
created
|
created
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import uploadcareWidget from 'uploadcare-widget';
|
||||||
|
|
||||||
|
export const uploadcare = (component, callback) => { // callback with signature parameter `url`
|
||||||
|
const uploadcarePanel = uploadcareWidget.openPanel(component.$refs['uploadcare-panel'], null, {
|
||||||
|
tabs: ['file'],
|
||||||
|
});
|
||||||
|
|
||||||
|
// HACK to change the text of the Uploadcare dynamically we need to change the text here directly
|
||||||
|
setTimeout(() => {
|
||||||
|
const formElem = component.$refs['documentform'];
|
||||||
|
if (formElem.getElementsByClassName('uploadcare--text_size_extra-large').length > 1) {
|
||||||
|
formElem.getElementsByClassName('uploadcare--text_size_extra-large')[1].innerText = 'Ziehen Sie ein Dokument hier hinein';
|
||||||
|
formElem.getElementsByClassName('uploadcare--tab__action-button')[0].innerText = 'Wählen Sie ein lokales Dokument';
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return uploadcarePanel.done(panelResult => {
|
||||||
|
panelResult.done(fileInfo => {
|
||||||
|
let urlWithFilename = fileInfo.cdnUrl + fileInfo.name;
|
||||||
|
callback(urlWithFilename);
|
||||||
|
});
|
||||||
|
|
||||||
|
panelResult.progress(p => {
|
||||||
|
});
|
||||||
|
|
||||||
|
panelResult.fail(uploadResult => {
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -22,6 +22,7 @@ class ProjectEntryInput(InputObjectType):
|
||||||
activity = graphene.String()
|
activity = graphene.String()
|
||||||
reflection = graphene.String()
|
reflection = graphene.String()
|
||||||
next_steps = graphene.String()
|
next_steps = graphene.String()
|
||||||
|
document_url = graphene.String()
|
||||||
|
|
||||||
|
|
||||||
class AddProjectEntryArgument(ProjectEntryInput):
|
class AddProjectEntryArgument(ProjectEntryInput):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.0.6 on 2019-04-24 08:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('portfolio', '0003_auto_20190325_1452'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='projectentry',
|
||||||
|
name='document_url',
|
||||||
|
field=models.TextField(blank=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -17,6 +17,7 @@ class ProjectEntry(models.Model):
|
||||||
activity = models.TextField(blank=True)
|
activity = models.TextField(blank=True)
|
||||||
reflection = models.TextField(blank=True)
|
reflection = models.TextField(blank=True)
|
||||||
next_steps = models.TextField(blank=True)
|
next_steps = models.TextField(blank=True)
|
||||||
|
document_url = models.TextField(blank=True)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
project = models.ForeignKey(Project, related_name='entries', on_delete=models.CASCADE)
|
project = models.ForeignKey(Project, related_name='entries', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ class ProjectSerializer(serializers.ModelSerializer):
|
||||||
class ProjectEntrySerializer(serializers.ModelSerializer):
|
class ProjectEntrySerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProjectEntry
|
model = ProjectEntry
|
||||||
fields = ('id', 'activity', 'reflection', 'next_steps', 'created', 'project')
|
fields = ('id', 'activity', 'reflection', 'next_steps', 'document_url', 'created', 'project')
|
||||||
read_only_fields = ('id', 'created',)
|
read_only_fields = ('id', 'created',)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue