Manager.vue 3.09 KB
Newer Older
Yadd's avatar
Yadd committed
1 2 3 4 5 6 7 8
<template>
  <div id="app">
    <vue-tree-nav
      :location="$route.fullPath"
      v-bind="treeNav"
    >
    </vue-tree-nav>
    <div style="height:70px">
Yadd's avatar
Yadd committed
9
    <router-view :struct="struct" v-bind:formdata.sync="formdata" @update="reset('Default')"/>
Yadd's avatar
Yadd committed
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 50 51 52 53 54
    </div>
  </div>
</template>

<script>
/** Configuration app
 *
 * Components:
 *  - vue-tree-nav: menu
 *  - forms: collection of forms to manage configuration items
 *           (loaded via routes)
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import treeNav from '@/components/menu.vue'
import colorschema from '@/colorschema.json'
import struct from '@/manager/struct.json'
import forms from '@/manager/Forms.vue'
import menu from '@/manager/menu.json'
import translator from '@/translate.js'

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/latest',
    },
    {
      path: '*',
      component: forms,
    }
  ]
});

export default {
  router: router,
  name: 'App',
  components: {
    'vue-tree-nav': treeNav,
  },
  data: function() {
    return {
      // vue-tree-nav data
      f: {schema: 'Default'},
      treeNav: {},
Yadd's avatar
Yadd committed
55 56
      formdata: {
        prefix: 'latest'
Yadd's avatar
Yadd committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
      },
      schemas: Object.keys(colorschema),
      // forms data: share struct.json
      struct: struct,
      translate: translator.translate,
      translateP: translator.translateP,
    }
  },
  mounted: function () {
    // menu initialization
    const me = this
    translator.setLanguage().then(function() {
      translator.translateJ(struct)
      me.reset('Default')
    })
    this.reset('Default')
    this.$data.f.side = JSON.stringify(this.$data.treeNav.side, undefined, 2)
    this.$data.f.left = JSON.stringify(this.$data.treeNav.left, undefined, 2)
    this.$data.f.right = JSON.stringify(this.$data.treeNav.right, undefined, 2)
  },
  watch: {
    'this.$data.index': 'reset',
  },
  methods: {
    // menu initialization
    reset: function (schema) {
      console.debug('reset()')
      var b = colorschema[schema]
      b['style'] = 'position:fixed;width:100%;top:0;'+(b['style'] ? b['style'] : '')
      Object.keys(b).forEach(key => {
        this.$set(this.$data.treeNav, key, b[key])
      })

Yadd's avatar
Yadd committed
90
      this.$set(this.$data.treeNav, 'prefix', this.formdata.prefix)
Yadd's avatar
Yadd committed
91
      console.debug('set menu prefix', this.$data.treeNav.prefix)
Yadd's avatar
Yadd committed
92 93 94 95 96 97
      this.$set(this.$data.treeNav, 'showPath', false)
      this.$set(this.$data.treeNav, 'sideScale', 1)
      this.$set(this.$data.treeNav, 'barScale', 1)
      this.$set(this.$data.treeNav, 'left', menu)
      this.$set(this.$data.treeNav, 'right', [
        {
Christophe Maudoux's avatar
Menu  
Christophe Maudoux committed
98
          href: 'https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng',
Yadd's avatar
Yadd committed
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
          icon: 'brands/github'
        }
      ])
      this.$set(this.$data.treeNav, 'side', struct)
    },
  },
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
fieldset {
  margin: 40px;
}
th, td {
  padding: 5px;
}
textarea {
  width: 100%;
}
img {
  margin: auto;
}
button {
  margin-left: 10px;
}
</style>