From 427d64e0d04f6fdb24f4ce22ecfbcb9981cacb3e Mon Sep 17 00:00:00 2001 From: Leonardo Merlin Date: Fri, 11 Sep 2015 09:04:06 -0300 Subject: [PATCH] Sync --- src/app/components/proposal-box/proposal-box.directive.js | 17 ++++++++++++++--- src/app/components/proposal-box/proposal-box.html | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- src/app/components/proposal-box/proposal-box.scss | 38 +++++++++++++++++--------------------- src/app/components/util-service/utils.service.js | 2 +- src/app/index.constants.js | 6 +++--- src/app/index.route.js | 2 +- src/app/pages/auth/auth.controller.js | 3 ++- src/app/pages/auth/signin.html | 3 +-- src/app/pages/inicio/inicio.html | 2 +- src/app/pages/programas/programa.controller.js | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- src/app/pages/programas/programa.html | 58 ++++++++++++++++++++++++++++++++++++++++++++-------------- 11 files changed, 302 insertions(+), 131 deletions(-) diff --git a/src/app/components/proposal-box/proposal-box.directive.js b/src/app/components/proposal-box/proposal-box.directive.js index 5553a47..369e80a 100644 --- a/src/app/components/proposal-box/proposal-box.directive.js +++ b/src/app/components/proposal-box/proposal-box.directive.js @@ -32,6 +32,8 @@ vm.focus = vm.focus || false; vm.STATE = null; vm.errorOnSkip = false; + vm.showAuthMessage = null; + vm.voteProposalRedirectURI = null; }; ProposalBoxController.prototype.addListeners = function () { @@ -43,9 +45,10 @@ } if(data.error){ - vm.errorOnSkip = true; + vm.errorOnSkip = data.error; } }); + vm.$scope.$on('proposal-box:vote-response', function(event, data){ vm.$log.debug('proposal-box:vote-response'); vm.$log.debug('event', event); @@ -57,10 +60,18 @@ if(data.error) { vm.STATE = vm.VOTE_STATUS.ERROR; - } + vm.message = data.message; }); + + vm.$scope.$watch('vm.voteProposalRedirectURI', function(newValue, oldValue){ + if(newValue && newValue !== oldValue){ + var slug = vm.topic.slug; + var proposal_id = vm.proposal.id; + vm.voteProposalRedirectURI = 'state=programa&task=vote-proposal&slug=' + slug + '&proposal_id=' + proposal_id; + } + }); }; ProposalBoxController.prototype.showContent = function (slug) { @@ -85,7 +96,7 @@ vm.$log.debug('Sending vote', value); }else{ vm.$log.info('Must be logged in...'); - + vm.showAuthMessage = true; } }; diff --git a/src/app/components/proposal-box/proposal-box.html b/src/app/components/proposal-box/proposal-box.html index 1cd98c3..b23cea6 100644 --- a/src/app/components/proposal-box/proposal-box.html +++ b/src/app/components/proposal-box/proposal-box.html @@ -1,16 +1,71 @@
-
- FEEDBACK -
-
-
-
-
-
- Carregando... + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+

{{vm.message}}

+
+
+
+
+
+
-
- Erro ao carregar nova proposta. +
+
+
+
+
+
+
+
+
+

Você precisa estar logado para votar na proposta

+
+

+ + Clique aqui para ir para a página de login +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Carregando...

+
+
+

Erro ao carregar nova proposta proposta.

+

{{vm.errorOnSkip}}

