Schema.vue 5.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<template>
  <div id="Schema">
    <div id="schema-main-div">
      <div v-if="!this.isLoading">
        <div class="container ml-5 mr-2">
          <div class="row">
            <div :class="classCollapsedMenu">
              <div class="mb-3 pull-right">
                <button @click="collapsed = !collapsed" type="button" class="btn main-button mb-5">
                  <span v-show="collapsed"><span class="chevron-toggle">&#8594;</span>  Ouvrir le panneau</span>
                  <span v-show="!collapsed"><span class="chevron-toggle">&#8592;</span>  Fermer le panneau</span>
                </button>
              </div>
              <div v-show="!collapsed">
                <h2 class="mb-5">Catégories</h2>
                <ul>
                  <li v-for="(category_value, id) in categories" :key="id">
                    <a href="#" :class="{selected: category==id}" @click="setCategory(id);">
                      {{ category_value.charAt(0).toUpperCase() + category_value.slice(1) }}
                    </a>
                  </li>
                </ul>
              </div>
            </div>
            <div v-show="!collapsed" :class="classCollapsedSeparator">
              <hr class="schema-vertical-separator">
            </div>
            <div :class="classCollapsedContent">
              <div v-if="this.show">
                <h2 class="mb-5">{{ this.categories[category] }} </h2>
                <dl v-for="(schema_row,id) in this.filteredSchema" :key="id">
                  <dt v-if="schema_row.label"> {{schema_row.label.charAt(0).toUpperCase() + schema_row.label.slice(1)}} <a :href="'#schema/'+id" class=anchor>#</a></dt>
                  <dt v-else> {{ schema_row.description }} <a :href="'#schema/'+id" class=anchor>#</a></dt>
                  <dd v-if="schema_row.value"><strong>Valeur constante :</strong> {{ formatValue(schema_row.value) }}</dd>
                  <dd v-if="schema_row.description"><strong>Description :</strong> {{schema_row.description}}</dd>
                  <dd v-if="schema_row.source"><strong>Source :</strong> {{schema_row.source}}</dd>
                  <dd v-if="schema_row.xpath"><strong>LHEO :</strong> {{schema_row.xpath}}</dd>
                  <dd v-if="schema_row.url"><strong>Ressource externe :</strong> <a :href="schema_row.url">{{ schema_row.url }}</a></dd>
                  <dd v-if="schema_row.enum">
                    <strong>Valeurs possibles</strong>
                    <ul>
                      <li v-for="(enum_label, enum_key) in schema_row.enum" :key="enum_key">{{ enum_key }} : {{ enum_label }}</li>
                    </ul>
                  </dd>
                  <dd><strong>Clé interne :</strong> {{ id }}</dd>
                  <dd><strong>Type interne :</strong> {{ schema_row.type }}</dd>
                </dl>
              </div>
              <div v-else>
50
                <h4 class="mt-5">Sélectionnez une catégorie dans le menu.</h4>
51 52 53 54 55 56
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-else class="text-center loading-gif">
57
        <img src="@/assets/images/loading.gif" alt="loading...">
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    name: 'Schema',
    data : function () {
      return {
        isLoading: true,
        schema: {},
        category: "",
        categories: {
          aide: 'Propriétés d\'aides',
          constante: 'Propriétés constantes',
          beneficiaire: 'Propriétés du bénéficiaire',
          formation: 'Propriétés de la formation',
          financement: 'Propriétés du financement',
76
          remuneration: 'Propriétés de rémunération',
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        },
        collapsed: false,
      }
    },
    computed: {
      show: function () {
        return this.category != ""
      },
      classCollapsedContent: function () {
        if(this.collapsed) return "col-md-12 col-sm-12 col-xs-12";
        return "col-md-8 col-sm-12 col-xs-12";
      },
      classCollapsedMenu: function () {
        if(this.collapsed) return "col-md-0 col-sm-0 col-xs-0";
        return "col-md-3 col-sm-12 col-xs-12";
      },
      classCollapsedSeparator: function () {
        if(this.collapsed) return "col-md-0 col-sm-0 col-xs-0";
        return "col-md-1 col-sm-0 col-xs-0";
      },
      filteredSchema: function () {
        var filteredSchema = [];
        if (this.show) {
          for(var i=0; i< Object.keys(this.schema).length; i++) {
            var schema_value = Object.keys(this.schema)[i];
            if (schema_value.split('.')[0]==this.category) filteredSchema.push(this.schema[schema_value]);
          }
        }
        return filteredSchema
      }
    },
    mounted: function () {
      this.load();
    },
    methods: {
      load : function () {
        this.$http.get('/explore/schema').then(response => {
          this.schema = response.body;
          this.isLoading=false;
        });
      },
      setCategory: function (category) {
        this.category = category;
      },
      formatValue: function (value) {
        if (Array.isArray(value)) return value.join(', ')
        return value
      }
    }
  }
</script>

<style scoped>
  #schema-main-div {
    padding-top: 3rem;
  }
  .schema-vertical-separator {
    border:         none;
    border-left:    1px solid #bfbfbf;
    height:         95%;
    width:          1px;
  }
  .selected {
    font-weight: bold;
  }
  .anchor {
    font-weight: normal;
    font-style: italic;
  }
  dl:target {
    background-color: #ddd;
  }
  dt {
    font-weight: bolder;
  }
  dt em {
    font-variant: normal;
  }
  dl {
    margin-top: 10px;
    font-size: 1.1em;
    padding: 5px;
  }
  dl:nth-child(even) {
    background: #f3f3f3;
  }
  dd {
    padding-left: 2.5rem;
  }
</style>