BCDRecords.vue 27.8 KB
Newer Older
1
<template>
Robert's avatar
Robert committed
2 3 4 5
  <div id="bcd-records">
    <Loading :data="[range]">
      <template v-if="range"> <!-- TODO: Fix Loading.. this shouldn't be necessary -->
        <h1 class="my-4">
Janis Streib's avatar
Janis Streib committed
6 7 8
          {{ range.name }} <small class="text-muted">Broadcastdomain</small>
        </h1>
        <div style="margin-bottom: 1.5rem">
9
          <b-button variant="outline-primary" @click="editBCD">
Janis Streib's avatar
Janis Streib committed
10 11 12 13 14 15 16 17
            BCD Bearbeiten
            <font-awesome-icon :icon="['far', 'edit']"></font-awesome-icon>
          </b-button>
          <b-button style="margin-left: 15px" variant="outline-secondary" @click="$bvModal.show('evlog_bcd')">
            Eventlog
            <font-awesome-icon icon="history"></font-awesome-icon>
          </b-button>
        </div>
Robert's avatar
Robert committed
18
        <b-row>
Janis Streib's avatar
Janis Streib committed
19
          <b-col cols="2" order="1" class="d-none d-lg-block bottom-space">
20 21
            <Loading style="top:75px" class="shadow sticky-top" :data="[loaded]">
              <b-list-group v-if="record_types" v-b-scrollspy="{offset: 250}">
Janis Streib's avatar
Janis Streib committed
22 23 24 25 26
                <b-list-group-item href="#overview" @click="scrollIntoView($event,0, 'overview')" class="text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[0]" :icon="['fas','chevron-left']"/>
                    </transition>
Janis Streib's avatar
Janis Streib committed
27
                    Broadcastdomain
Janis Streib's avatar
Janis Streib committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
                  </div>
                </b-list-group-item>
                <b-list-group-item href="#reserved" @click="scrollIntoView($event,1, 'reserved')"
                                   class="d-flex justify-content-between align-items-center text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[1]" :icon="['fas','chevron-left']"/>
                    </transition>
                    Reservierte Adressen
                  </div>
                  <b-badge variant="primary" pill>{{ reservedAddrCount }}</b-badge>
                </b-list-group-item>
                <b-list-group-item v-for="(record_type, index) in record_types" :key="record_type"
                                   :href="'#' + record_type + '-records'"
                                   @click="scrollIntoView($event,2+index, record_type+'-records')"
                                   class="d-flex justify-content-between align-items-center text-primary">
                  <div>
                    <transition name="squish">
                      <font-awesome-icon v-if="collapse_states[2+index]" :icon="['fas','chevron-left']"/>
                    </transition>
                    {{ record_type }} Records
                  </div>
                  <b-badge variant="primary" pill>{{ records[record_type].length }}</b-badge>
                </b-list-group-item>
52 53
              </b-list-group>
            </Loading>
Robert's avatar
Robert committed
54
          </b-col>
Janis Streib's avatar
Janis Streib committed
55
          <b-col cols="10" cols-lg="12">
Robert's avatar
Robert committed
56 57
            <b-card class="shadow mb-4" no-body :id="collapse_states[0] ? 'overview' : 'not-overview'">
              <b-card-header v-b-toggle:overview-collapse class="collapse-header">
Janis Streib's avatar
Janis Streib committed
58
                <h5>Broadcastdomain</h5>
Robert's avatar
Robert committed
59 60 61 62 63 64 65
                <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
              </b-card-header>
              <b-card-body body-class="p-0">
                <b-collapse id="overview-collapse" v-model="collapse_states[0]">
                  <b-table-simple responsive class="m-0" striped>
                    <b-tr>
                      <b-th>
Janis Streib's avatar
Janis Streib committed
66
                        Broadcastdomain-Name
Robert's avatar
Robert committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
                      </b-th>
                      <b-td>
                        {{ range.name }}
                      </b-td>
                    </b-tr>
                    <b-tr>
                      <b-th>
                        Beschreibung
                      </b-th>
                      <b-td>
                        {{ range.description }}
                      </b-td>
                    </b-tr>
                    <b-tr>
                      <b-th>
                        Organisationseinheit
                      </b-th>
                      <b-td>
