2017-09-17 15:32:39 +00:00
|
|
|
<template>
|
2017-11-04 16:59:48 +00:00
|
|
|
<modal-inner class="modal__inner-1--file-properties" aria-label="File properties">
|
|
|
|
<div class="modal__content">
|
2017-09-23 19:01:50 +00:00
|
|
|
<div class="tabs flex flex--row">
|
2017-10-07 11:22:24 +00:00
|
|
|
<tab :active="tab === 'custom'" @click="tab = 'custom'">
|
2017-09-17 15:32:39 +00:00
|
|
|
Current file properties
|
2017-10-07 11:22:24 +00:00
|
|
|
</tab>
|
|
|
|
<tab :active="tab === 'default'" @click="tab = 'default'">
|
2017-09-17 15:32:39 +00:00
|
|
|
Default properties
|
2017-10-07 11:22:24 +00:00
|
|
|
</tab>
|
|
|
|
</div>
|
|
|
|
<div class="form-entry" v-if="tab === 'custom'" role="tabpanel" aria-label="Current file properties">
|
|
|
|
<label class="form-entry__label">YAML</label>
|
|
|
|
<div class="form-entry__field">
|
|
|
|
<code-editor lang="yaml" :value="customProperties" key="custom-properties" @changed="setCustomProperties"></code-editor>
|
2017-09-17 15:32:39 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-10-07 11:22:24 +00:00
|
|
|
<div class="form-entry" v-else-if="tab === 'default'" role="tabpanel" aria-label="Default properties">
|
2017-09-17 15:32:39 +00:00
|
|
|
<label class="form-entry__label">YAML</label>
|
|
|
|
<div class="form-entry__field">
|
2017-10-07 11:22:24 +00:00
|
|
|
<code-editor lang="yaml" :value="defaultProperties" key="default-properties" disabled="true"></code-editor>
|
2017-09-17 15:32:39 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal__error modal__error--file-properties">{{error}}</div>
|
|
|
|
</div>
|
2017-11-04 16:59:48 +00:00
|
|
|
<div class="modal__button-bar">
|
|
|
|
<button class="button" @click="config.reject()">Cancel</button>
|
|
|
|
<button class="button" @click="resolve()">Ok</button>
|
|
|
|
</div>
|
|
|
|
</modal-inner>
|
2017-09-17 15:32:39 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import yaml from 'js-yaml';
|
2017-09-23 19:01:50 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2017-11-04 16:59:48 +00:00
|
|
|
import ModalInner from './common/ModalInner';
|
|
|
|
import Tab from './common/Tab';
|
2017-09-23 19:01:50 +00:00
|
|
|
import CodeEditor from '../CodeEditor';
|
2017-10-09 07:11:18 +00:00
|
|
|
import utils from '../../services/utils';
|
2017-09-23 19:01:50 +00:00
|
|
|
import defaultProperties from '../../data/defaultFileProperties.yml';
|
2017-09-17 15:32:39 +00:00
|
|
|
|
2017-11-04 16:59:48 +00:00
|
|
|
const emptyProperties = `# Add custom properties for the current file here
|
|
|
|
# to override the default properties.
|
|
|
|
`;
|
2017-09-17 15:32:39 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2017-11-04 16:59:48 +00:00
|
|
|
ModalInner,
|
2017-10-07 11:22:24 +00:00
|
|
|
Tab,
|
2017-09-17 15:32:39 +00:00
|
|
|
CodeEditor,
|
|
|
|
},
|
|
|
|
data: () => ({
|
2017-09-26 22:54:26 +00:00
|
|
|
contentId: null,
|
2017-09-17 15:32:39 +00:00
|
|
|
tab: 'custom',
|
|
|
|
defaultProperties,
|
|
|
|
customProperties: null,
|
|
|
|
error: null,
|
|
|
|
}),
|
|
|
|
computed: {
|
2017-09-23 19:01:50 +00:00
|
|
|
...mapGetters('modal', [
|
2017-09-17 15:32:39 +00:00
|
|
|
'config',
|
|
|
|
]),
|
|
|
|
strippedCustomProperties() {
|
|
|
|
return this.customProperties === emptyProperties ? '\n' : this.customProperties.replace(/\t/g, ' ');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
2017-09-26 22:54:26 +00:00
|
|
|
const content = this.$store.getters['content/current'];
|
|
|
|
this.contentId = content.id;
|
|
|
|
const properties = content.properties;
|
2017-09-17 15:32:39 +00:00
|
|
|
this.setCustomProperties(properties === '\n' ? emptyProperties : properties);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setCustomProperties(value) {
|
|
|
|
this.customProperties = value;
|
|
|
|
try {
|
|
|
|
yaml.safeLoad(this.strippedCustomProperties);
|
|
|
|
this.error = null;
|
|
|
|
} catch (e) {
|
|
|
|
this.error = e.message;
|
|
|
|
}
|
|
|
|
},
|
2017-09-26 22:54:26 +00:00
|
|
|
resolve() {
|
|
|
|
if (!this.error) {
|
|
|
|
this.$store.commit('content/patchItem', {
|
|
|
|
id: this.contentId,
|
2017-10-09 07:11:18 +00:00
|
|
|
properties: utils.sanitizeText(this.strippedCustomProperties),
|
2017-09-26 22:54:26 +00:00
|
|
|
});
|
|
|
|
this.config.resolve();
|
|
|
|
}
|
|
|
|
},
|
2017-09-17 15:32:39 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2017-09-23 19:01:50 +00:00
|
|
|
@import '../common/variables.scss';
|
2017-09-17 15:32:39 +00:00
|
|
|
|
|
|
|
.modal__inner-1--file-properties {
|
|
|
|
max-width: 600px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal__error--file-properties {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
font-family: $font-family-monospace;
|
|
|
|
font-size: $font-size-monospace;
|
|
|
|
}
|
|
|
|
</style>
|