All files / components/Admin AdminHeader.vue

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 50 51 52 53 54 55 56 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 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                                                                                                                        1x   1x   1x 2x                                                                                                                 1x                                                          
<template>
  <div
    class="
      header
      bg-white
      row
      w-100
      justify-content-between
      align-items-center
      m-0
      py-3
    "
  >
    <div
      class="
        left-side
        col-lg-3 col-sm-5 col-6
        d-flex
        align-items-center
        font-italic
      "
    >
      <div ref="menuButton" class="d-flex d-md-none pl-3">
        <BurgerMenuButton
          :isOpenMenu="isOpenMenu"
          v-on:isOpenMenu="$emit('isOpenMenuHeader', !isOpenMenu)"
          colorBlack
        />
      </div>
      <h5 class="px-3 m-0" v-on:click="$router.push(`/admin`)">strff</h5>
      <span class="p-1">{{ getDate() }}</span>
    </div>
    <div
      class="
        col-lg-5 col-sm-3 col-4
        d-flex
        align-items-center
        position-relative
      "
    ></div>
    <div class="col-sm-3 col-1 d-flex justify-content-end">
      <div
        class="
          user-name
          justify-content-end
          d-sm-flex d-none
          align-items-center
        "
      >
        <span class="text-ellipsis px-3 align-items-center p-0">
          {{ (user && user.username) || "user" }}
        </span>
      </div>
      <BDropdown id="dropdown-1" right :text="shortUserName()" class="m-md-2">
        <BDropdownItem v-on:click="exit">logout</BDropdownItem>
        <BDropdownItem v-on:click="profile">profile</BDropdownItem>
      </BDropdown>
    </div>
  </div>
</template>
 
<script>
import { mapGetters, mapActions } from "vuex";
 
import { getSeason } from "~/helpers";
import BurgerMenuButton from "~/components/common/BurgerMenuButton.vue";
 
export default {
  name: "AdminHeader",
  components: { BurgerMenuButton },
  props: {
    isOpenMenu: Boolean,
  },
  data: () => ({
    text: "",
    isMobile: true,
  }),
  computed: {
    ...mapGetters({ user: "auth/user" }),
  },
  methods: {
    getSeason,
    ...mapActions({ logout: "auth/logout" }),
    exit: function () {
      this.logout();
      this.$router.push("/admin/login");
    },
    profile: function () {
      const { fullPath } = this.$route;
      this.$router.push({
        name: "admin-profile",
        params: { backUrl: fullPath },
      });
      //this.$router.push("/admin/profile");
    },
    shortUserName: function () {
      if (this.user) {
        const { username, first_name, last_name } = this.user;
 
        if (username) {
          return username[0];
        }
 
        const first = first_name ? first_name[0] : "";
        const last = last_name ? first_name[0] : "";
 
        if (!first && !last) {
          return `u`;
        }
 
        return `${first} ${last}`.trim();
      }
      return "u";
    },
    getDate: function () {
      const date = new Date();
 
      const year = date.getFullYear();
 
      return `${this.getSeason(date)} ${year}`;
    },
  },
};
</script>
 
<style scoped>
.header {
  border-bottom: 1px solid #000;
}
 
.left-side > span {
  font-size: 0.7rem;
  border: 1px solid #000;
  border-radius: 5px;
}
 
input {
  position: relative;
  border: 1px solid #000;
  border-radius: 5px;
  padding-left: 30px;
}
 
.search-icon {
  z-index: 1;
  left: 1.4rem;
}
 
.user-name {
  width: calc(100% - 54px);
}
</style>