var app = angular.module('SawMaster', ['ngRoute'])
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/app/views/pick-0-material.html',
controller: 'pickMaterial',
title: 'SawMaster - Order Your Bandsaw Blade',
desc: 'Order made to measure Bandsaw blades',
})
.when('/cart', {
templateUrl: '/app/views/cart.html',
controller: 'cart',
title: 'SawMaster - Cart',
desc: 'Your Cart',
})
.when('/checkout', {
templateUrl: '/app/views/checkout.html',
controller: 'checkout',
title: 'Checking Out...',
desc: 'Check Out',
})
.when('/thanks', {
templateUrl: '/app/views/thanks.html',
controller: 'thanks',
title: 'SawMaster - Thanks for your order',
desc: 'Thanks for your Bandsaw blade order',
})
// .when('/faults', {
// templateUrl: '/app/views/faults.html',
// controller: 'faults',
// title: 'SawMaster - Fault Finding'
// })
// .when('/help', {
// templateUrl: '/app/views/help.html',
// title: 'SawMaster - Help'
// })
.when('/remote/addToCart', {
controller: 'remoteController',
templateUrl: '/app/views/loading.html',
title: 'SawMaster - Loading',
desc: '',
})
.when('/about', {
templateUrl: '/app/views/about.html',
title: 'SawMaster - About Us',
desc: 'About SawMaster and our Bandsaw blades',
})
.when('/guide-tooth-selection/:guide', {
controller: 'guidesToothSelection',
templateUrl: '/app/views/guide-tooth-selection.html',
title: 'SawMaster - Tooth Selection Guide',
desc: 'About SawMaster and our Bandsaw blades',
})
.when('/:material', {
templateUrl: '/app/views/pick-1-measurement.html',
controller: 'pickMeasurement',
title: 'SawMaster - Step 2 (Length)',
desc: 'Create your blade in :material',
})
.when('/:material/:unit', {
templateUrl: '/app/views/pick-2-length.html',
controller: 'pickLength',
title: 'SawMaster - Step 3 (Length)',
desc: 'Create your blade in :material measured in :unit',
})
.when('/:material/:unit/:size', {
templateUrl: '/app/views/pick-3-width.html',
controller: 'pickWidth',
title: 'SawMaster - Step 4 (Width)',
desc: 'Create your blade in :material measured at :sizemm',
})
.when('/:material/:unit/:size/:width', {
templateUrl: '/app/views/pick-4-tpi.html',
controller: 'pickTpi',
title: 'SawMaster - Step 5 (TPI)',
desc: 'Create your blade in :material measured at :sizemm :widthmm wide',
})
.when('/:material/:unit/:size/:width/:tpi', {
templateUrl: '/app/views/pick-5-overview.html',
controller: 'pickOverview',
title: 'SawMaster - Step 6 (Cart)',
desc: 'Create your blade in :material measured at :sizemm :widthmm wide with :tpi TPI',
})
.otherwise({
templateUrl: '/app/views/pick-0-material.html',
controller: 'pickMaterial',
title: 'SawMaster - bandsaw blades'
});
$locationProvider.html5Mode(true);
});
app.run(['$rootScope', '$route', function ($rootScope, $route) {
$rootScope.$on('$routeChangeSuccess', function () {
document.title = $route.current.title || '';
let desc = $route.current.desc;
try {
if ($route.current.params) {
for (const key in $route.current.params) {
desc = desc.replace(new RegExp(':' + key), $route.current.params[key]);
}
}
} catch (err) {
}
document.querySelector('meta[name=description]').attributes.getNamedItem('content').textContent = desc || 'Order made to measure Bandsaw blades';
window.scrollTo(0, 0);
});
}]);
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(http|https|ftp|mailto|callto):/);
}]);
setInterval(() => {
var height = (document.body.scrollHeight) + 175;
if (height !== window.lastSentHeight) {
window.lastSentHeight = height;
window.parent.postMessage({ height: height }, "https://sawmaster.co.uk");
}
}, 100);angular.module('SawMaster').controller('cart', ['$scope', '$route', '$routeParams', 'conversion', '$http', 'cart', '$location', function ($scope, $route, $routeParams, $conversion, $http, $cart, $location) {
$scope.cart = $cart.get();
$scope.orderId = new Date().valueOf().toString().slice(4, 14);
localStorage.setItem('orderId', $scope.orderId);
if (window.location.search.includes('framed')) {
$scope.returnButton = 'shop';
} else {
$scope.returnButton = 'start';
}
$scope.generateDetails = function () {
$scope.detailed = [];
$scope.total = 0;
$scope.preTaxTotal = 0;
$scope.taxTotal = 0;
for (var i = 0; i < $scope.cart.length; i++) {
var thisItem = $scope.cart[i];
$scope.cart[i].price = parseFloat($scope.cart[i].price);
if (thisItem.quantity > 1) {
for (var j = 0; j < thisItem.quantity; j++) {
$scope.tallyUp(thisItem.price);
$scope.detailed.push(thisItem);
}
} else {
$scope.tallyUp(thisItem.price);
$scope.detailed.push(thisItem);
}
}
$scope.subTotal = $scope.total;
$scope.calculateDelivery();
};
$scope.calculateDelivery = function () {
var preTaxTotal = $scope.preTaxTotal;
// below £20 = Free
// £20 -> £30 = £1.99
// £30 -> £40 = £3.50
// £40 -> £60 = £5
// £60 -> £90 = £8
// £90+ = £11
// console.log('Total:');
// console.log(preTaxTotal);
// FREE DELIVERY!
$scope.delivery = 0;
// if (preTaxTotal <= 20) {
// $scope.delivery = 0;
// } else if (preTaxTotal > 20 && preTaxTotal < 30) {
// $scope.delivery = 1.66; // 1.99
// } else if (preTaxTotal >= 30 && preTaxTotal < 40) {
// $scope.delivery = 2.92; // 3.50
// } else if (preTaxTotal >= 40 && preTaxTotal < 60) {
// $scope.delivery = 4.17; // 5.00
// } else if (preTaxTotal >= 60 && preTaxTotal < 90) {
// $scope.delivery = 6.67; // 8.00
// } else {
// $scope.delivery = 9.17; // 11.00
// }
// $scope.total += parseFloat($scope.delivery * 1.2);
}
$scope.tallyUp = function (price) {
var tax = parseFloat(((price / 100) * 20).toFixed(2));
$scope.preTaxTotal += parseFloat(price);
$scope.taxTotal += parseFloat(tax);
$scope.total += parseFloat(price + tax);
$scope.total = parseFloat($scope.total).toFixed(3);
$scope.total = parseFloat($scope.total);
};
$scope.removeItem = function (index) {
if (confirm('Are you sure you want to remove this from your order?')) {
$scope.cart.splice(index, 1);
$cart.save($scope.cart);
$scope.generateDetails();
}
};
$scope.onQuantityChange = function () {
$cart.save($scope.cart);
$scope.generateDetails();
};
$scope.checkout = function () {
if ($scope.cart.length) {
$scope.checkoutLoading = true;
$cart.save($scope.cart);
localStorage.setItem('preTaxTotal', $scope.preTaxTotal);
localStorage.setItem('taxTotal', $scope.taxTotal);
localStorage.setItem('total', $scope.total);
localStorage.setItem('breakdownHTML', document.getElementById('breakdown').outerHTML);
if (window.location.search.includes('framed')) {
$location.url('/checkout?framed=true');
} else {
$location.url('/checkout');
}
}
};
$scope.getGrandTotal = function () {
return $scope.total.toFixed(2);
};
$scope.goBackToStart = function () {
window.location.href = '/';
}
$scope.generateDetails();
}]);angular.module('SawMaster').controller('checkout', ['$scope', '$route', '$routeParams', 'conversion', '$http', 'cart', '$location', function ($scope, $route, $routeParams, $conversion, $http, $cart, $location) {
$scope.cart = $cart.get();
$scope.loading = false;
if (window.location.search.includes('framed')) {
$scope.returnButton = 'shop';
} else {
$scope.returnButton = 'start';
}
if ($scope.cart && $scope.cart.length > 0) {
var orderId = localStorage.getItem('orderId') || '0';
var breakdownHTML = localStorage.getItem('breakdownHTML') || '';
var preTaxTotal = localStorage.getItem('preTaxTotal');
var taxTotal = localStorage.getItem('taxTotal');
var total = localStorage.getItem('total');
$scope.total = parseFloat(total).toFixed(2);
$scope.checkoutPayPal = function () {
$scope.loading = true;
try { $cart.messageShop('checkoutRedirect:' + total); } catch (err) { }
setTimeout(() => {
$http.post('/api-checkout-paypal.php?orderId=' + orderId, { cart: $scope.cart, breakdown: breakdownHTML, preTaxTotal: preTaxTotal, taxTotal: taxTotal, total: total }).then(function (res) {
if (res && res.data && res.data.url) {
try {
// window.gtag('event', 'Conversion', {
// 'event_category': 'Checkout',
// 'event_label': 'Checkout',
// 'value': res['data']['total']
// });
// window.gtag('event', 'conversion', {
// 'send_to': 'AW-749741631/48grCJag8ZoBEL_MwOUC',
// 'transaction_id': '',
// 'event_callback': function () {
// if (typeof (url) != 'undefined') {
// window.location = url;
// }
// }
// });
} catch (err) {
console.log(err);
}
setTimeout(function () {
$scope.redirect(res.data.url);
}, 1000);
} else {
alert('Sorry, there was an issue checking out, please call us instead');
}
});
}, 1000);
}
} else {
$location.url('/cart');
}
$scope.goBack = function () {
$location.url('/cart');
}
$scope.checkoutStripe = function () {
$scope.loading = true;
try { $cart.messageShop('checkoutRedirect:' + total); } catch (err) { }
setTimeout(() => {
$http.post('/api-checkout-stripe.php?orderId=' + orderId, { cart: $scope.cart, breakdown: breakdownHTML, preTaxTotal: preTaxTotal, taxTotal: taxTotal, total: total }).then(function (res) {
if (res && res.data && res.data.url) {
setTimeout(function () {
$scope.redirect(res.data.url);
}, 1000);
}
});
}, 1000);
}
$scope.redirect = function (url) {
if (window.self === window.top) {
window.location.href = url;
} else {
window.parent.location.href = url;
}
}
}]);angular.module('SawMaster').controller('progress', ['$scope', '$rootScope', 'cart', 'config', '$sce', '$location', function ($scope, $rootScope, $cart, $config, $sce, $location) {
window.navigate = (path) => {
$location.url(path);
$scope.$apply();
}
$scope.setup = () => {
var paths = window.location.pathname.toString().split('/');
var current = 1;
if (window.location.pathname.includes('/cart'))
current = 0;
if (window.location.pathname.includes('/checkout'))
current = 0;
if (window.location.pathname.includes('/thanks'))
current = 0;
if (window.location.pathname !== '/' && current === 1) {
current = paths.length;
}
current--; // to match array index
const steps = [
{ label: 'Type', subLabel: 'Choose a type', path: '/', icon: 'list' },
{ label: 'Unit', subLabel: 'Choose a unit', path: `/${paths[1]}`, icon: 'toolbox' },
{ label: 'Length', subLabel: 'Choose a length', path: `/${paths[1]}/${paths[2]}`, icon: 'ruler-vertical' },
{ label: 'Width', subLabel: 'Choose a width', path: `/${paths[1]}/${paths[2]}/${paths[3]}`, icon: 'ruler-horizontal' },
{ label: 'TPI', subLabel: 'Choose a TPI', path: `/${paths[1]}/${paths[2]}/${paths[3]}/${paths[4]}`, icon: 'arrows-alt-h' },
{ label: 'Overview', subLabel: 'View your selected blade', path: `/${paths[1]}/${paths[2]}/${paths[3]}/${paths[4]}`, icon: 'arrows-alt-h' },
// { label: 'Basket', subLabel: 'View your order', path: `/cart`, icon: 'shopping-cart' },
// { label: 'Checkout', subLabel: 'Check out your order', path: `/checkout`, icon: 'credit-card' },
];
let html = ``;
if (window.location.pathname.includes('/guide-tooth-selection')){
return $scope.template = ``;
}
for (let i = 0; i < steps.length; i++) {
let step = steps[i];
var status = ''
if (i < current)
status = 'previous';
if (i === current)
status = 'active';
if (i > current)
status = 'future';
html += `
`;
if (status === 'active')
html += ``;
else
html += `${i + 1}
`;
html += `
${step.label}
${step.subLabel}
`
html += ``;
if (i !== (steps.length - 1)) {
html += `
`;
}
}
if (current === -1)
$scope.template = ``;
else
$scope.template = $sce.trustAsHtml(html);
};
$rootScope.$on('$routeChangeSuccess', function () {
$scope.setup();
});
}]);angular.module('SawMaster')
.directive('backButton', ['$compile', '$location', function ($compile, $location) {
return {
scope: { label: '@', subLabel: '@' },
link: function ($scope, element) {
const label = $scope.label || 'Back';
const subLabel = $scope.subLabel || '';
$scope.goBack = function () {
var steps = window.location.pathname.toString().split('/');
var currentUrl = window.location.pathname;
if (currentUrl[currentUrl.length] === '/') { //Remove trailing slash
delete currentUrl[currentUrl.length - 1];
}
var nextUrl = steps.slice(0, steps.length - 1).join('/');
$location.url(nextUrl);
};
var template = `${(label)}${(subLabel) ? `
${subLabel}` : ''}`
element.append($compile(template)($scope));
},
};
}]);angular.module('SawMaster')
.directive('cartButton', ['cart', function ($cart) {
if ($cart.get().length && !window.location.search.includes('framed')) {
return {
template: ''
};
} else {
return {
template: ''
}
}
}]);angular.module('SawMaster')
.directive('footer', [function($cart) {
return {
templateUrl: '/app/views/footer.html'
};
}]);angular.module('SawMaster').controller('faults', ['$scope', function ($scope) {
$scope.faultList = [
{
title: 'Blead Breakage',
subTitle: 'Straight break indicates failure',
image: 'blead-breakage',
causes: [
'Incorrect blade - teeth too coarse',
'Band tension too high',
'Excessive feed',
'Incorrect cutting fluid',
'Wheel diameter too small for blade',
'Teeth in contact with work before start saw',
'Guides too tight'
],
solutions: [
'Use finer tooth pitch',
'Reduce band tension. See machine operator\'s manual ',
'Reduce feed pressure',
'Check coolant',
'Use thinner blade and lower speed',
'Adjust wheel alignment',
'Allow 1/2" clearance before starting cut',
'See operator\'s manual'
]
},
{
title: 'Premature dulling of teeth',
image: 'premature-dulling',
causes: [
'Blade teeth inverted (backwards)',
'Improper break-in period',
'Hard spots in material (like scale)',
'Material work hardened (check for hardness and adjust feed)',
'Improper cutting fluid or mixture',
'Speed and feed too high',
],
solutions: [
'Install blade correctly',
'Reduce feeds and speeds during break-in period in accordance with manufacturer\'s recommendations',
'Check material for actual hardness-hard spots like scale or flame cut surfaces',
'Increase feed pressure',
'Check coolant',
'Check recommendation chart',
]
},
{
title: 'Inaccurate cut',
image: 'inaccurate-cut',
causes: [
'Teeth dull',
'Over or under feed',
'Improper pitch blade',
'Incorrect blade (too many teeth per inch)',
'Cutting fluid not applied evenly',
],
solutions: [
'Use new blade',
'Check recommendation chart',
'Adjust coolant nozzles',
'Tighten or replace guides',
]
},
{
title: 'Leading in cut',
image: 'leading-in-cut',
causes: [
'Over feed',
'Lack of band tension',
'Tooth set damage',
'Loose guide arms or set too far from work',
],
solutions: [
'Check recommendation chart',
'Check operator\'s manual for correct tension',
'Check material hardness',
'Adjust arm close to work as possible, tighten and align',
'Check machine guide',
]
},
{
title: 'Chip Welding',
image: 'chip-welding',
causes: [
'Improper or lack of cutting fluid',
'Wrong coolant concentration',
'Excessive speed or pressure',
'Incorrect blade (wrong pitch)',
],
solutions: [
'Check coolant',
'Reduce speed or pressure',
'Check recommendation chart',
]
},
{
title: 'Teeth fracture',
subTitle: 'back of tooth indicates work spinning in clamps',
image: 'teeth-fracture',
causes: [
'Incorrect feed and/or speed',
'Incorrect blae (wrong pitch)',
'Saw guides not adjusted properly',
],
solutions: [
'Check recommendation chart',
'Adjust or replace saw guides',
]
},
{
title: 'Irregular break',
subTitle: 'Indicates material movement',
image: 'irregular-break',
causes: [
'Indexing out of sequence',
'Material loose in vice',
],
solutions: [
'Check for correct indexing sequence (head rise)',
'Check hydraulic pressure',
]
},
{
title: 'Teeth stripping',
image: 'teeth-stripping',
causes: [
'Feed pressure too high',
'Tooth stuck in cut',
'No cuttig fluid or incorrect coolant',
'Hard spots scale, inclusions, etc',
'Incorrect blade (wrong pitch)',
'Work spinning in vice; loose "nest" or bundles',
'Blade teeth running backwards',
],
solutions: [
'Reduce feed pressure, see recommendation chart',
'Never enter same (old blade) cut with new blade',
'Check coolant table',
'Check hardness. Descale and or anneal if necessary',
'Check recommendation chart',
'Check hydraulic pressure; be sure work is firmly held',
'Reverse blade (turn inside out)',
]
},
{
title: 'Wear on back of blades',
image: 'wear-on-back',
causes: [
'Insufficient blade tension',
'Back-up guide frozen in position, damaged or worn',
'Guide arms to far apart, worn or loose',
'Blade rubbing on wheel flanges',
],
solutions: [
'See machine operator\'s manual for correct band tension',
'Reduce feed pressure, see recommendation chart',
'Free pressure block and realign. If worn replace (never regrind)',
'Move arms close to work as possible',
'Adjust wheel alignment',
]
},
{
title: 'Rough cut',
subTitle: 'Washboard surface vibration and/or chatter',
image: 'rough-cut',
causes: [
'Dull or damaged blade',
'Incorrect feed and/or speed',
'Lack of band support',
'Insufficient band tension',
'Incorrect pitch blade',
],
solutions: [
'Replace with new blade',
'Check recommendation chart: adjust until noise disappears',
'Set guide arm properly - as close to work as possible',
'Check operator\'s manual for correct tensions',
]
},
{
title: 'Wear lines, loss of set',
image: 'wear-lines',
causes: [
'Saw guide inserts or pulley on teeth',
'Insufficient blade tension',
'Hard spots',
'Backing guide worn',
],
solutions: [
'Check operator\'s manual for correct blade with',
'Check for correct blade tension',
'Check material hardness',
'Replace',
]
},
{
title: 'Twisted blade',
subTitle: 'Profile sawing',
image: 'twisted-blade',
causes: [
'Band sticking in cut',
'Side guides adjusted too tight',
'Work not held firmly',
'Incorrect or lack of cutting fluid',
],
solutions: [
'Check for over-feed, damage set, is blade too wide for radii being cut?',
'Set side guides properly',
'Check vice and hydraulics',
'Check coolant',
]
},
{
title: 'Blade wear',
subTitle: 'Teeth blued',
image: 'blade-wear',
causes: [
'Incorrect blade',
'Incorrect lead or speed',
'Improper or lack of cutting fluid',
],
solutions: [
'Check recommendation chart',
'Check coolant',
]
},
{
title: 'Broken teeth',
subTitle: 'Front of tooth indicates work spinning in vice',
image: 'broken-teeth',
causes: [
'Material loose in vice',
'Incorrect blade (wrong pitch)',
],
solutions: [
'Check hydraulic pressure',
'Check recommendation chart',
]
},
]
}]);app.filter('material', function () {
return function (material) {
switch (material) {
case 'bimetal':
return material;
case 'carbon':
return material;
case 'bio':
return 'Meat & Fish';
case 'synthetic':
return 'Foam & Leather';
default:
return material;
}
};
});app.filter('tpiLabel', function () {
return function (material) {
switch (material) {
case 'synthetic':
return 'Cutting Type';
default:
return 'TPI';
}
};
});angular.module('SawMaster').controller('guidesToothSelection', ['$scope', 'conversion', '$routeParams', function ($scope, $conversion, $routeParams) {
// dynamic page
// imperial measurements because backwards conversion is a pain in the ...
$scope.material = $routeParams.guide;
$scope.unit = 'in';
$scope.unitName = 'Inches';
$scope.selected = null;
$scope.tabular = null;
$scope.convert = $conversion;
var guides = {
bimetal: {
options: [
{
label: 'Rectangular Objects', subLabel: '(Use width for sizing)', value: 'rectangular', guideEnd: 30, data: [
{ label: '14/18', start: 0, end: 0.2, colspan: 2 },
{ label: '10/14', start: 0.2, end: 0.3, colspan: 1 },
{ label: '8/12', start: 0.3, end: 0.50, colspan: 2 },
{ label: '6/10', start: 0.50, end: 0.75, colspan: 1 },
{ label: '5/8', start: 0.75, end: 1, colspan: 4 },
{ label: '4/6', start: 1, end: 2.5, colspan: 4 },
{ label: '3/4', start: 2.5, end: 4.5, colspan: 8 },
{ label: '2/3', start: 4.5, end: 8, colspan: 4 },
{ label: '1.4 / 2.5', start: 8, end: 15, colspan: 3 },
{ label: '1 / 1.5', start: 15, end: 30, colspan: 1 },
],
points: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 5, 6, 7, 8, 9, 10, 15, 30]
},
{
label: 'Circular Objects', subLabel: '(Use diameter for sizing)', value: 'circular', guideEnd: 30, data: [
{ label: '14/18', start: 0, end: 0.25, colspan: 3 },
{ label: '10/14', start: 0.25, end: 0.4, colspan: 2 },
{ label: '8/12', start: 0.4, end: 0.65, colspan: 2 },
{ label: '6/10', start: 0.65, end: 0.85, colspan: 2 },
{ label: '5/8', start: 0.85, end: 1.25, colspan: 2 },
{ label: '4/6', start: 1.25, end: 2.75, colspan: 6 },
{ label: '3/4', start: 2.75, end: 5.5, colspan: 6 },
{ label: '2/3', start: 5.5, end: 9, colspan: 4 },
{ label: '1.4 / 2.5', start: 9, end: 15, colspan: 2 },
{ label: '1 / 1.5', start: 15, end: 30, colspan: 1 },
],
points: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 5, 6, 7, 8, 9, 10, 15, 30]
},
{
label: 'Pipe Tubing', subLabel: '(Use wall thickness for sizing)', value: 'pipe', guideEnd: 1.5, data: [
{ label: '10/14', start: 0.06, end: 0.125, colspan: 1 },
{ label: '8/12', start: 0.125, end: 0.1875, colspan: 1 },
{ label: '6/10', start: 0.1875, end: 0.25, colspan: 1 },
{ label: '5/8', start: 0.25, end: 0.375, colspan: 2 },
{ label: '4/6', start: 0.375, end: 0.75, colspan: 6 },
{ label: '3/4', start: 0.75, end: 1.25, colspan: 6 },
{ label: '2/3', start: 1.25, end: 1.5, colspan: 2 },
],
points: [0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1, 1.125, 1.25, 1.375, 1.5]
}],
},
carbon: {
options: [
{
label: 'Rectangular Objects', subLabel: '(Use width for sizing)', value: 'rectangular', guideEnd: 30, data: [
{ label: '24', start: 0, end: 0.1, colspan: 1 },
{ label: '18', start: 0.1, end: 0.2, colspan: 1 },
{ label: '14', start: 0.2, end: 0.4, colspan: 2 },
{ label: '10', start: 0.4, end: 0.7, colspan: 3 },
{ label: '8', start: 0.7, end: 1, colspan: 3 },
{ label: '6', start: 1, end: 3, colspan: 8 },
{ label: '4', start: 3, end: 10, colspan: 10 },
{ label: '3', start: 10, end: 30, colspan: 2 },
],
points: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 5, 6, 7, 8, 9, 10, 15, 30]
}, {
label: 'Circular Objects', subLabel: '(Use diameter for sizing)', value: 'circular', guideEnd: 30, data: [
{ label: '24', start: 0, end: 0.1, colspan: 1 },
{ label: '18', start: 0.1, end: 0.2, colspan: 1 },
{ label: '14', start: 0.2, end: 0.4, colspan: 2 },
{ label: '10', start: 0.4, end: 0.7, colspan: 3 },
{ label: '8', start: 0.7, end: 1, colspan: 3 },
{ label: '6', start: 1, end: 3, colspan: 8 },
{ label: '4', start: 3, end: 10, colspan: 10 },
{ label: '3', start: 10, end: 30, colspan: 2 },
],
points: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 5, 6, 7, 8, 9, 10, 15, 30]
},
]
}
};
// need to convert all the imperial measurements into metric
for (var material in guides) {
for (var option of guides[material].options) {
for (var point of option.points) {
option.points[option.points.indexOf(point)] = parseFloat((point * 25.4).toFixed(6));
}
}
}
if ($routeParams.guide in guides && guides[$routeParams.guide] && guides[$routeParams.guide].options) {
$scope.options = guides[$routeParams.guide].options;
}
$scope.setOption = function (option) {
$scope.selected = option;
}
$scope.setUnit = function (unit, unitName) {
$scope.unit = unit;
$scope.unitName = unitName;
}
// for (var i = 0; i < option.guideEnd; i += 0.25) {
// i = parseFloat(i.toFixed(2));
// option.points.push(i);
// for (var selection of option.data) {
// if (typeof selection.colspan === 'undefined') {
// selection.colspan = 0;
// }
// if (i === 0 && selection.start === 0) {
// selection.colspan++;
// break;
// }
// if (i > selection.start && i <= selection.end) {
// selection.colspan++;
// break;
// }
// }
// }
}]);angular.module('SawMaster').controller('pickMaterial', ['$scope', '$rootScope', 'cart', 'config', function ($scope, $rootScope, $cart, $config) {
$scope.showBimetal = $config.get('showBimetal') === 'true';
$scope.showCarbon = $config.get('showCarbon') === 'true';
$scope.showBio = $config.get('showBio') === 'true';
$scope.showSynthetic = $config.get('showSynthetic') === 'true';
$scope.showReciprocating = $config.get('showReciprocating') === 'true';
$scope.goToEbay = function () {
window.open('https://www.ebay.co.uk/sch/uk-sawmaster/m.html?_nkw=&_armrs=1&_ipg=&_from=', '_blank');
}
$scope.hasItemsInCart = false;
try {
$scope.hasItemsInCart = $cart.get().length > 0 || false;
} catch (err) {
}
}]);angular.module('SawMaster').controller('pickMeasurement', ['$scope', '$rootScope', '$routeParams', 'cart', function ($scope, $route, $routeParams, $cart) {
$scope.material = $routeParams.material;
$scope.displayMaterial = $routeParams.material;
if ($scope.displayMaterial === 'synthetic')
$scope.displayMaterial = 'Band Knife';
if ($scope.displayMaterial === 'bio')
$scope.displayMaterial = 'Reciprocating';
$scope.showBack = true;
if (window.location.search.includes('framed')) {
$scope.showBack = false;
}
$cart.get();
document.querySelector('link[rel=canonical]').attributes.getNamedItem('href').textContent = 'https://order.sawmaster.co.uk/' + $scope.material;
}]);angular.module('SawMaster').controller('pickLength', ['$scope', '$route', '$routeParams', 'conversion', '$location', 'config', function ($scope, $route, $routeParams, $conversion, $location, $config) {
document.querySelector('link[rel=canonical]').attributes.getNamedItem('href').textContent = 'https://order.sawmaster.co.uk/' + $routeParams.material + '/' + $routeParams.unit;
$scope.unit = $routeParams.unit;
if ($scope.unit === 'mm') {
$scope.step = 1;
} else {
$scope.step = 0.01;
}
const setBoundaries = function (min, max) {
$scope.minLengths = {
ft: $conversion('ft', min, true),
m: $conversion('m', min, true),
mm: $conversion('mm', min, true),
in: $conversion('in', min, true),
};
$scope.maxLengths = {
ft: $conversion('ft', max, true),
m: $conversion('m', max, true),
mm: $conversion('mm', max, true),
in: $conversion('in', max, true),
};
};
if ($routeParams.material === 'carbon')
setBoundaries($config.get('carbonMinimumSize'), $config.get('carbonMaximumSize'));
if ($routeParams.material === 'bimetal')
setBoundaries($config.get('bimetalMinimumSize'), $config.get('bimetalMaximumSize'));
if ($routeParams.material === 'bio')
setBoundaries($config.get('bioMinimumSize'), $config.get('bioMaximumSize'));
if ($routeParams.material === 'synthetic')
setBoundaries($config.get('syntheticMinimumSize'), $config.get('syntheticMaximumSize'));
if ($routeParams.material === 'reciprocating')
setBoundaries($config.get('reciprocatingMinimumSize'), $config.get('reciprocatingMaximumSize'));
$scope.steps = {
ft: 0.01,
m: 0.001,
mm: 1,
in: 0.1
};
if (localStorage.getItem('selectedUnit') === $scope.unit) {
$scope.typedLength = parseInt(localStorage.getItem('selectedLength'));
}
$scope.isBadLength = function () {
$scope.calcLength = Math.ceil(($conversion($scope.unit, $scope.typedLength)));
if ($scope.calcLength < $scope.minLengths['mm']) {
return true;
}
if ($scope.calcLength > $scope.maxLengths['mm']) {
return true;
}
return false;
}
$scope.submit = function () {
if (!$scope.isBadLength()) {
var newUrl = '/' + $routeParams.material + '/' + $routeParams.unit + '/' + $scope.calcLength;
$location.url(newUrl);
localStorage.setItem('selectedLength', $scope.typedLength);
localStorage.setItem('selectedUnit', $scope.unit);
}
}
$scope.parseInt = function (value) {
return parseInt(value);
}
$scope.parseFloat = function (value) {
return parseFloat(value);
}
$scope.isBadLength();
setTimeout(() => {
document.querySelector('.length-input').focus();
}, 250);
}]);angular.module('SawMaster').controller('pickWidth', ['$scope', '$route', '$routeParams', 'conversion', '$http', function($scope, $route, $routeParams, $conversion, $http) {
document.querySelector('link[rel=canonical]').attributes.getNamedItem('href').textContent = 'https://order.sawmaster.co.uk/' + $routeParams.material + '/' + $routeParams.unit + '/' + $routeParams.size;
$scope.unit = $routeParams.unit;
$scope.size = $routeParams.size;
$scope.currentUrl = window.location.pathname;
$scope.loading = true;
$scope.blades = [];
$http.get('/api-prices.php?material=' + $routeParams.material + '&length=' + $scope.size).then(function(res) {
$scope.blades = res.data;
$scope.loading = false;
});
}]);angular.module('SawMaster').controller('pickTpi', ['$scope', '$route', '$routeParams', 'conversion', '$http', function ($scope, $route, $routeParams, $conversion, $http) {
document.querySelector('link[rel=canonical]').attributes.getNamedItem('href').textContent = 'https://order.sawmaster.co.uk/' + $routeParams.material + '/' + $routeParams.unit + '/' + $routeParams.size + '/' + $routeParams.width;
$scope.width = $routeParams.width;
$scope.currentUrl = window.location.pathname;
$scope.loading = true;
$scope.blades = [];
$http.get('/api-tpi.php?material=' + $routeParams.material + '&width=' + $scope.width + '&length=' + $routeParams.size).then(function (res) {
$scope.blades = res.data;
$scope.loading = false;
});
$scope.tpiLabel = 'TPI';
if ($routeParams.material === 'synthetic'){
$scope.tpiLabel = 'Cutting Type';
}
$scope.encode = function (input) {
return encodeURIComponent(input);
}
}]);angular.module('SawMaster').controller('pickOverview', ['$scope', '$route', '$routeParams', 'conversion', '$http', 'cart', '$location', function ($scope, $route, $routeParams, $conversion, $http, $cart, $location) {
document.querySelector('link[rel=canonical]').attributes.getNamedItem('href').textContent = 'https://order.sawmaster.co.uk/' + $routeParams.material + '/' + $routeParams.unit + '/' + $routeParams.size + '/' + $routeParams.width + '/' + $routeParams.tpi;
$scope.loading = true;
$scope.width = $routeParams.width;
$scope.tpi = decodeURIComponent($routeParams.tpi);
$scope.calcSize = $routeParams.size;
//Selected
$scope.material = $routeParams.material;
$scope.size = localStorage.getItem('selectedLength');
$scope.unit = localStorage.getItem('selectedUnit');
$scope.addToCart = function () {
if (($scope.loading || !$scope.price) || !$scope.size || !$scope.unit)
return;
$cart.add($scope.material, $scope.size, $scope.unit, $scope.width, $scope.widthImperial, $scope.tpi, 1, $scope.price, $scope.prodId);
$location.url('/cart');
};
$scope.startAgain = function(){
$location.url('/');
};
$http.get('/api-prices.php?material=' + $routeParams.material + '&length=' + $scope.calcSize + '&width=' + $scope.width).then(function (res) {
if (res.data && res.data[0] && res.data[0]['price']) {
$scope.price = parseFloat(res.data[0]['price']);
$scope.widthImperial = res.data[0]['widthImperial'];
$scope.prodId = res.data[0]['id'];
$scope.material = res.data[0]['material'];
// $scope.freeDelivery = $cart.get().length === 0 || ((parseFloat($cart.getTotal()) + parseFloat($scope.price)).toFixed(2)) <= 20;
$scope.freeDelivery = true;
$scope.loading = false;
} else {
$scope.loading = false;
}
});
}]);
angular.module('SawMaster').controller('remoteController', ['$scope', '$route', '$routeParams', 'conversion', '$http', 'cart', '$location', function ($scope, $route, $routeParams, $conversion, $http, $cart, $location) {
const queryStringToObject = () => {
const search = window.location.search.substring(1);
return search.split('&').reduce((params, param) => {
let [key, value] = param.split('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, {});
};
const params = queryStringToObject();
if (params.custom) {
$cart.addCustom(params.title, params.price);
setTimeout(() => { window.location.href = params.returnTo }, 0);
} else {
$http.get('/api-prices.php?material=' + params.material + '&length=' + params.length + '&width=' + params.width).then(function (res) {
if (res.data && res.data[0] && res.data[0]['price']) {
const product = res.data[0];
$cart.add(params.material, params.length, 'mm', params.width, product.widthImperial, params.tpi, 1, product.price, product.id);
setTimeout(() => { window.location.href = params.returnTo }, 0);
}
});
}
}]);app.factory('cart', function () {
return {
add: function (material, size, unit, width, widthImperial, tpi, quantity, price, prodId) {
var cart = this.get();
for (var i = 0; i < cart.length; i++) {
var thisItem = cart[i];
if (thisItem['material'] === material && thisItem['size'] === size && thisItem['unit'] === unit && thisItem['width'] === width && thisItem['tpi'] === tpi) {
thisItem['quantity'] += quantity;
return this.save(cart);
}
}
cart.push({
material: material,
size: size,
unit: unit,
width: width,
widthImperial: widthImperial,
tpi: tpi,
quantity: quantity,
price: price,
prodId: prodId
});
this.save(cart);
this.messageShop('addToCart');
},
addCustom: function (title, price) {
var cart = this.get();
if (cart.find(item => item.title === title && item.price === price)) {
var item = cart.find(item => item.title === title && item.price === price);
item.quantity++;
} else {
cart.push({ title, price, quantity: 1 });
}
this.save(cart);
},
get: function () {
const cart = JSON.parse(localStorage.getItem('cart')) || [];
if (cart.length === 0) {
this.messageShop('cartEmpty');
} else {
this.messageShop('addToCart');
}
return cart;
},
getTotal: function () {
var cart = this.get();
var total = 0;
if (cart.length) {
for (var i = 0; i < cart.length; i++) {
if (cart[i].price) {
total += parseFloat(parseFloat((cart[i].price) * (cart[i].quantity || 1)).toFixed(2));
}
}
}
return total;
},
save: function (cart) {
this.cart = cart;
this.store();
},
store: function () {
if (this.cart) {
if (this.cart.length === 0)
this.messageShop('cartEmpty');
localStorage.setItem('cart', JSON.stringify(this.cart));
}
},
empty: function () {
this.save([]);
this.messageShop('cartEmpty');
},
messageShop: function (message) {
setTimeout(() => {
document.getElementById('shopFrame').src = 'https://sawmaster.co.uk/shop?message=' + message;
}, 0);
}
}
});
app.factory('config', function () {
return {
get: function (key) {
for (var i = 0; i <= window.appConfig.length; i++) {
if (window.appConfig[i] && window.appConfig[i].configName && window.appConfig[i].configName === key) {
return window.appConfig[i].configValue;
}
}
return null;
}
};
});
app.factory('conversion', function () {
return function (unit, size, backwards, pretty) {
backwards = !!backwards;
pretty = !!pretty;
var conversions = {
mm: 1,
ft: 304.8,
m: 1000,
in: 25.4
}
if (pretty && (unit === 'ft' || unit === 'in')) {
var value = parseFloat((size / conversions[unit] || 0).toFixed(6));
var gcd = function (a, b) {
if (b < 0.0000001) return a; // Since there is a limited precision we need to limit the value.
return gcd(b, Math.floor(a % b)); // Discard any fractions due to limitations in precision.
};
var prefix = '';
if (value > 1) {
prefix = parseInt(value).toString() + '+';
}
var fraction = (value - parseInt(value));
if (fraction === 0) {
return value.toString();
}
var len = fraction.toString().length - 2;
var denominator = Math.pow(10, len);
var numerator = fraction * denominator;
var divisor = gcd(numerator, denominator); // Should be 5
numerator /= divisor; // Should be 687
denominator /= divisor; // Should be 2000
return prefix + (Math.floor(numerator) + '/' + Math.floor(denominator));
} else {
if (backwards) {
return parseFloat((size / conversions[unit] || 0).toFixed(2));
} else {
return parseFloat((size * conversions[unit] || 0).toFixed(2));
}
}
}
});app.factory('prettyPrintImperial', function () {
return function (unit, size, backwards) {
}
});angular.module('SawMaster').controller('thanks', ['cart', function ($cart) {
$cart.empty();
localStorage.removeItem('breakdownHTML');
localStorage.removeItem('preTaxTotal');
localStorage.removeItem('taxTotal');
localStorage.removeItem('total');
}]);