85
                        {{ ou.name }} ({{ ou.short_name }})
Robert's avatar
Robert committed
86 87
                      </b-td>
                    </b-tr>
Janis Streib's avatar
Janis Streib committed
88 89 90
                    <b-tr>
                      <b-th>Betreuer/Administratoren</b-th>
                      <b-td>
Janis Streib's avatar
Janis Streib committed
91
                        <template v-if="parent_ous.length > 0">
Janis Streib's avatar
Janis Streib committed
92
                          Durch (übergeordnete) OEs:
Janis Streib's avatar
Janis Streib committed
93 94 95 96 97 98 99 100 101
                          <ul>
                            <li v-for="pou in parent_ous" v-bind:key="pou.short_name">
                              <b>{{ pou.name }} ({{ pou.short_name }})</b>
                              <ul>
                                <li v-for="mgr in parent_oe2mgr[pou.short_name]" v-bind:key="mgr.mgr_login_name">
                                  <b-link :href="'mailto:'+parent_oe_mgr[mgr.mgr_login_name].email">
                                    {{ parent_oe_mgr[mgr.mgr_login_name].first_name }}
                                    {{ parent_oe_mgr[mgr.mgr_login_name].last_name }}
                                  </b-link>
102
                                  ({{ mgr.mgr_login_name }})
Janis Streib's avatar
Janis Streib committed
103 104 105 106 107
                                </li>
                              </ul>
                            </li>
                          </ul>
                        </template>
Janis Streib's avatar
Janis Streib committed
108 109 110
                        Durch Gruppenzuordnungen:
                        <ul>
                          <li v-for="grp in bcd_groups" v-bind:key="grp.group_name">
Janis Streib's avatar
Janis Streib committed
111
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
112
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
113
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
Janis Streib's avatar
Janis Streib committed
114 115 116 117 118 119
                            <ul>
                              <li v-for="mgr in group2mgrs[grp.group_name]" v-bind:key="mgr.mgr_login_name">
                                <b-link :href="'mailto:'+group_mgrs[mgr.mgr_login_name].email">
                                  {{ group_mgrs[mgr.mgr_login_name].first_name }}
                                  {{ group_mgrs[mgr.mgr_login_name].last_name }}
                                </b-link>
120
                                ({{ mgr.mgr_login_name }})
Janis Streib's avatar
Janis Streib committed
121 122 123 124 125 126
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
Janis Streib's avatar
Janis Streib committed
127 128 129 130 131 132
                    <b-tr>
                      <b-th>Domains</b-th>
                      <b-td>
                        Durch Gruppenzuordnungen:
                        <ul>
                          <li v-for="grp in bcd_groups" v-bind:key="grp.group_name">
Janis Streib's avatar
Janis Streib committed
133
                            <b :title="groups[grp.group_name].description">{{ grp.group_name }} </b>
134
                            <b-badge v-if="groups[grp.group_name].is_admin" variant="danger">Admin</b-badge>
135
                            <b-badge v-if="groups[grp.group_name].is_own" variant="success">Mitglied</b-badge>
Janis Streib's avatar
Janis Streib committed
136 137
                            <ul>
                              <li v-for="fqdn in fqdns2group[grp.group_name]" v-bind:key="fqdn.fqdn_value">
Janis Streib's avatar
Janis Streib committed
138
                                <b-link :to="'/dnsvs/fqdns/'+fqdn.fqdn_value">{{ fqdn.fqdn_value }}</b-link>
Janis Streib's avatar
Janis Streib committed
139 140 141 142 143 144
                              </li>
                            </ul>
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
Robert's avatar
Robert committed
145 146 147 148 149 150 151 152
                    <b-tr>
                      <b-th>
                        Subnetz{{ subnets.length > 1 ? 'e' : '' }}
                      </b-th>
                      <b-td>
                        <code v-for="subnet in subnets" :key="subnet.cidr">{{ subnet.cidr }}<br></code>
                      </b-td>
                    </b-tr>