+
+
+
+
+
@@ -20,43 +75,43 @@
-
{{vm.proposal.abstract}}
-
-
- -
-
-
-
-
-
- +
{{vm.proposal.abstract}}
+
+
+ +
+
+
+
+
+
+ +
+
Apoio
-
Apoio
-
-
-
-
- - Colocação nos resultados: - {{vm.proposal.ranking_position}}º -
-
+
+ + Colocação nos resultados: + {{vm.proposal.ranking_position}}º +
+
diff --git a/src/app/components/proposal-box/proposal-box.scss b/src/app/components/proposal-box/proposal-box.scss index 3423b54..435d2ec 100644 --- a/src/app/components/proposal-box/proposal-box.scss +++ b/src/app/components/proposal-box/proposal-box.scss @@ -72,29 +72,25 @@ } } - .proposal-loading { - - .text { - position: absolute; - color: #fff; + .proposal-message-panel { + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; + z-index: 1000; + background-color: #f5f5f5; + background-color: rgba(245, 245, 245, 0.9); + + .row { height: 100%; } + .inside { position: relative; } + + .content { + color: #262626; font-size: 24px; + font-weight: bold; line-height: 24px; - z-index: 1000; - width: 100% - top: 50%; - left: 0; - margin-top: -12px; - } - - .shadow { - content: ""; - position: absolute; - z-index: 999; - width: 100%; - height: 100%; - top: 0; - left: 0; - background-color: rgba(0,0,0,.4); + padding: 10px 30px; } } diff --git a/src/app/components/util-service/utils.service.js b/src/app/components/util-service/utils.service.js index 381925d..b82bf29 100644 --- a/src/app/components/util-service/utils.service.js +++ b/src/app/components/util-service/utils.service.js @@ -72,7 +72,7 @@ } // Otherwise, use expected error message. - return $q.reject(error.data.message); + return $q.reject(error.data); } } })(); diff --git a/src/app/index.constants.js b/src/app/index.constants.js index 583fb31..1fe328e 100644 --- a/src/app/index.constants.js +++ b/src/app/index.constants.js @@ -38,9 +38,9 @@ LOADING: 0x100 }) .constant('VOTE_OPTIONS', { - UP: 0x1, - DOWN: 0x10, - SKIP: 0x100 + UP: 1, + DOWN: -1, + SKIP: 0 }) .constant('USER_ROLES', { all: '*', diff --git a/src/app/index.route.js b/src/app/index.route.js index e3a5c71..7d90455 100644 --- a/src/app/index.route.js +++ b/src/app/index.route.js @@ -23,7 +23,7 @@ } }) .state('entrar', { - url: '/entrar?redirect_uri', + url: '/entrar?redirect_uri&message', ncyBreadcrumb: {label: 'Entrar'}, views: { 'header': { templateUrl: 'app/pages/header/header.html' }, diff --git a/src/app/pages/auth/auth.controller.js b/src/app/pages/auth/auth.controller.js index 8149bb1..b85a5fe 100644 --- a/src/app/pages/auth/auth.controller.js +++ b/src/app/pages/auth/auth.controller.js @@ -159,7 +159,8 @@ case 'programa': vm.$state.go(state, { slug: vm.params.slug, - task: vm.params.task + task: vm.params.task, + proposal_id: vm.params.proposal_id, }); break; default: diff --git a/src/app/pages/auth/signin.html b/src/app/pages/auth/signin.html index 88a94f3..6d3c06c 100644 --- a/src/app/pages/auth/signin.html +++ b/src/app/pages/auth/signin.html @@ -152,9 +152,8 @@
diff --git a/src/app/pages/inicio/inicio.html b/src/app/pages/inicio/inicio.html index 2085b33..a86d3f9 100644 --- a/src/app/pages/inicio/inicio.html +++ b/src/app/pages/inicio/inicio.html @@ -135,7 +135,7 @@

Programas

diff --git a/src/app/pages/programas/programa.controller.js b/src/app/pages/programas/programa.controller.js index 517922c..4a34db0 100644 --- a/src/app/pages/programas/programa.controller.js +++ b/src/app/pages/programas/programa.controller.js @@ -6,13 +6,14 @@ .controller('ProgramaPageController', ProgramaPageController); /** @ngInject */ - function ProgramaPageController(DialogaService, PATH, $state, $location, $scope, $rootScope, $element, $timeout, $log) { + function ProgramaPageController(DialogaService, PATH, VOTE_OPTIONS, $state, $location, $scope, $rootScope, $element, $timeout, $log) { $log.debug('ProgramaPageController'); var vm = this; vm.DialogaService = DialogaService; vm.PATH = PATH; + vm.VOTE_OPTIONS = VOTE_OPTIONS; vm.$state = $state; vm.$location = $location; vm.$scope = $scope; @@ -31,7 +32,11 @@ vm.article = null; vm.category = null; + vm.loading = null; + vm.loadingTopProposals = null; + vm.loadingProposalBox = null; vm.sendProposalRedirectURI = null; + // vm.voteProposalRedirectURI = null; vm.search = vm.$location.search(); vm.error = false; @@ -45,7 +50,7 @@ // Get program by slug var slug = vm.$state.params.slug; - if(!slug){ + if (!slug) { vm.$log.error('slug not defined.'); vm.$log.info('Rollback to home page.'); vm.$state.go('inicio', {}, {location: true}); @@ -55,6 +60,7 @@ vm.article = article; vm.category = vm.article.categories[0]; vm.sendProposalRedirectURI = 'state=programa&task=send-proposal&slug=' + slug; + // vm.voteProposalRedirectURI = 'state=programa&task=vote-proposal&slug=' + slug; // update the breadcrumb vm.$rootScope.contentTitle = vm.article.title; @@ -67,43 +73,23 @@ }; } - vm.DialogaService.getProposalsByTopicId(vm.article.id, {}, function(data){ + vm.loadingTopProposals = true; + vm.DialogaService.getProposalsByTopicId(vm.article.id, {}, function(data) { vm.proposals = data.articles; vm.proposalsTopRated = vm.proposals.slice(0, 3); - }, function (error) { + vm.loadingTopProposals = false; + }, function(error) { vm.$log.error(error); + vm.loadingTopProposals = false; }); - if(vm.search.proposal_id){ - var proposalUrlId = vm.search.proposal_id; - vm.DialogaService.getProposalById(proposalUrlId, { - 'limit': '1' - }, _handleSuccessGetProposal, _handleErrorGetProposal); - - }else{ - // get random proposal - vm.DialogaService.getProposalsByTopicId(vm.article.id, { - 'order': 'random()', - 'limit': '1' - }, _handleSuccessGetProposal, _handleErrorGetProposal); - } - - function _handleSuccessGetProposal(data){ - if(data && data.articles){ - vm.randomProposal = data.articles[0]; - } - // scroll to focused proposal - if(vm.search.proposal_id){ - vm.$timeout(function(){ - var target = angular.element('.focused-proposal'); - angular.element('body').animate({scrollTop: target.offset().top}, 'fast'); - }, 300); - } - } - - function _handleErrorGetProposal(error){ - vm.$log.error(error); + vm.loadingProposalBox = true; + if (vm.search.proposal_id) { + vm.loadProposalById(vm.search.proposal_id); + }else { + // random proposal + vm.loadRandomProposal(); } vm.loading = false; @@ -111,9 +97,6 @@ vm.$log.error(error); vm.error = error; vm.loading = false; - - // vm.$log.info('Rollback to home page.'); - // vm.$state.go('inicio', {}, {location: true}); }); }; @@ -125,21 +108,117 @@ }); vm.$scope.$on('cadastro-proposa:startSendProposal', function(event, proposal) { - // vm.$log.debug('proposal', proposal); vm.creatingProposal = true; - vm.DialogaService.createProposal(proposal, vm.article.id, function (response){ + vm.DialogaService.createProposal(proposal, vm.article.id, function(response) { vm.$log.debug('response', response); vm.creatingProposal = false; - }, function (error) { + }, function(error) { vm.$log.error(error); vm.creatingProposal = false; }); }); vm.$scope.$on('proposal-box:vote', function(event, params) { + // vm.$log.debug('event', event); + // vm.$log.debug('params', params); + var proposal_id = params.proposal_id; + var OPTION = params.OPTION; + + switch (OPTION){ + case vm.VOTE_OPTIONS.UP: + case vm.VOTE_OPTIONS.DOWN: + case vm.VOTE_OPTIONS.SKIP: + vm.vote(proposal_id, OPTION); + break; + default: + vm.$log.error('Vote option not handled:', OPTION); + break; + } + }); + }; + + ProgramaPageController.prototype.loadProposalById = function(proposal_id) { + var vm = this; + + vm.DialogaService.getProposalById(proposal_id, { + 'limit': '1' + }, vm._handleSuccessOnGetProposal.bind(vm), vm._handleErrorOnGetProposal.bind(vm)); + }; + + ProgramaPageController.prototype.loadRandomProposal = function() { + var vm = this; + + vm.DialogaService.getProposalsByTopicId(vm.article.id, { + 'order': 'random()', + 'limit': '1' + }, vm._handleSuccessOnGetProposal.bind(vm), vm._handleErrorOnGetProposal.bind(vm)); + }; + + ProgramaPageController.prototype._handleSuccessOnGetProposal = function(data) { + var vm = this; + + if (data && data.articles) { + var MAX = data.articles.length; + vm.randomProposal = data.articles[Math.floor(Math.random() * MAX)]; + vm.loadingProposalBox = false; + vm.$scope.$broadcast('proposal-box:proposal-loaded', { success: true}); + } + + // scroll to focused proposal + if (vm.search.proposal_id) { + vm.$timeout(function() { + var target = angular.element('.focused-proposal'); + if (target && target.length > 0) { + angular.element('body').animate({scrollTop: target.offset().top}, 'fast'); + } + }, 300); + } + }; + + ProgramaPageController.prototype._handleErrorOnGetProposal = function(error) { + var vm = this; + vm.$log.error(error); + vm.$scope.$broadcast('proposal-box:proposal-loaded', { error: true}); + }; + + ProgramaPageController.prototype.voteSkip = function() { + var vm = this; + vm.loadRandomProposal(); + }; + + ProgramaPageController.prototype.vote = function(proposal_id, value) { + var vm = this; + + if (value === vm.VOTE_OPTIONS.SKIP) { + vm.voteSkip(); + return; + } + + if (!vm.$rootScope.currentUser) { + // vm.$state.go('entrar', { + // redirect_uri: vm.sendProposalRedirectURI, + // message: 'Você precisa estar logado para votar em uma proposta.' + // }, { + // location: true + // }); + return; + } + + vm.DialogaService.voteProposal(proposal_id, { + value: value + }, function(response) { + vm.$log.debug('response', response); + + response.success = true; + vm.$scope.$broadcast('proposal-box:vote-response', response); + }, function(error) { + vm.$log.error('error', error); + error.error = true; + vm.$scope.$broadcast('proposal-box:vote-response', error); }); }; + ProgramaPageController.prototype.voteHasBeenComputed = function() {}; ProgramaPageController.prototype.showProposalsList = function() { var vm = this; diff --git a/src/app/pages/programas/programa.html b/src/app/pages/programas/programa.html index 4cac0df..2de8a82 100644 --- a/src/app/pages/programas/programa.html +++ b/src/app/pages/programas/programa.html @@ -23,9 +23,11 @@
+

{{::pagePrograma.article.title}}

+
@@ -55,24 +57,52 @@
+
-
-

Propostas mais votadas

- -
-
-

Propostas nesse programa

- + + +
+ +
+ +
+ + +
+

Propostas mais votadas

+ +
-
-

Programas sem propostas

-

- Este programa ainda não possui nenhuma proposta. -

- + + +
+
+

Propostas nesse programa

+ +
+ + +
+ -

+
+
+ + +
+
+

Programas sem propostas

+

+ Este programa ainda não possui nenhuma proposta. +

+ +
+

+
-- libgit2 0.21.2