OU.vue 10.6 KB
Newer Older
Janis Streib's avatar
Janis Streib committed
1 2 3
<template>
  <div class="oe-overview">
    <h1>Organisationseinheiten</h1>
Janis Streib's avatar
Janis Streib committed
4 5
    <b-checkbox :value="true" :unchecked-value="false" v-model="only_own_oe" switch>Nur eigene Organisationseinheiten
      anzeigen
Janis Streib's avatar
Janis Streib committed
6 7 8
    </b-checkbox>
    <hr/>
    <Loading :data="[ous, mgrs]">
9 10 11 12 13 14 15 16 17 18 19
      <Paginator :items="ous" items_per_page="15">
        <template v-slot:item="card_data">
          <b-card no-body :key="'card-account-' + card_data.item.short_name" class="mb-4 shadow">
            <template v-slot:header>
              <b-row>
                <b-col>
                  <h4>
                    {{ card_data.item.name }} ({{ card_data.item.short_name }})
                  </h4>
                  <p class="text-muted">Organisationseinheit</p>
                </b-col>
Janis Streib's avatar
Janis Streib committed
20 21 22 23 24 25 26 27 28 29 30 31
                <b-col lg="2">
                  <b-button-group class="d-flex">
                    <b-button variant="outline-secondary" :id="'show-evlog-ou-' + card_data.item.short_name"
                              @click="showEvLog(card_data.item)">
                      <font-awesome-icon icon="history"></font-awesome-icon>
                    </b-button>
                    <b-tooltip :target="'show-evlog-ou-' +  card_data.item.short_name" triggers="hover"
                               variant="secondary" placement="bottom">
                      Eventlog
                    </b-tooltip>
                  </b-button-group>
                </b-col>
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
              </b-row>
            </template>
            <b-button block squared variant="outline-secondary" v-b-toggle="card_data.item.short_name + '-collapse'">
              OE-Betreuer<br/>
              <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
            </b-button>
            <b-collapse :id="card_data.item.short_name + '-collapse'">
              <b-table :items="mgrs2ou[card_data.item.short_name]" :fields="ou_list_fields">
                <template v-slot:cell(first_name)="data">
                  {{ mgrs[data.item.mgr_login_name].first_name }}
                </template>
                <template v-slot:cell(last_name)="data">
                  {{ mgrs[data.item.mgr_login_name].last_name }}
                </template>
                <template v-slot:cell(email)="data">
                  <b-link :href="'mailto:'+mgrs[data.item.mgr_login_name].email">
                    {{ mgrs[data.item.mgr_login_name].email }}
                  </b-link>
                </template>
                <template v-slot:head(actions)>
                  <b-button @click="assign_mgr(card_data.item.short_name)" block variant="outline-success"
                            :id="'button-assign-mgr-' +  card_data.item.short_name">
                    <font-awesome-icon :icon="['fas', 'plus']"/>
Janis Streib's avatar
Janis Streib committed
55
                  </b-button>
56 57 58
                  <b-tooltip :target="'button-assign-mgr-' +  card_data.item.short_name" triggers="hover"
                             variant="success" placement="left">
                    Neuen Account zuordnen
Janis Streib's avatar
Janis Streib committed
59
                  </b-tooltip>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
                </template>
                <template v-slot:cell(actions)="data">
                  <b-button-group class="d-flex">
                    <b-button @click="deleteMgrItem(data.item)" variant="outline-danger"
                              :id="'button-unassign-mgr-' +  data.item.bcd_name">
                      <font-awesome-icon :icon="['fas', 'unlink']"></font-awesome-icon>
                    </b-button>
                    <b-tooltip :target="'button-unassign-mgr-' +  data.item.bcd_name" triggers="hover"
                               variant="danger" placement="left">
                      Zuweisung aufheben
                    </b-tooltip>
                  </b-button-group>
                </template>
              </b-table>
            </b-collapse>
Janis Streib's avatar
Janis Streib committed
75 76
            <b-button block squared variant="outline-secondary"
                      v-b-toggle="card_data.item.short_name + '-collapse-domains'">
Janis Streib's avatar
Janis Streib committed
77
              Domains
Janis Streib's avatar
Janis Streib committed
78 79 80 81
              <b-badge pill v-if="fqdns2ou[card_data.item.short_name]">{{
                  fqdns2ou[card_data.item.short_name].length
                }}
              </b-badge>
Janis Streib's avatar
Janis Streib committed
82 83 84 85 86 87 88 89
              <b-badge pill v-else>0</b-badge>
              <br/>
              <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
            </b-button>
            <b-collapse :id="card_data.item.short_name + '-collapse-domains'">
              <b-table :items="fqdns2ou[card_data.item.short_name]" :fields="fqdn_list_fields">
                <template v-slot:head(actions)>
                  <b-button block variant="outline-success"
