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

85 lines
1.7 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
methods: {
2019-07-07 11:18:12 +05:30
outputType(output) {
if (output.text) {
return 'text/plain';
} else if (output.data['image/png']) {
return 'image/png';
} else if (output.data['text/html']) {
return 'text/html';
} else if (output.data['image/svg+xml']) {
return 'image/svg+xml';
}
return 'text/plain';
},
2019-03-02 22:35:43 +05:30
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']) {
return ImageOutput;
} else if (output.data['text/html']) {
return HtmlOutput;
} else if (output.data['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
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-07-07 11:18:12 +05:30
return this.dataForType(output, this.outputType(output));
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"
2019-07-07 11:18:12 +05:30
:output-type="outputType(output)"
2019-03-02 22:35:43 +05:30
:count="count"
:index="index"
:raw-code="rawCode(output)"
:code-css-class="codeCssClass"
/>
</div>
2018-03-17 18:26:18 +05:30
</template>