153 154 155 156 157 158 159 160 161 162 163 164
                    <b-tr>
                      <b-th>
                        VLANs
                      </b-th>
                      <b-td>
                        <ul>
                          <li v-for="vlan in vlans" :key="vlan.id" :title="vlan.net_instnc">{{ vlan.name }}
                            ({{ vlan.id }})
                          </li>
                        </ul>
                      </b-td>
                    </b-tr>
Janis Streib's avatar
Janis Streib committed
165 166 167 168
                    <b-tr>
                      <b-th>NATVS-Bereich</b-th>
                      <b-td>
                        <b-link
Janis Streib's avatar
Janis Streib committed
169 170
                          target="_blank"
                          :href="$sysinfo.host_oper_mode.is_prod?`https://www-net.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/`:`https://www-net-${$sysinfo.host_oper_mode.mode}.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/`"
Janis Streib's avatar
Janis Streib committed
171
                        >{{ range.name }}
Janis Streib's avatar
Janis Streib committed
172
                        </b-link>
Janis Streib's avatar
Janis Streib committed
173 174
                      </b-td>
                    </b-tr>
Janis Streib's avatar
Janis Streib committed
175 176 177 178 179 180
                    <b-tr>
                      <b-th>Gateways</b-th>
                      <b-td>
                        <code v-for="g in gateways" v-bind:key="g.ip_addr">{{ g.ip_addr }}<br/></code>
                      </b-td>
                    </b-tr>
Robert's avatar
Robert committed
181 182 183 184 185 186 187 188 189 190 191
                  </b-table-simple>
                </b-collapse>
              </b-card-body>
            </b-card>
            <b-card class="shadow mb-4" no-body :id="collapse_states[1] ? 'reserved' : 'not-reserved'">
              <b-card-header v-b-toggle:reserved-collapse class="collapse-header">
                <h5>Reservierte Adressen</h5>
                <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
              </b-card-header>
              <b-card-body body-class="p-0">
                <b-collapse id="reserved-collapse" v-model="collapse_states[1]">
192 193 194 195 196
                  <b-pagination v-if="loaded && reserved_addrs.length > per_page" :per_page="per_page"
                                align="center" v-model="current_page['_reserved']"
                                :total-rows="reserved_addrs.length"></b-pagination>
                  <b-table :items="reserved_addrs" :fields="reserved_addrs_list_fields" :per-page="per_page"
                           :current-page="current_page['_reserved']">
Janis Streib's avatar
Janis Streib committed
197
                    <template v-slot:cell(value)="data">
198 199
                      <code>{{ data.item.value }}</code>
                      <b-badge v-if="data.item.is_dhcp">DHCP</b-badge>
Janis Streib's avatar
Janis Streib committed
200 201
                    </template>
                  </b-table>
202 203 204
                  <b-pagination v-if="loaded && reserved_addrs.length > per_page" :per_page="per_page"
                                align="center" v-model="current_page['_reserved']"
                                :total-rows="reserved_addrs.length"></b-pagination>
Robert's avatar
Robert committed
205 206 207
                </b-collapse>
              </b-card-body>
            </b-card>
Janis Streib's avatar
Janis Streib committed
208 209 210 211 212 213 214 215 216 217
            <Loading :data="[record_types]">
              <b-card class="shadow mb-4" no-body
                      v-for="(record_type, index) in record_types" :key="record_type"
                      :id="collapse_states[2+index]?record_type+'-records':'not-'+record_type+'-records'">
                <b-card-header v-b-toggle="'records-'+record_type+'-collapse'" class="collapse-header">
                  <h5>{{ record_type }} Records</h5>
                  <font-awesome-icon class="collapse-icon" :icon="['fas','chevron-down']"/>
                </b-card-header>
                <b-card-body body-class="p-0">
                  <b-collapse :id="'records-'+record_type+'-collapse'" v-model="collapse_states[2+index]">
218 219
                    <FilterInput v-model="filter[record_type]"></FilterInput>
                    <b-pagination v-if="(!(record_type in filter) || filter[record_type] === '')&& loaded && records[record_type].length > per_page" :per_page="per_page"
