Skip to content

Commit

Permalink
Remove AJAX filter temporary, add and testing proper sorting filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
raylight75 committed Jun 29, 2016
1 parent b6e0688 commit 2cb6ef0
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 459 deletions.
456 changes: 169 additions & 287 deletions .idea/workspace.xml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions app/Repositories/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ public static function pagination($parent)
if (!empty(Request::input('brand'))) {
$query->whereIn('brand_id', Request::input('brand'));
};
$query->orderBy('price', Request::input('price'));
$query->orderBy('name', Request::input('name'));
if(Request::input('name')){
$query->orderBy('name', Request::input('name'));
}else{
$query->orderBy('price', Request::input('price'));
}
//$query->orderBy('price', Request::input('price'));
//$query->orderBy('name', Request::input('name'));
$query->groupBy('product_id');
$result = $query->paginate(6);
return $result;
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/ShareRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static function prepareFilter(Request $request,$parent)
'size' => (array)$request->input('size'),
'color' => (array)$request->input('color'),
'brand' => (array)$request->input('brand'),
'price' => (array)$request->input('price'),
'name' => (array)$request->input('name'),
//'price' => (array)$request->input('price'),
//'name' => (array)$request->input('name'),
'category' => (array)$request->input('categ')
);
return $data;
Expand Down
227 changes: 124 additions & 103 deletions public/js/customjs.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,143 @@
// Ajax pagination
$(window).on('hashchange', function () {
if (window.location.hash) {
var page = window.location.hash.replace('#', '');
if (page == Number.NaN || page <= 0) {
return false;
} else {
getProducts(page);
}
}
});
$(function () {
$('#ajaxproducts').on('click', '.pagination a', function (e) {
var url = $(this).attr('href');
var hashes = url.split("?")[1];
var page = $(this).attr('href').split('page=')[1];
getProducts(hashes.split('page').reverse()[1], page);
e.preventDefault();
});
});
function getProducts(data, page) {
$.ajax({
url: '?' + data + 'page=' + page,
type: "GET",
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Posts could not be loaded.');
});
}
/*$(window).on('hashchange', function () {
if (window.location.hash) {
var page = window.location.hash.replace('#', '');
if (page == Number.NaN || page <= 0) {
return false;
} else {
getProducts(page);
}
}
});
$(function () {
$('#ajaxproducts').on('click', '.pagination a', function (e) {
var url = $(this).attr('href');
var hashes = url.split("?")[1];
var page = $(this).attr('href').split('page=')[1];
getProducts(hashes.split('page').reverse()[1], page);
e.preventDefault();
});
});
function getProducts(data, page) {
$.ajax({
url: '?' + data + 'page=' + page,
type: "GET",
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Posts could not be loaded.');
});
}*/
// End Ajax pagination
//Repair brower back button with pushState.
/*$(function(){
var replacePage = function(url) {
$.ajax({
type: "GET",
url: url,
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Items could not be loaded.');
});
}
var replacePage = function(url) {
$.ajax({
type: "GET",
url: url,
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Items could not be loaded.');
});
}
$(document).on('click', '.pagination a', function(e){
console.log(this.href);
history.pushState(null, null, this.href);
replacePage(this.href);
e.preventDefault();
});
$(document).on('click', '.pagination a', function(e){
console.log(this.href);
history.pushState(null, null, this.href);
replacePage(this.href);
e.preventDefault();
});
$('#status').val($('#status').val() + ' on ' + new Date());
$('#status').val($('#status').val() + ' on ' + new Date());
$(window).bind('popstate', function(){
replacePage(location.pathname);
});
});*/
$(window).bind('popstate', function(){
replacePage(location.pathname);
});
});*/
//End repair back button.
//Start checkbox filter
$(document).ready(function () {
function showValues() {
var baseUrl = document.location.origin;
var url = $(location).attr('href');
var parentId = url.split( '/')[5].split('?').reverse()[1];
var categ = '';
var size = '';
var color = '';
var brand = '';
var price = '';
var name = '';
$("input:checkbox").each(function () {
categ = $('input[name="categ[]"]:checked').serialize();
size = $('input[name="size[]"]:checked').serialize();
color = $('input[name="color[]"]:checked').serialize();
brand = $('input[name="brand[]"]:checked').serialize();
price = $('input[name="price"]:checked').serialize();
name = $('input[name="name"]:checked').serialize();
});

$("input[name=price]").on('change', function() {
$("input[name=price]").not(this).prop('checked', false);
});
$("input[name=name]").on('change', function() {
$("input[name=name]").not(this).prop('checked', false);
});
var main_string = categ+"&"+size+"&"+color+"&"+brand+"&"+price+"&"+name;

$.ajax({
type: "GET",
url: baseUrl + "/filter/products/"+parentId,
data: main_string,
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Items could not be loaded.');
});
}
$("input[type='checkbox']").on("click", showValues);
});
//End checkbox filter
/*$(function() {
$('#categories input:checkbox').on('click', function() {
if ($(this).is(":checked"))
$("#categories").submit();
if ($('input:checkbox').is(':checked'))
$("#categories").submit();
});
$(".submit").hide();
/*$(document).ready(function () {
function showValues() {
var baseUrl = document.location.origin;
var url = $(location).attr('href');
var parentId = url.split( '/')[5].split('?').reverse()[1];
var categ = '';
var size = '';
var color = '';
var brand = '';
var price = '';
var name = '';
$("input:checkbox").each(function () {
categ = $('input[name="categ[]"]:checked').serialize();
size = $('input[name="size[]"]:checked').serialize();
color = $('input[name="color[]"]:checked').serialize();
brand = $('input[name="brand[]"]:checked').serialize();
price = $('input[name="price"]:checked').serialize();
name = $('input[name="name"]:checked').serialize();
});
$("input[name=price]").on('change', function() {
$("input[name=price]").not(this).prop('checked', false);
});
$("input[name=name]").on('change', function() {
$("input[name=name]").not(this).prop('checked', false);
});*/
});
var main_string = categ+"&"+size+"&"+color+"&"+brand+"&"+price+"&"+name;
$.ajax({
type: "GET",
url: baseUrl + "/filter/products/"+parentId,
data: main_string,
dataType: 'json',
}).done(function (data) {
$('#ajaxproducts').html(data);
}).fail(function () {
alert('Items could not be loaded.');
});
}
$("input[type='checkbox']").on("click", showValues);
});*/
//End checkbox filter
$(function () {
$('#categories input:checkbox').on('click', function () {
if ($(this).is(":checked"))
$("#categories").submit();
if ($('input:checkbox').is(':checked'))
$("#categories").submit();
});
$(".submit").hide();
});
/*$("input[name=price]").on('change', function () {
$("input[name=price]").not(this).prop('checked', false);
});
$("input[name=name]").on('change', function () {
$("input[name=name]").not(this).prop('checked', false);
});*/
$(document).ready(function () {
$('#priceasc,#pricedesc,#nameasc,#namedesc').on('click', function (e) {
e.preventDefault();
var inputAttr = {};
inputAttr.type = 'hidden';
if (this.id == 'priceasc') {
inputAttr.name = 'price';
inputAttr.value = 'asc';
} else if (this.id == 'pricedesc') {
inputAttr.name = 'price';
inputAttr.value = 'desc';
} else if (this.id == 'nameasc') {
inputAttr.name = 'name';
inputAttr.value = 'asc';
} else if (this.id == 'namedesc') {
inputAttr.name = 'name';
inputAttr.value = 'desc';
}
$('<input>').attr(inputAttr).appendTo('form');
$('#categories').submit();
});
});
/* $(document).ready(function(){
$("li.pagination a, li.prev a, li.next a, li.active a ").click(function() {
$.ajax({
Expand Down
Loading

0 comments on commit 2cb6ef0

Please sign in to comment.