index.vue 3.4 KB
Newer Older
Johannes Edmeier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
  - Copyright 2014-2018 the original author or authors.
  -
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
  -->

<template>
18 19 20 21 22 23 24 25 26
  <section class="section">
    <div class="container">
      <div v-if="error" class="message is-warning">
        <div class="message-body">
          <strong>
            <font-awesome-icon class="has-text-warning" icon="exclamation-triangle"/>
            Server connection failed.
          </strong>
          <p v-text="error.message"/>
Johannes Edmeier committed
27
        </div>
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 55 56 57 58 59 60 61
      </div>
      <div class="level">
        <div class="level-item has-text-centered">
          <div>
            <p class="heading">Applications</p>
            <p class="title" v-text="applicationsCount">1</p>
          </div>
        </div>
        <div class="level-item has-text-centered">
          <div>
            <p class="heading">Instances</p>
            <p class="title" v-text="instancesCount">1</p>
          </div>
        </div>
        <div class="level-item has-text-centered">
          <div v-if="downCount === 0">
            <p class="heading">Status</p>
            <p class="title has-text-success">all up</p>
          </div>
          <div v-else>
            <p class="heading">instances down</p>
            <p class="title has-text-danger" v-text="downCount"/>
          </div>
        </div>
      </div>
      <div v-for="group in statusGroups" :key="group.status">
        <p class="heading" v-text="group.status"/>
        <applications-list :applications="group.applications"/>
      </div>
      <div v-if="statusGroups.length === 0">
        <p class="is-muted">No applications registered.</p>
      </div>
    </div>
  </section>
Johannes Edmeier committed
62 63 64 65
</template>

<script>
  import * as _ from 'lodash';
66
  import applicationsList from './applications-list';
67
  import handle from './handle';
Johannes Edmeier committed
68

69
  const component = {
Johannes Edmeier committed
70 71 72 73
    components: {
      applicationsList,
    },
    computed: {
Johannes Edmeier committed
74
      applications() {
75
        return this.$root.applications;
Johannes Edmeier committed
76
      },
77 78
      error() {
        return this.$root.error;
79
      },
Johannes Edmeier committed
80
      statusGroups() {
Johannes Edmeier committed
81
        const byStatus = _.groupBy(this.applications, application => application.status);
Johannes Edmeier committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        const list = _.transform(byStatus, (result, value, key) => {
          result.push({status: key, applications: value})
        }, []);
        return _.sortBy(list, [item => item.status]);
      },
      applicationsCount() {
        return this.applications.length;
      },
      instancesCount() {
        return this.applications.reduce((current, next) => current + next.instances.length, 0);
      },
      downCount() {
        return this.applications.reduce((current, next) => {
          return current + (next.instances.filter(instance => instance.statusInfo.status !== 'UP').length);
        }, 0);
      }
    },
99
    methods: {}
100
  };
Johannes Edmeier committed
101

102 103 104 105 106 107 108 109
  export default component;
  export const view = {
    path: '/applications',
    name: 'applications',
    handle: handle,
    order: 0,
    component: component
  };
110
</script>