Janis Streib's avatar
Janis Streib committed
220
                                  align="center" v-model="current_page[record_type]"
Janis Streib's avatar
Janis Streib committed
221
                                  :total-rows="records[record_type].length"></b-pagination>
222 223
                    <b-table responsive :filter="filter[record_type]" :items="records[record_type]"
                             :per-page="(!(record_type in filter) || filter[record_type] === '') ? per_page : null"
Janis Streib's avatar
Janis Streib committed
224 225
                             :current-page="current_page[record_type]"
                             :fields="record_list_fields">
Janis Streib's avatar
Janis Streib committed
226
                      <template v-slot:cell(fqdn)="data">
Janis Streib's avatar
Janis Streib committed
227
                        {{ data.item.fqdn }}
Janis Streib's avatar
Janis Streib committed
228 229
                        <b-badge variant="primary" v-if="data.item.fqdn_type === 'domain'">Domain</b-badge>
                      </template>
Janis Streib's avatar
Janis Streib committed
230 231 232 233 234 235 236 237 238 239 240 241
                      <template v-slot:cell(info)="data">
                        <b-dropdown>
                          <template v-slot:button-content>
                            <font-awesome-icon :icon="['fas', 'info-circle']"></font-awesome-icon>
                          </template>
                          <b-dropdown-item :to="'/dnsvs/fqdns/' + data.item.fqdn + '/records'">Records auf FQDN
                          </b-dropdown-item>
                          <b-dropdown-item :to="'/dnsvs/fqdns/' + data.item.fqdn + '/references'">Referenzen auf FQDN
                          </b-dropdown-item>
                        </b-dropdown>
                      </template>
                      <template v-slot:cell(data)="data">
242 243
                        <code>{{ data.value }} </code>
                        <b-badge v-if="!data.item.target_is_singleton" variant="warning">RR-Set</b-badge>
Janis Streib's avatar
Janis Streib committed
244
                        <b-badge v-if="data.item.host_is_nws" variant="primary"
Janis Streib's avatar
Janis Streib committed
245
                                 :href="$sysinfo.host_oper_mode.is_prod?`https://www-net.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/nat_index.html`:`https://www-net-${$sysinfo.host_oper_mode.mode}.scc.kit.edu/~netadmin/natvs/user/wrapper.cgi/${range.name}/0/${range.name}/0/nat_index.html`"
Janis Streib's avatar
Janis Streib committed
246 247
                                 title="Host besitzt einen NATVS-Eintrag">NATVS
                        </b-badge>
248
                        <b-badge v-if="data.item.target_is_reverse_unique" title="Rückwärts-eindeutig">PTR</b-badge>
Janis Streib's avatar
Janis Streib committed
249 250 251
                      </template>
                      <template v-slot:cell(actions)="data">
                        <b-button-group>
252 253 254 255 256 257
                          <b-dropdown @click="editItem(data.item)" split variant="outline-primary">
                            <template #button-content>
                              <font-awesome-icon :icon="['far', 'edit']"></font-awesome-icon>
                            </template>
                            <b-dropdown-item @click="editFQDN(fqdns[data.item.fqdn])">FQDN Bearbeiten</b-dropdown-item>
                          </b-dropdown>
258 259 260 261 262 263 264 265 266
                          <b-dropdown @click="deleteItem(data.item, false)" split variant="outline-danger">
                            <template #button-content>
                              <font-awesome-icon :icon="['far', 'trash-alt']"></font-awesome-icon>
                            </template>
                            <b-dropdown-item @click="deleteItem(data.item, true)">Falls FQDN gelöscht wird: Alle den
                              FQDN referenzierende Records
                              mitlöschen
                            </b-dropdown-item>
                          </b-dropdown>
Janis Streib's avatar
Janis Streib committed
267 268 269 270 271 272 273 274 275 276 277
                        </b-button-group>
                      </template>
                      <template v-slot:cell(ttl)="data">
                        <template v-if="data.item.ttl != null">{{ data.item.ttl }}s</template>
                        <span v-else title="Geerbt von Zone"
                              class="text-black-50">{{ data.item.ttl_zone_default }}s</span>
                        <span v-if="data.item.ttl_reset_days"
                              class="text-danger"><br/>Reset in {{ data.item.ttl_reset_days }} Tagen</span>
                      </template>
                      <template v-slot:head(actions)>
                        <b-button block variant="outline-success"
