Ignore:
Timestamp:
01/03/24 00:00:07 (11 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
53765dd
Parents:
77205be
Message:

Add all bug fixes.

Location:
src/main/resources/static/js
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/js/admin.js

    r77205be r1413ee2  
    2020            }
    2121        });
    22         console.log(JSON.stringify(companiesToSave));
    2322
    2423
    2524        $.ajax({
    26             url: "http://localhost:8080/api/business",
     25            url: "http://localhost:8080/api/admin",
    2726            type:"PATCH",
    2827            data: JSON.stringify(companiesToSave),
  • src/main/resources/static/js/business_admin.js

    r77205be r1413ee2  
    22    var business = {};
    33
    4     getBusinessInfo(business);
     4    getBusinessInfo().then(function (data) {
     5        business = data;
     6    });
    57
    68    getAppointments();
     
    3335    $("#update_services_button").click(function () {
    3436        businesses = [];
    35         console.log("Gjoko");
    3637        servicesObj = [];
    3738        $.each($('#predefined_services_admin_panel input:checked').siblings(), function (index, label) {
     
    4344            var price = $($($(label).parent()).siblings()[1]).children()[0].value;
    4445
    45             var serviceType = {}
     46            var serviceType = {};
    4647            if (parseInt(id) != -1) {
    4748                service['id'] = parseInt(id);
     
    5657            servicesObj.push(service);
    5758        });
    58         business['services'] = servicesObj;
    59 
    60         businesses.push(business);
    61         console.log(JSON.stringify(businesses));
    62 
    63         $.ajax({
    64             url: "http://localhost:8080/api/business",
    65             type:"PATCH",
    66             data: JSON.stringify(businesses),
    67             contentType:"application/json; charset=utf-8",
    68             dataType: 'text',
    69             success: function(succ){
    70                 alert( "Updates applied successfully" );
    71             },
    72             error: function(err) {
    73                 alert(err);
    74             }
    75         });
     59
     60        var servicesForDelete=[];
     61        $.each($('#predefined_services_admin_panel input:not(:checked)').siblings(), function (index, label) {
     62            let id = $(label).prop('for');
     63            let foundService = business['services'].find(obj => obj.id === parseInt(id));
     64            if (foundService !== undefined && foundService['serviceStatus'] === 'ACTIVE') {
     65                let service1 = {};
     66                service1['id'] = id;
     67                servicesForDelete.push(service1);
     68            }
     69        });
     70
     71
     72        updateServices(servicesObj).then(function (response) {
     73            getBusinessInfo().then(function (data) {
     74                business = data;
     75            });
     76        });
     77
     78        if (servicesForDelete.length > 0) {
     79            deleteServices(servicesForDelete).then(function (response) {
     80                getBusinessInfo().then(function (data) {
     81                    business = data;
     82                });
     83            });
     84        }
     85
    7686        event.preventDefault();
    7787    });
     
    7989    $("#update_owner_button").click(function() {
    8090        businesses = [];
    81         business['owner']['firstName'] = $('#firstName').val();
    82         business['owner']['lastName'] = $('#lastName').val();
    83         business['owner']['email'] = $('#email').val();
    84         business['owner']['phoneNumber'] = $('#phoneNumber').val();
    85         business['owner']['username'] = $('#username').val();
     91        owner={};
     92        owner['firstName'] = $('#firstName').val();
     93        owner['lastName'] = $('#lastName').val();
     94        owner['email'] = $('#email').val();
     95        owner['phoneNumber'] = $('#phoneNumber').val();
     96        owner['username'] = $('#username').val();
     97
     98        business['owner'] = owner;
    8699
    87100        businesses.push(business);
    88         console.log(JSON.stringify(businesses));
    89 
    90         $.ajax({
    91             url: "http://localhost:8080/api/business",
    92             type:"PATCH",
    93             data: JSON.stringify(businesses),
    94             contentType:"application/json; charset=utf-8",
    95             dataType: 'text',
    96             success: function(succ){
    97                 alert( "Updates applied successfully" );
    98             },
    99             error: function(err) {
    100                 alert(err);
    101             }
     101
     102        updateBusinessInfo(businesses).then(function() {
     103            getBusinessInfo().then(function (found) {
     104                business = found;
     105            });
    102106        });
    103107    });
    104108    event.preventDefault();
    105109});
     110
     111function updateBusinessInfo(businessList) {
     112    return $.ajax({
     113        url: "http://localhost:8080/api/business",
     114        type:"PATCH",
     115        data: JSON.stringify(businessList),
     116        contentType:"application/json; charset=utf-8",
     117        dataType: 'text',
     118        success: function(succ){
     119            alert( "Updates applied successfully" );
     120        },
     121        error: function(err) {
     122            alert(err);
     123        }
     124    });
     125}
     126
     127function updateServices(serviceList) {
     128    return $.ajax({
     129        url: "http://localhost:8080/api/service",
     130        type:"PATCH",
     131        data: JSON.stringify(serviceList),
     132        contentType:"application/json; charset=utf-8",
     133        dataType: 'text',
     134        success: function(succ){
     135            alert( "Updates applied successfully" );
     136        },
     137        error: function(err) {
     138            alert(err);
     139        }
     140    });
     141}
     142
     143function deleteServices(services) {
     144    return $.ajax({
     145        url: "http://localhost:8080/api/service/delete",
     146        type:"POST",
     147        data: JSON.stringify(services),
     148        contentType:"application/json; charset=utf-8",
     149        dataType: 'text',
     150        success: function(succ){
     151            console.log("services deleted successfully");
     152        },
     153        error: function(err) {
     154            console.error(err);
     155        }
     156    });
     157}
    106158
    107159function cancelAppointment(appointmentId) {
     
    123175        url: "http://localhost:8080/api/appointment/future/me"
    124176    }).then(function (data) {
    125         console.log(data);
    126177        var $el = $("#bookings-table-body");
    127178        $el.empty();
     
    154205}
    155206
    156 function getBusinessInfo(business) {
    157     $.ajax({
     207function getBusinessInfo() {
     208    return $.ajax({
    158209        url: "http://localhost:8080/api/business/me"
    159     }).then(function (data) {
    160         business = data;
     210    }).then(function (business) {
    161211        var $header = $("#header");
    162212
    163213        // header
    164         $header.text($header.text() + " " + business["owner"]['firstName'] + " " + business['owner']['lastName']);
     214        $header.text("Welcome back " + business["owner"]['firstName'] + " " + business['owner']['lastName']);
    165215
    166216        // business info
     
    181231        var $el = $("#predefined_services_admin_panel");
    182232        $el.empty();
     233
    183234        $.each(business['services'], function (index, obj) {
    184             $el.append(
    185                 '<div class=\"form-outline mb-4\">' +
     235
     236            var element = '<div class=\"form-outline mb-4\">' +
    186237                '    <div class="row">' +
    187238                '        <div class="col-md-6">\n' +
    188                 '            <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' +
     239                '            <input class="form-check-input" type="checkbox" ';
     240
     241            if (obj['serviceStatus'] === 'ACTIVE') {
     242                element += 'checked';
     243            }
     244
     245            element += ' value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' +
    189246                '            <label class="form-check-label" for=\"' + obj.id + '\">\n' + obj['serviceType'].name + '</label>\n' +
    190247                '        </div>' +
     
    196253                '        </div>' +
    197254                '    </div>' +
    198                 '</div>');
    199         });
    200     });
    201 }
     255                '</div>';
     256
     257            $el.append(element);
     258        });
     259        return business;
     260    });
     261}
  • src/main/resources/static/js/customer_admin.js

    r77205be r1413ee2  
    1616        customerForSave['phoneNumber'] = $('#phoneNumber').val();
    1717        customerForSave['username'] = $('#username').val();
    18 
    19         console.log(JSON.stringify(customerForSave));
    2018
    2119        $.ajax({
     
    5553        const recipientId = button.getAttribute('data-bs-id');
    5654
    57         console.log(recipientName + ' ' + recipientId);
    58         // If necessary, you could initiate an Ajax request here
    59         // and then do the updating in a callback.
    60 
    6155        // Update the modal's content.
    6256        const modalTitle = reviewModal.querySelector('.modal-title');
     
    9791        url: "http://localhost:8080/api/appointment/future/me"
    9892    }).then(function (data) {
    99         console.log(data);
    10093        var $el = $("#appointments-table-body");
    10194        $el.empty();
     
    194187        url: "http://localhost:8080/api/review/me"
    195188    }).then(function (data) {
    196         console.log(data);
    197189        var $el = $("#my-reviews");
    198190        $el.empty();
     
    233225            $('#reviewModal').modal('toggle');
    234226            getPastAppointments();
     227            getReviewsForCustomer();
    235228        },
    236229        error: function(error) {
     
    248241        }).success(function (data) {
    249242            alert("Appointment successfully canceled.")
    250             getAppointments();
     243            getFutureAppointments();
    251244        }).error(function (error) {
    252245            alert("Something went wrong.");
  • src/main/resources/static/js/homepage.js

    r77205be r1413ee2  
    102102            // get already stored service from in-memory
    103103            selectedServices = businesses.find(item => item.id == selectedVal)['services'];
     104            console.log(selectedServices);
    104105            resetAndAppendServices(selectedServices);
    105106        });
     
    164165
    165166    $.each(services, function (index, obj) {
    166         $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>");
     167        if (obj.serviceStatus === 'ACTIVE') {
     168            $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>");
     169        }
    167170    });
    168171}
Note: See TracChangeset for help on using the changeset viewer.