2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
|
|
|
<div class="ngbfujlo">
|
2020-10-17 11:12:00 +00:00
|
|
|
<MkTextarea :value="text" readonly style="margin: 0;"></MkTextarea>
|
|
|
|
<MkButton class="button" primary @click="post()" :disabled="posting || posted"><Fa v-if="posted" :icon="faCheck"/><Fa v-else :icon="faPaperPlane"/></MkButton>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 01:59:05 +00:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
2020-04-19 08:39:54 +00:00
|
|
|
import { faCheck, faPaperPlane } from '@fortawesome/free-solid-svg-icons';
|
2020-01-29 19:37:25 +00:00
|
|
|
import MkTextarea from '../ui/textarea.vue';
|
|
|
|
import MkButton from '../ui/button.vue';
|
2020-10-17 11:12:00 +00:00
|
|
|
import { apiUrl } from '@/config';
|
|
|
|
import * as os from '@/os';
|
2021-01-30 01:59:05 +00:00
|
|
|
import { PostBlock } from '@/scripts/hpml/block';
|
|
|
|
import { Hpml } from '@/scripts/hpml/evaluator';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-01-29 19:37:25 +00:00
|
|
|
components: {
|
|
|
|
MkTextarea,
|
|
|
|
MkButton,
|
|
|
|
},
|
|
|
|
props: {
|
2021-01-30 01:59:05 +00:00
|
|
|
block: {
|
|
|
|
type: Object as PropType<PostBlock>,
|
2020-01-29 19:37:25 +00:00
|
|
|
required: true
|
|
|
|
},
|
2020-04-20 12:35:27 +00:00
|
|
|
hpml: {
|
2021-01-30 01:59:05 +00:00
|
|
|
type: Object as PropType<Hpml>,
|
2020-01-29 19:37:25 +00:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-01-30 01:59:05 +00:00
|
|
|
text: this.hpml.interpolate(this.block.text),
|
2020-01-29 19:37:25 +00:00
|
|
|
posted: false,
|
|
|
|
posting: false,
|
2020-04-19 08:39:54 +00:00
|
|
|
faCheck, faPaperPlane
|
2020-01-29 19:37:25 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2020-04-20 12:35:27 +00:00
|
|
|
'hpml.vars': {
|
2020-01-29 19:37:25 +00:00
|
|
|
handler() {
|
2021-01-30 01:59:05 +00:00
|
|
|
this.text = this.hpml.interpolate(this.block.text);
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-19 00:05:20 +00:00
|
|
|
upload() {
|
2020-10-18 01:11:34 +00:00
|
|
|
const promise = new Promise((ok) => {
|
2021-01-30 01:59:05 +00:00
|
|
|
const canvas = this.hpml.canvases[this.block.canvasId];
|
2020-04-19 00:05:20 +00:00
|
|
|
canvas.toBlob(blob => {
|
|
|
|
const data = new FormData();
|
|
|
|
data.append('file', blob);
|
2020-12-19 01:55:52 +00:00
|
|
|
data.append('i', this.$i.token);
|
|
|
|
if (this.$store.state.uploadFolder) {
|
|
|
|
data.append('folderId', this.$store.state.uploadFolder);
|
2020-04-21 15:34:56 +00:00
|
|
|
}
|
2020-04-19 00:05:20 +00:00
|
|
|
|
|
|
|
fetch(apiUrl + '/drive/files/create', {
|
|
|
|
method: 'POST',
|
|
|
|
body: data
|
|
|
|
})
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(f => {
|
|
|
|
ok(f);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2020-10-18 01:11:34 +00:00
|
|
|
os.promiseDialog(promise);
|
|
|
|
return promise;
|
2020-04-19 00:05:20 +00:00
|
|
|
},
|
|
|
|
async post() {
|
2020-01-29 19:37:25 +00:00
|
|
|
this.posting = true;
|
2021-01-30 01:59:05 +00:00
|
|
|
const file = this.block.attachCanvasImage ? await this.upload() : null;
|
2020-10-17 11:12:00 +00:00
|
|
|
os.apiWithDialog('notes/create', {
|
2020-04-19 08:40:46 +00:00
|
|
|
text: this.text === '' ? null : this.text,
|
2020-04-19 00:05:20 +00:00
|
|
|
fileIds: file ? [file.id] : undefined,
|
2020-01-29 19:37:25 +00:00
|
|
|
}).then(() => {
|
|
|
|
this.posted = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ngbfujlo {
|
2020-04-19 00:05:20 +00:00
|
|
|
position: relative;
|
2020-01-30 22:01:45 +00:00
|
|
|
padding: 32px;
|
2020-01-29 19:37:25 +00:00
|
|
|
border-radius: 6px;
|
2020-01-30 22:01:45 +00:00
|
|
|
box-shadow: 0 2px 8px var(--shadow);
|
2020-04-19 00:05:20 +00:00
|
|
|
z-index: 1;
|
2020-01-30 22:01:45 +00:00
|
|
|
|
|
|
|
> .button {
|
|
|
|
margin-top: 32px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
@media (max-width: 600px) {
|
2020-01-30 22:01:45 +00:00
|
|
|
padding: 16px;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-01-30 22:01:45 +00:00
|
|
|
> .button {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|