Ejemplo n.º 1
0
    function buildTimeSlots(schedule, provider_breaks, service_duration, reserved_timeslots) {

        var timeslots = [];
        var d = new XDate(date);
        var curr_date = d.getDate();
        var curr_month = d.getMonth() + 1;
        var curr_year = d.getFullYear();
        var schedule_start = new XDate(curr_month + '/' + curr_date + '/' + curr_year + ' ' + schedule.start, false);
        var schedule_end = new XDate(curr_month + '/' + curr_date + '/' + curr_year + ' ' +  schedule.end, false);

        Logger.info('schedule_start %j', schedule_start.toString());

        while(schedule_start.getTime() <= schedule_end.getTime()) {

            var start = new XDate(schedule_start).getTime();
            var end = new XDate(schedule_start).addMinutes(service_duration.duration_minutes + service_duration.padding_after_minutes).getTime();
            var valid = true;

            _.each(provider_breaks, function(provider_break) {
                var break_start = new XDate(curr_month + '/' + curr_date + '/' + curr_year + ' ' + provider_break.from, false).getTime();
                var break_to = new XDate(curr_month + '/' + curr_date + '/' + curr_year + ' ' + provider_break.to, false).getTime();

                if (break_start >= start && break_start <= end) {
                    valid = false;
                    return;
                }
                if (break_to >= start && break_to <= end) {
                    valid = false;
                    return;
                }
            });

            _.each(reserved_timeslots, function(reserved_timeslot) {
                var timeslot_start = reserved_timeslot.start;
                var timeslot_end = reserved_timeslot.end;

                if (timeslot_start >= start && timeslot_start < end) {
                    valid = false;
                    return;
                }
                if (timeslot_end > start && timeslot_end <= end) {
                    valid = false;
                    return;
                }
            });

            if (end > schedule_end.getTime()) {
                valid = false;
            }

            if (valid) {
                timeslots.push({key: schedule_start.toString("HH:mm"), value: schedule_start.toString("HH:mm:TT")});
            }
            schedule_start.addMinutes(service_duration.duration_minutes + service_duration.padding_after_minutes);

        }

        return timeslots;
    }
Ejemplo n.º 2
0
        function renderProviders(services, locations, cb) {

            var startTime = new XDate(2014, 1, 1, 0, 0, 0, 0);
            var endTime = new XDate(2014, 1, 1, 23, 55, 0, 0);
            var step = 30;
            var breaks = ["none"];

            while (startTime.getTime() <= endTime.getTime()) {
                breaks.push(startTime.toString("hh:mmTT"));
                startTime = startTime.addMinutes(step);
            }

            var titles = Constants.PERSONAL_TITLES;

            var all_services = _.map(services, function (service) {
                return {
                    _id: service._id.toString(),
                    name: service.name,
                    service_options: service.service_options,
                    selected: false
                };
            });

            var all_locations = _.map(locations, function (location) {
                return {
                    _id: location._id.toString(),
                    name: location.name,
                    selected: false
                };
            });

            if (provider_id !== undefined) {

                providerService.getProviderById(provider_id, function (err, provider) {

                    _.each(all_services, function (service) {
                        if (_.contains(provider.services, service._id)) {
                            service.selected = true;
                        }
                    });

                    _.each(all_locations, function (location) {
                        if (_.contains(provider.locations, location._id)) {
                            location.selected = true;
                        }
                    });

                    if (err) {
                        res.send({ result: 'error', error: err });
                        return;
                    }
                    res.render('management/provider', {
                        title: 'Edit Provider',
                        personal_titles: titles,
                        provider: provider,
                        provider_breaks: breaks,
                        services: all_services,
                        locations: all_locations
                    });
                });
            } else {

                var provider = new Provider();

                res.render('management/provider', {
                    title: 'New Provider',
                    personal_titles: titles,
                    provider: provider,
                    provider_breaks: breaks,
                    services: all_services,
                    locations: all_locations
                });

            }
        }