Janis Streib's avatar
Janis Streib committed
90 91
                            :id="'button-assign-fqdn-' +  card_data.item.short_name"
                            @click="createFqdn2OU(card_data.item.short_name)">
Janis Streib's avatar
Janis Streib committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
                    <font-awesome-icon :icon="['fas', 'plus']"/>
                  </b-button>
                  <b-tooltip :target="'button-assign-fqdn-' +  card_data.item.short_name" triggers="hover"
                             variant="success" placement="left">
                    Neue Domain zuordnen
                  </b-tooltip>
                </template>
                <template v-slot:cell(actions)="data">
                  <b-button-group class="d-flex">
                    <b-button @click="deleteFqdnItem(data.item)" variant="outline-danger"
                              :id="'button-unassign-fqdn-' +  data.item.fqdn_value">
                      <font-awesome-icon :icon="['fas', 'unlink']"></font-awesome-icon>
                    </b-button>
                    <b-tooltip :target="'button-unassign-fqdn-' +  data.item.fqdn_value" triggers="hover"
                               variant="danger" placement="bottom">
                      Zuweisung aufheben
                    </b-tooltip>
                  </b-button-group>
                </template>
              </b-table>
            </b-collapse>
113 114 115
          </b-card>
        </template>
      </Paginator>
116 117 118 119
      <div v-if="!ous || ous.length === 0"
           class="font-italic text-center mb-3">
        Keine Organisationseinheiten vorhanden
      </div>
Janis Streib's avatar
Janis Streib committed
120
    </Loading>
Janis Streib's avatar
Janis Streib committed
121 122 123 124
    <DBEditor modal_id="assign_user_to_oe" object_function="create" object_fq_name="cntl.mgr2ou"
              :presets="db_editor_presets"
              :non_optionals_order="['ou_short_name', 'mgr_login_name']"
              object_title="Konto-zu-Organisationseinheits-Zuordnung"></DBEditor>
Janis Streib's avatar
Janis Streib committed
125 126 127 128
    <DBEditor modal_id="assign_fqdn_to_oe" object_function="create" object_fq_name="dns.fqdn2ou"
              :presets="db_editor_presets"
              :non_optionals_order="['ou_short_name', 'fqdn_value']"
              object_title="Domain-zu-Organisationseinheits-Zuordnung"></DBEditor>
Janis Streib's avatar
Janis Streib committed
129 130
    <EVLogViewer v-if="evlogOu" modal_id="ou_evlog" ref_obj_fq="org.unit" refobj_id_field="short_name"
                 :refobj_id_value="evlogOu.short_name"
Janis Streib's avatar
Janis Streib committed
131
                 :title="'Organisationseinheit: ' + evlogOu.name"></EVLogViewer>
Janis Streib's avatar
Janis Streib committed
132 133 134 135 136 137
  </div>
</template>

<script>
import OUService from '@/api-services/ou.service'
import Loading from '@/components/Loading'
Janis Streib's avatar
Janis Streib committed
138
import EVLogViewer from '@/components/EVLogViewer'
139
import Paginator from '@/components/Paginator'
Janis Streib's avatar
Janis Streib committed
140
import apiutil from '@/util/apiutil'
Janis Streib's avatar
Janis Streib committed
141
import DBEditor from '@/components/DBEditor'
Janis Streib's avatar
Janis Streib committed
142 143
import transactionutil from '@/util/transactionutil'
import Mgr2OuService from '@/api-services.gen/cntl.mgr2ou'
Janis Streib's avatar
Janis Streib committed
144
import FQDN2OuService from '@/api-services.gen/dns.fqdn2ou'
Janis Streib's avatar
Janis Streib committed
145 146 147

