Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versão com design responsivo #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var app = angular.module('store', []);

app.run(function($rootScope) {
$rootScope.cart = [];
});
130 changes: 130 additions & 0 deletions app/store/store.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
app.controller('storeCtrl', function($scope, $http) {

$http.get("filtros.json")
.then(function(response) {
$scope.checkboxlist = response.data;
});

$http.get("produtos.json")
.then(function(response) {
$scope.produtos = response.data.produtos;
});

$scope.addThis = function(produto) {
$scope.cart.push(produto);
};

$scope.limite = 9;
$scope.loadMore = function() {
var incremento = $scope.limite + 9;
if(incremento > $scope.produtos.length) {
$scope.limite = $scope.produtos.length;
} else {
$scope.limite = incremento;
}
};

$scope.limiteCores = 5;
$scope.showAllCores = function() {
var incremento = $scope.limiteCores + 9;
if(incremento > $scope.checkboxlist.cores.length) {
$scope.limiteCores = $scope.checkboxlist.cores.length;
} else {
$scope.limiteCores = incremento;
}
};

$scope.toggleFilters = "hidden-xs";
$scope.showFilters = function() {
$scope.toggleFilters = "visible-xs";
};
$scope.hideFilters = function() {
$scope.toggleFilters = "hidden-xs";
};

$scope.toggleSelOrder = "hidden-xs";
$scope.showSelOrder = function() {
$scope.toggleSelOrder = "visible-xs";
};
$scope.hideSelOrder = function() {
$scope.toggleSelOrder = "hidden-xs";
};
});

app.filter('preco', function() {
return function(items, precos) {
if(precos != null || precos != undefined) {
var filtered = [];
var checkedFlag = false;
angular.forEach(items, function(item) {
for(var i=0; i<precos.length; i++) {
if(precos[i].checked) {
checkedFlag = true;
var precoItem = parseInt(item.preco);
var precoMin = parseInt(precos[i].min);
var precoMax = parseInt(precos[i].max);
if(precoItem >= precoMin && precoItem < precoMax + 1) {
filtered.push(item);
break;
}
}
}
});

if(checkedFlag) {
return filtered;
}
}
return items;
};
});

app.filter('cor', function() {
return function(items, cores) {
if(cores != null || cores != undefined) {
var filtered = [];
var checkedFlag = false;
angular.forEach(items, function(item) {
for(var i=0; i<cores.length; i++) {
if(cores[i].checked) {
checkedFlag = true;
var cor = cores[i].nome.toLowerCase();
if(item.cores.indexOf(cor) !== -1) {
filtered.push(item);
break;
}
}
}
});

if(checkedFlag) {
return filtered;
}
}
return items;
};
});

app.filter('tamanho', function() {
return function(items, tamanhos) {
if(tamanhos != null || tamanhos != undefined) {
var filtered = [];
var checkedFlag = false;
angular.forEach(items, function(item) {
for(var i=0; i<tamanhos.length; i++) {
if(tamanhos[i].checked) {
checkedFlag = true;
if(item.tamanhos.indexOf(tamanhos[i].nome) !== -1) {
filtered.push(item);
break;
}
}
}
});
if(checkedFlag) {
return filtered;
}
}
return items;
};
});
Loading