All files / ui/src/components Header.vue

0% Statements 0/36
0% Branches 0/10
0% Functions 0/6
0% Lines 0/36

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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
<template>
  <div class="container">
    <nav class="navbar navbar-expand-md navbar-dark">
      <span class="logo">MARYVILLE GUIDE</span>
      <button
        class="navbar-toggler"
        data-toggle="collapse"
        data-target="#expandNav"
      >
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="expandNav">
        <div class="navbar-nav ml-auto">
          <router-link to="/" tag="button">
            <button class="button" v-if="!null">Home</button>
          </router-link>
 
          <button
            class="button"
            style="width: 60px"
            v-if="authenticated && !this.loading"
            data-toggle="modal"
            data-target="#edit"
          >
            Edit
          </button>
 
          <div
            class="modal fade"
            id="edit"
            tabindex="-1"
            role="dialog"
            aria-labelledby="editModalLabel"
            aria-hidden="true"
          >
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="editModalLabel">
                    Enter Passcode to Edit Location
                  </h5>
                  <button
                    type="button"
                    class="close"
                    data-dismiss="modal"
                    aria-label="Cancel"
                  >
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <label for="passcode" class="col-form-label">Passcode:</label>
                  <input
                    type="password"
                    class="form-control"
                    id="passcode"
                    v-model="passcode"
                  />
                </div>
                <div class="modal-footer">
                  <button
                    type="button"
                    class="btn btn-secondary"
                    data-dismiss="modal"
                  >
                    Cancel
                  </button>
                  <button
                    type="button"
                    class="btn btn-primary"
                    data-dismiss="modal"
                    @click="editLocation()"
                  >
                    Edit
                  </button>
                </div>
              </div>
            </div>
          </div>
 
          <button
            class="button"
            style="width: 60px"
            v-if="authenticated && !this.loading"
            data-toggle="modal"
            data-target="#delete"
          >
            Delete
          </button>
 
          <div
            class="modal fade"
            id="delete"
            tabindex="-1"
            role="dialog"
            aria-labelledby="deleteModalLabel"
            aria-hidden="true"
          >
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabel">
                    Enter Passcode to Delete Location
                  </h5>
                  <button
                    type="button"
                    class="close"
                    data-dismiss="modal"
                    aria-label="Cancel"
                  >
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <label for="passcode" class="col-form-label">Passcode:</label>
                  <input
                    type="password"
                    class="form-control"
                    id="passcode"
                    v-model="passcode"
                  />
                </div>
                <div class="modal-footer">
                  <button
                    type="button"
                    class="btn btn-secondary"
                    data-dismiss="modal"
                  >
                    Cancel
                  </button>
                  <button
                    type="button"
                    class="btn btn-danger"
                    data-dismiss="modal"
                    @click="deleteLocation"
                  >
                    Delete
                  </button>
                </div>
              </div>
            </div>
          </div>
 
          <router-link to="/addLocation" tag="button">
            <button class="button" v-if="authenticated && !this.loading">
              Add
            </button>
          </router-link>
          <router-link
            to="/SignUp"
            tag="button"
            v-if="!authenticated && !this.loading"
          >
            <button class="button">Sign Up</button>
          </router-link>
 
          <button
            class="button"
            style="width: 60px"
            @click="login"
            v-if="!authenticated && !this.loading"
          >
            Login
          </button>
 
          <button
            class="button"
            style="width: 60px"
            @click="logout"
            v-if="authenticated && !this.loading"
          >
            Logout
          </button>
        </div>
      </div>
    </nav>
  </div>
</template>
 
<script>
import router from "../router";
import LocationService from "../LocationService";
export default {
  name: "Header",
  data() {
    return {
      auth0: null,
      data: null,
      loading: true,
      authenticated: false,
      passcode: "",
    };
  },
 
  /**
   * @vuese
   * Checks whether a user is authenticated or not, everytime the app is reloaded.
   */
  async mounted() {
    this.auth0 = await this.$auth0;
 
    this.data = await this.auth0.getUser();
 
    if (this.data == undefined) {
      this.authenticated = false;
    } else {
      this.authenticated = true;
    }
 
    this.loading = false;
 
    console.log("mounted auth0", this.auth0);
    console.log("mounted data", this.data);
    console.log("mounted aunthenti", this.authenticated);
  },
  // await this.user.loginWithPopup({});
 
  // this.data = await this.user.getUser();
 
  // console.log(this.data);
 
  methods: {
    /**
     * @vuese
     * Logs in the user using GitHub and auth0.
     */
    async login() {
      try {
        await this.auth0.loginWithPopup({});
      } catch (e) {
        window.alert("Login Cancelled");
      }
 
      this.data = await this.auth0.getUser();
 
      console.log("login data", this.data);
 
      if (this.data == undefined) {
        this.authenticated = false;
      } else {
        this.authenticated = true;
      }
    },
 
    /**
     * @vuese
     * Logs out the users.
     */
    async logout() {
      await this.auth0.logout({});
 
      this.data = await this.auth0.getUser();
 
      if (this.data == undefined) {
        this.authenticated = false;
      } else {
        this.authenticated = true;
      }
    },
 
    /**
     * @vuese
     * Delets the current location from the database.
     */
    async deleteLocation() {
      if (this.passcode === "123") {
        const currentLocation = await JSON.parse(
          sessionStorage.getItem("currentLocation")
        );
        await LocationService.deleteLocation(currentLocation);
        sessionStorage.removeItem("currentLocation");
        window.alert("Location Deleted Successfully");
        router.go("/");
      } else {
        window.alert("Invalid Passcode");
      }
    },
 
    /**
     * @vuese
     * Redirects the user to edit page.
     */
    async editLocation() {
      if (this.passcode === "123") {
        await router.push("/editLocation");
      } else {
        window.alert("Invalid Passcode");
      }
    },
  },
};
</script>
 
<style scoped>
.container {
  margin-top: 1rem;
  margin-bottom: 2rem;
}
 
.button {
  font-weight: bold;
  padding: 0.5rem;
  font-size: 0.8rem;
  min-width: fit-content;
  /* width: 60px; */
  margin: 0.5rem;
  border: none;
  outline: none;
  border-radius: 12px;
  background-color: #e0e5ec;
  box-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
    -9px -9px 16px rgba(255, 255, 255, 0.5);
  transition: box-shadow 500ms;
}
 
.button:hover {
  box-shadow: inset 9px 9px 16px rgb(163, 177, 198, 0.6),
    inset -9px -9px 16px rgba(255, 255, 255, 0.5);
}
 
.navbar-toggler:focus,
.navbar-toggler:active {
  outline: none;
  border: none;
}
 
.navbar-dark .navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(1,1,1, 2)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}
 
.logo {
  color: #363233;
  font-size: 1.4rem;
  font-family: Luminari, fantasy;
  font-weight: 100;
  text-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
    -9px -9px 16px rgba(255, 255, 255, 0.5);
}
</style>