From e6dd6a9f1bfdac6416ca362dc1a5a6e4b582a003 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Tue, 20 Nov 2018 16:37:59 -0800 Subject: [PATCH 01/12] starting --- index.css | 8 ++++ index.html | 45 +++++++++++++++++++++++ index.js | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 index.css create mode 100644 index.html create mode 100644 index.js diff --git a/index.css b/index.css new file mode 100644 index 00000000..17e6ca79 --- /dev/null +++ b/index.css @@ -0,0 +1,8 @@ +body { + font-family: sans-serif; +} + +main { + display: grid; + grid-template-columns: 1fr 1fr; +} diff --git a/index.html b/index.html new file mode 100644 index 00000000..0a1916c5 --- /dev/null +++ b/index.html @@ -0,0 +1,45 @@ + + + + + Sites with axios + + + + + + +
+

TAKE A TREK! A whole big world is waiting!

+
+
+
+

List-o-Trips

+ + +
+
+
+

Reserve a trip

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ + diff --git a/index.js b/index.js new file mode 100644 index 00000000..dc20fd6c --- /dev/null +++ b/index.js @@ -0,0 +1,106 @@ +const URL = "https://trektravel.herokuapp.com/trips"; + +// +// Status Management +// +const reportStatus = message => { + $("#status-message").html(message); +}; + +const reportError = (message, errors) => { + let content = `

${message}