278 279
                                  :id="'button-create-record-' +  record_type" @click="createItem(record_type)"
                                  v-if="user_possible_record_types.includes(record_type)">
Janis Streib's avatar
Janis Streib committed
280
                          <font-awesome-icon :icon="['fas', 'plus']"/>
281
                        </b-button>
Janis Streib's avatar
Janis Streib committed
282
                        <b-tooltip :target="'button-create-record-' +  record_type" triggers="hover"
Janis Streib's avatar
Janis Streib committed
283 284 285 286 287
                                   variant="success" placement="left">
                          Neuen Record anlegen
                        </b-tooltip>
                      </template>
                    </b-table>
288
                    <b-pagination v-if="(!(record_type in filter) || filter[record_type] === '') && loaded && records[record_type].length > per_page" :per_page="per_page"
Janis Streib's avatar
Janis Streib committed
289
                                  align="center" v-model="current_page[record_type]"
Janis Streib's avatar
Janis Streib committed
290
                                  :total-rows="records[record_type].length"></b-pagination>
Janis Streib's avatar
Janis Streib committed
291 292 293 294
                  </b-collapse>
                </b-card-body>
              </b-card>
            </Loading>
Robert's avatar
Robert committed
295 296 297
          </b-col>
        </b-row>
      </template>
Janis Streib's avatar
Janis Streib committed
298 299 300
      <DBEditor :presets="db_editor_presets" :input_reducer="create_record_reducer" modal_id="create_record"
                :object_title="object_title"
                :object_function="db_editor_function" object_fq_name="dns.record" :old_data="db_editor_old_data"
Janis Streib's avatar
Janis Streib committed
301 302 303 304 305
                :non_optionals_order="['fqdn', 'type', 'data', 'fqdn_description', 'target_is_singleton', 'target_is_reverse_unique']">
      </DBEditor>
      <DBEditor :presets="range" modal_id="edit_bcd"
                :object_title="object_title"
                object_function="update" object_fq_name="nd.bcd" :old_data="db_editor_old_data"
Janis Streib's avatar
Janis Streib committed
306
                :non_optionals_order="['description']">
Janis Streib's avatar
Janis Streib committed
307
      </DBEditor>
308 309 310 311 312
      <DBEditor :presets="db_editor_presets" modal_id="edit_fqdn"
                :object_title="object_title" :input_reducer="full_edit_fqdn_reducer"
                object_function="update" object_fq_name="dns.fqdn" :old_data="db_editor_old_data"
                :non_optionals_order="['value', 'description']">
      </DBEditor>
313
      <EVLogViewer v-if="range" modal_id="evlog_bcd" :title="'BCD \''+ range.name + '\''"
Janis Streib's avatar
Janis Streib committed
314
                   ref_obj_fq="nd.bcd" refobj_id_field="name_list" :refobj_id_value="[range.name]"></EVLogViewer>
Robert's avatar
Robert committed
315 316
    </Loading>
  </div>
317 318 319
</template>

<script>
Janis Streib's avatar
Janis Streib committed
320 321
import RangeService from '@/api-services/dns_bcd.service'
import RecordService from '@/api-services.gen/dns.record'
Robert's avatar
Robert committed
322
import Loading from '../../components/Loading'
Janis Streib's avatar
Janis Streib committed
323 324
import DBEditor from '../../components/DBEditor'
import transactionutil from '@/util/transactionutil'
325
import apiutil from '@/util/apiutil'
Janis Streib's avatar
Janis Streib committed
326
import EVLogViewer from '@/components/EVLogViewer'
327
import ipaddress from '@/util/ipaddress'
328
import FilterInput from '@/components/FilterInput'
329

