All files / ui/src/views EditLocation.vue

23.53% Statements 4/17
100% Branches 0/0
33.33% Functions 1/3
23.53% Lines 4/17

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                                                                                                                                              3x 3x   3x     1x                                                                                                                                                                                                            
<template>
  <div class="container text-center">
    <div class="card mx-auto">
      <div class="card-header">
        <span>EDIT LOCATION</span>
      </div>
      <form
        @submit.prevent="submit"
        method="PATCH"
        enctype="multipart/form-data"
        id="locationForm"
      >
        <div class="form-group">
          <label for="locationName">Location Name</label>
          <input
            v-model="locationName"
            type="text"
            class="form-control"
            id="locationName"
            name="locationName"
            placeholder="Location Name"
            required
          />
        </div>
        <div class="form-group">
          <label for="address">Address</label>
          <input
            v-model="address"
            type="text"
            class="form-control"
            id="address"
            name="address"
            placeholder="Address"
            required
          />
        </div>
        <div class="form-group">
          <label for="hours">Hours</label>
          <input
            v-model="hours"
            type="text"
            class="form-control"
            id="hours"
            name="hours"
            placeholder="Hours"
            required
          />
        </div>
        <div class="form-group">
          <label for="phoneNumber">Phone Number</label>
          <input
            v-model="phoneNumber"
            type="text"
            class="form-control"
            id="phoneNumber"
            name="phoneNumber"
            placeholder="Phone Number"
            required
          />
        </div>
        <div class="form-group">
          <label for="photo">Upload Image</label>
          <input type="file" class="form-control" name="photo" id="photo" />
        </div>
        <button class="button" type="submit">Save</button>
      </form>
    </div>
  </div>
</template>
 
<script>
import LocationService from "../LocationService";
import router from "@/router";
 
export default {
  name: "EditLocation",
  data() {
    return {
      editLocation: null,
      _id: "",
      locationName: "",
      address: "",
      hours: "",
      phoneNumber: "",
      likeCount: 0,
    };
  },
  async mounted() {
    this.editLocation = await JSON.parse(
      sessionStorage.getItem("currentLocation")
    );
    this._id = this.editLocation._id;
    this.locationName = this.editLocation.locationName;
    this.address = this.editLocation.address;
    this.hours = this.editLocation.hours;
    this.phoneNumber = this.editLocation.phoneNumber;
    this.photo = this.editLocation.photo;
  },
  methods: {
    /**
     * @vuese
     * Takes in the edited Location form data and sends it to the patch Loation Api to update the selected location.
     */
    async submit() {
      let editL = new FormData(locationForm);
      editL.append("_id", this._id);
      editL.append("photo", this.photo);
      await LocationService.putLocation(editL);
      window.alert("Location Edited!");
      await router.push("/allLocations");
    },
  },
};
</script>
 
<style scoped>
.card {
  width: 26rem;
  height: fit-content;
  font-weight: bold;
  font-size: 0.9rem;
  padding: 0.5rem;
  margin-bottom: 2rem;
  border: none;
  outline: none;
  border-radius: 22px;
  background-color: #e0e5ec;
  box-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
    -9px -9px 16px rgba(255, 255, 255, 0.5);
}
 
.card-header {
  font-weight: 100;
  font-family: Luminari, fantasy;
  font-size: 1.8rem;
  border: none;
  outline: none;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  background-color: #e0e5ec;
  margin: 2rem 0rem;
}
 
.form-control {
  width: 25rem;
  height: max-content;
  font-weight: bold;
  padding: 1rem;
  font-size: 1.1rem;
  border: none;
  outline: none;
  border-radius: 22px;
  background-color: #e0e5ec;
  box-shadow: inset 9px 9px 16px rgb(163, 177, 198, 0.6),
    inset -9px -9px 16px rgba(255, 255, 255, 0.5);
  transition: box-shadow 500ms;
}
 
.button {
  width: 25rem;
  font-weight: bold;
  padding: 1rem;
  font-size: 1.1rem;
  margin: 1rem 0rem;
  border: none;
  outline: none;
  color: #007bff;
  border-radius: 22px;
  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);
}
</style>