"; + reportStatus(content); +}; + +// +// Loading Pets +// +const loadTrips = () => { + reportStatus("Loading trips..."); + + const tripList = $("#trip-list"); + tripList.empty(); + + axios + .get(URL) + .then(response => { + reportStatus(`Successfully loaded ${response.data.length} trips`); + response.data.forEach(trip => { + tripList.append(`
  • `
  • ).addClass("showTrip"); + }); + }) + .catch(error => { + reportStatus( + `Encountered an error while loading trips: ${error.message}` + ); + console.log(error); + }); +}; + +// +// Creating Pets +// +const readFormData = () => { + const parsedFormData = {}; + + const nameFromForm = $(`#pet-form input[name="name"]`).val(); + parsedFormData["name"] = nameFromForm ? nameFromForm : undefined; + + const ageFromForm = $(`#pet-form input[name="age"]`).val(); + parsedFormData["age"] = ageFromForm ? ageFromForm : undefined; + + const ownerFromForm = $(`#pet-form input[name="owner"]`).val(); + parsedFormData["owner"] = ownerFromForm ? ownerFromForm : undefined; + + return parsedFormData; +}; + +const clearForm = () => { + $(`#pet-form input[name="name"]`).val(""); + $(`#pet-form input[name="email"]`).val(""); + $(`#pet-form input[name="trip-name"]`).val(""); +}; + +const createTrip = event => { + // Note that createPet is a handler for a `submit` + // event, which means we need to call `preventDefault` + // to avoid a page reload + event.preventDefault(); + + const tripData = readFormData(); + console.log(tripData); + + reportStatus("Sending trip data..."); + + axios + .post(URL, tripData) + .then(response => { + reportStatus(`Successfully reserved a trip with ID ${response.data.id}!`); + clearForm(); + }) + .catch(error => { + console.log(error.response); + if (error.response.data && error.response.data.errors) { + reportError( + `Encountered an error: ${error.message}`, + error.response.data.errors + ); + } else { + reportStatus(`Encountered an error: ${error.message}`); + } + }); +}; + +// +// OK GO!!!!! +// +$(document).ready(() => { + $("#load").click(loadTrips); + $("#pet-form").submit(createTrip); +}); From a82ca5016b7ce6d43561a7dabaee7c5b7d886c0a Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Tue, 20 Nov 2018 17:56:00 -0800 Subject: [PATCH 02/12] trip list working, created links, then changed to fake links, finding alt way to show trip info --- index.html | 4 ++++ index.js | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 0a1916c5..a3ca84e2 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,10 @@

    List-o-Trips


    +
    + +
    +

    Reserve a trip

    diff --git a/index.js b/index.js index dc20fd6c..988f2189 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,15 @@ const loadTrips = () => { .then(response => { reportStatus(`Successfully loaded ${response.data.length} trips`); response.data.forEach(trip => { - tripList.append(`
  • `
  • ).addClass("showTrip"); + tripList + // .append( + // `
  • ${ + // trip.name + // }
  • ` + // ) + // .addClass("show-trip"); + .append(`
  • ${trip.name}
  • `) + .addClass("show-trip)"); }); }) .catch(error => { @@ -42,6 +50,9 @@ const loadTrips = () => { console.log(error); }); }; +// const showTrip = (trip.id)=>{ +// $(`${trip.id}`).click(${trip.name}); +// } // // Creating Pets @@ -67,13 +78,14 @@ const clearForm = () => { $(`#pet-form input[name="trip-name"]`).val(""); }; -const createTrip = event => { +const reserveTrip = event => { // Note that createPet is a handler for a `submit` // event, which means we need to call `preventDefault` // to avoid a page reload event.preventDefault(); const tripData = readFormData(); + console.log(tripData); reportStatus("Sending trip data..."); @@ -102,5 +114,6 @@ const createTrip = event => { // $(document).ready(() => { $("#load").click(loadTrips); - $("#pet-form").submit(createTrip); + $("#trip-form").submit(reserveTrip); + // $("#trip-list").on("click","a", function() }); From f9275e3276cc69d371f3c89378d5325bb5cfa784 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Tue, 20 Nov 2018 22:03:44 -0800 Subject: [PATCH 03/12] working on function to show trip details --- index.html | 58 +++++++++++++++++++++++++++--------------------------- index.js | 29 ++++++++++++++++----------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/index.html b/index.html index a3ca84e2..7e558b2a 100644 --- a/index.html +++ b/index.html @@ -12,38 +12,38 @@

    TAKE A TREK! A whole big world is waiting!

    -
    +
    -
    -

    List-o-Trips

    - -
      -
      -
      -
      +
      +

      List-o-Trips

      + +
        +
        +
        +
        -
        +
        -
        -

        Reserve a trip

        - -
        - - -
        +
        +

        Reserve a trip

        + +
        + + +
        -
        - - -
        +
        + + +
        -
        - - -
        +
        + + +
        - -
        -
        - - + +
        + + + diff --git a/index.js b/index.js index 988f2189..80f08444 100644 --- a/index.js +++ b/index.js @@ -50,9 +50,12 @@ const loadTrips = () => { console.log(error); }); }; -// const showTrip = (trip.id)=>{ -// $(`${trip.id}`).click(${trip.name}); -// } +const showTrip = id => { + axios.get(URL + `${trip.id}`).then(response => { + console.log(`${trip.id}`); + response.data; + }); +}; // // Creating Pets @@ -60,22 +63,22 @@ const loadTrips = () => { const readFormData = () => { const parsedFormData = {}; - const nameFromForm = $(`#pet-form input[name="name"]`).val(); + const nameFromForm = $(`#trip-form input[name="name"]`).val(); parsedFormData["name"] = nameFromForm ? nameFromForm : undefined; - const ageFromForm = $(`#pet-form input[name="age"]`).val(); - parsedFormData["age"] = ageFromForm ? ageFromForm : undefined; + const emailFromForm = $(`#trip-form input[name="email"]`).val(); + parsedFormData["email"] = emailFromForm ? emailFromForm : undefined; - const ownerFromForm = $(`#pet-form input[name="owner"]`).val(); - parsedFormData["owner"] = ownerFromForm ? ownerFromForm : undefined; + const tripNameFromForm = $(`#trip-form input[name="trip-name"]`).val(); + parsedFormData["trip-name"] = tripNameFromForm ? tripNameFromForm : undefined; return parsedFormData; }; const clearForm = () => { - $(`#pet-form input[name="name"]`).val(""); - $(`#pet-form input[name="email"]`).val(""); - $(`#pet-form input[name="trip-name"]`).val(""); + $(`#trip-form input[name="name"]`).val(""); + $(`#trip-form input[name="email"]`).val(""); + $(`#trip-form input[name="trip-name"]`).val(""); }; const reserveTrip = event => { @@ -115,5 +118,7 @@ const reserveTrip = event => { $(document).ready(() => { $("#load").click(loadTrips); $("#trip-form").submit(reserveTrip); - // $("#trip-list").on("click","a", function() + $("#show-trip").on("click", "a", function() { + showTrip(this.id); + }); }); From 43cbb5c8660a9293909e35fe42b86e0a6f908a35 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sat, 24 Nov 2018 13:01:49 -0800 Subject: [PATCH 04/12] trip show details is working --- index.html | 61 +++++++++++++++++++++++--------------------- index.js | 74 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 72 insertions(+), 63 deletions(-) diff --git a/index.html b/index.html index 7e558b2a..7f9baeee 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,8 @@ src="https://code.jquery.com/jquery-3.3.1.js"> + + @@ -14,36 +16,39 @@

        TAKE A TREK! A whole big world is waiting!


        -
        -

        List-o-Trips

        - -
          -
          -
          -
          -
          +
          +
          +
          +

          List-o-Trips

          + +
            +
            +
            +

            Journey

            +

            -

            -

            Reserve a trip

            -
            -
            - - -
            +

            +
            +

            Reserve a trip

            + +
            + + +
            -
            - - -
            +
            + + +
            -
            - - -
            +
            + + +
            - - -
            - - + +

            + + + diff --git a/index.js b/index.js index 80f08444..ca44252b 100644 --- a/index.js +++ b/index.js @@ -18,48 +18,54 @@ const reportError = (message, errors) => { reportStatus(content); }; -// -// Loading Pets -// const loadTrips = () => { reportStatus("Loading trips..."); const tripList = $("#trip-list"); - tripList.empty(); - axios - .get(URL) - .then(response => { - reportStatus(`Successfully loaded ${response.data.length} trips`); - response.data.forEach(trip => { - tripList - // .append( - // `
          • ${ - // trip.name - // }
          • ` - // ) - // .addClass("show-trip"); - .append(`
          • ${trip.name}
          • `) - .addClass("show-trip)"); + axios.get(URL).then(response => { + reportStatus(`Successfully loaded ${response.data.length} trips`); + response.data + .forEach(trip => { + const vacation = $( + `
          • ${trip.name}
          • ` + ); + tripList.append(vacation).addClass("show-trip)"); + console.log(`${trip.name},${trip.id},${trip.about}}`); + + const individualTrip = showTrip(trip.id); + vacation.click(individualTrip); + }) + .catch(error => { + reportStatus( + `Encountered an error while loading trips: ${error.message}` + ); + + console.log(error); }); - }) - .catch(error => { - reportStatus( - `Encountered an error while loading trips: ${error.message}` - ); - console.log(error); - }); + }); }; const showTrip = id => { - axios.get(URL + `${trip.id}`).then(response => { - console.log(`${trip.id}`); - response.data; - }); + return () => { + axios + .get(`${URL}/${id}`) + .then(response => { + $(".showList").append(`
            Trip Name: ${response.data.name}
            +
            Trip continent: ${response.data.continent}
            +
            Description: ${response.data.about}
            +
            Weeks: ${response.data.weeks}
            +
            Cost: ${response.data.cost}
            `); + }) + .catch(error => { + reportStatus( + `Encountered an error while loading trips: ${error.message}` + ); + console.log(error); + }); + }; }; +// ******************************************************* -// -// Creating Pets -// const readFormData = () => { const parsedFormData = {}; @@ -82,9 +88,6 @@ const clearForm = () => { }; const reserveTrip = event => { - // Note that createPet is a handler for a `submit` - // event, which means we need to call `preventDefault` - // to avoid a page reload event.preventDefault(); const tripData = readFormData(); @@ -119,6 +122,7 @@ $(document).ready(() => { $("#load").click(loadTrips); $("#trip-form").submit(reserveTrip); $("#show-trip").on("click", "a", function() { + console.log("loading trip"); showTrip(this.id); }); }); From 23ff0a5f4721fc3ae235afe25b96fb1b9a509018 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sat, 24 Nov 2018 13:26:08 -0800 Subject: [PATCH 05/12] fixed display with some bootstrap --- index.html | 3 +++ index.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 7f9baeee..0147f885 100644 --- a/index.html +++ b/index.html @@ -27,7 +27,10 @@

            List-o-Trips

            Journey

            +

            +

            +

            Reserve a trip

            diff --git a/index.js b/index.js index ca44252b..7eee04fc 100644 --- a/index.js +++ b/index.js @@ -50,11 +50,14 @@ const showTrip = id => { axios .get(`${URL}/${id}`) .then(response => { - $(".showList").append(`
            Trip Name: ${response.data.name}
            -
            Trip continent: ${response.data.continent}
            -
            Description: ${response.data.about}
            -
            Weeks: ${response.data.weeks}
            -
            Cost: ${response.data.cost}
            `); + $(".showList").append(`
            Trip Name: ${ + response.data.name + }
            +
            Trip continent: ${response.data.continent}
            +
            Description: ${response.data.about}
            +
            Weeks: ${response.data.weeks}
            +
            Cost: ${response.data.cost}
            +


            `); }) .catch(error => { reportStatus( From 82361c4ce69569b802898ebe5c8fcc1b0ace370f Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sat, 24 Nov 2018 22:35:59 -0800 Subject: [PATCH 06/12] wave two completed, working on submit form --- index.html | 4 ++-- index.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 0147f885..85c04270 100644 --- a/index.html +++ b/index.html @@ -46,8 +46,8 @@

            Reserve a trip

            - - + +
            diff --git a/index.js b/index.js index 7eee04fc..a74cb5da 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ const reserveTrip = event => { reportStatus("Sending trip data..."); axios - .post(URL, tripData) + .post(`${URL}/${id}/reservations`) .then(response => { reportStatus(`Successfully reserved a trip with ID ${response.data.id}!`); clearForm(); @@ -117,7 +117,13 @@ const reserveTrip = event => { } }); }; - +// $(function() { //shorthand document.ready function +// $('#login_form').on('submit', function(e) { //use on if jQuery 1.7+ +// e.preventDefault(); //prevent form from submitting +// var data = $("#login_form :input").serializeArray(); +// console.log(data); //use the console for debugging, F12 in Chrome, not alerts +// }); +// }); // // OK GO!!!!! // From 5e13a0b9b634732036eb66dd4415db597ffc68a9 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sun, 25 Nov 2018 10:49:51 -0800 Subject: [PATCH 07/12] submit form passing in postman,need to update trip field --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 85c04270..0e41be2e 100644 --- a/index.html +++ b/index.html @@ -46,8 +46,8 @@

            Reserve a trip

            - - + +
            From 2a0f6d18cac9fe8383333114eb8879751c024146 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sun, 25 Nov 2018 16:24:28 -0800 Subject: [PATCH 08/12] working on creating trip --- index.css | 1 + index.html | 68 ++++++++++++++++++++++++++++++++++-------------------- index.js | 44 +++++++++++++++++++++++++---------- 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/index.css b/index.css index 17e6ca79..320fbd6b 100644 --- a/index.css +++ b/index.css @@ -5,4 +5,5 @@ body { main { display: grid; grid-template-columns: 1fr 1fr; + padding: 5px; } diff --git a/index.html b/index.html index 0e41be2e..f78ec0bd 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,8 @@ src="https://code.jquery.com/jquery-3.3.1.js"> - - + + @@ -20,38 +20,56 @@

            TAKE A TREK! A whole big world is waiting!

            -

            List-o-Trips

            - -
              -
              -
              -

              Journey

              -

              -

              +

              List-o-Trips

              + +
                +
                +
                +

                Journey

                +

                +

                -

                -
                -

                -
                -

                Reserve a trip

                -
                -
                - - -
                +

                +
                +

                +
                +

                Reserve a trip

                + +
                + + +
                -
                - - -
                +
                + + +
                - +

                +
                +

                Create a Trip!

                +
                +
                + + +
                + +
                + + +
                + +
                + + +
                +
                diff --git a/index.js b/index.js index a74cb5da..93b31673 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,6 @@ const loadTrips = () => { reportStatus( `Encountered an error while loading trips: ${error.message}` ); - console.log(error); }); }); @@ -79,7 +78,7 @@ const readFormData = () => { parsedFormData["email"] = emailFromForm ? emailFromForm : undefined; const tripNameFromForm = $(`#trip-form input[name="trip-name"]`).val(); - parsedFormData["trip-name"] = tripNameFromForm ? tripNameFromForm : undefined; + parsedFormData["showTrip"] = tripNameFromForm ? tripNameFromForm : undefined; return parsedFormData; }; @@ -117,16 +116,36 @@ const reserveTrip = event => { } }); }; -// $(function() { //shorthand document.ready function -// $('#login_form').on('submit', function(e) { //use on if jQuery 1.7+ -// e.preventDefault(); //prevent form from submitting -// var data = $("#login_form :input").serializeArray(); -// console.log(data); //use the console for debugging, F12 in Chrome, not alerts -// }); -// }); -// -// OK GO!!!!! -// + +const createTrip = event => { + event.preventDefault(); + + const tripData = readFormData(); + console.log(tripData); + + reportStatus("Sending trip data..."); + + axios + .post(URL, tripData) + .then(response => { + reportStatus(`Successfully added a trip with ID ${response.data.id}!`); + clearForm(); + }) + .catch(error => { + console.log(error.response); + if (error.response.data && error.response.data.errors) { + reportError( + `Encountered an error: ${error.message}`, + error.response.data.errors + ); + } else { + reportStatus(`Encountered an error: ${error.message}`); + } + }); +}; +// const trips = +// ["Cairo to Zanzibar","Everest Base Camp Trek","Golden Triangle""Egypt & Jordan Adventure","Best of New Zealand","Trans-Mongolian Adventure","Sziget Festival Experience", "Dunes, Deltas & Falls","Highlights of Morocco","Local Living Ecuador—Amazon Jungle","Costa Rica Volcanoes & Surfing","Sheepshead World Championships","In Search of Iguassu–Rio to Buenos Aires","Jamaica Encompassed","Antarctica Classic in Depth","Rio de Janeiro Carnival Experience","Kenya & Uganda Gorilla Adventure", "San Diego, Grand Canyon & Vegas","Sin, Surf & Sierras","Historic American Cities by Rail", "Best of Australia","Explore Whitsundays: Solway Lass Tall Ship Sailing","Great Ocean Road - Melbourne to Adelaide", "Ultimate Sydney","Sunnyville ","Blanery Castle","Northern Choice (Auckland to Wellington)","Complete Australia","Remote Northern Lau and Kadavu Discovery Cruise","Local Living Croatia","Whisky Tour from Edinburgh","Clubbing in Bucharest Tour","Hokkaido Winter Festivals","Ancient Empires—Beijing to Tokyo","Cambodia on a Shoestring","Essential India","Northern Hilltribes & Villages","Titanic Journey to New York City","✨✨ Hogwarts Castle Tour ✨✨","Mission to Mars","Mission to Saturn"] + $(document).ready(() => { $("#load").click(loadTrips); $("#trip-form").submit(reserveTrip); @@ -134,4 +153,5 @@ $(document).ready(() => { console.log("loading trip"); showTrip(this.id); }); + $("#trip-form").submit(createTrip); }); From 902616e20f3076614cad25a6cd9c123552fbc445 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Sun, 25 Nov 2018 21:28:52 -0800 Subject: [PATCH 09/12] added new trip form --- index.html | 20 ++++++++++++++++---- index.js | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index f78ec0bd..d638bb83 100644 --- a/index.html +++ b/index.html @@ -56,19 +56,31 @@

                Reserve a trip

                Create a Trip!

                - +
                - - + +
                - +
                +
                + + +
                +
                + + +
                +
                + + +
                diff --git a/index.js b/index.js index 93b31673..196f024e 100644 --- a/index.js +++ b/index.js @@ -116,17 +116,43 @@ const reserveTrip = event => { } }); }; +const tripFormData = () => { + const parsedTripFormData = {}; + + const tripNameFromForm = $(`#new-trip-form input[name="trip-name"]`).val(); + parsedTripFormData["trip-name"] = tripNameFromForm + ? tripNameFromForm + : undefined; + + const continentFromForm = $(`#new-trip-form input[name="continent"]`).val(); + parsedTripFormData["email"] = continentFromForm + ? continentFromForm + : undefined; + + const aboutFromForm = $(`#new-trip-form input[name="about"]`).val(); + parsedTripFormData["about"] = aboutFromForm ? aboutFromForm : undefined; + + const categoryFromForm = $(`#new-trip-form input[name="about"]`).val(); + parsedTripFormData["about"] = categoryFromForm ? categoryFromForm : undefined; + + const weeksFromForm = $(`#new-trip-form input[name="weeks"]`).val(); + parsedTripFormData["weeks"] = weeksFromForm ? weeksFromForm : undefined; + + const costFromForm = $(`#new-trip-form input[name="cost"]`).val(); + parsedTripFormData["cost"] = costFromForm ? costFromForm : undefined; + return parsedTripFormData; +}; const createTrip = event => { event.preventDefault(); - const tripData = readFormData(); - console.log(tripData); + const newTripData = readFormData(); + console.log(newTripData); reportStatus("Sending trip data..."); axios - .post(URL, tripData) + .post(URL, newTripData) .then(response => { reportStatus(`Successfully added a trip with ID ${response.data.id}!`); clearForm(); @@ -153,5 +179,5 @@ $(document).ready(() => { console.log("loading trip"); showTrip(this.id); }); - $("#trip-form").submit(createTrip); + $("#new-trip-form").submit(createTrip); }); From 64fd78f63629a1bb9b4985dd2e66688c88b57838 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Mon, 26 Nov 2018 17:57:49 -0800 Subject: [PATCH 10/12] updated forms and when they appear --- index.html | 55 ++++---------------------------- index.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 63 deletions(-) diff --git a/index.html b/index.html index d638bb83..c4f7fe49 100644 --- a/index.html +++ b/index.html @@ -25,63 +25,20 @@

                List-o-Trips

                  -

                  Journey

                  -

                  +


                  -

                  Reserve a trip

                  -
                  -
                  - - -
                  + +
                  -
                  - - -
                  +
                  -
                  - - -
                  - - -

                  -
                  -

                  Create a Trip!

                  -
                  -
                  - - -
                  - -
                  - - -
                  - -
                  - - -
                  -
                  - - -
                  -
                  - - -
                  -
                  - - -
                  -
                  +
                  +
                  diff --git a/index.js b/index.js index 196f024e..b7f84090 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const URL = "https://trektravel.herokuapp.com/trips"; - +let hiddenID = null; // // Status Management // @@ -22,7 +22,7 @@ const loadTrips = () => { reportStatus("Loading trips..."); const tripList = $("#trip-list"); - + tripList.empty(); axios.get(URL).then(response => { reportStatus(`Successfully loaded ${response.data.length} trips`); response.data @@ -46,17 +46,13 @@ const loadTrips = () => { }; const showTrip = id => { return () => { + hiddenID = id; axios .get(`${URL}/${id}`) .then(response => { - $(".showList").append(`
                  Trip Name: ${ - response.data.name - }
                  -
                  Trip continent: ${response.data.continent}
                  -
                  Description: ${response.data.about}
                  -
                  Weeks: ${response.data.weeks}
                  -
                  Cost: ${response.data.cost}
                  -


                  `); + getTripTemplate(response); + getReserveTemplate(response); + getTripCreateTemplate(); }) .catch(error => { reportStatus( @@ -66,6 +62,74 @@ const showTrip = id => { }); }; }; +function getTripTemplate(response) { + console.log(response.data.name); + $("#showList").html(`
                  Trip Name: ${ + response.data.name + }
                  +
                  + Trip continent: ${response.data.continent} +
                  +
                  Description: ${response.data.about}
                  +
                  Weeks: ${response.data.weeks}
                  +
                  Cost: ${response.data.cost}
                  +


                  `); +} +function getReserveTemplate(response) { + $("#trip-form").html( + `

                  Reserve a trip

                  +
                  + + +
                  +
                  + + +
                  + +
                  + + +
                  +
                  + +
                  + + ` + ); +} +function getTripCreateTemplate() { + $("#new-trip-form").html( + `
                  + + +
                  + +
                  + + +
                  + +
                  + + +
                  +
                  + + +
                  +
                  + + +
                  +
                  + + +
                  + ` + ); +} + // ******************************************************* const readFormData = () => { @@ -99,7 +163,7 @@ const reserveTrip = event => { reportStatus("Sending trip data..."); axios - .post(`${URL}/${id}/reservations`) + .post(`${URL}/${hiddenID}/reservations`, tripData) .then(response => { reportStatus(`Successfully reserved a trip with ID ${response.data.id}!`); clearForm(); @@ -146,15 +210,16 @@ const tripFormData = () => { const createTrip = event => { event.preventDefault(); - const newTripData = readFormData(); - console.log(newTripData); + const tripFormData = readFormData(); + console.log(tripFormData); reportStatus("Sending trip data..."); axios - .post(URL, newTripData) + .post(`${URL}, newTripData`) .then(response => { reportStatus(`Successfully added a trip with ID ${response.data.id}!`); + $("#trip-list").append(tripFormData); clearForm(); }) .catch(error => { From 48a03dcd64b3cbc7dba4f7e3c8b359ffc9453fd8 Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Mon, 26 Nov 2018 18:10:12 -0800 Subject: [PATCH 11/12] reservation works --- index.html | 3 +++ index.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index c4f7fe49..af596323 100644 --- a/index.html +++ b/index.html @@ -30,6 +30,7 @@

                  List-o-Trips


                  +

                  @@ -38,6 +39,8 @@

                  List-o-Trips

                  +
                  +
                  diff --git a/index.js b/index.js index b7f84090..0fc0867f 100644 --- a/index.js +++ b/index.js @@ -216,7 +216,7 @@ const createTrip = event => { reportStatus("Sending trip data..."); axios - .post(`${URL}, newTripData`) + .post(URL, parsedTripFormData) .then(response => { reportStatus(`Successfully added a trip with ID ${response.data.id}!`); $("#trip-list").append(tripFormData); From 3a3bfb2d5c40e8459f615ba7ca3afc4b4bcdeb7f Mon Sep 17 00:00:00 2001 From: Xtina <2006peacegypsy@gmail.com> Date: Mon, 26 Nov 2018 20:50:47 -0800 Subject: [PATCH 12/12] create trip almost working, why is category sending blank --- index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 0fc0867f..4befef67 100644 --- a/index.js +++ b/index.js @@ -130,8 +130,6 @@ function getTripCreateTemplate() { ); } -// ******************************************************* - const readFormData = () => { const parsedFormData = {}; @@ -184,20 +182,20 @@ const tripFormData = () => { const parsedTripFormData = {}; const tripNameFromForm = $(`#new-trip-form input[name="trip-name"]`).val(); - parsedTripFormData["trip-name"] = tripNameFromForm - ? tripNameFromForm - : undefined; + parsedTripFormData["name"] = tripNameFromForm ? tripNameFromForm : undefined; const continentFromForm = $(`#new-trip-form input[name="continent"]`).val(); - parsedTripFormData["email"] = continentFromForm + parsedTripFormData["continent"] = continentFromForm ? continentFromForm : undefined; const aboutFromForm = $(`#new-trip-form input[name="about"]`).val(); parsedTripFormData["about"] = aboutFromForm ? aboutFromForm : undefined; - const categoryFromForm = $(`#new-trip-form input[name="about"]`).val(); - parsedTripFormData["about"] = categoryFromForm ? categoryFromForm : undefined; + const categoryFromForm = $(`#new-trip-form input[name="category"]`).val(); + parsedTripFormData["category"] = categoryFromForm + ? categoryFromForm + : undefined; const weeksFromForm = $(`#new-trip-form input[name="weeks"]`).val(); parsedTripFormData["weeks"] = weeksFromForm ? weeksFromForm : undefined; @@ -210,13 +208,13 @@ const tripFormData = () => { const createTrip = event => { event.preventDefault(); - const tripFormData = readFormData(); + const formData = tripFormData(); console.log(tripFormData); reportStatus("Sending trip data..."); axios - .post(URL, parsedTripFormData) + .post(URL, formData) .then(response => { reportStatus(`Successfully added a trip with ID ${response.data.id}!`); $("#trip-list").append(tripFormData); @@ -234,8 +232,6 @@ const createTrip = event => { } }); }; -// const trips = -// ["Cairo to Zanzibar","Everest Base Camp Trek","Golden Triangle""Egypt & Jordan Adventure","Best of New Zealand","Trans-Mongolian Adventure","Sziget Festival Experience", "Dunes, Deltas & Falls","Highlights of Morocco","Local Living Ecuador—Amazon Jungle","Costa Rica Volcanoes & Surfing","Sheepshead World Championships","In Search of Iguassu–Rio to Buenos Aires","Jamaica Encompassed","Antarctica Classic in Depth","Rio de Janeiro Carnival Experience","Kenya & Uganda Gorilla Adventure", "San Diego, Grand Canyon & Vegas","Sin, Surf & Sierras","Historic American Cities by Rail", "Best of Australia","Explore Whitsundays: Solway Lass Tall Ship Sailing","Great Ocean Road - Melbourne to Adelaide", "Ultimate Sydney","Sunnyville ","Blanery Castle","Northern Choice (Auckland to Wellington)","Complete Australia","Remote Northern Lau and Kadavu Discovery Cruise","Local Living Croatia","Whisky Tour from Edinburgh","Clubbing in Bucharest Tour","Hokkaido Winter Festivals","Ancient Empires—Beijing to Tokyo","Cambodia on a Shoestring","Essential India","Northern Hilltribes & Villages","Titanic Journey to New York City","✨✨ Hogwarts Castle Tour ✨✨","Mission to Mars","Mission to Saturn"] $(document).ready(() => { $("#load").click(loadTrips);