SchemaFormWidget.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!--
  2. Copyright 2019 Hackware SpA <human@hackware.cl>
  3. This file is part of "Hackware Userland" and licensed under the terms
  4. of the GNU Affero General Public License version 3, or (at your option)
  5. a later version. You should have received a copy of this license along
  6. with the software. If not, see <https://www.gnu.org/licenses/>.
  7. -->
  8. <template>
  9. <component
  10. :is="widget"
  11. :name="name"
  12. :property="property"
  13. :readonly="isReadOnly"
  14. />
  15. </template>
  16. <script>
  17. import SchemaFormInputWidget from './SchemaFormInputWidget.vue';
  18. import SchemaFormSelectWidget from './SchemaFormSelectWidget.vue';
  19. export default {
  20. name: 'SchemaFormWidget',
  21. components: {
  22. SchemaFormInputWidget,
  23. SchemaFormSelectWidget,
  24. },
  25. props: {
  26. name: {
  27. type: String,
  28. required: true,
  29. },
  30. property: {
  31. type: Object,
  32. required: true,
  33. },
  34. },
  35. computed: {
  36. widget() {
  37. if (this.isSelect) {
  38. return 'SchemaFormSelectWidget';
  39. }
  40. return 'SchemaFormInputWidget';
  41. },
  42. isSelect() {
  43. if ('enum' in this.property || 'oneOf' in this.property) {
  44. return true;
  45. }
  46. return false;
  47. },
  48. isReadOnly() {
  49. return ('readOnly' in this.property) && this.property.readOnly === true;
  50. },
  51. },
  52. };
  53. </script>