Giter VIP home page Giter VIP logo

coffeerun's Introduction

CoffeeRun

DigitalCrafts: Learning LocalStorage

Overall:

  • CoffeeRun's primary learning experience was working with localstorage and APIs.
  • The first goal was to save to our personal localstorage.
  • From there, I worked with an API that our instructor provided.
  • This created the ability to work with an API on a smaller scale and learn how obtain the necessary data.
  • Styling was optional; however, personally, I enjoy going back and fourth from HTML and CSS to JavaScript, Ajax, and jQuery.

Difficulties:

  • This project was my first incounter with APIs. Using another database with nested objects that I didn't personally create was interesting. Great learning experience to read through code and figure out how to extract the data needed.

Showcases the primary content of Coffee Run

snipit of coffee run main application with form for submitting coffee order


Shows search rendering

return of coffee order search


Code snipit of jQuery used within Coffee Run to retreive data from our API in a JSON format

// gets data from API in JSON format
function getDataFromAPI(){
    return $.getJSON(URL);
}
// callback: gets all data from API and then prints to DOM
function getOrdersFromAPI(){
    getDataFromAPI()
        .then(appendOrderToDOM);
};
// appends orders to DOM from API
function appendOrderToDOM(data){
    $.each(data, function(key, val){
        $(".past-order span")
            .append("Order: " + key + ": " + 
            "orders a " + val['coffee'] + " " + 
            checkForUndefined(val['size']) + " " + 
            checkForUndefined(val['flavor']) + " " + 
            setStrengthOfCoffee(val['strength']) + " " + "coffee." + " " + "<input id='chk_" + "'data-type='check-box' type='checkbox' value='" + true + "' />"  + "<br />" ); 
    });
};
// Delets order from API
function deleteOrderFromAPI(){
    var $checkBoxContainer = $("[data-type='check-box-container']");
    $checkBoxContainer.on('click', "input[type='checkbox']", function (){
        prompt("Would you like to delete this order?");
    });
};


// Code snipit of jQuery: searches item, then accounts for any blank values retreived from API
// --------------------------------
// when search container is filled out and search is click, this initializes</h5>
// gets data from API</h5>
// then searchs the API for particular email input by user</h5>
// then uses a counter so person can hide search bar</h5>
function searchForOrder(){
    $('[data-type-button="find-order"]').on('click', function () {
        event.preventDefault();
        getDataFromAPI()
            .then(searchAPI);
    });
};
// after getting data from API
// takes value submited in search area. 
// creates a blank object so can sort through specific data associated with email address
// if email is found within data...
// order will be set to data[$email] / this enables the ability to print different key values of data[$email] object
// if the email has been found, the order will be appended to the DOM
// if email was NOT found, user will recieve error 
function searchAPI(data){
    emptyText($(".searched-order span"));
    var $email = $('.email-search').val();
    var order = {};
    if (data[$email]){
        order = data[$email];
        $(".searched-order span")
            .append($email + ": " + 
            checkForUndefined(order.coffee) + " " + 
            checkForUndefined(order.size) + " " + 
            checkForUndefined(order.flavor) + " " + 
            setStrengthOfCoffee(order.strength)  + 
            " coffee." + "<br />");
    } else {
        $(".searched-order span").append("We do not have that email on file.");
    }
};
// emptys DOM in certain text fields so if button is clicked multiple times, the information is not printed over and over and over.
function emptyText(className){
    className.empty("");
}

coffeerun's People

Contributors

klane11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.