<commit_before>/* Copyright 2020 Google LLC 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 https://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>
  <div>
    <NavBarCustomer></NavBarCustomer>
    <cookieinfo></cookieinfo>
    <cookieackno></cookieackno>
    <div class="card">
      <div class="card-content">
        <p class="title">{{shopinfo.shop.shopName}}</p>
        <p
          v-if="isTokenInCookie"
          class="title"
        >Number of People ahead in the queue are: {{tokeninfo.customersAhead}}</p>
        <p
          v-else
          class="title"
        >Number of people currently in queue are {{shopinfo.customersInQueue}}</p>
        <p v-if="totalWaitingTime != 0" class="title">Approx. waiting time is: {{totalWaitingTime}} mins</p>
        <p class="subtitle">{{shopinfo.shop.shopType}}</p>
        <p class="subtitle">{{shopinfo.shop.address}}</p>
        <p class="subtitle">{{shopinfo.shop.phoneNumber}}</p>
      </div>
      <footer class="card-footer">
        <p class="card-footer-item">
          <button
            class="button is-primary is-medium"
            v-if="isTokenInCookie"
            v-on:click="getShopInfo()"
          >Refresh token</button>
          <button class="button is-primary is-medium" v-else v-on:click="getToken()">Take token</button>
        </p>
        <p class="card-footer-item">
          <button
            class="button is-danger is-medium"
            v-on:click="deleteToken()"
            v-if="isTokenInCookie"
          >Cancel token</button>
        </p>
      </footer>
      <div v-if="isTokenInCookie">
        <div v-if="tokeninfo.customersAhead == 0">
          <shopTurn></shopTurn>
        </div>
      </div>
      <div v-if="!isTokenActive">
        <statusUpdate></statusUpdate>
      </div>
      <div v-if="isTokenInCookie">
        <div class="panel panel-default">
          <div class="table-responsive">
            <table class="table">
              <caption>
                <h1 style="margin: 20px 0" class="is-vcentered">Your Token information</h1>
              </caption>
              <thead>
                <th id="head">Token Number</th>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <a>{{tokeninfo.token.tokenNumber}}</a>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import NavBarCustomer from "@/components/NavBarCustomer";
import cookieinfo from "@/components/cookieinfo";
import cookieackno from "@/components/cookieackno";
import axios from "axios";
import shopTurn from "@/components/shopTurn";
import Cookie from "js-cookie";
import statusUpdate from "@/components/statusUpdate";
export default {
  name: "specificShop",
  components: {
    NavBarCustomer,
    cookieinfo,
    cookieackno,
    shopTurn,
    statusUpdate
  },
  data() {
    return {
      shopid: this.$route.params.Id,
      shopinfo: "",
      timer: "",
      isTokenInCookie: false,
      tokeninfo: null,
      allCookieList: [],
      cookieValue: "",
      token: null,
      isTokenActive: true,
      waitingTimePerCustomer: 0, 
      totalWaitingTime: 0
    };
  },
  methods: {
    getShopInfo() {
      const self = this;
      axios
        .get("http://penguin.termina.linux.test:8080/shops/" + this.shopid)
        .then(function(res) {
          self.shopinfo = res.data;
          self.allCookieList = JSON.parse(Cookie.get("tokenid"));
          var i;
          for (i = 0; i < self.allCookieList.length; i++) {
            self.cookieValue = self.allCookieList[i].toString();
            axios({
              method: "GET",
              url:
                "http://penguin.termina.linux.test:8080/token/" +
                self.cookieValue
            }).then(function(res) {
              if (res.data.token.shopId == self.shopid) {
                if (res.data.token.status == "ACTIVE") {
                  self.isTokenInCookie = true;
                  self.tokeninfo = res.data;
                } else {
                  self.allCookieList.splice(
                    self.allCookieList.indexOf(res.data.token.tokenId),
                    1
                  );
                  Cookie.set("tokenid", JSON.stringify(self.allCookieList));
                  self.isTokenInCookie = false;
                  self.isTokenActive = false;
                }
              }
            });
          }
        });

        self.getWaitingTime();

        if(this.isTokenInCookie) {
          this.totalWaitingTime = this.waitingTimePerCustomer * this.tokeninfo.customersAhead;
        } else{
          this.totalWaitingTime = this.waitingTimePerCustomer * this.shopinfo.customersInQueue;
        }
    },

    getWaitingTime() {
      const self = this;
      axios({
        method: "GET",
        url: "http://penguin.termina.linux.test:8080/waitingtime"
      }).then(function(res) {
        self.waitingTimePerCustomer = res.data.waitingTimePerCustomer;
      });
      
    },

    getToken() {
      const self = this;
      axios({
        method: "POST",
        url: "http://penguin.termina.linux.test:8080/tokens/" + this.shopid
      }).then(function(res) {
        self.token = res.data.token;
        self.allCookieList.push(self.token.tokenId);
        Cookie.set("tokenid", JSON.stringify(self.allCookieList), {
          expires: 1
        });<commit_msg>remove extra newlines<commit_after>/* Copyright 2020 Google LLC 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 https://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>
  <div>
    <NavBarCustomer></NavBarCustomer>
    <cookieinfo></cookieinfo>
    <cookieackno></cookieackno>
    <div class="card">
      <div class="card-content">
        <p class="title">{{shopinfo.shop.shopName}}</p>
        <p
          v-if="isTokenInCookie"
          class="title"
        >Number of People ahead in the queue are: {{tokeninfo.customersAhead}}</p>
        <p
          v-else
          class="title"
        >Number of people currently in queue are {{shopinfo.customersInQueue}}</p>
        <p v-if="totalWaitingTime != 0" class="title">Approx. waiting time is: {{totalWaitingTime}} mins</p>
        <p class="subtitle">{{shopinfo.shop.shopType}}</p>
        <p class="subtitle">{{shopinfo.shop.address}}</p>
        <p class="subtitle">{{shopinfo.shop.phoneNumber}}</p>
      </div>
      <footer class="card-footer">
        <p class="card-footer-item">
          <button
            class="button is-primary is-medium"
            v-if="isTokenInCookie"
            v-on:click="getShopInfo()"
          >Refresh token</button>
          <button class="button is-primary is-medium" v-else v-on:click="getToken()">Take token</button>
        </p>
        <p class="card-footer-item">
          <button
            class="button is-danger is-medium"
            v-on:click="deleteToken()"
            v-if="isTokenInCookie"
          >Cancel token</button>
        </p>
      </footer>
      <div v-if="isTokenInCookie">
        <div v-if="tokeninfo.customersAhead == 0">
          <shopTurn></shopTurn>
        </div>
      </div>
      <div v-if="!isTokenActive">
        <statusUpdate></statusUpdate>
      </div>
      <div v-if="isTokenInCookie">
        <div class="panel panel-default">
          <div class="table-responsive">
            <table class="table">
              <caption>
                <h1 style="margin: 20px 0" class="is-vcentered">Your Token information</h1>
              </caption>
              <thead>
                <th id="head">Token Number</th>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <a>{{tokeninfo.token.tokenNumber}}</a>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import NavBarCustomer from "@/components/NavBarCustomer";
import cookieinfo from "@/components/cookieinfo";
import cookieackno from "@/components/cookieackno";
import axios from "axios";
import shopTurn from "@/components/shopTurn";
import Cookie from "js-cookie";
import statusUpdate from "@/components/statusUpdate";
export default {
  name: "specificShop",
  components: {
    NavBarCustomer,
    cookieinfo,
    cookieackno,
    shopTurn,
    statusUpdate
  },
  data() {
    return {
      shopid: this.$route.params.Id,
      shopinfo: "",
      timer: "",
      isTokenInCookie: false,
      tokeninfo: null,
      allCookieList: [],
      cookieValue: "",
      token: null,
      isTokenActive: true,
      waitingTimePerCustomer: 0, 
      totalWaitingTime: 0
    };
  },
  methods: {
    getShopInfo() {
      const self = this;
      axios
        .get("http://penguin.termina.linux.test:8080/shops/" + this.shopid)
        .then(function(res) {
          self.shopinfo = res.data;
          self.allCookieList = JSON.parse(Cookie.get("tokenid"));
          var i;
          for (i = 0; i < self.allCookieList.length; i++) {
            self.cookieValue = self.allCookieList[i].toString();
            axios({
              method: "GET",
              url:
                "http://penguin.termina.linux.test:8080/token/" +
                self.cookieValue
            }).then(function(res) {
              if (res.data.token.shopId == self.shopid) {
                if (res.data.token.status == "ACTIVE") {
                  self.isTokenInCookie = true;
                  self.tokeninfo = res.data;
                } else {
                  self.allCookieList.splice(
                    self.allCookieList.indexOf(res.data.token.tokenId),
                    1
                  );
                  Cookie.set("tokenid", JSON.stringify(self.allCookieList));
                  self.isTokenInCookie = false;
                  self.isTokenActive = false;
                }
              }
            });
          }
        });
        self.getWaitingTime();
        if (this.isTokenInCookie) {
          this.totalWaitingTime = this.waitingTimePerCustomer * this.tokeninfo.customersAhead;
        } else {
          this.totalWaitingTime = this.waitingTimePerCustomer * this.shopinfo.customersInQueue;
        }
    },
    getWaitingTime() {
      const self = this;
      axios({
        method: "GET",
        url: "http://penguin.termina.linux.test:8080/waitingtime"
      }).then(function(res) {
        self.waitingTimePerCustomer = res.data.waitingTimePerCustomer;
      });
    },
    getToken() {
      const self = this;
      axios({
        method: "POST",
        url: "http://penguin.termina.linux.test:8080/tokens/" + this.shopid
      }).then(function(res) {
        self.token = res.data.token;
        self.allCookieList.push(self.token.tokenId);
        Cookie.set("tokenid", JSON.stringify(self.allCookieList), {
          expires: 1
        });
{'fraction_non_alphanumeric': 0.13191093048852764, 'fraction_numerical': 0.006096012192024384, 'mean_word_length': 1.9252105002476474, 'pattern_counts': {'":': 0, '<': 155, '<?xml version=': 0, '>': 153, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '357898', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3367, 'n_words': 727}