debian-mirror-gitlab/app/assets/javascripts/notebook/cells/output/index.vue

84 lines
1.6 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2019-03-02 22:35:43 +05:30
import CodeOutput from '../code/index.vue';
import HtmlOutput from './html.vue';
import ImageOutput from './image.vue';
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
export default {
props: {
codeCssClass: {
type: String,
required: false,
default: '',
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
count: {
type: Number,
required: false,
default: 0,
2017-08-17 22:00:37 +05:30
},
2019-03-02 22:35:43 +05:30
outputs: {
type: Array,
2019-02-15 15:39:39 +05:30
required: true,
2018-12-13 13:39:08 +05:30
},
},
2019-03-02 22:35:43 +05:30
data() {
return {
outputType: '',
};
},
methods: {
dataForType(output, type) {
let data = output.data[type];
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
if (typeof data === 'object') {
data = data.join('');
2018-12-13 13:39:08 +05:30
}
2019-03-02 22:35:43 +05:30
return data;
2018-12-13 13:39:08 +05:30
},
2019-03-02 22:35:43 +05:30
getComponent(output) {
if (output.text) {
return CodeOutput;
} else if (output.data['image/png']) {
this.outputType = 'image/png';
return ImageOutput;
} else if (output.data['text/html']) {
this.outputType = 'text/html';
return HtmlOutput;
} else if (output.data['image/svg+xml']) {
this.outputType = 'image/svg+xml';
return HtmlOutput;
2018-12-13 13:39:08 +05:30
}
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
this.outputType = 'text/plain';
return CodeOutput;
2017-08-17 22:00:37 +05:30
},
2019-03-02 22:35:43 +05:30
rawCode(output) {
if (output.text) {
return output.text.join('');
2018-12-13 13:39:08 +05:30
}
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
return this.dataForType(output, this.outputType);
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2017-08-17 22:00:37 +05:30
</script>
2018-03-17 18:26:18 +05:30
<template>
2019-03-02 22:35:43 +05:30
<div>
<component
:is="getComponent(output)"
v-for="(output, index) in outputs"
:key="index"
type="output"
:output-type="outputType"
:count="count"
:index="index"
:raw-code="rawCode(output)"
:code-css-class="codeCssClass"
/>
</div>
2018-03-17 18:26:18 +05:30
</template>