我有这个js。我需要创建一个“视图”选项,以选择我的网页显示的图像数量。例如,如果有人选择"全部",该人将会查看我的类别中的每张图片。此外,我的过滤器只有1页。我需要它来过滤类别中的每个分页,即使它有60页。有人可以帮我吗?
代码:
categoriesApp.factory('LikeProduct', function ($resource) {
return $resource('firesale/front/ecommerce/likeproduct/', {}, {
save: {method: 'POST'},
delete: {method: 'POST', url: 'firesale/front/ecommerce/dislikeproduct/'},
});
})
categoriesApp.controller('CategoryListCtrl', function ($rootScope, $scope, $window, $routeParams, $sce, categories, FactoryWishList, EcommerceCart, LikeProduct) {
$scope.width2 = $window.innerWidth;
console.log($scope.width2);
$scope.is_loading = true;
$scope.coin_code = coin_code;
$scope.coin_currency = coin_currency;
$scope.site_url = site_url;
$scope.filterColor = null;
$rootScope.productToFilter = [];
$scope.filterProduct = [];
$scope.currentPage = 1;
$scope.numPerPage = 30;
$scope.maxSize = 5;
$scope.width2 = $window.innerWidth;
if ($scope.width2 <= 641) {
$scope.numPerPage = 30;
}
var page = 1;
if (angular.isUndefined($routeParams.pagination)) {
page = 1;
} else {
page = $routeParams.pagination;
}
categories.list('empty', page, $scope.numPerPage, function (data) {
$scope.data = data;
$rootScope.productToFilter = $scope.data.products;
$scope.pagination = $scope.data.pagination;
$scope.is_loading = false;
$scope.sortField = 'title';
$scope.reverse = false;
$scope.is_user_logged = is_user_logged;
$scope.search_prod_list = search_term;
$scope.$watch('cart_content', function (newValue, oldValue) {
angular.forEach($scope.data.products, function (entry) {
entry.qty = 0;
angular.forEach(newValue.data, function (entry2) {
if (entry.id === entry2.id)
{
entry.qty = entry2.qty;
}
});
});
});
$scope.$watch('search_prod_list', function (newValue) {
if (newValue.length > 0)
{
$scope.filterProduct = $rootScope.productToFilter;
console.log($scope.filterProduct);
}
else
{
$scope.search_prod_list = '';
$scope.currentPage = 1;
$scope.paginatorfunction();
}
});
/* Páginador */
$scope.numPages = function () {
return Math.ceil($scope.data.products.length / $scope.numPerPage);
};
$scope.pageChanged = function (currentPage) {
$scope.currentPage = currentPage;
};
$scope.paginatorfunction = function ()
{
if ($scope.search_prod_list.length == 0)
{
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filterProduct = $scope.data.products.slice(begin, end);
}
}
$scope.$watch('currentPage', function () {
$scope.paginatorfunction();
});
$scope.trustedHtml = function (plainText) {
return $sce.trustAsHtml(plainText);
}
$scope.prevent_default_paginate = function (paginate) {
if (paginate.length > 0) {
angular.element(document).ready(function () {
var url_actual = window.location.href;
var category = url_actual.split('#')[1];
var current_page = category.split('/')[2];
if (current_page != '' || current_page != null) {
$('.a-pagination-w').each(function (key, element) {
if ($(element).data('ci-pagination-page') == current_page) {
$(element).parent().addClass('active');
$(element).attr('disabled');
}
});
}
});
return true;
} else {
return false;
}
}
});
categories.resent_products(function (data) {
$scope.resent_products = data;
});
categories.featured_products(function (data) {
$scope.featured_products = data;
});
$scope.clickQuickView = function (product) {
FactoryWishList.quickView(product);
}
$scope.clickWishList = function (id_product) {
$rootScope.current_product_wish_list_id = id_product;
}
$scope.insertInWishList = function (wishlist) {
FactoryWishList.insertInWishList(wishlist);
}
$scope.deleteInWishList = function (wishlist) {
FactoryWishList.deleteInWishList(wishlist);
}
$scope.insertInCart = function (ecommerceCart) {
var cart = new EcommerceCart();
cart.id = ecommerceCart.id;
cart.qty = ecommerceCart.qty;
cart.$save(function (response) {
$rootScope.cart_content = response.cart_content;
});
}
$scope.dislikeProduct = function (product_data) {
if (is_user_logged)
{
var product_like = new LikeProduct();
product_like.id_product = product_data.id;
product_like.$delete(function (response) {
product_data.product_likes.userlikes = response.userlikes;
product_data.product_likes.count = response.count;
});
}
else
{
console.log('Debes estar logeado para dar dislike');
}
}
$scope.likeProduct = function (product_data) {
if (is_user_logged)
{
var product_like = new LikeProduct();
product_like.id_product = product_data.id;
product_like.$save(function (response) {
product_data.product_likes.userlikes = response.userlikes;
product_data.product_likes.count = response.count;
});
}
else
{
console.log('Debes estar logeado para dar like');
}
}
$scope.filterColorFunct = function (color) {
$scope.filterColor = color;
}
$scope.DeletefilterColorFunct = function () {
$scope.filterColor = null;
};
});
categoriesApp.controller('CategoryFilterListCtrl', function ($rootScope, $scope, $routeParams, $window, $sce, categories, FactoryWishList, EcommerceCart, LikeProduct) {
$scope.is_loading = true;
$scope.site_url = site_url;
$scope.coin_code = coin_code;
$scope.coin_currency = coin_currency;
$scope.filterColor = null;
$rootScope.productToFilter = [];
$scope.filterProduct = [];
$scope.currentPage = 1;
$scope.numPerPage = 30;
$scope.maxSize = 5;
$scope.width2 = $window.innerWidth;
if ($scope.width2 <= 641) {
$scope.numPerPage = 30;
}
categories.filter_list($routeParams.categoryId, 1, $scope.numPerPage, function (data) {
$scope.data = data;
$scope.pagination = $scope.data.pagination;
$rootScope.productToFilter = $scope.data.products;
$scope.is_loading = false;
$scope.sortField = 'title';
$scope.reverse = false;
$scope.is_user_logged = is_user_logged;
$scope.search_prod_list = '';
$scope.$watch('cart_content', function (newValue, oldValue) {
angular.forEach($scope.data.products, function (entry) {
entry.qty = 1;
angular.forEach(newValue.data, function (entry2) {
if (entry.id === entry2.id)
{
entry.qty = entry2.qty;
}
});
});
});
$scope.$watch('search_prod_list', function (newValue) {
if (newValue.length > 0)
{
$scope.filterProduct = $rootScope.productToFilter;
}
else
{
$scope.search_prod_list = '';
$scope.currentPage = 1;
$scope.paginatorfunction();
}
});
/* Páginador */
$scope.numPages = function () {
return Math.ceil($scope.data.products.length / $scope.numPerPage);
};
$scope.pageChanged = function (currentPage) {
$scope.currentPage = currentPage;
};
$scope.trustedHtml = function (plainText) {
return $sce.trustAsHtml(plainText);
}
$scope.paginatorfunction = function ()
{
if ($scope.search_prod_list.length == 0)
{
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filterProduct = $scope.data.products.slice(begin, end);
}
}
$scope.$watch('currentPage', function () {
$scope.paginatorfunction();
});
$scope.prevent_default_paginate = function (paginate) {
if (paginate.length > 0) {
angular.element(document).ready(function () {
$('.pagination > ul > li a').unbind().click(function (e) {
// $(this).removeAttr('href');
// var page = $(this).data('ci-pagination-page');
// e.stopPropagation();
});
});
return true;
} else {
return false;
}
}
});
categories.resent_products(function (data) {
$scope.resent_products = data;
});
categories.featured_products(function (data) {
$scope.featured_products = data;
});
$scope.clickQuickView = function (product) {
FactoryWishList.quickView(product);
}
$scope.clickWishList = function (id_product) {
$rootScope.current_product_wish_list_id = id_product;
}
$scope.insertInWishList = function (wishlist) {
FactoryWishList.insertInWishList(wishlist);
}
$scope.deleteInWishList = function (wishlist) {
FactoryWishList.deleteInWishList(wishlist);
}
$scope.insertInCart = function (ecommerceCart) {
console.log('asdas');
var cart = new EcommerceCart();
cart.id = ecommerceCart.id;
cart.qty = ecommerceCart.qty;
cart.$save(function (response) {
$rootScope.cart_content = response.cart_content;
});
}
$scope.changeCartPos = function (cart_data) {
if (cart_data.qty == undefined)
{
cart_data.qty = 0;
}
cart_data.qty = cart_data.qty + 1;
$scope.insertInCart(cart_data);
}
$scope.changeCartNeg = function (cart_data) {
if (cart_data.qty == undefined)
{
cart_data.qty = 0;
}
cart_data.qty = cart_data.qty - 1;
$scope.insertInCart(cart_data);
}
$scope.dislikeProduct = function (product_data) {
if (is_user_logged)
{
var product_like = new LikeProduct();
product_like.id_product = product_data.id;
product_like.$delete(function (response) {
product_data.product_likes.userlikes = response.userlikes;
product_data.product_likes.count = response.count;
});
}
else
{
console.log('Debes estar logeado para dar dislike');
}
}
$scope.likeProduct = function (product_data) {
if (is_user_logged)
{
var product_like = new LikeProduct();
product_like.id_product = product_data.id;
product_like.$save(function (response) {
product_data.product_likes.userlikes = response.userlikes;
product_data.product_likes.count = response.count;
});
}
else
{
console.log('Debes estar logeado para dar like');
}
}
$scope.filterColorFunct = function (color) {
$scope.filterColor = color;
}
$scope.DeletefilterColorFunct = function () {
$scope.filterColor = null;
};
});
categoriesApp.controller('CategoryFilterListPaginationCtrl', function ($rootScope, $scope, $routeParams, $window, $sce, categories, FactoryWishList, EcommerceCart, LikeProduct) {
$scope.is_loading = true;
$scope.site_url = site_url;
$scope.coin_code = coin_code;
$scope.coin_currency = coin_currency;
$scope.filterColor = null;
$rootScope.productToFilter = [];
$scope.filterProduct = [];
$scope.currentPage = 1;
$scope.numPerPage = 30;
$scope.maxSize = 5;
$scope.width2 = $window.innerWidth;
if ($scope.width2 <= 641) {
$scope.numPerPage = 30;
}
var page = 1;
if (angular.isUndefined($routeParams.pagination)) {
page = 1;
} else {
page = $routeParams.pagination;
}
categories.filter_list_paginate($routeParams.categoryId, page, $scope.numPerPage, function (data) {
$scope.data = data;
$scope.pagination = $scope.data.pagination;
$rootScope.productToFilter = $scope.data.products;
$scope.is_loading = false;
$scope.sortField = 'title';
$scope.reverse = false;
$scope.is_user_logged = is_user_logged;
$scope.search_prod_list = '';
$scope.$watch('cart_content', function (newValue, oldValue) {
angular.forEach($scope.data.products, function (entry) {
entry.qty = 1;
angular.forEach(newValue.data, function (entry2) {
if (entry.id === entry2.id)
{
entry.qty = entry2.qty;
}
});
});
});
$scope.$watch('search_prod_list', function (newValue) {
if (newValue.length > 0)
{
$scope.filterProduct = $rootScope.productToFilter;
}
else
{
$scope.search_prod_list = '';
$scope.currentPage = 1;
$scope.paginatorfunction();
}
});
/* Páginador */
$scope.numPages = function () {
return Math.ceil($scope.data.products.length / $scope.numPerPage);
};
$scope.pageChanged = function (currentPage) {
$scope.currentPage = currentPage;
};
$scope.trustedHtml = function (plainText) {
return $sce.trustAsHtml(plainText);
}
$scope.paginatorfunction = function ()
{
if ($scope.search_prod_list.length == 0)
{
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filterProduct = $scope.data.products.slice(begin, end);
}
}
$scope.$watch('currentPage', function () {
$scope.paginatorfunction();
});
$scope.prevent_default_paginate = function (paginate) {
if (paginate.length > 0) {
angular.element(document).ready(function () {
var url_actual = window.location.href;
var category = url_actual.split('#')[1];
var current_page = category.split('/')[2];
if (current_page != '' || current_page != null) {
$('.a-pagination-w').each(function (key, element) {
if ($(element).data('ci-pagination-page') == current_page) {
$(element).parent().addClass('active');
$(element).attr('disabled');
}
});
}
});
return true;
} else {
return false;
}
}
});
categories.resent_products(function (data) {
$scope.resent_products = data;
});
categories.featured_products(function (data) {
$scope.featured_products = data;
});
$scope.clickQuickView = function (product) {
FactoryWishList.quickView(product);
}
$scope.clickWishList = function (id_product) {
$rootScope.current_product_wish_list_id = id_product;
}
$scope.insertInWishList = function (wishlist) {
FactoryWishList.insertInWishList(wishlist);
}
$scope.deleteInWishList = function (wishlist) {
FactoryWishList.deleteInWishList(wishlist);
}
$scope.insertInCart = function (ecommerceCart) {
console.log('asdas');
var cart = new EcommerceCart();
cart.id = ecommerceCart.id;
cart.qty = ecommerceCart.qty;
cart.$save(function (response) {
$rootScope.cart_content = response.cart_content;
});
}