Janis Streib's avatar
Janis Streib committed
330 331
export default {
  name: 'BCDRecords',
332
  components: {FilterInput, EVLogViewer, Loading, DBEditor},
333
  data() {
Janis Streib's avatar
Janis Streib committed
334
    return {
335
      filter: {},
336
      vlans: null,
337
      fqdns: null,
338
      groups: null,
Janis Streib's avatar
Janis Streib committed
339
      gateways: null,
Janis Streib's avatar
Janis Streib committed
340 341
      parent_oe2mgr: null,
      parent_oe_mgr: null,
Janis Streib's avatar
Janis Streib committed
342 343
      bcd_groups: null,
      group2mgrs: null,
Janis Streib's avatar
Janis Streib committed
344
      fqdns2group: null,
Janis Streib's avatar
Janis Streib committed
345
      group_mgrs: null,
346
      user_possible_record_types: [],
Janis Streib's avatar
Janis Streib committed
347 348 349
      loaded: null,
      per_page: 50,
      current_page: {},
350
      full_create_record_reducer: undefined,
351
      full_edit_fqdn_reducer: undefined,
Janis Streib's avatar
Janis Streib committed
352 353 354
      create_record_reducer: undefined,
      object_title: null,
      db_editor_function: 'create',
355
      db_editor_presets: {fqdn: this.fqdn},
Janis Streib's avatar
Janis Streib committed
356
      db_editor_old_data: {},
Janis Streib's avatar
Janis Streib committed
357
      range: null,
Robert's avatar
Robert committed
358 359
      subnets: null,
      ou: null,
Janis Streib's avatar
Janis Streib committed
360
      parent_ous: null,
Janis Streib's avatar
Janis Streib committed
361
      reserved_addrs: null,
Janis Streib's avatar
Janis Streib committed
362
      records: null,
Robert's avatar
Robert committed
363
      record_types: null,
364
      record_types_by_name: null,
Janis Streib's avatar
Janis Streib committed
365
      collapse_states: [true],
Janis Streib's avatar
Janis Streib committed
366 367 368 369 370 371 372 373
      reserved_addrs_list_fields: [
        {
          label: 'Adresse',
          key: 'value',
          sortable: false // TODO: Sort function
        }

      ],
Janis Streib's avatar
Janis Streib committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
      record_list_fields: [
        {
          label: 'FQDN',
          key: 'fqdn',
          sortable: true
        },
        {
          label: 'Weitere Info',
          key: 'info',
          sortable: false
        },
        {
          label: 'FQDN-Beschreibung',
          key: 'fqdn_description',
          sortable: true
        },
        {
          label: 'Record-Data',
          key: 'data',
393
          sortable: false
Janis Streib's avatar
Janis Streib committed
394 395 396 397 398 399 400 401 402 403 404 405
        },
        {
          label: 'TTL',
          key: 'ttl',
          sortable: true
        },
        {
          label: 'Aktionen',
          key: 'actions',
          sortable: false
        }
      ]
Janis Streib's avatar
Janis Streib committed
406 407
    }
  },
Robert's avatar
Robert committed
408
  computed: {
409
    reservedAddrCount() {
Robert's avatar
Robert committed
410 411 412
      let count = 0
      for (let i = 0; i < this.subnets.length; i++) {
        count += this.subnets[i].dns_addr_rsv_count
Janis Streib's avatar
Janis Streib committed
413
      }
Robert's avatar
Robert committed
414 415 416
      return count
    }
  },
417
  created() {
Robert's avatar
Robert committed
418 419
    this.fetchData()
  },
420 421 422 423 424 425
  watch: {
    $route() {
      this.range = null
      this.fetchData()
    }
  },
Robert's avatar
Robert committed
426
  methods: {
427 428 429 430 431 432 433
    deleteItem: function (item, force_del_ref_records) {
      const itc = {}
      Object.assign(itc, item)
      itc.force_del_ref_records = force_del_ref_records
      const ta = transactionutil.generateDeleteElement('dns.record', RecordService.deleteParamsList(), itc,
        item.type + '-Record auf FQDN ' + item.fqdn +
        (force_del_ref_records ? ' Falls der FQDN gelöscht wird, werden auch alle ihn referenzierenden DNS-Resource-Records automatisch gelöscht.' : ''))
Janis Streib's avatar
Janis Streib committed
434 435 436 437 438 439
      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
440 441 442 443 444 445
    editBCD: function () {
      this.db_editor_old_data = this.range
      this.db_editor_presets = this.range
      this.object_title = this.range.name
      this.$root.$emit('bv::show::modal', 'edit_bcd')
    },
Janis Streib's avatar
Janis Streib committed
446 447 448 449 450
    editItem: function (item) {
      this.db_editor_function = 'update'
      this.db_editor_old_data = item
      this.db_editor_presets = item
      this.object_title = item.type + '-Record auf FQDN ' + item.fqdn
451
      this.create_record_reducer = {fqdn: false}
Janis Streib's avatar
Janis Streib committed
452 453
      this.$root.$emit('bv::show::modal', 'create_record')
    },
454 455 456 457 458 459 460
    editFQDN: function (item) {
      this.db_editor_function = 'update'
      this.db_editor_old_data = item
      this.db_editor_presets = item
      this.object_title = 'FQDN ' + item.value
      this.$root.$emit('bv::show::modal', 'edit_fqdn')
    },
461
    createItem: function (record_type) {
Janis Streib's avatar
Janis Streib committed
462 463
      this.db_editor_function = 'create'
      this.db_editor_old_data = {}
464 465 466 467 468 469
      const recobj = this.record_types_by_name[record_type]
      this.db_editor_presets = {
        type: record_type,
        target_is_singleton: recobj.target_is_singleton_dflt,
        target_is_reverse_unique: recobj.target_is_reverse_unique_dflt
      }
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
      if (record_type === 'A') {
        let sub = null
        let multi = false
        this.subnets.forEach((item) => {
          if (item.type === '4') {
            if (sub !== null) {
              multi = true
            }
            sub = item
          }
          if (sub !== null && !multi) {
            const first = ipaddress.ip_net_get_first(sub.cidr)
            const last = ipaddress.ip_net_get_last(sub.cidr)
            let index = 0
            while (first.slice(0, index) === last.slice(0, index)) {
              index++
            }
            this.db_editor_presets.data = first.slice(0, index)
          }
        })
      } else if (record_type === 'AAAA') {
        let sub = null
        let multi = false
        this.subnets.forEach((item) => {
          if (item.type === '6') {
            if (sub !== null) {
              multi = true
            }
            sub = item
          }
        })
        if (sub !== null && !multi) {
          this.db_editor_presets.data = sub.cidr.split('/')[0]
        }
      }
505
      this.create_record_reducer = {type: false}
Janis Streib's avatar
Janis Streib committed
506 507
      this.$root.$emit('bv::show::modal', 'create_record')
    },
508
    async fetchData() {
Janis Streib's avatar
Janis Streib committed
509
      this.loaded = null
510 511 512 513
      const rangeResponse = await RangeService.getDetail(this.$store.state.netdb_axios_config, this.$route.params.name)
      this.range = rangeResponse.data[0][0]
      this.ou = rangeResponse.data[1][0]
      this.subnets = rangeResponse.data[2]
Janis Streib's avatar
Janis Streib committed
514
      this.reserved_addrs = rangeResponse.data[3]
Janis Streib's avatar
Janis Streib committed
515 516 517 518 519 520 521 522 523 524
      this.bcd_groups = rangeResponse.data[4]
      this.group2mgrs = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[6], 'group_name')
      this.group_mgrs = apiutil.dict_by_value_of_array(rangeResponse.data[7], 'login_name')
      this.gateways = apiutil.dict_by_value_of_array(rangeResponse.data[11], 'ip_addr')
      this.fqdns2group = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[12], 'group_name')
      this.groups = apiutil.dict_by_value_of_array(rangeResponse.data[5], 'name')
      this.parent_ous = rangeResponse.data[13]
      this.parent_oe2mgr = apiutil.dict_of_lists_by_value_of_array(rangeResponse.data[14], 'ou_short_name')
      this.parent_oe_mgr = apiutil.dict_by_value_of_array(rangeResponse.data[15], 'login_name')
      this.vlans = rangeResponse.data[16]
Robert's avatar
Robert committed
525

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
      const recordQuery = await RangeService.getRecords(this.$store.state.netdb_axios_config, this.$route.params.name)
      this.fqdns = apiutil.dict_by_value_of_array(recordQuery.data[1], 'value')
      this.record_types_by_name = apiutil.dict_by_value_of_array(recordQuery.data[3], 'name')
      const types = recordQuery.data[2]
      const selections = {}
      const fqdnSelections = {}
      for (const t of types) {
        selections[t.record_type] = {display_name: t.record_type}
      }
      for (const t of recordQuery.data[4]) {
        let disp_name = t.description
        disp_name += ' ['
        disp_name += t.is_nonterminal ? 'nicht-terminal' : 'terminal'
        disp_name += ']'
        fqdnSelections[t.name] = {display_name: disp_name}
      }
      this.full_edit_fqdn_reducer = {
        type: fqdnSelections
      }
      this.full_create_record_reducer = {
        type: selections
      }

      this.records = apiutil.dict_of_lists_by_value_of_array(recordQuery.data[0], 'type')
550 551
      this.record_types = Object.keys(this.records)
      for (let i = 0; i < this.record_types.length; i++) {
Janis Streib's avatar
Janis Streib committed
552
        if (!(this.record_types[i] in this.current_page)) {
553
          this.$root.$set(this.current_page, this.record_types[i], 1)
Janis Streib's avatar
Janis Streib committed
554
        }
555 556 557 558 559
        if (this.record_types[i] in this.records) {
          continue
        }
        this.records[this.record_types[i]] = []
      }
560
      for (const inttype of types) {
561 562 563
        if (!this.user_possible_record_types.includes(inttype.record_type)) {
          this.user_possible_record_types.push(inttype.record_type)
        }
564 565 566 567 568 569 570
        if (inttype.record_type in this.records) {
          continue
        }
        this.record_types.push(inttype.record_type)
        this.records[inttype.record_type] = []
      }
      this.record_types.sort()
Janis Streib's avatar
Janis Streib committed
571
      this.loaded = true
Janis Streib's avatar
Janis Streib committed
572
    },
Robert's avatar
Robert committed
573

574
    scrollIntoView(e, index, id) {
Robert's avatar
Robert committed
575 576 577 578 579 580 581 582 583 584 585 586
      e.preventDefault()
      let target = document.getElementById(id)
      if (e.target.classList.contains('active') || e.target.parentElement.classList.contains('active')) {
        this.$set(this.collapse_states, index, false)
      } else {
        if (target) {
          const offset = window.innerWidth > 1200 ? 140 : 410
          window.scrollTo({left: window.scrollX, top: target.offsetTop + offset, behavior: 'smooth'})
        } else {
          target = document.getElementById('not-' + id)
          this.$set(this.collapse_states, index, true)
          const offset = window.innerWidth > 1200 ? 140 : 410
587 588 589 590 591
          setTimeout(() => window.scrollTo({
            left: window.scrollX,
            top: target.offsetTop + offset,
            behavior: 'smooth'
          }), 350)
Janis Streib's avatar
Janis Streib committed
592 593 594
        }
      }
    }
Robert's avatar
Robert committed
595
  }
Janis Streib's avatar
Janis Streib committed
596
}
597
</script>
Robert's avatar
Robert committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623

<style scoped>
.list-group-item.active {
  color: white !important;
}

.collapse-icon {
  position: absolute;
  top: 20px;
  right: 20px;

  transition: transform;
  transition-duration: 250ms;
}

.not-collapsed > .collapse-icon {
  transform: rotate(-180deg);
}

.bottom-space {
  padding-bottom: 200px;
}

.squish-enter-active, .squish-leave-active {
  transition: width 250ms, padding-left 250ms, padding-right 250ms;
}
624

Robert's avatar
Robert committed
625 626 627 628 629 630 631
.squish-enter, .squish-leave-to {
  width: 0;
  padding-right: 0;
  padding-left: 0;
}

</style>