export default {
  name: 'OE',
Janis Streib's avatar
Janis Streib committed
148
  components: {DBEditor, Loading, Paginator, EVLogViewer},
Janis Streib's avatar
Janis Streib committed
149 150 151 152 153 154 155 156 157 158
  watch: {
    only_own_oe: {
      immediate: true,
      async handler() {
        await this.refresh()
      }
    }
  },
  data() {
    return {
Janis Streib's avatar
Janis Streib committed
159
      evlogOu: null,
Janis Streib's avatar
Janis Streib committed
160 161
      only_own_oe: true,
      mgrs2ou: null,
Janis Streib's avatar
Janis Streib committed
162
      fqdnss2ou: null,
Janis Streib's avatar
Janis Streib committed
163 164
      mgrs: null,
      ous: null,
Janis Streib's avatar
Janis Streib committed
165
      db_editor_presets: {},
Janis Streib's avatar
Janis Streib committed
166 167 168 169 170 171 172 173 174 175 176 177
      fqdn_list_fields: [
        {
          key: 'fqdn_value',
          label: 'FQDN',
          sortable: true
        },
        {
          key: 'actions',
          label: 'Aktionen',
          sortable: false
        }
      ],
Janis Streib's avatar
Janis Streib committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
      ou_list_fields: [
        {
          key: 'mgr_login_name',
          label: 'Login Name',
          sortable: false
        },
        {
          key: 'first_name',
          label: 'Vorname',
          sortable: false
        },
        {
          key: 'last_name',
          label: 'Nachname',
          sortable: false
        },
        {
          key: 'email',
          label: 'E-Mail',
          sortable: false
        },
        {
          key: 'actions',
          label: 'Aktionen',
          sortable: false
        }
      ]
    }
  },
  methods: {
    async refresh() {
      this.mgrs = this.mgrs2ou = this.ous = null
Janis Streib's avatar
Janis Streib committed
210 211 212 213
      let res = null
      if (this.only_own_oe) {
        res = (await OUService.listOwn(this.$store.state.netdb_axios_config)).data
        this.mgrs2ou = apiutil.dict_of_lists_by_value_of_array(res[2], 'ou_short_name')
Janis Streib's avatar
Janis Streib committed
214
        this.fqdns2ou = apiutil.dict_of_lists_by_value_of_array(res[4], 'ou_short_name')
Janis Streib's avatar
Janis Streib committed
215 216 217 218 219 220
        this.mgrs = apiutil.dict_by_value_of_array(res[3], 'login_name')
        this.ous = res[1]
      } else {
        res = (await OUService.listAll(this.$store.state.netdb_axios_config)).data
        this.mgrs2ou = apiutil.dict_of_lists_by_value_of_array(res[1], 'ou_short_name')
        this.mgrs = apiutil.dict_by_value_of_array(res[2], 'login_name')
Janis Streib's avatar
Janis Streib committed
221
        this.fqdns2ou = apiutil.dict_of_lists_by_value_of_array(res[3], 'ou_short_name')
Janis Streib's avatar
Janis Streib committed
222 223
        this.ous = res[0]
      }
Janis Streib's avatar
Janis Streib committed
224 225
    },
    assign_mgr(oe) {
Janis Streib's avatar
Janis Streib committed
226
      this.db_editor_presets = {ou_short_name: oe}
Janis Streib's avatar
Janis Streib committed
227
      this.$root.$emit('bv::show::modal', 'assign_user_to_oe')
Janis Streib's avatar
Janis Streib committed
228
    },
Janis Streib's avatar
Janis Streib committed
229 230 231 232
    createFqdn2OU(oe) {
      this.db_editor_presets = {ou_short_name: oe}
      this.$root.$emit('bv::show::modal', 'assign_fqdn_to_oe')
    },
Janis Streib's avatar
Janis Streib committed
233
    deleteMgrItem(item) {
234
      const ta = transactionutil.generateDeleteElement('cntl.mgr2ou', Mgr2OuService.deleteParamsList(), item, item.mgr_login_name + ' aus OE ' + item.ou_short_name)
Janis Streib's avatar
Janis Streib committed
235 236 237 238 239
      this.$store.commit('addTransactionElement', ta)
      this.$emit('commited', ta)
      if (!this.isMobile() && !this.$store.state.show_sidebar) {
        this.$store.state.show_sidebar = true
      }
Janis Streib's avatar
Janis Streib committed
240 241 242 243 244 245 246 247
    },
    deleteFqdnItem(item) {
      const ta = transactionutil.generateDeleteElement('dns.fqdn2ou', FQDN2OuService.deleteParamsList(), item, item.fqdn_value + ' aus OE ' + item.ou_short_name)
      this.$store.commit('addTransactionElement', ta)
      this.$emit('commited', ta)
      if (!this.isMobile() && !this.$store.state.show_sidebar) {
        this.$store.state.show_sidebar = true
      }
Janis Streib's avatar
Janis Streib committed
248 249 250 251 252 253
    },
    showEvLog(ou) {
      this.evlogOu = ou
      this.$root.$nextTick(() => {
        this.$root.$emit('bv::show::modal', 'ou_evlog')
      })
Janis Streib's avatar
Janis Streib committed
254 255 256 257 258 259 260 261 262 263 264
    }
  },
  async mounted() {
    await this.refresh()
  }
}
</script>

<style scoped>

</style>